Skip to content

Commit 6c104b6

Browse files
Merge pull request #432 from gabriel-samfira/use-friendly-names
Allow usage of friendly names in most commands
2 parents 7c2086b + 808af82 commit 6c104b6

6 files changed

Lines changed: 284 additions & 18 deletions

File tree

cmd/garm-cli/cmd/enterprise.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,14 @@ var enterpriseShowCmd = &cobra.Command{
112112
if len(args) > 1 {
113113
return fmt.Errorf("too many arguments")
114114
}
115+
116+
enterpriseID, err := resolveEnterprise(args[0], enterpriseEndpoint)
117+
if err != nil {
118+
return err
119+
}
120+
115121
showEnterpriseReq := apiClientEnterprises.NewGetEnterpriseParams()
116-
showEnterpriseReq.EnterpriseID = args[0]
122+
showEnterpriseReq.EnterpriseID = enterpriseID
117123
response, err := apiCli.Enterprises.GetEnterprise(showEnterpriseReq, authToken)
118124
if err != nil {
119125
return err
@@ -139,8 +145,14 @@ var enterpriseDeleteCmd = &cobra.Command{
139145
if len(args) > 1 {
140146
return fmt.Errorf("too many arguments")
141147
}
148+
149+
enterpriseID, err := resolveEnterprise(args[0], enterpriseEndpoint)
150+
if err != nil {
151+
return err
152+
}
153+
142154
deleteEnterpriseReq := apiClientEnterprises.NewDeleteEnterpriseParams()
143-
deleteEnterpriseReq.EnterpriseID = args[0]
155+
deleteEnterpriseReq.EnterpriseID = enterpriseID
144156
if err := apiCli.Enterprises.DeleteEnterprise(deleteEnterpriseReq, authToken); err != nil {
145157
return err
146158
}
@@ -165,13 +177,18 @@ var enterpriseUpdateCmd = &cobra.Command{
165177
if len(args) > 1 {
166178
return fmt.Errorf("too many arguments")
167179
}
180+
enterpriseID, err := resolveEnterprise(args[0], enterpriseEndpoint)
181+
if err != nil {
182+
return err
183+
}
184+
168185
updateEnterpriseReq := apiClientEnterprises.NewUpdateEnterpriseParams()
169186
updateEnterpriseReq.Body = params.UpdateEntityParams{
170187
WebhookSecret: repoWebhookSecret,
171188
CredentialsName: repoCreds,
172189
PoolBalancerType: params.PoolBalancerType(poolBalancerType),
173190
}
174-
updateEnterpriseReq.EnterpriseID = args[0]
191+
updateEnterpriseReq.EnterpriseID = enterpriseID
175192
response, err := apiCli.Enterprises.UpdateEnterprise(updateEnterpriseReq, authToken)
176193
if err != nil {
177194
return err
@@ -196,6 +213,10 @@ func init() {
196213
enterpriseUpdateCmd.Flags().StringVar(&enterpriseWebhookSecret, "webhook-secret", "", "The webhook secret for this enterprise")
197214
enterpriseUpdateCmd.Flags().StringVar(&enterpriseCreds, "credentials", "", "Credentials name. See credentials list.")
198215
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.")
199220

200221
enterpriseCmd.AddCommand(
201222
enterpriseListCmd,

cmd/garm-cli/cmd/organization.go

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

79+
orgID, err := resolveOrganization(args[0], orgEndpoint)
80+
if err != nil {
81+
return err
82+
}
83+
7984
installWebhookReq := apiClientOrgs.NewInstallOrgWebhookParams()
80-
installWebhookReq.OrgID = args[0]
85+
installWebhookReq.OrgID = orgID
8186
installWebhookReq.Body.InsecureSSL = insecureOrgWebhook
8287
installWebhookReq.Body.WebhookEndpointType = params.WebhookEndpointDirect
8388

@@ -105,9 +110,12 @@ var orgHookInfoShowCmd = &cobra.Command{
105110
if len(args) > 1 {
106111
return fmt.Errorf("too many arguments")
107112
}
108-
113+
orgID, err := resolveOrganization(args[0], orgEndpoint)
114+
if err != nil {
115+
return err
116+
}
109117
showWebhookInfoReq := apiClientOrgs.NewGetOrgWebhookInfoParams()
110-
showWebhookInfoReq.OrgID = args[0]
118+
showWebhookInfoReq.OrgID = orgID
111119

112120
response, err := apiCli.Organizations.GetOrgWebhookInfo(showWebhookInfoReq, authToken)
113121
if err != nil {
@@ -134,10 +142,15 @@ var orgWebhookUninstallCmd = &cobra.Command{
134142
return fmt.Errorf("too many arguments")
135143
}
136144

145+
orgID, err := resolveOrganization(args[0], orgEndpoint)
146+
if err != nil {
147+
return err
148+
}
149+
137150
uninstallWebhookReq := apiClientOrgs.NewUninstallOrgWebhookParams()
138-
uninstallWebhookReq.OrgID = args[0]
151+
uninstallWebhookReq.OrgID = orgID
139152

140-
err := apiCli.Organizations.UninstallOrgWebhook(uninstallWebhookReq, authToken)
153+
err = apiCli.Organizations.UninstallOrgWebhook(uninstallWebhookReq, authToken)
141154
if err != nil {
142155
return err
143156
}
@@ -216,13 +229,19 @@ var orgUpdateCmd = &cobra.Command{
216229
if len(args) > 1 {
217230
return fmt.Errorf("too many arguments")
218231
}
232+
233+
orgID, err := resolveOrganization(args[0], orgEndpoint)
234+
if err != nil {
235+
return err
236+
}
237+
219238
updateOrgReq := apiClientOrgs.NewUpdateOrgParams()
220239
updateOrgReq.Body = params.UpdateEntityParams{
221240
WebhookSecret: orgWebhookSecret,
222241
CredentialsName: orgCreds,
223242
PoolBalancerType: params.PoolBalancerType(poolBalancerType),
224243
}
225-
updateOrgReq.OrgID = args[0]
244+
updateOrgReq.OrgID = orgID
226245
response, err := apiCli.Organizations.UpdateOrg(updateOrgReq, authToken)
227246
if err != nil {
228247
return err
@@ -270,8 +289,14 @@ var orgShowCmd = &cobra.Command{
270289
if len(args) > 1 {
271290
return fmt.Errorf("too many arguments")
272291
}
292+
293+
orgID, err := resolveOrganization(args[0], orgEndpoint)
294+
if err != nil {
295+
return err
296+
}
297+
273298
showOrgReq := apiClientOrgs.NewGetOrgParams()
274-
showOrgReq.OrgID = args[0]
299+
showOrgReq.OrgID = orgID
275300
response, err := apiCli.Organizations.GetOrg(showOrgReq, authToken)
276301
if err != nil {
277302
return err
@@ -297,8 +322,14 @@ var orgDeleteCmd = &cobra.Command{
297322
if len(args) > 1 {
298323
return fmt.Errorf("too many arguments")
299324
}
325+
326+
orgID, err := resolveOrganization(args[0], orgEndpoint)
327+
if err != nil {
328+
return err
329+
}
330+
300331
deleteOrgReq := apiClientOrgs.NewDeleteOrgParams()
301-
deleteOrgReq.OrgID = args[0]
332+
deleteOrgReq.OrgID = orgID
302333
deleteOrgReq.KeepWebhook = &keepOrgWebhook
303334
if err := apiCli.Organizations.DeleteOrg(deleteOrgReq, authToken); err != nil {
304335
return err
@@ -326,12 +357,22 @@ func init() {
326357
orgAddCmd.MarkFlagRequired("name") //nolint
327358

328359
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.")
329363

330364
orgUpdateCmd.Flags().StringVar(&orgWebhookSecret, "webhook-secret", "", "The webhook secret for this organization")
331365
orgUpdateCmd.Flags().StringVar(&orgCreds, "credentials", "", "Credentials name. See credentials list.")
332366
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.")
333368

334369
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+
335376
orgWebhookCmd.AddCommand(
336377
orgWebhookInstallCmd,
337378
orgWebhookUninstallCmd,

cmd/garm-cli/cmd/pool.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,26 @@ Example:
105105
switch len(args) {
106106
case 0:
107107
if cmd.Flags().Changed("repo") {
108+
poolRepository, err = resolveRepository(poolRepository, endpointName)
109+
if err != nil {
110+
return err
111+
}
108112
listRepoPoolsReq := apiClientRepos.NewListRepoPoolsParams()
109113
listRepoPoolsReq.RepoID = poolRepository
110114
response, err = apiCli.Repositories.ListRepoPools(listRepoPoolsReq, authToken)
111115
} else if cmd.Flags().Changed("org") {
116+
poolOrganization, err = resolveOrganization(poolOrganization, endpointName)
117+
if err != nil {
118+
return err
119+
}
112120
listOrgPoolsReq := apiClientOrgs.NewListOrgPoolsParams()
113121
listOrgPoolsReq.OrgID = poolOrganization
114122
response, err = apiCli.Organizations.ListOrgPools(listOrgPoolsReq, authToken)
115123
} else if cmd.Flags().Changed("enterprise") {
124+
poolEnterprise, err = resolveEnterprise(poolEnterprise, endpointName)
125+
if err != nil {
126+
return err
127+
}
116128
listEnterprisePoolsReq := apiClientEnterprises.NewListEnterprisePoolsParams()
117129
listEnterprisePoolsReq.EnterpriseID = poolEnterprise
118130
response, err = apiCli.Enterprises.ListEnterprisePools(listEnterprisePoolsReq, authToken)
@@ -250,16 +262,28 @@ var poolAddCmd = &cobra.Command{
250262
var err error
251263
var response poolPayloadGetter
252264
if cmd.Flags().Changed("repo") {
265+
poolRepository, err = resolveRepository(poolRepository, endpointName)
266+
if err != nil {
267+
return err
268+
}
253269
newRepoPoolReq := apiClientRepos.NewCreateRepoPoolParams()
254270
newRepoPoolReq.RepoID = poolRepository
255271
newRepoPoolReq.Body = newPoolParams
256272
response, err = apiCli.Repositories.CreateRepoPool(newRepoPoolReq, authToken)
257273
} else if cmd.Flags().Changed("org") {
274+
poolOrganization, err = resolveOrganization(poolOrganization, endpointName)
275+
if err != nil {
276+
return err
277+
}
258278
newOrgPoolReq := apiClientOrgs.NewCreateOrgPoolParams()
259279
newOrgPoolReq.OrgID = poolOrganization
260280
newOrgPoolReq.Body = newPoolParams
261281
response, err = apiCli.Organizations.CreateOrgPool(newOrgPoolReq, authToken)
262282
} else if cmd.Flags().Changed("enterprise") {
283+
poolEnterprise, err = resolveEnterprise(poolEnterprise, endpointName)
284+
if err != nil {
285+
return err
286+
}
263287
newEnterprisePoolReq := apiClientEnterprises.NewCreateEnterprisePoolParams()
264288
newEnterprisePoolReq.EnterpriseID = poolEnterprise
265289
newEnterprisePoolReq.Body = newPoolParams
@@ -387,6 +411,8 @@ func init() {
387411
poolListCmd.Flags().StringVarP(&poolEnterprise, "enterprise", "e", "", "List all pools within this enterprise.")
388412
poolListCmd.Flags().BoolVarP(&poolAll, "all", "a", false, "List all pools, regardless of org or repo.")
389413
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+
390416
poolListCmd.MarkFlagsMutuallyExclusive("repo", "org", "all", "enterprise")
391417

392418
poolUpdateCmd.Flags().StringVar(&poolImage, "image", "", "The provider-specific image name to use for runners in this pool.")
@@ -420,6 +446,8 @@ func init() {
420446
poolAddCmd.Flags().UintVar(&poolRunnerBootstrapTimeout, "runner-bootstrap-timeout", 20, "Duration in minutes after which a runner is considered failed if it does not join Github.")
421447
poolAddCmd.Flags().UintVar(&poolMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
422448
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+
423451
poolAddCmd.MarkFlagRequired("provider-name") //nolint
424452
poolAddCmd.MarkFlagRequired("image") //nolint
425453
poolAddCmd.MarkFlagRequired("flavor") //nolint

cmd/garm-cli/cmd/repository.go

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

81+
repoID, err := resolveRepository(args[0], repoEndpoint)
82+
if err != nil {
83+
return err
84+
}
85+
8186
installWebhookReq := apiClientRepos.NewInstallRepoWebhookParams()
82-
installWebhookReq.RepoID = args[0]
87+
installWebhookReq.RepoID = repoID
8388
installWebhookReq.Body.InsecureSSL = insecureRepoWebhook
8489
installWebhookReq.Body.WebhookEndpointType = params.WebhookEndpointDirect
8590

@@ -108,8 +113,13 @@ var repoHookInfoShowCmd = &cobra.Command{
108113
return fmt.Errorf("too many arguments")
109114
}
110115

116+
repoID, err := resolveRepository(args[0], repoEndpoint)
117+
if err != nil {
118+
return err
119+
}
120+
111121
showWebhookInfoReq := apiClientRepos.NewGetRepoWebhookInfoParams()
112-
showWebhookInfoReq.RepoID = args[0]
122+
showWebhookInfoReq.RepoID = repoID
113123

114124
response, err := apiCli.Repositories.GetRepoWebhookInfo(showWebhookInfoReq, authToken)
115125
if err != nil {
@@ -136,10 +146,15 @@ var repoWebhookUninstallCmd = &cobra.Command{
136146
return fmt.Errorf("too many arguments")
137147
}
138148

149+
repoID, err := resolveRepository(args[0], repoEndpoint)
150+
if err != nil {
151+
return err
152+
}
153+
139154
uninstallWebhookReq := apiClientRepos.NewUninstallRepoWebhookParams()
140-
uninstallWebhookReq.RepoID = args[0]
155+
uninstallWebhookReq.RepoID = repoID
141156

142-
err := apiCli.Repositories.UninstallRepoWebhook(uninstallWebhookReq, authToken)
157+
err = apiCli.Repositories.UninstallRepoWebhook(uninstallWebhookReq, authToken)
143158
if err != nil {
144159
return err
145160
}
@@ -243,13 +258,19 @@ var repoUpdateCmd = &cobra.Command{
243258
if len(args) > 1 {
244259
return fmt.Errorf("too many arguments")
245260
}
261+
262+
repoID, err := resolveRepository(args[0], repoEndpoint)
263+
if err != nil {
264+
return err
265+
}
266+
246267
updateReposReq := apiClientRepos.NewUpdateRepoParams()
247268
updateReposReq.Body = params.UpdateEntityParams{
248269
WebhookSecret: repoWebhookSecret,
249270
CredentialsName: repoCreds,
250271
PoolBalancerType: params.PoolBalancerType(poolBalancerType),
251272
}
252-
updateReposReq.RepoID = args[0]
273+
updateReposReq.RepoID = repoID
253274

254275
response, err := apiCli.Repositories.UpdateRepo(updateReposReq, authToken)
255276
if err != nil {
@@ -275,8 +296,14 @@ var repoShowCmd = &cobra.Command{
275296
if len(args) > 1 {
276297
return fmt.Errorf("too many arguments")
277298
}
299+
300+
repoID, err := resolveRepository(args[0], repoEndpoint)
301+
if err != nil {
302+
return err
303+
}
304+
278305
showRepoReq := apiClientRepos.NewGetRepoParams()
279-
showRepoReq.RepoID = args[0]
306+
showRepoReq.RepoID = repoID
280307
response, err := apiCli.Repositories.GetRepo(showRepoReq, authToken)
281308
if err != nil {
282309
return err
@@ -302,8 +329,14 @@ var repoDeleteCmd = &cobra.Command{
302329
if len(args) > 1 {
303330
return fmt.Errorf("too many arguments")
304331
}
332+
333+
repoID, err := resolveRepository(args[0], repoEndpoint)
334+
if err != nil {
335+
return err
336+
}
337+
305338
deleteRepoReq := apiClientRepos.NewDeleteRepoParams()
306-
deleteRepoReq.RepoID = args[0]
339+
deleteRepoReq.RepoID = repoID
307340
deleteRepoReq.KeepWebhook = &keepRepoWebhook
308341
if err := apiCli.Repositories.DeleteRepo(deleteRepoReq, authToken); err != nil {
309342
return err
@@ -334,12 +367,21 @@ func init() {
334367
repoAddCmd.MarkFlagRequired("name") //nolint
335368

336369
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.")
337373

338374
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.")
339375
repoUpdateCmd.Flags().StringVar(&repoCreds, "credentials", "", "Credentials name. See credentials list.")
340376
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.")
341378

342379
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.")
343385

344386
repoWebhookCmd.AddCommand(
345387
repoWebhookInstallCmd,

0 commit comments

Comments
 (0)