Skip to content

Commit bb8607c

Browse files
author
Enda Phelan
committed
chore: delete current user service accounts
1 parent 7a056de commit bb8607c

File tree

5 files changed

+12
-63
lines changed

5 files changed

+12
-63
lines changed

pkg/cmd/serviceaccount/resetcredentials/reset_credentials.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,14 @@ func runResetCredentials(opts *options) (err error) {
109109

110110
api := conn.API()
111111

112-
serviceacct, httpRes, err := api.ServiceAccount().GetServiceAccountById(opts.Context, opts.id).Execute()
112+
_, httpRes, err := api.ServiceAccount().GetServiceAccountById(opts.Context, opts.id).Execute()
113113
if httpRes != nil {
114114
defer httpRes.Body.Close()
115115
}
116116

117117
if err != nil {
118118
return err
119119
}
120-
serviceAcctName := serviceacct.GetName()
121-
122120
if opts.interactive {
123121
err = runInteractivePrompt(opts)
124122
if err != nil {
@@ -152,7 +150,7 @@ func runResetCredentials(opts *options) (err error) {
152150
}
153151
}
154152

155-
updatedServiceAccount, err := resetCredentials(serviceAcctName, opts)
153+
updatedServiceAccount, err := resetCredentials(opts)
156154
if err != nil {
157155
return fmt.Errorf("%v: %w", opts.localizer.MustLocalize("serviceAccount.resetCredentials.error.resetError", localize.NewEntry("ID", opts.id)), err)
158156
}
@@ -181,7 +179,7 @@ func runResetCredentials(opts *options) (err error) {
181179
return nil
182180
}
183181

184-
func resetCredentials(name string, opts *options) (*kafkamgmtclient.ServiceAccount, error) {
182+
func resetCredentials(opts *options) (*kafkamgmtclient.ServiceAccount, error) {
185183
conn, err := opts.Connection(connection.DefaultConfigSkipMasAuth)
186184
if err != nil {
187185
return nil, err

pkg/editor/linux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// nolint
2+
13
// +build !windows
24

35
package editor

pkg/serviceaccount/validation/validation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
const (
1111
// name validation rules
1212
legalShortDescriptionChars = "^[a-z]([-a-z0-9]*[a-z0-9])?$"
13-
maxNameLength = 50
14-
minNameLength = 1
15-
legalUUID = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
13+
maxNameLength = 50
14+
minNameLength = 1
15+
legalUUID = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
1616
)
1717

1818
// Validator is a type for validating service account configuration values

pkg/serviceaccount/validation/validation_test.go

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func init() {
1616
}
1717
}
1818

19-
func TestValidateName(t *testing.T) {
19+
func TestValidateShortDescription(t *testing.T) {
2020
type args struct {
2121
val interface{}
2222
}
@@ -75,7 +75,7 @@ func TestValidateName(t *testing.T) {
7575
for _, tt := range tests {
7676
t.Run(tt.name, func(t *testing.T) {
7777
if err := validator.ValidateShortDescription(tt.args.val); (err != nil) != tt.wantErr {
78-
t.Errorf("ValidateName() error = %v, wantErr %v", err, tt.wantErr)
78+
t.Errorf("ValidateShortDescription() error = %v, wantErr %v", err, tt.wantErr)
7979
}
8080
})
8181
}
@@ -131,54 +131,3 @@ func TestValidateUUID(t *testing.T) {
131131
})
132132
}
133133
}
134-
135-
func TestValidateDescription(t *testing.T) {
136-
type args struct {
137-
val interface{}
138-
}
139-
tests := []struct {
140-
name string
141-
args args
142-
wantErr bool
143-
}{
144-
{
145-
name: "passes when empty",
146-
args: args{""},
147-
wantErr: false,
148-
},
149-
{
150-
name: "passes on max length (255)",
151-
args: args{"trl1rmcyl6dp4xxqy0rwudhodbpjc4crja8ibf2yco6obalko6qor9n2a1wsqruolg0ewrndumw2xkezzuwg8pjo6ntsmi1cjw99hjcko4t2kjkxmaswzgk8ko75pcs4js0pzypuyjxxnld4dijxadzs8peioi6d5jjxxtfl9vicufmxuacvu7m8ycbwhsbiu9ipw5fxplf0ojs8bxd7hwt4rn4phbcdgivxdzprhyfjamkgjzytjz25cmqagtw"},
152-
wantErr: false,
153-
},
154-
{
155-
name: "fails when exceeds max length",
156-
args: args{"trl1rmcyl6dp4xxqy0rwudhodbpjc4crja8ibf2yco6obalko6qor9n2a1wsqruolg0ewrndumw2xkezzuwg8pjo6ntsmi1cjw99hjcko4t2kjkxmaswzgk8ko75pcs4js0pzypuyjxxnld4dijxadzs8peioi6d5jjxxtfl9vicufmxuacvu7m8ycbwhsbiu9ipw5fxplf0ojs8bxd7hwt4rn4phbcdgivxdzprhyfjamkgjzytjz25cmqagtwa"},
157-
wantErr: true,
158-
},
159-
{
160-
name: "passes with spaces",
161-
args: args{"here is a description"},
162-
wantErr: false,
163-
},
164-
{
165-
name: "fails with special character",
166-
args: args{"here is a description!"},
167-
wantErr: true,
168-
},
169-
{
170-
name: "passes with capital letters",
171-
args: args{"Hello"},
172-
wantErr: false,
173-
},
174-
}
175-
176-
for _, tt := range tests {
177-
// nolint:scopelint
178-
t.Run(tt.name, func(t *testing.T) {
179-
if err := validator.ValidateDescription(tt.args.val); (err != nil) != tt.wantErr {
180-
t.Errorf("ValidateDescription() error = %v, wantErr %v", err, tt.wantErr)
181-
}
182-
})
183-
}
184-
}

scripts/util/delete-service-accounts.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ set -uo pipefail
44

55
echo "Deleting all service accounts"
66

7-
serviceaccount_uuids=$(rhoas serviceaccount list -o json | jq -rc '.items[].id')
7+
serviceaccount_uuids=$(rhoas service-account list -o json | jq --arg iamwho $(rhoas whoami) -rc '.items[] | select( .owner == $iamwho)' | jq -rc '.id')
88

99
for id in ${serviceaccount_uuids}; do
1010
echo "Deleting service account '$id'..."
11-
rhoas serviceaccount delete -y --id $id
11+
rhoas service-account delete -y --id $id
1212
done

0 commit comments

Comments
 (0)