Skip to content

Commit 37f70fb

Browse files
committed
chore: add possible roles for SAs and expand fixtures covering all roles
1 parent 9f1e043 commit 37f70fb

4 files changed

Lines changed: 34 additions & 8 deletions

File tree

cmd/kosli/root.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ The ^.kosli_ignore^ will be treated as part of the artifact like any other file,
9494
// the server is the authority on which types are actually accepted
9595
validEnvTypesList = "K8S, ECS, S3, lambda, server, docker, azure-apps, cloud-run, logical"
9696

97+
// single source of truth for the service account privilege list shown in
98+
// flag help texts; the server is the authority on which privileges are
99+
// actually accepted
100+
validServiceAccountPrivilegesList = "admin, member, snapshotter, reader"
101+
97102
// flags
98103
apiTokenFlag = "The Kosli API token."
99104
artifactName = "[optional] Artifact display name, if different from file, image or directory name."
@@ -121,7 +126,7 @@ The ^.kosli_ignore^ will be treated as part of the artifact like any other file,
121126
ignoreCaseFlag = "[optional] Perform case-insensitive matching for --name. By default matching is case sensitive."
122127
serviceAccountNameFlag = "The name of the service account whose API keys are managed."
123128
serviceAccountDescriptionFlag = "[optional] A description for the service account."
124-
serviceAccountPrivilegeFlag = "The privilege granted to the service account."
129+
serviceAccountPrivilegeFlag = "The privilege granted to the service account. One of: [" + validServiceAccountPrivilegesList + "]."
125130
serviceAccountAssumeYesFlag = "[optional] Skip the confirmation prompt and delete the service account without asking. (alias: --yes)"
126131
apiKeyDescriptionFlag = "A description for the API key."
127132
apiKeyExpiresAtFlag = "[optional] When the API key expires. Accepts an epoch timestamp or a date like '2026-06-04', '2026-06-04 15:04:05', or an RFC3339 timestamp. Defaults to no expiry."

cmd/kosli/serviceAccount_test.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,23 @@ func TestPrintServiceAccountAsTableEmptyDescription(t *testing.T) {
4747

4848
func TestPrintServiceAccountsListAsTable(t *testing.T) {
4949
raw := `[{"name":"ci-bot","description":"first","privilege":"member","created_at":1780584129.5},` +
50-
`{"name":"deployer","description":"","privilege":"admin","created_at":1780584130.5}]`
50+
`{"name":"deployer","description":"","privilege":"admin","created_at":1780584130.5},` +
51+
`{"name":"snapshot-bot","description":"snaps","privilege":"snapshotter","created_at":1780584131.5},` +
52+
`{"name":"auditor","description":"ro","privilege":"reader","created_at":1780584132.5}]`
5153

5254
var buf bytes.Buffer
5355
err := printServiceAccountsListAsTable(raw, &buf, 0)
5456
require.NoError(t, err)
5557

5658
out := buf.String()
57-
for _, want := range []string{"NAME", "DESCRIPTION", "PRIVILEGE", "CREATED", "ci-bot", "first", "deployer", "admin"} {
59+
// every privilege must render in the PRIVILEGE column
60+
for _, want := range []string{
61+
"NAME", "DESCRIPTION", "PRIVILEGE", "CREATED",
62+
"ci-bot", "first", "member",
63+
"deployer", "admin",
64+
"snapshot-bot", "snapshotter",
65+
"auditor", "reader",
66+
} {
5867
require.Contains(t, out, want)
5968
}
6069
// the deployer's empty description must render as N/A, not blank
@@ -90,6 +99,18 @@ func (suite *ServiceAccountCommandTestSuite) TestCreateServiceAccountCmd() {
9099
cmd: "create sa ci-bot --privilege member --dry-run" + suite.defaultKosliArguments,
91100
goldenRegex: `service-accounts/docs-cmd-test-user`,
92101
},
102+
{
103+
wantError: false,
104+
name: "the snapshotter privilege passes through to the payload (dry-run)",
105+
cmd: "create service-account snapshot-bot --privilege snapshotter --dry-run" + suite.defaultKosliArguments,
106+
goldenRegex: `(?s)service-accounts/docs-cmd-test-user.*"privilege": "snapshotter"`,
107+
},
108+
{
109+
wantError: false,
110+
name: "the reader privilege passes through to the payload (dry-run)",
111+
cmd: "create service-account auditor --privilege reader --dry-run" + suite.defaultKosliArguments,
112+
goldenRegex: `(?s)service-accounts/docs-cmd-test-user.*"privilege": "reader"`,
113+
},
93114
{
94115
wantError: true,
95116
name: "create fails when NAME argument is missing",
@@ -220,9 +241,9 @@ func (suite *ServiceAccountCommandTestSuite) TestServiceAccountSuccessOutput() {
220241
},
221242
{
222243
wantError: false,
223-
name: "list prints the returned service accounts",
224-
cmd: "list service-accounts --output json" + args,
225-
goldenRegex: `(?s)ci-bot.*deployer`,
244+
name: "list prints the returned service accounts across all privileges",
245+
cmd: "list service-accounts" + args,
246+
goldenRegex: `(?s)ci-bot.*member.*deployer.*admin.*snapshot-bot.*snapshotter.*auditor.*reader`,
226247
},
227248
{
228249
wantError: false,

cmd/kosli/testdata/service-account/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ response contract lives in one place.
2020
| Fixture | Endpoint / response |
2121
|---------|---------------------|
2222
| `created_service_account.json` | `POST /service-accounts/{org}``201` (create) |
23-
| `listed_service_accounts.json` | `GET /service-accounts/{org}``200` (list) |
23+
| `listed_service_accounts.json` | `GET /service-accounts/{org}``200` (list; one account per privilege: member, admin, snapshotter, reader) |
2424
| `service_account.json` | `GET /service-accounts/{org}/{name}``200` (get) |
2525
| `updated_service_account.json` | `PATCH /service-accounts/{org}/{name}``200` (update) |
2626
| `delete_success.json` | `DELETE /service-accounts/{org}/{name}``200` (bare `"OK"`) |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"name":"ci-bot","description":"CI service account","privilege":"member","created_at":1780584129.5},{"name":"deployer","description":"","privilege":"admin","created_at":1780584130.5}]
1+
[{"name":"ci-bot","description":"CI service account","privilege":"member","created_at":1780584129.5},{"name":"deployer","description":"","privilege":"admin","created_at":1780584130.5},{"name":"snapshot-bot","description":"reports env snapshots","privilege":"snapshotter","created_at":1780584131.5},{"name":"auditor","description":"read-only access","privilege":"reader","created_at":1780584132.5}]

0 commit comments

Comments
 (0)