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

Commit89f848f

Browse files
author
Faris Huskovic
committed
context adjustments
1 parentbc7bcb8 commit89f848f

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

‎internal/clog/error.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ func LogSuccess(header string, lines ...string) {
6868
}.String())
6969
}
7070

71+
// LogWarn prints the given warn message to stderr.
72+
funcLogWarn(headerstring,lines...string) {
73+
fmt.Fprint(os.Stderr,CLIMessage{
74+
Level:"warning",
75+
Color:color.FgYellow,
76+
Header:header,
77+
Lines:lines,
78+
}.String())
79+
}
80+
7181
// Warn creates an error with the level "warning".
7282
funcWarn(headerstring,lines...string)CLIError {
7383
returnCLIError{

‎internal/cmd/ceapi.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,25 @@ func getImgs(ctx context.Context, client *coder.Client, email, orgName string) (
141141
orgs=lookupUserOrgs(u,orgs)
142142

143143
for_,org:=rangeorgs {
144-
iforgName==org.Name {
145-
imgs,err:=client.GetOrganizationImages(ctx,org.ID)
146-
iferr!=nil {
147-
returnnil,err
148-
}
144+
imgs,err:=client.GetOrganizationImages(ctx,org.ID)
145+
iferr!=nil {
146+
returnnil,err
147+
}
148+
// If orgName is set we know the user is a multi-org member
149+
// so we should only return the imported images that beong to the org they specified.
150+
iforgName!=""&&orgName==org.Name {
151+
returnimgs,nil
152+
}
153+
154+
iforgName=="" {
155+
// if orgName is unset we know the user is only part of one org.
149156
returnimgs,nil
150157
}
151158
}
152159
returnnil,xerrors.Errorf("org name %q not found",orgName)
153160
}
154161

155-
funcisMultiOrgMember(emailstring) (*bool,error) {
156-
ctx,cancel:=context.WithCancel(context.Background())
157-
defercancel()
158-
162+
funcisMultiOrgMember(ctx context.Context,emailstring) (*bool,error) {
159163
client,err:=newClient()
160164
iferr!=nil {
161165
returnnil,err

‎internal/cmd/envs.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ import (
1717
"golang.org/x/xerrors"
1818
)
1919

20-
const (
21-
defaultOrg="default"
22-
defaultImgTag="latest"
23-
)
20+
constdefaultImgTag="latest"
2421

2522
funcenvsCommand()*cobra.Command {
2623
varuserstring
@@ -170,7 +167,7 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
170167
returnxerrors.New("image unset")
171168
}
172169

173-
multiOrgMember,err:=isMultiOrgMember(*user)
170+
multiOrgMember,err:=isMultiOrgMember(cmd.Context(),*user)
174171
iferr!=nil {
175172
returnerr
176173
}
@@ -214,7 +211,7 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
214211
createReq.DiskGB=importedImg.DefaultDiskGB
215212
}
216213

217-
env,err:=client.CreateEnvironment(cmd.Context(),org,*createReq)
214+
env,err:=client.CreateEnvironment(cmd.Context(),importedImg.OrganizationID,*createReq)
218215
iferr!=nil {
219216
returnxerrors.Errorf("create environment: %w",err)
220217
}
@@ -234,7 +231,7 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
234231
returnnil
235232
},
236233
}
237-
cmd.Flags().StringVarP(&org,"org","o",defaultOrg,"ID of the organization the environment should be created under.")
234+
cmd.Flags().StringVarP(&org,"org","o","","ID of the organization the environment should be created under.")
238235
cmd.Flags().StringVarP(&tag,"tag","t",defaultImgTag,"tag of the image the environment will be based off of.")
239236
cmd.Flags().Float32P("cpu","c",0,"number of cpu cores the environment should be provisioned with.")
240237
cmd.Flags().Float32P("memory","m",0,"GB of RAM an environment should be provisioned with.")
@@ -280,7 +277,7 @@ coder envs edit back-end-env --disk 20`,
280277
returnerr
281278
}
282279

283-
multiOrgMember,err:=isMultiOrgMember(*user)
280+
multiOrgMember,err:=isMultiOrgMember(cmd.Context(),*user)
284281
iferr!=nil {
285282
returnerr
286283
}
@@ -332,7 +329,7 @@ coder envs edit back-end-env --disk 20`,
332329
returnnil
333330
},
334331
}
335-
cmd.Flags().StringVarP(&org,"org","o",defaultOrg,"name of the organization the environment should be created under.")
332+
cmd.Flags().StringVarP(&org,"org","o","","name of the organization the environment should be created under.")
336333
cmd.Flags().StringVarP(&img,"image","i","","name of the image you wan't the environment to be based off of.")
337334
cmd.Flags().StringVarP(&tag,"tag","t","latest","image tag of the image you wan't to base the environment off of.")
338335
cmd.Flags().Float32P("cpu","c",cpuCores,"The number of cpu cores the environment should be provisioned with.")
@@ -484,6 +481,9 @@ func buildUpdateReq(ctx context.Context, conf updateConf) (*coder.UpdateEnvironm
484481
// if the user accidentally requests it or if the default diskGB value for a
485482
// newly requested image is smaller than the current amount the environment is using.
486483
if*updateReq.DiskGB<conf.environment.DiskGB {
484+
clog.LogWarn("disk can not be shrunk",
485+
fmt.Sprintf("keeping environment disk at %d GB",conf.environment.DiskGB),
486+
)
487487
updateReq.DiskGB=&conf.environment.DiskGB
488488
}
489489

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp