Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit 5db27d0

Browse files
committed
Fix linter suggestions
1 parent 9100e7f commit 5db27d0

4 files changed

Lines changed: 16 additions & 23 deletions

File tree

internals/secrethub/migrate.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ func newReferenceMapping(p *plan) referenceMapping {
5252
}
5353

5454
// addVarPossibilities adds variations to the index for all values in the passed in vars map
55-
func (m referenceMapping) addVarPossibilities(vars map[string][]string) (nonExistingValues []string, err error) {
55+
func (m referenceMapping) addVarPossibilities(vars map[string][]string) error {
5656
exists := make(map[string]string)
5757
for varname, possibleValues := range vars {
5858
varname = strings.ToUpper(varname)
5959
for _, value := range possibleValues {
6060
if otherVarname := exists[value]; otherVarname != "" && otherVarname != varname {
61-
return nil, fmt.Errorf("you've ran into a limitation of the migration tool. You can't have multiple variables with the same value: '%s' now occurs in both '%s' and '%s'", value, varname, otherVarname)
61+
return fmt.Errorf("you've ran into a limitation of the migration tool. You can't have multiple variables with the same value: '%s' now occurs in both '%s' and '%s'", value, varname, otherVarname)
6262
}
6363
exists[value] = varname
6464
}
@@ -80,14 +80,12 @@ func (m referenceMapping) addVarPossibilities(vars map[string][]string) (nonExis
8080
for secretHubVariation, opVariation := range variations {
8181
m[strings.ReplaceAll(secrethubRef, value, secretHubVariation)] = strings.ReplaceAll(opRef, value, opVariation)
8282
}
83-
} else {
84-
nonExistingValues = append(nonExistingValues, value)
8583
}
8684
}
8785
}
8886
}
8987

90-
return
88+
return nil
9189
}
9290

9391
// stripSecretHubURIScheme removes the secrethub:// prefix from the index keys so it can be

internals/secrethub/migrate_config_envfile.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ func (cmd *MigrateConfigEnvfileCommand) Run() error {
1616
return err
1717
}
1818

19-
vars, err := parseVarPossibilities(cmd.vars)
20-
if err != nil {
21-
return err
22-
}
23-
19+
vars := parseVarPossibilities(cmd.vars)
2420
refMapping := newReferenceMapping(plan)
25-
_, err = refMapping.addVarPossibilities(vars)
21+
err = refMapping.addVarPossibilities(vars)
2622
if err != nil {
2723
return err
2824
}

internals/secrethub/migrate_config_templates.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ func (cmd *MigrateConfigTemplatesCommand) Run() error {
2020
return err
2121
}
2222

23-
vars, err := parseVarPossibilities(cmd.vars)
24-
if err != nil {
25-
return err
26-
}
27-
23+
vars := parseVarPossibilities(cmd.vars)
2824
refMapping := newReferenceMapping(plan)
29-
_, err = refMapping.addVarPossibilities(vars)
25+
err = refMapping.addVarPossibilities(vars)
3026
if err != nil {
3127
return err
3228
}
29+
3330
refMapping.stripSecretHubURIScheme()
3431

3532
for _, filepath := range cmd.inFiles {
@@ -123,7 +120,7 @@ func (cmd *MigrateConfigTemplatesCommand) Register(r cli.Registerer) {
123120
clause.BindAction(cmd.Run)
124121
}
125122

126-
func parseVarPossibilities(unparsed map[string]string) (map[string][]string, error) {
123+
func parseVarPossibilities(unparsed map[string]string) map[string][]string {
127124
result := make(map[string][]string)
128125
for varname, optionsStr := range unparsed {
129126
options := strings.Split(optionsStr, ",")
@@ -134,5 +131,5 @@ func parseVarPossibilities(unparsed map[string]string) (map[string][]string, err
134131
result[varname] = options
135132
}
136133

137-
return result, nil
134+
return result
138135
}

internals/secrethub/migrate_config_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ func TestMigrateTemplates(t *testing.T) {
106106
var out bytes.Buffer
107107
m := referenceMapping(tc.mapping)
108108
m.stripSecretHubURIScheme()
109-
m.addVarPossibilities(tc.vars)
109+
err := m.addVarPossibilities(tc.vars)
110+
assert.OK(t, err)
110111

111-
_, err := migrateTemplateTags(bytes.NewReader([]byte(tc.in)), &out, m, "{{ %s }}")
112+
_, err = migrateTemplateTags(bytes.NewReader([]byte(tc.in)), &out, m, "{{ %s }}")
112113
if tc.expectedErr {
113114
assert.Equal(t, err != nil, true)
114115
return
@@ -227,9 +228,10 @@ func TestMigrateEnvfile(t *testing.T) {
227228
var out bytes.Buffer
228229
m := referenceMapping(tc.mapping)
229230
m.stripSecretHubURIScheme()
230-
m.addVarPossibilities(tc.vars)
231+
err := m.addVarPossibilities(tc.vars)
232+
assert.OK(t, err)
231233

232-
err := func() error {
234+
err = func() error {
233235
err := checkForCompositeSecrets([]byte(tc.in))
234236
if err != nil {
235237
return err

0 commit comments

Comments
 (0)