Skip to content

Commit

Permalink
refactor: remove pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
avirtopeanu-ionos committed Jan 28, 2025
1 parent f0ec7dd commit c1acb15
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 55 deletions.
2 changes: 1 addition & 1 deletion commands/container-registry/registry/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func CmdDelete(c *core.CommandConfig) error {
return err
}

for _, reg := range *regs.Items {
for _, reg := range regs.Items {
msg := fmt.Sprintf("delete Container Registry: %s", *reg.Id)

if !confirm.FAsk(c.Command.Command.InOrStdin(), msg, viper.GetBool(constants.ArgForce)) {
Expand Down
2 changes: 1 addition & 1 deletion commands/container-registry/registry/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func CmdUpdate(c *core.CommandConfig) error {
}

if viper.IsSet(core.GetFlagName(c.NS, "garbage-collection-schedule-time")) {
*v.Time = viper.GetString(core.GetFlagName(c.NS, "garbage-collection-schedule-time"))
v.Time = viper.GetString(core.GetFlagName(c.NS, "garbage-collection-schedule-time"))
} else {
v.SetTime("01:23:00+00:00")
}
Expand Down
10 changes: 5 additions & 5 deletions commands/container-registry/registry/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ func CmdPost(c *core.CommandConfig) error {
}

if viper.IsSet(core.GetFlagName(c.NS, FlagRegGCTime)) {
*v.Time = viper.GetString(core.GetFlagName(c.NS, FlagRegGCTime))
v.Time = viper.GetString(core.GetFlagName(c.NS, FlagRegGCTime))
} else {
v.SetTime("01:23:00+00:00")
}

feat := containerregistry.NewRegistryFeaturesWithDefaults()
featEnabled := viper.GetBool(core.GetFlagName(c.NS, constants.FlagRegistryVulnScan))
feat.SetVulnerabilityScanning(containerregistry.FeatureVulnerabilityScanning{Enabled: &featEnabled})
feat.SetVulnerabilityScanning(containerregistry.FeatureVulnerabilityScanning{Enabled: featEnabled})

regPostProperties.SetName(name)
regPostProperties.SetLocation(location)
Expand All @@ -129,7 +129,7 @@ func CmdPost(c *core.CommandConfig) error {
}

regPrint := containerregistry.NewRegistryResponseWithDefaults()
regPrint.SetProperties(*reg.GetProperties())
regPrint.SetProperties(reg.GetProperties())

cols, _ := c.Command.Command.Flags().GetStringSlice(constants.ArgCols)

Expand All @@ -149,8 +149,8 @@ func getLocForAutoComplete() []string {
locs, _, _ := client.Must().RegistryClient.LocationsApi.LocationsGet(context.Background()).Execute()
list := locs.GetItems()

for _, item := range *list {
locations = append(locations, *item.GetId())
for _, item := range list {
locations = append(locations, item.GetId())
}

return locations
Expand Down
6 changes: 3 additions & 3 deletions commands/container-registry/registry/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ func CmdPut(c *core.CommandConfig) error {
}

if viper.IsSet(core.GetFlagName(c.NS, FlagRegGCTime)) {
*v.Time = viper.GetString(core.GetFlagName(c.NS, FlagRegGCTime))
v.Time = viper.GetString(core.GetFlagName(c.NS, FlagRegGCTime))
} else {
v.SetTime("01:23:00+00:00")
}

feat := containerregistry.NewRegistryFeaturesWithDefaults()
featEnabled := viper.GetBool(core.GetFlagName(c.NS, constants.FlagRegistryVulnScan))
feat.SetVulnerabilityScanning(containerregistry.FeatureVulnerabilityScanning{Enabled: &featEnabled})
feat.SetVulnerabilityScanning(containerregistry.FeatureVulnerabilityScanning{Enabled: featEnabled})

regPutProperties.SetName(name)
regPutProperties.SetLocation(location)
Expand All @@ -126,7 +126,7 @@ func CmdPut(c *core.CommandConfig) error {
}

regPrint := containerregistry.NewRegistryResponseWithDefaults()
regPrint.SetProperties(*reg.GetProperties())
regPrint.SetProperties(reg.GetProperties())

cols, _ := c.Command.Command.Flags().GetStringSlice(constants.ArgCols)

Expand Down
4 changes: 2 additions & 2 deletions commands/container-registry/registry/registries.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func RegsIds() []string {
svc := resources.NewRegistriesService(client.Must(), context.Background())
regs, _, _ := svc.List("")
return functional.Map(
*regs.GetItems(), func(reg containerregistry.RegistryResponse) string {
return *reg.GetId()
regs.GetItems(), func(reg containerregistry.RegistryResponse) string {
return reg.GetId()
},
)
}
4 changes: 2 additions & 2 deletions commands/container-registry/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func RepositoryNames(registryId string) []string {
}

return functional.Map(
*repos.Items, func(repo containerregistry.RepositoryRead) string {
return *repo.Properties.Name
repos.Items, func(repo containerregistry.RepositoryRead) string {
return repo.Properties.Name
},
)
}
6 changes: 3 additions & 3 deletions commands/container-registry/token/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func CmdDeleteToken(c *core.CommandConfig) error {
return err
}

for _, token := range *tokens.GetItems() {
for _, token := range tokens.GetItems() {
msg := fmt.Sprintf("delete Token: %s", *token.Id)

if !confirm.FAsk(c.Command.Command.InOrStdin(), msg, viper.GetBool(constants.ArgForce)) {
Expand All @@ -112,13 +112,13 @@ func CmdDeleteToken(c *core.CommandConfig) error {
return err
}

for _, reg := range *regs.GetItems() {
for _, reg := range regs.GetItems() {
tokens, _, err := c.ContainerRegistryServices.Token().List(*reg.Id)
if err != nil {
return err
}

for _, token := range *tokens.GetItems() {
for _, token := range tokens.GetItems() {
msg := fmt.Sprintf("delete Token: %s", *token.Id)

if !confirm.FAsk(c.Command.Command.InOrStdin(), msg, viper.GetBool(constants.ArgForce)) {
Expand Down
2 changes: 1 addition & 1 deletion commands/container-registry/token/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func CmdListToken(c *core.CommandConfig) error {
}

if items, ok := regs.GetItemsOk(); ok && items != nil {
for _, reg := range *items {
for _, reg := range items {
tokens, _, err := c.ContainerRegistryServices.Token().List(*reg.Id)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion commands/container-registry/token/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func CmdPostToken(c *core.CommandConfig) error {
}

tokenPrint := containerregistry.NewTokenResponseWithDefaults()
tokenPrint.SetProperties(*token.GetProperties())
tokenPrint.SetProperties(token.GetProperties())

cols, _ := c.Command.Command.Flags().GetStringSlice(constants.ArgCols)

Expand Down
2 changes: 1 addition & 1 deletion commands/container-registry/token/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func CmdPutToken(c *core.CommandConfig) error {
}

tokenPrint := containerregistry.NewTokenResponseWithDefaults()
tokenPrint.SetProperties(*token.GetProperties())
tokenPrint.SetProperties(token.GetProperties())

cols, _ := c.Command.Command.Flags().GetStringSlice(constants.ArgCols)

Expand Down
10 changes: 3 additions & 7 deletions commands/container-registry/token/scopes/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,9 @@ func CmdTokenScopesAdd(c *core.CommandConfig) error {
}

updateToken := containerregistry.NewPatchTokenInput()
if token.Properties.GetExpiryDate() != nil {
updateToken.SetExpiryDate(*token.Properties.GetExpiryDate())
}
if token.Properties.GetStatus() != nil {
updateToken.SetStatus(*token.Properties.GetStatus())
}
scopes := *token.Properties.GetScopes()
updateToken.SetExpiryDate(token.Properties.GetExpiryDate())
updateToken.SetStatus(token.Properties.GetStatus())
scopes := token.Properties.GetScopes()
scopes = append(scopes, scope)
updateToken.SetScopes(scopes)

Expand Down
20 changes: 7 additions & 13 deletions commands/container-registry/token/scopes/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,9 @@ func CmdGetTokenScopesDelete(c *core.CommandConfig) error {
if viper.GetBool(core.GetFlagName(c.NS, constants.ArgAll)) {
updateToken := containerregistry.NewPutTokenInputWithDefaults()
updateProp := containerregistry.NewPostTokenPropertiesWithDefaults()

if token.Properties.GetExpiryDate() != nil {
updateProp.SetExpiryDate(*token.Properties.GetExpiryDate())
}

if token.Properties.GetStatus() != nil {
updateProp.SetStatus(*token.Properties.GetStatus())
}
updateProp.SetName(*token.Properties.GetName())
updateProp.SetExpiryDate(token.Properties.GetExpiryDate())
updateProp.SetStatus(token.Properties.GetStatus())
updateProp.SetName(token.Properties.GetName())
updateToken.SetProperties(*updateProp)

msg := fmt.Sprintf("delete all scopes from Token: %s", *token.Id)
Expand Down Expand Up @@ -116,12 +110,12 @@ func CmdGetTokenScopesDelete(c *core.CommandConfig) error {
updateToken := containerregistry.NewPutTokenInputWithDefaults()
updateProp := containerregistry.NewPostTokenPropertiesWithDefaults()

scopes := *token.Properties.GetScopes()
scopes := token.Properties.GetScopes()
scopes = append(scopes[:id], scopes[id+1:]...)

updateProp.SetExpiryDate(*token.Properties.GetExpiryDate())
updateProp.SetStatus(*token.Properties.GetStatus())
updateProp.SetName(*token.Properties.GetName())
updateProp.SetExpiryDate(token.Properties.GetExpiryDate())
updateProp.SetStatus(token.Properties.GetStatus())
updateProp.SetName(token.Properties.GetName())
updateProp.SetScopes(scopes)
updateToken.SetProperties(*updateProp)

Expand Down
2 changes: 1 addition & 1 deletion commands/container-registry/token/scopes/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func CmdGetTokenScopesList(c *core.CommandConfig) error {
cols, _ := c.Command.Command.Flags().GetStringSlice(constants.ArgCols)

out, err := jsontabwriter.GenerateOutput(
"", allScopeJSONPaths, *scopes,
"", allScopeJSONPaths, scopes,
tabheaders.GetHeaders(allScopeCols, defaultScopeCols, cols),
)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions commands/container-registry/token/scopes/scopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,28 @@ func TokensIds(regId string) []string {

tokens, _, _ := svcToken.List(regId)

allTokens = append(allTokens, *tokens.GetItems()...)
allTokens = append(allTokens, tokens.GetItems()...)

return functional.Map(
allTokens, func(reg containerregistry.TokenResponse) string {
return *reg.GetId()
return reg.GetId()
},
)
}

svc := resources.NewRegistriesService(client.Must(), context.Background())
regs, _, _ := svc.List("")
regsIDs := *regs.GetItems()
regsIDs := regs.GetItems()

for _, regID := range regsIDs {
tokens, _, _ := svcToken.List(*regID.GetId())
tokens, _, _ := svcToken.List(regID.GetId())

allTokens = append(allTokens, *tokens.GetItems()...)
allTokens = append(allTokens, tokens.GetItems()...)
}

return functional.Map(
allTokens, func(reg containerregistry.TokenResponse) string {
return *reg.GetId()
return reg.GetId()
},
)
}
12 changes: 6 additions & 6 deletions commands/container-registry/token/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ func TokensIds(regId string) []string {

tokens, _, _ := svcToken.List(regId)

allTokens = append(allTokens, *tokens.GetItems()...)
allTokens = append(allTokens, tokens.GetItems()...)

return functional.Map(
allTokens, func(reg containerregistry.TokenResponse) string {
return *reg.GetId()
return reg.GetId()
},
)
}

regs, _, _ := resources.NewRegistriesService(client.Must(), context.Background()).List("")
regsIDs := *regs.GetItems()
regsIDs := regs.GetItems()

for _, regID := range regsIDs {
tokens, _, _ := svcToken.List(*regID.GetId())
tokens, _, _ := svcToken.List(regID.GetId())

allTokens = append(allTokens, *tokens.GetItems()...)
allTokens = append(allTokens, tokens.GetItems()...)
}

return functional.Map(
allTokens, func(reg containerregistry.TokenResponse) string {
return *reg.GetId()
return reg.GetId()
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func ConvertContainerRegistryVulnerabilitiesToTable(vulnerabilities containerreg
}

var convertedVulnerabilities []map[string]interface{}
for _, vulnerability := range *items {
for _, vulnerability := range items {
convertedVulnerability, err := ConvertContainerRegistryVulnerabilityToTable(vulnerability)
if err != nil {
return nil, err
Expand Down Expand Up @@ -48,7 +48,7 @@ func ConvertContainerRegistryVulnerabilityToTable(vulnerability containerregistr
}

var affectsFormatted []interface{}
for _, affect := range *affects {
for _, affect := range affects {
name, ok := affect.GetNameOk()
if !ok || name == nil {
return nil, fmt.Errorf("could not retrieve Container Registry Vulnerability affects name")
Expand Down

0 comments on commit c1acb15

Please sign in to comment.