Skip to content

Commit 8971b03

Browse files
author
Gustavo Bazan
authored
task: improve sa management example (#530)
1 parent bf403d4 commit 8971b03

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

examples/service_account_management/sa_management.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func main() {
5050
}
5151
orgID = orgs.GetResults()[0].GetId()
5252
}
53-
53+
const oneYearHours = 365 * 24
5454
// 1. Create Service Account
5555
request := sdk.ServiceAccountsApi.CreateServiceAccount(
5656
ctx,
@@ -59,7 +59,7 @@ func main() {
5959
"SA created by sdk-example",
6060
"example",
6161
[]string{"ORG_READ_ONLY"},
62-
365*24,
62+
oneYearHours,
6363
),
6464
)
6565
sa, _, err := request.Execute()
@@ -74,7 +74,7 @@ func main() {
7474
orgID,
7575
sa.GetClientId(),
7676
&admin.ServiceAccountSecretRequest{
77-
SecretExpiresAfterHours: 365 * 24,
77+
SecretExpiresAfterHours: oneYearHours,
7878
},
7979
).Execute()
8080
if err != nil {
@@ -99,10 +99,14 @@ func main() {
9999
// might have up to 2 secrets
100100
admin.UseOAuthAuth(ctx, sa.GetClientId(), newSecret.GetSecret()),
101101
)
102-
102+
if err != nil {
103+
log.Fatalf("Error: %v", err)
104+
}
103105
// 5. Make request using new Service Account
104-
projects, _, err := newSDK.ProjectsApi.ListProjectsWithParams(ctx,
105-
&admin.ListProjectsApiParams{}).Execute()
106+
projects, _, err := newSDK.ProjectsApi.ListProjectsWithParams(
107+
ctx,
108+
&admin.ListProjectsApiParams{},
109+
).Execute()
106110
if err != nil {
107111
log.Fatalf("Error: %v", err)
108112
}

0 commit comments

Comments
 (0)