Skip to content

Commit

Permalink
fix: do not complain about empty roles
Browse files Browse the repository at this point in the history
Refs #3421.

Signed-off-by: Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
  • Loading branch information
AlekSi authored and talos-bot committed Jun 15, 2021
1 parent 11918a1 commit caec306
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions pkg/machinery/role/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,18 @@ func Parse(str []string) (Set, error) {
var err *multierror.Error

for _, r := range str {
r = strings.TrimSpace(r)

// Client certificates generated by previous Talos versions contained one empty organization.
if r == "" {
continue
}

role := Role(r)
if _, ok := all[role]; !ok {
err = multierror.Append(err, fmt.Errorf("unexpected role %q", r))
}

role = Role(strings.TrimSpace(r))
if role == "" {
continue
}

res[role] = struct{}{}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/machinery/role/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
func TestRole(t *testing.T) {
t.Parallel()

set, err := role.Parse([]string{"os:admin", "os:reader", "os:future", "os:impersonator", " "})
assert.EqualError(t, err, "2 errors occurred:\n\t* unexpected role \"os:future\"\n\t* unexpected role \" \"\n\n")
set, err := role.Parse([]string{"os:admin", "os:reader", "os:future", "os:impersonator", "", " "})
assert.EqualError(t, err, "1 error occurred:\n\t* unexpected role \"os:future\"\n\n")
assert.Equal(t, role.MakeSet(role.Admin, role.Reader, role.Role("os:future"), role.Impersonator), set)

assert.Equal(t, []string{"os:admin", "os:future", "os:impersonator", "os:reader"}, set.Strings())
Expand Down

0 comments on commit caec306

Please sign in to comment.