Skip to content

Commit 5146175

Browse files
committed
remove option to change expires at for sa token
1 parent 2275140 commit 5146175

File tree

7 files changed

+12
-211
lines changed

7 files changed

+12
-211
lines changed

integration_tests/serviceaccount_tokens.lua

+4-83
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ Test.gql("Create service account token", function(t)
146146
serviceAccountID: "%s"
147147
name: "my-token"
148148
description: "some description"
149+
expiresAt: "2029-01-01"
149150
}
150151
) {
151152
secret
@@ -156,6 +157,7 @@ Test.gql("Create service account token", function(t)
156157
id
157158
name
158159
description
160+
expiresAt
159161
}
160162
}
161163
}
@@ -172,50 +174,20 @@ Test.gql("Create service account token", function(t)
172174
id = Save("tokenID"),
173175
name = "my-token",
174176
description = "some description",
177+
expiresAt = "2029-01-01",
175178
},
176179
},
177180
},
178181
}
179182
end)
180183

181-
Test.gql("Update service account token with empty expiresAt", function(t)
182-
t.query(string.format([[
183-
mutation {
184-
updateServiceAccountToken(
185-
input: {
186-
serviceAccountTokenID: "%s"
187-
expiresAt: { }
188-
}
189-
) {
190-
serviceAccountToken {
191-
expiresAt
192-
}
193-
}
194-
}
195-
]], State.tokenID))
196-
197-
t.check {
198-
data = Null,
199-
errors = {
200-
{
201-
extensions = {
202-
code = "GRAPHQL_VALIDATION_FAILED",
203-
},
204-
locations = NotNull(),
205-
message = "OneOf Input Object \"UpdateServiceAccountTokenExpiresAtInput\" must specify exactly one key.",
206-
},
207-
},
208-
}
209-
end)
210-
211184
Test.gql("Update service account token", function(t)
212185
t.query(string.format([[
213186
mutation {
214187
updateServiceAccountToken(
215188
input: {
216189
serviceAccountTokenID: "%s"
217190
description: "some other description"
218-
expiresAt: { removeExpiry: true }
219191
}
220192
) {
221193
serviceAccountToken {
@@ -233,58 +205,7 @@ Test.gql("Update service account token", function(t)
233205
serviceAccountToken = {
234206
id = State.tokenID,
235207
description = "some other description",
236-
expiresAt = Null,
237-
},
238-
},
239-
},
240-
}
241-
end)
242-
243-
Test.gql("Update service account token set expiresAt", function(t)
244-
t.query(string.format([[
245-
mutation {
246-
updateServiceAccountToken(
247-
input: {
248-
serviceAccountTokenID: "%s"
249-
expiresAt: {
250-
expiresAt: "2029-04-04"
251-
}
252-
}
253-
) {
254-
serviceAccount {
255-
tokens {
256-
nodes {
257-
description
258-
expiresAt
259-
}
260-
}
261-
}
262-
serviceAccountToken {
263-
id
264-
description
265-
expiresAt
266-
}
267-
}
268-
}
269-
]], State.tokenID))
270-
271-
t.check {
272-
data = {
273-
updateServiceAccountToken = {
274-
serviceAccountToken = {
275-
id = State.tokenID,
276-
description = "some other description",
277-
expiresAt = "2029-04-04",
278-
},
279-
serviceAccount = {
280-
tokens = {
281-
nodes = {
282-
{
283-
description = "some other description",
284-
expiresAt = "2029-04-04",
285-
},
286-
},
287-
},
208+
expiresAt = "2029-01-01",
288209
},
289210
},
290211
},

internal/graph/gengql/generated.go

+1-73
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/graph/schema/serviceaccounts.graphqls

-22
Original file line numberDiff line numberDiff line change
@@ -199,28 +199,6 @@ input UpdateServiceAccountTokenInput {
199199
If not specified, the description will remain unchanged.
200200
"""
201201
description: String
202-
203-
"""
204-
The new expiry date of the token.
205-
"""
206-
expiresAt: UpdateServiceAccountTokenExpiresAtInput
207-
}
208-
209-
"""
210-
Input type for the expiresAt field.
211-
212-
Only one of the fields must be specified.
213-
"""
214-
input UpdateServiceAccountTokenExpiresAtInput @oneOf {
215-
"""
216-
The new expiry date of the token.
217-
"""
218-
expiresAt: Date
219-
220-
"""
221-
Remove the existing expiry date of the token, causing the token to never expire.
222-
"""
223-
removeExpiry: Boolean
224202
}
225203

226204
input DeleteServiceAccountTokenInput {

internal/serviceaccount/model.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,10 @@ type UpdateServiceAccountPayload struct {
120120
ServiceAccount *ServiceAccount `json:"serviceAccount,omitempty"`
121121
}
122122

123-
type UpdateServiceAccountTokenExpiresAtInput struct {
124-
ExpiresAt *scalar.Date `json:"expiresAt,omitempty"`
125-
RemoveExpiry *bool `json:"removeExpiry,omitempty"`
126-
}
127-
128123
type UpdateServiceAccountTokenInput struct {
129-
ServiceAccountTokenID ident.Ident `json:"serviceAccountTokenID"`
130-
Name *string `json:"name,omitempty"`
131-
Description *string `json:"description,omitempty"`
132-
ExpiresAt *UpdateServiceAccountTokenExpiresAtInput `json:"expiresAt,omitempty"`
124+
ServiceAccountTokenID ident.Ident `json:"serviceAccountTokenID"`
125+
Name *string `json:"name,omitempty"`
126+
Description *string `json:"description,omitempty"`
133127
}
134128

135129
type UpdateServiceAccountTokenPayload struct {

internal/serviceaccount/queries.go

-12
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,10 @@ func UpdateToken(ctx context.Context, input UpdateServiceAccountTokenInput) (*Se
249249
return nil, nil, err
250250
}
251251

252-
expiresAt := token.ExpiresAt.PgDate()
253-
if e := input.ExpiresAt; e != nil {
254-
if e.ExpiresAt == nil && e.RemoveExpiry == nil {
255-
return nil, nil, apierror.Errorf("Either expiresAt or removeExpiry must be set.")
256-
} else if e.ExpiresAt != nil {
257-
expiresAt = e.ExpiresAt.PgDate()
258-
} else if *e.RemoveExpiry {
259-
expiresAt = pgtype.Date{}
260-
}
261-
}
262-
263252
var t *serviceaccountsql.ServiceAccountToken
264253
err = database.Transaction(ctx, func(ctx context.Context) error {
265254
t, err = db(ctx).UpdateToken(ctx, serviceaccountsql.UpdateTokenParams{
266255
ID: token.UUID,
267-
ExpiresAt: expiresAt,
268256
Name: input.Name,
269257
Description: input.Description,
270258
})

internal/serviceaccount/queries/service_accounts.sql

-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ RETURNING
115115
-- name: UpdateToken :one
116116
UPDATE service_account_tokens
117117
SET
118-
expires_at = @expires_at,
119118
name = COALESCE(sqlc.narg('name'), name),
120119
description = COALESCE(sqlc.narg('description'), description)
121120
WHERE

internal/serviceaccount/serviceaccountsql/service_accounts.sql.go

+4-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)