Skip to content

Commit f08be0e

Browse files
Add endpoint option to all relevant commands
In case of ambiguity when using the name of a repo, org or enterprise, an --endpoint flag can be used to uniquely identify an entity against an endpoint. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
1 parent e92b2c1 commit f08be0e

6 files changed

Lines changed: 73 additions & 36 deletions

File tree

cmd/garm-cli/cmd/enterprise.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ var enterpriseShowCmd = &cobra.Command{
113113
return fmt.Errorf("too many arguments")
114114
}
115115

116-
enterpriseID, err := resolveEnterprise(args[0])
116+
enterpriseID, err := resolveEnterprise(args[0], enterpriseEndpoint)
117117
if err != nil {
118118
return err
119119
}
@@ -146,7 +146,7 @@ var enterpriseDeleteCmd = &cobra.Command{
146146
return fmt.Errorf("too many arguments")
147147
}
148148

149-
enterpriseID, err := resolveEnterprise(args[0])
149+
enterpriseID, err := resolveEnterprise(args[0], enterpriseEndpoint)
150150
if err != nil {
151151
return err
152152
}
@@ -177,7 +177,7 @@ var enterpriseUpdateCmd = &cobra.Command{
177177
if len(args) > 1 {
178178
return fmt.Errorf("too many arguments")
179179
}
180-
enterpriseID, err := resolveEnterprise(args[0])
180+
enterpriseID, err := resolveEnterprise(args[0], enterpriseEndpoint)
181181
if err != nil {
182182
return err
183183
}
@@ -213,6 +213,10 @@ func init() {
213213
enterpriseUpdateCmd.Flags().StringVar(&enterpriseWebhookSecret, "webhook-secret", "", "The webhook secret for this enterprise")
214214
enterpriseUpdateCmd.Flags().StringVar(&enterpriseCreds, "credentials", "", "Credentials name. See credentials list.")
215215
enterpriseUpdateCmd.Flags().StringVar(&poolBalancerType, "pool-balancer-type", "", "The balancing strategy to use when creating runners in pools matching requested labels.")
216+
enterpriseUpdateCmd.Flags().StringVar(&enterpriseEndpoint, "endpoint", "", "When using the name of the enterprise, the endpoint must be specified when multiple enterprises with the same name exist.")
217+
218+
enterpriseDeleteCmd.Flags().StringVar(&enterpriseEndpoint, "endpoint", "", "When using the name of the enterprise, the endpoint must be specified when multiple enterprises with the same name exist.")
219+
enterpriseShowCmd.Flags().StringVar(&enterpriseEndpoint, "endpoint", "", "When using the name of the enterprise, the endpoint must be specified when multiple enterprises with the same name exist.")
216220

217221
enterpriseCmd.AddCommand(
218222
enterpriseListCmd,

cmd/garm-cli/cmd/organization.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var orgWebhookInstallCmd = &cobra.Command{
7676
return fmt.Errorf("too many arguments")
7777
}
7878

79-
orgID, err := resolveOrganization(args[0])
79+
orgID, err := resolveOrganization(args[0], orgEndpoint)
8080
if err != nil {
8181
return err
8282
}
@@ -110,7 +110,7 @@ var orgHookInfoShowCmd = &cobra.Command{
110110
if len(args) > 1 {
111111
return fmt.Errorf("too many arguments")
112112
}
113-
orgID, err := resolveOrganization(args[0])
113+
orgID, err := resolveOrganization(args[0], orgEndpoint)
114114
if err != nil {
115115
return err
116116
}
@@ -142,7 +142,7 @@ var orgWebhookUninstallCmd = &cobra.Command{
142142
return fmt.Errorf("too many arguments")
143143
}
144144

145-
orgID, err := resolveOrganization(args[0])
145+
orgID, err := resolveOrganization(args[0], orgEndpoint)
146146
if err != nil {
147147
return err
148148
}
@@ -230,7 +230,7 @@ var orgUpdateCmd = &cobra.Command{
230230
return fmt.Errorf("too many arguments")
231231
}
232232

233-
orgID, err := resolveOrganization(args[0])
233+
orgID, err := resolveOrganization(args[0], orgEndpoint)
234234
if err != nil {
235235
return err
236236
}
@@ -290,7 +290,7 @@ var orgShowCmd = &cobra.Command{
290290
return fmt.Errorf("too many arguments")
291291
}
292292

293-
orgID, err := resolveOrganization(args[0])
293+
orgID, err := resolveOrganization(args[0], orgEndpoint)
294294
if err != nil {
295295
return err
296296
}
@@ -323,7 +323,7 @@ var orgDeleteCmd = &cobra.Command{
323323
return fmt.Errorf("too many arguments")
324324
}
325325

326-
orgID, err := resolveOrganization(args[0])
326+
orgID, err := resolveOrganization(args[0], orgEndpoint)
327327
if err != nil {
328328
return err
329329
}
@@ -351,18 +351,28 @@ func init() {
351351

352352
orgListCmd.Flags().BoolVarP(&long, "long", "l", false, "Include additional info.")
353353
orgListCmd.Flags().StringVarP(&orgName, "name", "n", "", "Exact org name to filter by.")
354-
orgListCmd.Flags().StringVarP(&orgEndpoint, "endpoint", "e", "", "Exact endpoint name to filter by.")
354+
orgListCmd.Flags().StringVar(&orgEndpoint, "endpoint", "", "Exact endpoint name to filter by.")
355355

356356
orgAddCmd.MarkFlagRequired("credentials") //nolint
357357
orgAddCmd.MarkFlagRequired("name") //nolint
358358

359359
orgDeleteCmd.Flags().BoolVar(&keepOrgWebhook, "keep-webhook", false, "Do not delete any existing webhook when removing the organization from GARM.")
360+
orgDeleteCmd.Flags().StringVar(&orgEndpoint, "endpoint", "", "When using the name of the org, the endpoint must be specified when multiple organizations with the same name exist.")
361+
362+
orgShowCmd.Flags().StringVar(&orgEndpoint, "endpoint", "", "When using the name of the org, the endpoint must be specified when multiple organizations with the same name exist.")
360363

361364
orgUpdateCmd.Flags().StringVar(&orgWebhookSecret, "webhook-secret", "", "The webhook secret for this organization")
362365
orgUpdateCmd.Flags().StringVar(&orgCreds, "credentials", "", "Credentials name. See credentials list.")
363366
orgUpdateCmd.Flags().StringVar(&poolBalancerType, "pool-balancer-type", "", "The balancing strategy to use when creating runners in pools matching requested labels.")
367+
orgUpdateCmd.Flags().StringVar(&orgEndpoint, "endpoint", "", "When using the name of the org, the endpoint must be specified when multiple organizations with the same name exist.")
364368

365369
orgWebhookInstallCmd.Flags().BoolVar(&insecureOrgWebhook, "insecure", false, "Ignore self signed certificate errors.")
370+
orgWebhookInstallCmd.Flags().StringVar(&orgEndpoint, "endpoint", "", "When using the name of the org, the endpoint must be specified when multiple organizations with the same name exist.")
371+
372+
orgWebhookUninstallCmd.Flags().StringVar(&orgEndpoint, "endpoint", "", "When using the name of the org, the endpoint must be specified when multiple organizations with the same name exist.")
373+
374+
orgHookInfoShowCmd.Flags().StringVar(&orgEndpoint, "endpoint", "", "When using the name of the org, the endpoint must be specified when multiple organizations with the same name exist.")
375+
366376
orgWebhookCmd.AddCommand(
367377
orgWebhookInstallCmd,
368378
orgWebhookUninstallCmd,

cmd/garm-cli/cmd/pool.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,23 @@ Example:
105105
switch len(args) {
106106
case 0:
107107
if cmd.Flags().Changed("repo") {
108-
poolRepository, err = resolveRepository(poolRepository)
108+
poolRepository, err = resolveRepository(poolRepository, endpointName)
109109
if err != nil {
110110
return err
111111
}
112112
listRepoPoolsReq := apiClientRepos.NewListRepoPoolsParams()
113113
listRepoPoolsReq.RepoID = poolRepository
114114
response, err = apiCli.Repositories.ListRepoPools(listRepoPoolsReq, authToken)
115115
} else if cmd.Flags().Changed("org") {
116-
poolOrganization, err = resolveOrganization(poolOrganization)
116+
poolOrganization, err = resolveOrganization(poolOrganization, endpointName)
117117
if err != nil {
118118
return err
119119
}
120120
listOrgPoolsReq := apiClientOrgs.NewListOrgPoolsParams()
121121
listOrgPoolsReq.OrgID = poolOrganization
122122
response, err = apiCli.Organizations.ListOrgPools(listOrgPoolsReq, authToken)
123123
} else if cmd.Flags().Changed("enterprise") {
124-
poolEnterprise, err = resolveEnterprise(poolEnterprise)
124+
poolEnterprise, err = resolveEnterprise(poolEnterprise, endpointName)
125125
if err != nil {
126126
return err
127127
}
@@ -262,7 +262,7 @@ var poolAddCmd = &cobra.Command{
262262
var err error
263263
var response poolPayloadGetter
264264
if cmd.Flags().Changed("repo") {
265-
poolRepository, err = resolveRepository(poolRepository)
265+
poolRepository, err = resolveRepository(poolRepository, endpointName)
266266
if err != nil {
267267
return err
268268
}
@@ -271,7 +271,7 @@ var poolAddCmd = &cobra.Command{
271271
newRepoPoolReq.Body = newPoolParams
272272
response, err = apiCli.Repositories.CreateRepoPool(newRepoPoolReq, authToken)
273273
} else if cmd.Flags().Changed("org") {
274-
poolOrganization, err = resolveOrganization(poolOrganization)
274+
poolOrganization, err = resolveOrganization(poolOrganization, endpointName)
275275
if err != nil {
276276
return err
277277
}
@@ -280,7 +280,7 @@ var poolAddCmd = &cobra.Command{
280280
newOrgPoolReq.Body = newPoolParams
281281
response, err = apiCli.Organizations.CreateOrgPool(newOrgPoolReq, authToken)
282282
} else if cmd.Flags().Changed("enterprise") {
283-
poolEnterprise, err = resolveEnterprise(poolEnterprise)
283+
poolEnterprise, err = resolveEnterprise(poolEnterprise, endpointName)
284284
if err != nil {
285285
return err
286286
}
@@ -411,6 +411,8 @@ func init() {
411411
poolListCmd.Flags().StringVarP(&poolEnterprise, "enterprise", "e", "", "List all pools within this enterprise.")
412412
poolListCmd.Flags().BoolVarP(&poolAll, "all", "a", false, "List all pools, regardless of org or repo.")
413413
poolListCmd.Flags().BoolVarP(&long, "long", "l", false, "Include additional info.")
414+
poolListCmd.Flags().StringVar(&endpointName, "endpoint", "", "When using the name of an entity, the endpoint must be specified when multiple entities with the same name exist.")
415+
414416
poolListCmd.MarkFlagsMutuallyExclusive("repo", "org", "all", "enterprise")
415417

416418
poolUpdateCmd.Flags().StringVar(&poolImage, "image", "", "The provider-specific image name to use for runners in this pool.")
@@ -444,6 +446,8 @@ func init() {
444446
poolAddCmd.Flags().UintVar(&poolRunnerBootstrapTimeout, "runner-bootstrap-timeout", 20, "Duration in minutes after which a runner is considered failed if it does not join Github.")
445447
poolAddCmd.Flags().UintVar(&poolMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
446448
poolAddCmd.Flags().BoolVar(&poolEnabled, "enabled", false, "Enable this pool.")
449+
poolAddCmd.Flags().StringVar(&endpointName, "endpoint", "", "When using the name of an entity, the endpoint must be specified when multiple entities with the same name exist.")
450+
447451
poolAddCmd.MarkFlagRequired("provider-name") //nolint
448452
poolAddCmd.MarkFlagRequired("image") //nolint
449453
poolAddCmd.MarkFlagRequired("flavor") //nolint

cmd/garm-cli/cmd/repository.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var repoWebhookInstallCmd = &cobra.Command{
7878
return fmt.Errorf("too many arguments")
7979
}
8080

81-
repoID, err := resolveRepository(args[0])
81+
repoID, err := resolveRepository(args[0], repoEndpoint)
8282
if err != nil {
8383
return err
8484
}
@@ -113,7 +113,7 @@ var repoHookInfoShowCmd = &cobra.Command{
113113
return fmt.Errorf("too many arguments")
114114
}
115115

116-
repoID, err := resolveRepository(args[0])
116+
repoID, err := resolveRepository(args[0], repoEndpoint)
117117
if err != nil {
118118
return err
119119
}
@@ -146,7 +146,7 @@ var repoWebhookUninstallCmd = &cobra.Command{
146146
return fmt.Errorf("too many arguments")
147147
}
148148

149-
repoID, err := resolveRepository(args[0])
149+
repoID, err := resolveRepository(args[0], repoEndpoint)
150150
if err != nil {
151151
return err
152152
}
@@ -259,7 +259,7 @@ var repoUpdateCmd = &cobra.Command{
259259
return fmt.Errorf("too many arguments")
260260
}
261261

262-
repoID, err := resolveRepository(args[0])
262+
repoID, err := resolveRepository(args[0], repoEndpoint)
263263
if err != nil {
264264
return err
265265
}
@@ -297,7 +297,7 @@ var repoShowCmd = &cobra.Command{
297297
return fmt.Errorf("too many arguments")
298298
}
299299

300-
repoID, err := resolveRepository(args[0])
300+
repoID, err := resolveRepository(args[0], repoEndpoint)
301301
if err != nil {
302302
return err
303303
}
@@ -330,7 +330,7 @@ var repoDeleteCmd = &cobra.Command{
330330
return fmt.Errorf("too many arguments")
331331
}
332332

333-
repoID, err := resolveRepository(args[0])
333+
repoID, err := resolveRepository(args[0], repoEndpoint)
334334
if err != nil {
335335
return err
336336
}
@@ -360,19 +360,28 @@ func init() {
360360
repoListCmd.Flags().BoolVarP(&long, "long", "l", false, "Include additional info.")
361361
repoListCmd.Flags().StringVarP(&repoName, "name", "n", "", "Exact repo name to filter by.")
362362
repoListCmd.Flags().StringVarP(&repoOwner, "owner", "o", "", "Exact repo owner to filter by.")
363-
repoListCmd.Flags().StringVarP(&repoEndpoint, "endpoint", "e", "", "Exact endpoint name to filter by.")
363+
repoListCmd.Flags().StringVar(&repoEndpoint, "endpoint", "", "Exact endpoint name to filter by.")
364364

365365
repoAddCmd.MarkFlagRequired("credentials") //nolint
366366
repoAddCmd.MarkFlagRequired("owner") //nolint
367367
repoAddCmd.MarkFlagRequired("name") //nolint
368368

369369
repoDeleteCmd.Flags().BoolVar(&keepRepoWebhook, "keep-webhook", false, "Do not delete any existing webhook when removing the repo from GARM.")
370+
repoDeleteCmd.Flags().StringVar(&repoEndpoint, "endpoint", "", "When using the name of the repo, the endpoint must be specified when multiple repositories with the same name exist.")
371+
372+
repoShowCmd.Flags().StringVar(&repoEndpoint, "endpoint", "", "When using the name of the repo, the endpoint must be specified when multiple repositories with the same name exist.")
370373

371374
repoUpdateCmd.Flags().StringVar(&repoWebhookSecret, "webhook-secret", "", "The webhook secret for this repository. If you update this secret, you will have to manually update the secret in GitHub as well.")
372375
repoUpdateCmd.Flags().StringVar(&repoCreds, "credentials", "", "Credentials name. See credentials list.")
373376
repoUpdateCmd.Flags().StringVar(&poolBalancerType, "pool-balancer-type", "", "The balancing strategy to use when creating runners in pools matching requested labels.")
377+
repoUpdateCmd.Flags().StringVar(&repoEndpoint, "endpoint", "", "When using the name of the repo, the endpoint must be specified when multiple repositories with the same name exist.")
374378

375379
repoWebhookInstallCmd.Flags().BoolVar(&insecureRepoWebhook, "insecure", false, "Ignore self signed certificate errors.")
380+
repoWebhookInstallCmd.Flags().StringVar(&repoEndpoint, "endpoint", "", "When using the name of the repo, the endpoint must be specified when multiple repositories with the same name exist.")
381+
382+
repoWebhookUninstallCmd.Flags().StringVar(&repoEndpoint, "endpoint", "", "When using the name of the repo, the endpoint must be specified when multiple repositories with the same name exist.")
383+
384+
repoHookInfoShowCmd.Flags().StringVar(&repoEndpoint, "endpoint", "", "When using the name of the repo, the endpoint must be specified when multiple repositories with the same name exist.")
376385

377386
repoWebhookCmd.AddCommand(
378387
repoWebhookInstallCmd,

cmd/garm-cli/cmd/scalesets.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,23 @@ Example:
105105
switch len(args) {
106106
case 0:
107107
if cmd.Flags().Changed("repo") {
108-
scalesetRepository, err = resolveRepository(scalesetRepository)
108+
scalesetRepository, err = resolveRepository(scalesetRepository, endpointName)
109109
if err != nil {
110110
return err
111111
}
112112
listRepoScaleSetsReq := apiClientRepos.NewListRepoScaleSetsParams()
113113
listRepoScaleSetsReq.RepoID = scalesetRepository
114114
response, err = apiCli.Repositories.ListRepoScaleSets(listRepoScaleSetsReq, authToken)
115115
} else if cmd.Flags().Changed("org") {
116-
scalesetOrganization, err = resolveOrganization(scalesetOrganization)
116+
scalesetOrganization, err = resolveOrganization(scalesetOrganization, endpointName)
117117
if err != nil {
118118
return err
119119
}
120120
listOrgScaleSetsReq := apiClientOrgs.NewListOrgScaleSetsParams()
121121
listOrgScaleSetsReq.OrgID = scalesetOrganization
122122
response, err = apiCli.Organizations.ListOrgScaleSets(listOrgScaleSetsReq, authToken)
123123
} else if cmd.Flags().Changed("enterprise") {
124-
scalesetEnterprise, err = resolveEnterprise(scalesetEnterprise)
124+
scalesetEnterprise, err = resolveEnterprise(scalesetEnterprise, endpointName)
125125
if err != nil {
126126
return err
127127
}
@@ -256,7 +256,7 @@ var scaleSetAddCmd = &cobra.Command{
256256
var err error
257257
var response scalesetPayloadGetter
258258
if cmd.Flags().Changed("repo") {
259-
scalesetRepository, err = resolveRepository(scalesetRepository)
259+
scalesetRepository, err = resolveRepository(scalesetRepository, endpointName)
260260
if err != nil {
261261
return err
262262
}
@@ -265,7 +265,7 @@ var scaleSetAddCmd = &cobra.Command{
265265
newRepoScaleSetReq.Body = newScaleSetParams
266266
response, err = apiCli.Repositories.CreateRepoScaleSet(newRepoScaleSetReq, authToken)
267267
} else if cmd.Flags().Changed("org") {
268-
scalesetOrganization, err = resolveOrganization(scalesetOrganization)
268+
scalesetOrganization, err = resolveOrganization(scalesetOrganization, endpointName)
269269
if err != nil {
270270
return err
271271
}
@@ -274,7 +274,7 @@ var scaleSetAddCmd = &cobra.Command{
274274
newOrgScaleSetReq.Body = newScaleSetParams
275275
response, err = apiCli.Organizations.CreateOrgScaleSet(newOrgScaleSetReq, authToken)
276276
} else if cmd.Flags().Changed("enterprise") {
277-
scalesetEnterprise, err = resolveEnterprise(scalesetEnterprise)
277+
scalesetEnterprise, err = resolveEnterprise(scalesetEnterprise, endpointName)
278278
if err != nil {
279279
return err
280280
}
@@ -402,6 +402,7 @@ func init() {
402402
scalesetListCmd.Flags().StringVarP(&scalesetEnterprise, "enterprise", "e", "", "List all scale sets within this enterprise.")
403403
scalesetListCmd.Flags().BoolVarP(&scalesetAll, "all", "a", false, "List all scale sets, regardless of org or repo.")
404404
scalesetListCmd.MarkFlagsMutuallyExclusive("repo", "org", "all", "enterprise")
405+
scalesetListCmd.Flags().StringVar(&endpointName, "endpoint", "", "When using the name of an entity, the endpoint must be specified when multiple entities with the same name exist.")
405406

406407
scaleSetUpdateCmd.Flags().StringVar(&scalesetImage, "image", "", "The provider-specific image name to use for runners in this scale set.")
407408
scaleSetUpdateCmd.Flags().StringVar(&scalesetFlavor, "flavor", "", "The flavor to use for the runners in this scale set.")
@@ -432,6 +433,7 @@ func init() {
432433
scaleSetAddCmd.Flags().UintVar(&scalesetRunnerBootstrapTimeout, "runner-bootstrap-timeout", 20, "Duration in minutes after which a runner is considered failed if it does not join Github.")
433434
scaleSetAddCmd.Flags().UintVar(&scalesetMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
434435
scaleSetAddCmd.Flags().BoolVar(&scalesetEnabled, "enabled", false, "Enable this scale set.")
436+
scaleSetAddCmd.Flags().StringVar(&endpointName, "endpoint", "", "When using the name of an entity, the endpoint must be specified when multiple entities with the same name exist.")
435437
scaleSetAddCmd.MarkFlagRequired("provider-name") //nolint
436438
scaleSetAddCmd.MarkFlagRequired("name") //nolint
437439
scaleSetAddCmd.MarkFlagRequired("image") //nolint

0 commit comments

Comments
 (0)