Skip to content

Commit e980276

Browse files
authored
feat(iam): add create jwt method (#1172)
1 parent 3bdf84c commit e980276

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

packages/clients/src/api/iam/v1alpha1/api.gen.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
marshalCreateAPIKeyRequest,
1414
marshalCreateApplicationRequest,
1515
marshalCreateGroupRequest,
16+
marshalCreateJWTRequest,
1617
marshalCreatePolicyRequest,
1718
marshalCreateSSHKeyRequest,
1819
marshalCreateUserRequest,
@@ -27,6 +28,7 @@ import {
2728
marshalUpdateUserRequest,
2829
unmarshalAPIKey,
2930
unmarshalApplication,
31+
unmarshalEncodedJWT,
3032
unmarshalGroup,
3133
unmarshalJWT,
3234
unmarshalListAPIKeysResponse,
@@ -56,6 +58,7 @@ import type {
5658
CreateAPIKeyRequest,
5759
CreateApplicationRequest,
5860
CreateGroupRequest,
61+
CreateJWTRequest,
5962
CreatePolicyRequest,
6063
CreateSSHKeyRequest,
6164
CreateUserRequest,
@@ -66,6 +69,7 @@ import type {
6669
DeletePolicyRequest,
6770
DeleteSSHKeyRequest,
6871
DeleteUserRequest,
72+
EncodedJWT,
6973
GetAPIKeyRequest,
7074
GetApplicationRequest,
7175
GetGroupRequest,
@@ -1088,6 +1092,25 @@ export class API extends ParentAPI {
10881092
listJWTs = (request: Readonly<ListJWTsRequest> = {}) =>
10891093
enrichForPagination('jwts', this.pageOfListJWTs, request)
10901094

1095+
/**
1096+
* Create a JWT.
1097+
*
1098+
* @param request - The request {@link CreateJWTRequest}
1099+
* @returns A Promise of EncodedJWT
1100+
*/
1101+
createJWT = (request: Readonly<CreateJWTRequest>) =>
1102+
this.client.fetch<EncodedJWT>(
1103+
{
1104+
body: JSON.stringify(
1105+
marshalCreateJWTRequest(request, this.client.settings),
1106+
),
1107+
headers: jsonContentHeaders,
1108+
method: 'POST',
1109+
path: `/iam/v1alpha1/jwts`,
1110+
},
1111+
unmarshalEncodedJWT,
1112+
)
1113+
10911114
/**
10921115
* Get a JWT.
10931116
*

packages/clients/src/api/iam/v1alpha1/index.gen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type {
1111
CreateAPIKeyRequest,
1212
CreateApplicationRequest,
1313
CreateGroupRequest,
14+
CreateJWTRequest,
1415
CreatePolicyRequest,
1516
CreateSSHKeyRequest,
1617
CreateUserRequest,
@@ -21,6 +22,7 @@ export type {
2122
DeletePolicyRequest,
2223
DeleteSSHKeyRequest,
2324
DeleteUserRequest,
25+
EncodedJWT,
2426
GetAPIKeyRequest,
2527
GetApplicationRequest,
2628
GetGroupRequest,

packages/clients/src/api/iam/v1alpha1/marshalling.gen.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import type {
1616
CreateAPIKeyRequest,
1717
CreateApplicationRequest,
1818
CreateGroupRequest,
19+
CreateJWTRequest,
1920
CreatePolicyRequest,
2021
CreateSSHKeyRequest,
2122
CreateUserRequest,
23+
EncodedJWT,
2224
Group,
2325
JWT,
2426
ListAPIKeysResponse,
@@ -237,6 +239,20 @@ export const unmarshalUser = (data: unknown): User => {
237239
} as User
238240
}
239241

242+
export const unmarshalEncodedJWT = (data: unknown): EncodedJWT => {
243+
if (!isJSONObject(data)) {
244+
throw new TypeError(
245+
`Unmarshalling the type 'EncodedJWT' failed as data isn't a dictionary.`,
246+
)
247+
}
248+
249+
return {
250+
jwt: data.jwt ? unmarshalJWT(data.jwt) : undefined,
251+
renewToken: data.renew_token,
252+
token: data.token,
253+
} as EncodedJWT
254+
}
255+
240256
export const unmarshalListAPIKeysResponse = (
241257
data: unknown,
242258
): ListAPIKeysResponse => {
@@ -500,6 +516,14 @@ export const marshalCreateGroupRequest = (
500516
tags: request.tags,
501517
})
502518

519+
export const marshalCreateJWTRequest = (
520+
request: CreateJWTRequest,
521+
defaults: DefaultValues,
522+
): Record<string, unknown> => ({
523+
referrer: request.referrer,
524+
user_id: request.userId,
525+
})
526+
503527
const marshalRuleSpecs = (
504528
request: RuleSpecs,
505529
defaults: DefaultValues,

packages/clients/src/api/iam/v1alpha1/types.gen.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,13 @@ export type CreateGroupRequest = {
462462
tags?: string[]
463463
}
464464

465+
export type CreateJWTRequest = {
466+
/** ID of the user the JWT will be created for. */
467+
userId: string
468+
/** Referrer of the JWT. */
469+
referrer: string
470+
}
471+
465472
export type CreatePolicyRequest = {
466473
/** Name of the policy to create (max length is 64 characters). */
467474
name?: string
@@ -558,6 +565,15 @@ export type DeleteUserRequest = {
558565
userId: string
559566
}
560567

568+
export interface EncodedJWT {
569+
/** The renewed JWT. */
570+
jwt?: JWT
571+
/** The encoded token of the renewed JWT. */
572+
token: string
573+
/** The encoded renew token. This token is necessary to renew the JWT. */
574+
renewToken: string
575+
}
576+
561577
export type GetAPIKeyRequest = {
562578
/** Access key to search for. */
563579
accessKey: string

0 commit comments

Comments
 (0)