Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit7fcfe98

Browse files
authored
fix: improve API version mismatch error and show after login (#206)
1 parentf492f2d commit7fcfe98

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

‎coder-sdk/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
// APIVersion parses the coder-version http header from an authenticated request.
99
func (cClient)APIVersion(ctx context.Context) (string,error) {
1010
constcoderVersionHeaderKey="coder-version"
11-
resp,err:=c.request(ctx,http.MethodGet,"/api/private/users/"+Me,nil)
11+
resp,err:=c.request(ctx,http.MethodGet,"/api",nil)
1212
iferr!=nil {
1313
return"",err
1414
}

‎internal/cmd/auth.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func newClient(ctx context.Context) (*coder.Client, error) {
5353
}
5454

5555
apiVersion,err:=c.APIVersion(ctx)
56+
ifapiVersion!=""&&!version.VersionsMatch(apiVersion) {
57+
logVersionMismatchError(apiVersion)
58+
}
5659
iferr!=nil {
5760
varhe*coder.HTTPError
5861
ifxerrors.As(err,&he) {
@@ -63,14 +66,14 @@ func newClient(ctx context.Context) (*coder.Client, error) {
6366
returnnil,err
6467
}
6568

66-
if!version.VersionsMatch(apiVersion) {
67-
clog.LogWarn(
68-
"version mismatch detected",
69-
fmt.Sprintf("coder-cli version: %s",version.Version),
70-
fmt.Sprintf("Coder API version: %s",apiVersion),clog.BlankLine,
71-
clog.Tipf("download the appropriate version here: https://github.com/cdr/coder-cli/releases"),
72-
)
73-
}
74-
7569
returnc,nil
7670
}
71+
72+
funclogVersionMismatchError(apiVersionstring) {
73+
clog.LogWarn(
74+
"version mismatch detected",
75+
fmt.Sprintf("Coder CLI version: %s",version.Version),
76+
fmt.Sprintf("Coder API version: %s",apiVersion),clog.BlankLine,
77+
clog.Tipf("download the appropriate version here: https://github.com/cdr/coder-cli/releases"),
78+
)
79+
}

‎internal/cmd/login.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"cdr.dev/coder-cli/coder-sdk"
1212
"cdr.dev/coder-cli/internal/config"
1313
"cdr.dev/coder-cli/internal/loginsrv"
14+
"cdr.dev/coder-cli/internal/version"
1415
"cdr.dev/coder-cli/pkg/clog"
1516
"github.com/pkg/browser"
1617
"github.com/spf13/cobra"
@@ -64,7 +65,13 @@ func newLocalListener() (net.Listener, error) {
6465
// Not using the SDK as we want to verify the url/token pair before storing the config files.
6566
funcpingAPI(ctx context.Context,envURL*url.URL,tokenstring)error {
6667
client:=&coder.Client{BaseURL:envURL,Token:token}
67-
if_,err:=client.Me(ctx);err!=nil {
68+
ifapiVersion,err:=client.APIVersion(ctx);err==nil {
69+
ifapiVersion!=""&&!version.VersionsMatch(apiVersion) {
70+
logVersionMismatchError(apiVersion)
71+
}
72+
}
73+
_,err:=client.Me(ctx)
74+
iferr!=nil {
6875
returnxerrors.Errorf("call api: %w",err)
6976
}
7077
returnnil

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp