Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(iam): add create jwt method #1172

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/clients/src/api/iam/v1alpha1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
marshalCreateAPIKeyRequest,
marshalCreateApplicationRequest,
marshalCreateGroupRequest,
marshalCreateJWTRequest,
marshalCreatePolicyRequest,
marshalCreateSSHKeyRequest,
marshalCreateUserRequest,
Expand All @@ -27,6 +28,7 @@ import {
marshalUpdateUserRequest,
unmarshalAPIKey,
unmarshalApplication,
unmarshalEncodedJWT,
unmarshalGroup,
unmarshalJWT,
unmarshalListAPIKeysResponse,
Expand Down Expand Up @@ -56,6 +58,7 @@ import type {
CreateAPIKeyRequest,
CreateApplicationRequest,
CreateGroupRequest,
CreateJWTRequest,
CreatePolicyRequest,
CreateSSHKeyRequest,
CreateUserRequest,
Expand All @@ -66,6 +69,7 @@ import type {
DeletePolicyRequest,
DeleteSSHKeyRequest,
DeleteUserRequest,
EncodedJWT,
GetAPIKeyRequest,
GetApplicationRequest,
GetGroupRequest,
Expand Down Expand Up @@ -1088,6 +1092,25 @@ export class API extends ParentAPI {
listJWTs = (request: Readonly<ListJWTsRequest> = {}) =>
enrichForPagination('jwts', this.pageOfListJWTs, request)

/**
* Create a JWT.
*
* @param request - The request {@link CreateJWTRequest}
* @returns A Promise of EncodedJWT
*/
createJWT = (request: Readonly<CreateJWTRequest>) =>
this.client.fetch<EncodedJWT>(
{
body: JSON.stringify(
marshalCreateJWTRequest(request, this.client.settings),
),
headers: jsonContentHeaders,
method: 'POST',
path: `/iam/v1alpha1/jwts`,
},
unmarshalEncodedJWT,
)

/**
* Get a JWT.
*
Expand Down
2 changes: 2 additions & 0 deletions packages/clients/src/api/iam/v1alpha1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type {
CreateAPIKeyRequest,
CreateApplicationRequest,
CreateGroupRequest,
CreateJWTRequest,
CreatePolicyRequest,
CreateSSHKeyRequest,
CreateUserRequest,
Expand All @@ -21,6 +22,7 @@ export type {
DeletePolicyRequest,
DeleteSSHKeyRequest,
DeleteUserRequest,
EncodedJWT,
GetAPIKeyRequest,
GetApplicationRequest,
GetGroupRequest,
Expand Down
24 changes: 24 additions & 0 deletions packages/clients/src/api/iam/v1alpha1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import type {
CreateAPIKeyRequest,
CreateApplicationRequest,
CreateGroupRequest,
CreateJWTRequest,
CreatePolicyRequest,
CreateSSHKeyRequest,
CreateUserRequest,
EncodedJWT,
Group,
JWT,
ListAPIKeysResponse,
Expand Down Expand Up @@ -237,6 +239,20 @@ export const unmarshalUser = (data: unknown): User => {
} as User
}

export const unmarshalEncodedJWT = (data: unknown): EncodedJWT => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'EncodedJWT' failed as data isn't a dictionary.`,
)
}

return {
jwt: data.jwt ? unmarshalJWT(data.jwt) : undefined,
renewToken: data.renew_token,
token: data.token,
} as EncodedJWT
}

export const unmarshalListAPIKeysResponse = (
data: unknown,
): ListAPIKeysResponse => {
Expand Down Expand Up @@ -500,6 +516,14 @@ export const marshalCreateGroupRequest = (
tags: request.tags,
})

export const marshalCreateJWTRequest = (
request: CreateJWTRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
referrer: request.referrer,
user_id: request.userId,
})

const marshalRuleSpecs = (
request: RuleSpecs,
defaults: DefaultValues,
Expand Down
16 changes: 16 additions & 0 deletions packages/clients/src/api/iam/v1alpha1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ export type CreateGroupRequest = {
tags?: string[]
}

export type CreateJWTRequest = {
/** ID of the user the JWT will be created for. */
userId: string
/** Referrer of the JWT. */
referrer: string
}

export type CreatePolicyRequest = {
/** Name of the policy to create (max length is 64 characters). */
name?: string
Expand Down Expand Up @@ -558,6 +565,15 @@ export type DeleteUserRequest = {
userId: string
}

export interface EncodedJWT {
/** The renewed JWT. */
jwt?: JWT
/** The encoded token of the renewed JWT. */
token: string
/** The encoded renew token. This token is necessary to renew the JWT. */
renewToken: string
}

export type GetAPIKeyRequest = {
/** Access key to search for. */
accessKey: string
Expand Down
Loading