Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nil pointer dereference #165

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions cmd/garm-cli/cmd/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ var (
poolGitHubRunnerGroup string
)

type poolPayloadGetter interface {
GetPayload() params.Pools
}

// runnerCmd represents the runner command
var poolCmd = &cobra.Command{
Use: "pool",
Expand Down Expand Up @@ -95,34 +99,26 @@ Example:
return errNeedsInitError
}

var pools []params.Pool
var response poolPayloadGetter
var err error

switch len(args) {
case 0:
if cmd.Flags().Changed("repo") {
var response *apiClientRepos.ListRepoPoolsOK
listRepoPoolsReq := apiClientRepos.NewListRepoPoolsParams()
listRepoPoolsReq.RepoID = poolRepository
response, err = apiCli.Repositories.ListRepoPools(listRepoPoolsReq, authToken)
pools = response.Payload
} else if cmd.Flags().Changed("org") {
var response *apiClientOrgs.ListOrgPoolsOK
listOrgPoolsReq := apiClientOrgs.NewListOrgPoolsParams()
listOrgPoolsReq.OrgID = poolOrganization
response, err = apiCli.Organizations.ListOrgPools(listOrgPoolsReq, authToken)
pools = response.Payload
} else if cmd.Flags().Changed("enterprise") {
var response *apiClientEnterprises.ListEnterprisePoolsOK
listEnterprisePoolsReq := apiClientEnterprises.NewListEnterprisePoolsParams()
listEnterprisePoolsReq.EnterpriseID = poolEnterprise
response, err = apiCli.Enterprises.ListEnterprisePools(listEnterprisePoolsReq, authToken)
pools = response.Payload
} else if cmd.Flags().Changed("all") {
var response *apiClientPools.ListPoolsOK
listPoolsReq := apiClientPools.NewListPoolsParams()
response, err = apiCli.Pools.ListPools(listPoolsReq, authToken)
pools = response.Payload
} else {
cmd.Help() //nolint
os.Exit(0)
Expand All @@ -135,7 +131,7 @@ Example:
if err != nil {
return err
}
formatPools(pools)
formatPools(response.GetPayload())
return nil
},
}
Expand Down
18 changes: 7 additions & 11 deletions cmd/garm-cli/cmd/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ list all instances.`,
Run: nil,
}

type instancesPayloadGetter interface {
GetPayload() params.Instances
}

var runnerListCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Expand Down Expand Up @@ -80,7 +84,7 @@ Example:
return errNeedsInitError
}

var instances []params.Instance
var response instancesPayloadGetter
var err error

switch len(args) {
Expand All @@ -92,35 +96,25 @@ Example:

return fmt.Errorf("specifying a pool ID and any of [all org repo enterprise] are mutually exclusive")
}
var response *apiClientInstances.ListPoolInstancesOK
listPoolInstancesReq := apiClientInstances.NewListPoolInstancesParams()
listPoolInstancesReq.PoolID = args[0]
response, err = apiCli.Instances.ListPoolInstances(listPoolInstancesReq, authToken)
instances = response.Payload
case 0:
if cmd.Flags().Changed("repo") {
var response *apiClientRepos.ListRepoInstancesOK
listRepoInstancesReq := apiClientRepos.NewListRepoInstancesParams()
listRepoInstancesReq.RepoID = runnerRepository
response, err = apiCli.Repositories.ListRepoInstances(listRepoInstancesReq, authToken)
instances = response.Payload
} else if cmd.Flags().Changed("org") {
var response *apiClientOrgs.ListOrgInstancesOK
listOrgInstancesReq := apiClientOrgs.NewListOrgInstancesParams()
listOrgInstancesReq.OrgID = runnerOrganization
response, err = apiCli.Organizations.ListOrgInstances(listOrgInstancesReq, authToken)
instances = response.Payload
} else if cmd.Flags().Changed("enterprise") {
var response *apiClientEnterprises.ListEnterpriseInstancesOK
listEnterpriseInstancesReq := apiClientEnterprises.NewListEnterpriseInstancesParams()
listEnterpriseInstancesReq.EnterpriseID = runnerEnterprise
response, err = apiCli.Enterprises.ListEnterpriseInstances(listEnterpriseInstancesReq, authToken)
instances = response.Payload
} else if cmd.Flags().Changed("all") {
var response *apiClientInstances.ListInstancesOK
listInstancesReq := apiClientInstances.NewListInstancesParams()
response, err = apiCli.Instances.ListInstances(listInstancesReq, authToken)
instances = response.Payload
} else {
cmd.Help() //nolint
os.Exit(0)
Expand All @@ -133,6 +127,8 @@ Example:
if err != nil {
return err
}

instances := response.GetPayload()
formatInstances(instances)
return nil
},
Expand Down