Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 985b877

Browse files
author
Faris Huskovic
committed
suggested changes
1 parent 89f848f commit 985b877

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

internal/cmd/ceapi.go

+20-8
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ func findImg(ctx context.Context, client *coder.Client, email, imgName, orgName
9191
return nil, xerrors.New("image name unset")
9292
}
9393

94-
imgs, err := getImgs(ctx, client, email, orgName)
94+
imgs, err := getImgs(ctx,
95+
getImgsConf{
96+
client: client,
97+
email: email,
98+
orgName: orgName,
99+
},
100+
)
95101
if err != nil {
96102
return nil, err
97103
}
@@ -127,36 +133,42 @@ func findImg(ctx context.Context, client *coder.Client, email, imgName, orgName
127133
)
128134
}
129135

130-
func getImgs(ctx context.Context, client *coder.Client, email, orgName string) ([]coder.Image, error) {
131-
u, err := client.UserByEmail(ctx, email)
136+
type getImgsConf struct {
137+
client *coder.Client
138+
email string
139+
orgName string
140+
}
141+
142+
func getImgs(ctx context.Context, conf getImgsConf) ([]coder.Image, error) {
143+
u, err := conf.client.UserByEmail(ctx, conf.email)
132144
if err != nil {
133145
return nil, err
134146
}
135147

136-
orgs, err := client.Organizations(ctx)
148+
orgs, err := conf.client.Organizations(ctx)
137149
if err != nil {
138150
return nil, err
139151
}
140152

141153
orgs = lookupUserOrgs(u, orgs)
142154

143155
for _, org := range orgs {
144-
imgs, err := client.GetOrganizationImages(ctx, org.ID)
156+
imgs, err := conf.client.GetOrganizationImages(ctx, org.ID)
145157
if err != nil {
146158
return nil, err
147159
}
148160
// If orgName is set we know the user is a multi-org member
149161
// so we should only return the imported images that beong to the org they specified.
150-
if orgName != "" && orgName == org.Name {
162+
if conf.orgName != "" && conf.orgName == org.Name {
151163
return imgs, nil
152164
}
153165

154-
if orgName == "" {
166+
if conf.orgName == "" {
155167
// if orgName is unset we know the user is only part of one org.
156168
return imgs, nil
157169
}
158170
}
159-
return nil, xerrors.Errorf("org name %q not found", orgName)
171+
return nil, xerrors.Errorf("org name %q not found", conf.orgName)
160172
}
161173

162174
func isMultiOrgMember(ctx context.Context, email string) (*bool, error) {

0 commit comments

Comments
 (0)