Skip to content

Commit c02f332

Browse files
committed
Provide role scopes as csv to align with config
Config already provides its scopes as csv. Use-case: I want to set `allowed_parameters` in the policy for `scopes`. However, this is only string based. When using this with terraform and supplying the scopes string based, there will be a constant state drift as the response is different (an array vs a string).
1 parent b675d08 commit c02f332

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

entry_role.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gitlab
33
import (
44
"context"
55
"fmt"
6+
"strings"
67
"time"
78

89
"github.com/hashicorp/vault/sdk/logical"
@@ -35,7 +36,7 @@ func (e EntryRole) LogicalResponseData() map[string]any {
3536
"role_name": e.RoleName,
3637
"path": e.Path,
3738
"name": e.Name,
38-
"scopes": e.Scopes,
39+
"scopes": strings.Join(e.Scopes, ", "),
3940
"access_level": e.AccessLevel.String(),
4041
"ttl": int64(e.TTL / time.Second),
4142
"token_type": e.TokenType.String(),
@@ -54,5 +55,4 @@ func getRole(ctx context.Context, name string, s logical.Storage) (role *EntryRo
5455
_ = entry.DecodeJSON(role)
5556
}
5657
return role, err
57-
5858
}

path_role_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ func TestPathRoles(t *testing.T) {
325325
"path": "user",
326326
"name": "Example user personal token",
327327
"token_type": token.TypePersonal.String(),
328-
"scopes": []string{
328+
"scopes": strings.Join([]string{
329329
"invalid_scope",
330-
},
330+
}, ", "),
331331
},
332332
})
333333
require.Error(t, err)
@@ -423,10 +423,10 @@ func TestPathRoles(t *testing.T) {
423423
"token_type": token.TypePersonal.String(),
424424
"ttl": int64((5 * 24 * time.Hour).Seconds()),
425425
"gitlab_revokes_token": false,
426-
"scopes": []string{
426+
"scopes": strings.Join([]string{
427427
token.ScopeApi.String(),
428428
token.ScopeReadRegistry.String(),
429-
},
429+
}, ", "),
430430
}
431431

432432
// create a role

0 commit comments

Comments
 (0)