Skip to content

feat(iam): add methods for public logs #957

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

Merged
merged 1 commit into from
Oct 26, 2023
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
45 changes: 45 additions & 0 deletions packages/clients/src/api/iam/v1alpha1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ import {
unmarshalListApplicationsResponse,
unmarshalListGroupsResponse,
unmarshalListJWTsResponse,
unmarshalListLogsResponse,
unmarshalListPermissionSetsResponse,
unmarshalListPoliciesResponse,
unmarshalListQuotaResponse,
unmarshalListRulesResponse,
unmarshalListSSHKeysResponse,
unmarshalListUsersResponse,
unmarshalLog,
unmarshalPolicy,
unmarshalQuotum,
unmarshalSSHKey,
Expand Down Expand Up @@ -67,6 +69,7 @@ import type {
GetApplicationRequest,
GetGroupRequest,
GetJWTRequest,
GetLogRequest,
GetPolicyRequest,
GetQuotumRequest,
GetSSHKeyRequest,
Expand All @@ -81,6 +84,8 @@ import type {
ListGroupsResponse,
ListJWTsRequest,
ListJWTsResponse,
ListLogsRequest,
ListLogsResponse,
ListPermissionSetsRequest,
ListPermissionSetsResponse,
ListPoliciesRequest,
Expand All @@ -93,6 +98,7 @@ import type {
ListSSHKeysResponse,
ListUsersRequest,
ListUsersResponse,
Log,
Policy,
Quotum,
RemoveGroupMemberRequest,
Expand Down Expand Up @@ -1151,4 +1157,43 @@ export class API extends ParentAPI {
method: 'DELETE',
path: `/iam/v1alpha1/jwts/${validatePathParam('jti', request.jti)}`,
})

protected pageOfListLogs = (request: Readonly<ListLogsRequest> = {}) =>
this.client.fetch<ListLogsResponse>(
{
method: 'GET',
path: `/iam/v1alpha1/logs`,
urlParams: urlParams(
['action', request.action ?? 'unknown_action'],
['created_after', request.createdAfter],
['created_before', request.createdBefore],
['order_by', request.orderBy ?? 'created_at_asc'],
[
'organization_id',
request.organizationId ??
this.client.settings.defaultOrganizationId,
],
['page', request.page],
[
'page_size',
request.pageSize ?? this.client.settings.defaultPageSize,
],
['resource_type', request.resourceType ?? 'unknown_resource_type'],
['search', request.search],
),
},
unmarshalListLogsResponse,
)

listLogs = (request: Readonly<ListLogsRequest> = {}) =>
enrichForPagination('logs', this.pageOfListLogs, request)

getLog = (request: Readonly<GetLogRequest>) =>
this.client.fetch<Log>(
{
method: 'GET',
path: `/iam/v1alpha1/logs/${validatePathParam('logId', request.logId)}`,
},
unmarshalLog,
)
}
7 changes: 7 additions & 0 deletions packages/clients/src/api/iam/v1alpha1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type {
GetApplicationRequest,
GetGroupRequest,
GetJWTRequest,
GetLogRequest,
GetPolicyRequest,
GetQuotumRequest,
GetSSHKeyRequest,
Expand All @@ -43,6 +44,9 @@ export type {
ListJWTsRequest,
ListJWTsRequestOrderBy,
ListJWTsResponse,
ListLogsRequest,
ListLogsRequestOrderBy,
ListLogsResponse,
ListPermissionSetsRequest,
ListPermissionSetsRequestOrderBy,
ListPermissionSetsResponse,
Expand All @@ -60,6 +64,9 @@ export type {
ListUsersRequest,
ListUsersRequestOrderBy,
ListUsersResponse,
Log,
LogAction,
LogResourceType,
PermissionSet,
PermissionSetScopeType,
Policy,
Expand Down
35 changes: 35 additions & 0 deletions packages/clients/src/api/iam/v1alpha1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import type {
ListApplicationsResponse,
ListGroupsResponse,
ListJWTsResponse,
ListLogsResponse,
ListPermissionSetsResponse,
ListPoliciesResponse,
ListQuotaResponse,
ListRulesResponse,
ListSSHKeysResponse,
ListUsersResponse,
Log,
PermissionSet,
Policy,
Quotum,
Expand Down Expand Up @@ -128,6 +130,26 @@ export const unmarshalJWT = (data: unknown) => {
} as JWT
}

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

return {
action: data.action,
bearerId: data.bearer_id,
createdAt: unmarshalDate(data.created_at),
id: data.id,
ip: data.ip,
organizationId: data.organization_id,
resourceId: data.resource_id,
resourceType: data.resource_type,
userAgent: data.user_agent,
} as Log
}

const unmarshalPermissionSet = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down Expand Up @@ -298,6 +320,19 @@ export const unmarshalListJWTsResponse = (data: unknown) => {
} as ListJWTsResponse
}

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

return {
logs: unmarshalArrayOfObject(data.logs, unmarshalLog),
totalCount: data.total_count,
} as ListLogsResponse
}

export const unmarshalListPermissionSetsResponse = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down
68 changes: 68 additions & 0 deletions packages/clients/src/api/iam/v1alpha1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export type ListJWTsRequestOrderBy =
| 'updated_at_asc'
| 'updated_at_desc'

export type ListLogsRequestOrderBy = 'created_at_asc' | 'created_at_desc'

export type ListPermissionSetsRequestOrderBy =
| 'name_asc'
| 'name_desc'
Expand Down Expand Up @@ -67,6 +69,16 @@ export type ListUsersRequestOrderBy =
| 'last_login_asc'
| 'last_login_desc'

export type LogAction = 'unknown_action' | 'created' | 'updated' | 'deleted'

export type LogResourceType =
| 'unknown_resource_type'
| 'api_key'
| 'user'
| 'application'
| 'group'
| 'policy'

export type PermissionSetScopeType =
| 'unknown_scope_type'
| 'projects'
Expand Down Expand Up @@ -200,6 +212,14 @@ export interface ListJWTsResponse {
totalCount: number
}

/** List logs response. */
export interface ListLogsResponse {
/** List of logs. */
logs: Log[]
/** Total count of logs. */
totalCount: number
}

/** List permission sets response. */
export interface ListPermissionSetsResponse {
/** List of permission sets. */
Expand Down Expand Up @@ -248,6 +268,28 @@ export interface ListUsersResponse {
totalCount: number
}

/** Log. */
export interface Log {
/** Log ID. */
id: string
/** Creation date of the log. */
createdAt?: Date
/** IP address of the HTTP request linked to the log. */
ip: string
/** User-Agent of the HTTP request linked to the log. */
userAgent: string
/** Action linked to the log. */
action: LogAction
/** ID of the principal at the origin of the log. */
bearerId: string
/** ID of Organization linked to the log. */
organizationId: string
/** Type of the resource linked to the log. */
resourceType: LogResourceType
/** ID of the resource linked to the log. */
resourceId: string
}

/** Permission set. */
export interface PermissionSet {
/** Id of the permission set. */
Expand Down Expand Up @@ -919,3 +961,29 @@ export type DeleteJWTRequest = {
/** JWT ID of the JWT to delete. */
jti: string
}

export type ListLogsRequest = {
/** Criteria for sorting results. */
orderBy?: ListLogsRequestOrderBy
/** Filter by Organization ID. */
organizationId?: string
/** Number of results per page. Value must be between 1 and 100. */
pageSize?: number
/** Page number. Value must be greater to 1. */
page?: number
/** Defined whether or not to filter out logs created after this timestamp. */
createdAfter?: Date
/** Defined whether or not to filter out logs created before this timestamp. */
createdBefore?: Date
/** Defined whether or not to filter out by a specific action. */
action?: LogAction
/** Defined whether or not to filter out by a specific type of resource. */
resourceType?: LogResourceType
/** Defined whether or not to filter out log by bearer ID or resource ID. */
search?: string
}

export type GetLogRequest = {
/** ID of the log. */
logId: string
}
10 changes: 10 additions & 0 deletions packages/clients/src/api/iam/v1alpha1/validation-rules.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ export const ListJWTsRequest = {
},
}

export const ListLogsRequest = {
page: {
greaterThan: 0,
},
pageSize: {
greaterThanOrEqual: 1,
lessThanOrEqual: 100,
},
}

export const ListPermissionSetsRequest = {
page: {
greaterThan: 0,
Expand Down