Skip to content

Commit 84a7095

Browse files
authored
feat(iam): add methods for public logs (#957)
1 parent 3ad21cb commit 84a7095

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ import {
3232
unmarshalListApplicationsResponse,
3333
unmarshalListGroupsResponse,
3434
unmarshalListJWTsResponse,
35+
unmarshalListLogsResponse,
3536
unmarshalListPermissionSetsResponse,
3637
unmarshalListPoliciesResponse,
3738
unmarshalListQuotaResponse,
3839
unmarshalListRulesResponse,
3940
unmarshalListSSHKeysResponse,
4041
unmarshalListUsersResponse,
42+
unmarshalLog,
4143
unmarshalPolicy,
4244
unmarshalQuotum,
4345
unmarshalSSHKey,
@@ -67,6 +69,7 @@ import type {
6769
GetApplicationRequest,
6870
GetGroupRequest,
6971
GetJWTRequest,
72+
GetLogRequest,
7073
GetPolicyRequest,
7174
GetQuotumRequest,
7275
GetSSHKeyRequest,
@@ -81,6 +84,8 @@ import type {
8184
ListGroupsResponse,
8285
ListJWTsRequest,
8386
ListJWTsResponse,
87+
ListLogsRequest,
88+
ListLogsResponse,
8489
ListPermissionSetsRequest,
8590
ListPermissionSetsResponse,
8691
ListPoliciesRequest,
@@ -93,6 +98,7 @@ import type {
9398
ListSSHKeysResponse,
9499
ListUsersRequest,
95100
ListUsersResponse,
101+
Log,
96102
Policy,
97103
Quotum,
98104
RemoveGroupMemberRequest,
@@ -1151,4 +1157,43 @@ export class API extends ParentAPI {
11511157
method: 'DELETE',
11521158
path: `/iam/v1alpha1/jwts/${validatePathParam('jti', request.jti)}`,
11531159
})
1160+
1161+
protected pageOfListLogs = (request: Readonly<ListLogsRequest> = {}) =>
1162+
this.client.fetch<ListLogsResponse>(
1163+
{
1164+
method: 'GET',
1165+
path: `/iam/v1alpha1/logs`,
1166+
urlParams: urlParams(
1167+
['action', request.action ?? 'unknown_action'],
1168+
['created_after', request.createdAfter],
1169+
['created_before', request.createdBefore],
1170+
['order_by', request.orderBy ?? 'created_at_asc'],
1171+
[
1172+
'organization_id',
1173+
request.organizationId ??
1174+
this.client.settings.defaultOrganizationId,
1175+
],
1176+
['page', request.page],
1177+
[
1178+
'page_size',
1179+
request.pageSize ?? this.client.settings.defaultPageSize,
1180+
],
1181+
['resource_type', request.resourceType ?? 'unknown_resource_type'],
1182+
['search', request.search],
1183+
),
1184+
},
1185+
unmarshalListLogsResponse,
1186+
)
1187+
1188+
listLogs = (request: Readonly<ListLogsRequest> = {}) =>
1189+
enrichForPagination('logs', this.pageOfListLogs, request)
1190+
1191+
getLog = (request: Readonly<GetLogRequest>) =>
1192+
this.client.fetch<Log>(
1193+
{
1194+
method: 'GET',
1195+
path: `/iam/v1alpha1/logs/${validatePathParam('logId', request.logId)}`,
1196+
},
1197+
unmarshalLog,
1198+
)
11541199
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type {
2525
GetApplicationRequest,
2626
GetGroupRequest,
2727
GetJWTRequest,
28+
GetLogRequest,
2829
GetPolicyRequest,
2930
GetQuotumRequest,
3031
GetSSHKeyRequest,
@@ -43,6 +44,9 @@ export type {
4344
ListJWTsRequest,
4445
ListJWTsRequestOrderBy,
4546
ListJWTsResponse,
47+
ListLogsRequest,
48+
ListLogsRequestOrderBy,
49+
ListLogsResponse,
4650
ListPermissionSetsRequest,
4751
ListPermissionSetsRequestOrderBy,
4852
ListPermissionSetsResponse,
@@ -60,6 +64,9 @@ export type {
6064
ListUsersRequest,
6165
ListUsersRequestOrderBy,
6266
ListUsersResponse,
67+
Log,
68+
LogAction,
69+
LogResourceType,
6370
PermissionSet,
6471
PermissionSetScopeType,
6572
Policy,

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ import type {
2525
ListApplicationsResponse,
2626
ListGroupsResponse,
2727
ListJWTsResponse,
28+
ListLogsResponse,
2829
ListPermissionSetsResponse,
2930
ListPoliciesResponse,
3031
ListQuotaResponse,
3132
ListRulesResponse,
3233
ListSSHKeysResponse,
3334
ListUsersResponse,
35+
Log,
3436
PermissionSet,
3537
Policy,
3638
Quotum,
@@ -128,6 +130,26 @@ export const unmarshalJWT = (data: unknown) => {
128130
} as JWT
129131
}
130132

133+
export const unmarshalLog = (data: unknown) => {
134+
if (!isJSONObject(data)) {
135+
throw new TypeError(
136+
`Unmarshalling the type 'Log' failed as data isn't a dictionary.`,
137+
)
138+
}
139+
140+
return {
141+
action: data.action,
142+
bearerId: data.bearer_id,
143+
createdAt: unmarshalDate(data.created_at),
144+
id: data.id,
145+
ip: data.ip,
146+
organizationId: data.organization_id,
147+
resourceId: data.resource_id,
148+
resourceType: data.resource_type,
149+
userAgent: data.user_agent,
150+
} as Log
151+
}
152+
131153
const unmarshalPermissionSet = (data: unknown) => {
132154
if (!isJSONObject(data)) {
133155
throw new TypeError(
@@ -298,6 +320,19 @@ export const unmarshalListJWTsResponse = (data: unknown) => {
298320
} as ListJWTsResponse
299321
}
300322

323+
export const unmarshalListLogsResponse = (data: unknown) => {
324+
if (!isJSONObject(data)) {
325+
throw new TypeError(
326+
`Unmarshalling the type 'ListLogsResponse' failed as data isn't a dictionary.`,
327+
)
328+
}
329+
330+
return {
331+
logs: unmarshalArrayOfObject(data.logs, unmarshalLog),
332+
totalCount: data.total_count,
333+
} as ListLogsResponse
334+
}
335+
301336
export const unmarshalListPermissionSetsResponse = (data: unknown) => {
302337
if (!isJSONObject(data)) {
303338
throw new TypeError(

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export type ListJWTsRequestOrderBy =
3535
| 'updated_at_asc'
3636
| 'updated_at_desc'
3737

38+
export type ListLogsRequestOrderBy = 'created_at_asc' | 'created_at_desc'
39+
3840
export type ListPermissionSetsRequestOrderBy =
3941
| 'name_asc'
4042
| 'name_desc'
@@ -67,6 +69,16 @@ export type ListUsersRequestOrderBy =
6769
| 'last_login_asc'
6870
| 'last_login_desc'
6971

72+
export type LogAction = 'unknown_action' | 'created' | 'updated' | 'deleted'
73+
74+
export type LogResourceType =
75+
| 'unknown_resource_type'
76+
| 'api_key'
77+
| 'user'
78+
| 'application'
79+
| 'group'
80+
| 'policy'
81+
7082
export type PermissionSetScopeType =
7183
| 'unknown_scope_type'
7284
| 'projects'
@@ -200,6 +212,14 @@ export interface ListJWTsResponse {
200212
totalCount: number
201213
}
202214

215+
/** List logs response. */
216+
export interface ListLogsResponse {
217+
/** List of logs. */
218+
logs: Log[]
219+
/** Total count of logs. */
220+
totalCount: number
221+
}
222+
203223
/** List permission sets response. */
204224
export interface ListPermissionSetsResponse {
205225
/** List of permission sets. */
@@ -248,6 +268,28 @@ export interface ListUsersResponse {
248268
totalCount: number
249269
}
250270

271+
/** Log. */
272+
export interface Log {
273+
/** Log ID. */
274+
id: string
275+
/** Creation date of the log. */
276+
createdAt?: Date
277+
/** IP address of the HTTP request linked to the log. */
278+
ip: string
279+
/** User-Agent of the HTTP request linked to the log. */
280+
userAgent: string
281+
/** Action linked to the log. */
282+
action: LogAction
283+
/** ID of the principal at the origin of the log. */
284+
bearerId: string
285+
/** ID of Organization linked to the log. */
286+
organizationId: string
287+
/** Type of the resource linked to the log. */
288+
resourceType: LogResourceType
289+
/** ID of the resource linked to the log. */
290+
resourceId: string
291+
}
292+
251293
/** Permission set. */
252294
export interface PermissionSet {
253295
/** Id of the permission set. */
@@ -919,3 +961,29 @@ export type DeleteJWTRequest = {
919961
/** JWT ID of the JWT to delete. */
920962
jti: string
921963
}
964+
965+
export type ListLogsRequest = {
966+
/** Criteria for sorting results. */
967+
orderBy?: ListLogsRequestOrderBy
968+
/** Filter by Organization ID. */
969+
organizationId?: string
970+
/** Number of results per page. Value must be between 1 and 100. */
971+
pageSize?: number
972+
/** Page number. Value must be greater to 1. */
973+
page?: number
974+
/** Defined whether or not to filter out logs created after this timestamp. */
975+
createdAfter?: Date
976+
/** Defined whether or not to filter out logs created before this timestamp. */
977+
createdBefore?: Date
978+
/** Defined whether or not to filter out by a specific action. */
979+
action?: LogAction
980+
/** Defined whether or not to filter out by a specific type of resource. */
981+
resourceType?: LogResourceType
982+
/** Defined whether or not to filter out log by bearer ID or resource ID. */
983+
search?: string
984+
}
985+
986+
export type GetLogRequest = {
987+
/** ID of the log. */
988+
logId: string
989+
}

packages/clients/src/api/iam/v1alpha1/validation-rules.gen.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ export const ListJWTsRequest = {
112112
},
113113
}
114114

115+
export const ListLogsRequest = {
116+
page: {
117+
greaterThan: 0,
118+
},
119+
pageSize: {
120+
greaterThanOrEqual: 1,
121+
lessThanOrEqual: 100,
122+
},
123+
}
124+
115125
export const ListPermissionSetsRequest = {
116126
page: {
117127
greaterThan: 0,

0 commit comments

Comments
 (0)