Skip to content

Commit 84cf476

Browse files
Provide role scopes as csv to align with config (#246)
* 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). * add missing strings import --------- Co-authored-by: Ilija Matoski <[email protected]>
1 parent aa79c1c commit 84cf476

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"cmp"
77
"fmt"
88
"os"
9+
"strings"
910
"testing"
1011
"time"
1112

@@ -325,9 +326,9 @@ func TestPathRoles(t *testing.T) {
325326
"path": "user",
326327
"name": "Example user personal token",
327328
"token_type": token.TypePersonal.String(),
328-
"scopes": []string{
329+
"scopes": strings.Join([]string{
329330
"invalid_scope",
330-
},
331+
}, ", "),
331332
},
332333
})
333334
require.Error(t, err)
@@ -423,10 +424,10 @@ func TestPathRoles(t *testing.T) {
423424
"token_type": token.TypePersonal.String(),
424425
"ttl": int64((5 * 24 * time.Hour).Seconds()),
425426
"gitlab_revokes_token": false,
426-
"scopes": []string{
427+
"scopes": strings.Join([]string{
427428
token.ScopeApi.String(),
428429
token.ScopeReadRegistry.String(),
429-
},
430+
}, ", "),
430431
}
431432

432433
// create a role

0 commit comments

Comments
 (0)