Skip to content

Commit

Permalink
refactor(cli): split survey limits into diff funcs
Browse files Browse the repository at this point in the history
Signed-off-by: Salim Afiune Maya <[email protected]>
  • Loading branch information
afiune committed Aug 4, 2021
1 parent d3756e4 commit 1e1dca4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
9 changes: 4 additions & 5 deletions api/container_registries_ghcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ func TestContainerRegistriesNewGhcr(t *testing.T) {
subject := api.NewContainerRegistry("integration_name",
api.GhcrContainerRegistry,
api.GhcrData{
RegistryDomain: "southamerica-east1-docker.pkg.dev",
LimitByTag: []string{"foo"},
LimitByLabel: []map[string]string{{"key": "value"}},
LimitByRep: []string{"xyz/name"},
LimitNumImg: 15,
LimitByTag: []string{"foo"},
LimitByLabel: []map[string]string{{"key": "value"}},
LimitByRep: []string{"xyz/name"},
LimitNumImg: 15,
Credentials: api.GhcrCredentials{
Username: "user",
Password: "pass",
Expand Down
24 changes: 21 additions & 3 deletions cli/cmd/integration_ctr_reg_limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func castStringToLimitByLabel(labels string) []map[string]string {
return out
}

func askForV2Limits(answers interface{}) error {
func askV2LimitByTags(answers interface{}) error {
custom := false
if err := survey.AskOne(&survey.Confirm{
Message: "Configure limit of scans by tags?",
Expand All @@ -63,7 +63,11 @@ func askForV2Limits(answers interface{}) error {
}
}

custom = false
return nil
}

func askV2LimitByLabels(answers interface{}) error {
custom := false
if err := survey.AskOne(&survey.Confirm{
Message: "Configure limit of scans by labels?",
}, &custom); err != nil {
Expand All @@ -83,7 +87,11 @@ func askForV2Limits(answers interface{}) error {
}
}

custom = false
return nil
}

func askV2LimitByRepositories(answers interface{}) error {
custom := false
if err := survey.AskOne(&survey.Confirm{
Message: "Configure limit of scans by repositories?",
}, &custom); err != nil {
Expand All @@ -105,3 +113,13 @@ func askForV2Limits(answers interface{}) error {

return nil
}

func askV2Limits(answers interface{}) error {
if err := askV2LimitByTags(answers); err != nil {
return err
}
if err := askV2LimitByLabels(answers); err != nil {
return err
}
return askV2LimitByRepositories(answers)
}
2 changes: 1 addition & 1 deletion cli/cmd/integration_gar.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func createGarIntegration() error {
}

// @afiune these are the new API v2 limits
if err := askForV2Limits(&answers); err != nil {
if err := askV2Limits(&answers); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/integration_ghcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func createGhcrIntegration() error {
}

// @afiune these are the new API v2 limits
if err := askForV2Limits(&answers); err != nil {
if err := askV2Limits(&answers); err != nil {
return err
}

Expand Down

0 comments on commit 1e1dca4

Please sign in to comment.