Skip to content

Commit 9ca66aa

Browse files
feat(audit_trail): add authentication events in public API (#2374)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 50278b2 commit 9ca66aa

File tree

6 files changed

+222
-33
lines changed

6 files changed

+222
-33
lines changed

packages_generated/audit_trail/src/v1alpha1/api.gen.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import {
99
validatePathParam,
1010
} from '@scaleway/sdk-client'
1111
import {
12+
unmarshalListAuthenticationEventsResponse,
1213
unmarshalListEventsResponse,
1314
unmarshalListProductsResponse,
1415
} from './marshalling.gen'
1516
import type {
17+
ListAuthenticationEventsRequest,
18+
ListAuthenticationEventsResponse,
1619
ListEventsRequest,
1720
ListEventsResponse,
1821
ListProductsRequest,
@@ -70,6 +73,38 @@ export class API extends ParentAPI {
7073
unmarshalListEventsResponse,
7174
)
7275

76+
/**
77+
* List authentication events. Retrieve the list of Audit Trail authentication events for a Scaleway Organization. You must specify the `organization_id`.
78+
*
79+
* @param request - The request {@link ListAuthenticationEventsRequest}
80+
* @returns A Promise of ListAuthenticationEventsResponse
81+
*/
82+
listAuthenticationEvents = (
83+
request: Readonly<ListAuthenticationEventsRequest> = {},
84+
) =>
85+
this.client.fetch<ListAuthenticationEventsResponse>(
86+
{
87+
method: 'GET',
88+
path: `/audit-trail/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/authentication-events`,
89+
urlParams: urlParams(
90+
['order_by', request.orderBy],
91+
[
92+
'organization_id',
93+
request.organizationId ??
94+
this.client.settings.defaultOrganizationId,
95+
],
96+
[
97+
'page_size',
98+
request.pageSize ?? this.client.settings.defaultPageSize,
99+
],
100+
['page_token', request.pageToken],
101+
['recorded_after', request.recordedAfter],
102+
['recorded_before', request.recordedBefore],
103+
),
104+
},
105+
unmarshalListAuthenticationEventsResponse,
106+
)
107+
73108
/**
74109
* Retrieve the list of Scaleway resources for which you have Audit Trail events.
75110
*

packages_generated/audit_trail/src/v1alpha1/index.gen.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ export type {
77
AccountProjectInfo,
88
AccountUserInfo,
99
AppleSiliconServerInfo,
10+
AuthenticationEvent,
11+
AuthenticationEventFailureReason,
12+
AuthenticationEventMethod,
13+
AuthenticationEventMFAType,
14+
AuthenticationEventOrigin,
15+
AuthenticationEventResult,
1016
BaremetalServerInfo,
1117
BaremetalSettingInfo,
1218
Event,
@@ -19,6 +25,9 @@ export type {
1925
KubernetesClusterInfo,
2026
KubernetesNodeInfo,
2127
KubernetesPoolInfo,
28+
ListAuthenticationEventsRequest,
29+
ListAuthenticationEventsRequestOrderBy,
30+
ListAuthenticationEventsResponse,
2231
ListEventsRequest,
2332
ListEventsRequestOrderBy,
2433
ListEventsResponse,

packages_generated/audit_trail/src/v1alpha1/marshalling.gen.ts

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
AccountProjectInfo,
1111
AccountUserInfo,
1212
AppleSiliconServerInfo,
13+
AuthenticationEvent,
1314
BaremetalServerInfo,
1415
BaremetalSettingInfo,
1516
Event,
@@ -22,6 +23,7 @@ import type {
2223
KubernetesClusterInfo,
2324
KubernetesNodeInfo,
2425
KubernetesPoolInfo,
26+
ListAuthenticationEventsResponse,
2527
ListEventsResponse,
2628
ListProductsResponse,
2729
LoadBalancerAclInfo,
@@ -323,30 +325,6 @@ const unmarshalSecretManagerSecretVersionInfo = (
323325
} as SecretManagerSecretVersionInfo
324326
}
325327

326-
const unmarshalEventPrincipal = (data: unknown): EventPrincipal => {
327-
if (!isJSONObject(data)) {
328-
throw new TypeError(
329-
`Unmarshalling the type 'EventPrincipal' failed as data isn't a dictionary.`,
330-
)
331-
}
332-
333-
return {
334-
id: data.id,
335-
} as EventPrincipal
336-
}
337-
338-
const unmarshalEventSystem = (data: unknown): EventSystem => {
339-
if (!isJSONObject(data)) {
340-
throw new TypeError(
341-
`Unmarshalling the type 'EventSystem' failed as data isn't a dictionary.`,
342-
)
343-
}
344-
345-
return {
346-
name: data.name,
347-
} as EventSystem
348-
}
349-
350328
export const unmarshalResource = (data: unknown): Resource => {
351329
if (!isJSONObject(data)) {
352330
throw new TypeError(
@@ -443,6 +421,68 @@ export const unmarshalResource = (data: unknown): Resource => {
443421
} as Resource
444422
}
445423

424+
const unmarshalAuthenticationEvent = (data: unknown): AuthenticationEvent => {
425+
if (!isJSONObject(data)) {
426+
throw new TypeError(
427+
`Unmarshalling the type 'AuthenticationEvent' failed as data isn't a dictionary.`,
428+
)
429+
}
430+
431+
return {
432+
countryCode: data.country_code ? data.country_code : undefined,
433+
failureReason: data.failure_reason ? data.failure_reason : undefined,
434+
id: data.id,
435+
method: data.method,
436+
mfaType: data.mfa_type ? data.mfa_type : undefined,
437+
organizationId: data.organization_id,
438+
origin: data.origin,
439+
recordedAt: unmarshalDate(data.recorded_at),
440+
resources: unmarshalArrayOfObject(data.resources, unmarshalResource),
441+
result: data.result,
442+
sourceIp: data.source_ip,
443+
userAgent: data.user_agent,
444+
} as AuthenticationEvent
445+
}
446+
447+
export const unmarshalListAuthenticationEventsResponse = (
448+
data: unknown,
449+
): ListAuthenticationEventsResponse => {
450+
if (!isJSONObject(data)) {
451+
throw new TypeError(
452+
`Unmarshalling the type 'ListAuthenticationEventsResponse' failed as data isn't a dictionary.`,
453+
)
454+
}
455+
456+
return {
457+
events: unmarshalArrayOfObject(data.events, unmarshalAuthenticationEvent),
458+
nextPageToken: data.next_page_token,
459+
} as ListAuthenticationEventsResponse
460+
}
461+
462+
const unmarshalEventPrincipal = (data: unknown): EventPrincipal => {
463+
if (!isJSONObject(data)) {
464+
throw new TypeError(
465+
`Unmarshalling the type 'EventPrincipal' failed as data isn't a dictionary.`,
466+
)
467+
}
468+
469+
return {
470+
id: data.id,
471+
} as EventPrincipal
472+
}
473+
474+
const unmarshalEventSystem = (data: unknown): EventSystem => {
475+
if (!isJSONObject(data)) {
476+
throw new TypeError(
477+
`Unmarshalling the type 'EventSystem' failed as data isn't a dictionary.`,
478+
)
479+
}
480+
481+
return {
482+
name: data.name,
483+
} as EventSystem
484+
}
485+
446486
export const unmarshalEvent = (data: unknown): Event => {
447487
if (!isJSONObject(data)) {
448488
throw new TypeError(

packages_generated/audit_trail/src/v1alpha1/types.gen.ts

Lines changed: 103 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
// This file was automatically generated. DO NOT EDIT.
22
// If you have any remark or suggestion do not hesitate to open an issue.
33
import type { Region as ScwRegion } from '@scaleway/sdk-client'
4+
import type { CountryCode as StdCountryCode } from '@scaleway/sdk-std'
5+
6+
export type AuthenticationEventFailureReason =
7+
| 'unknown_failure_reason'
8+
| 'invalid_mfa'
9+
| 'invalid_password'
10+
11+
export type AuthenticationEventMFAType = 'unknown_mfa_type' | 'totp'
12+
13+
export type AuthenticationEventMethod =
14+
| 'unknown_method'
15+
| 'password'
16+
| 'authentication_code'
17+
| 'oauth2'
18+
| 'saml'
19+
20+
export type AuthenticationEventOrigin =
21+
| 'unknown_origin'
22+
| 'public_api'
23+
| 'admin_api'
24+
25+
export type AuthenticationEventResult = 'unknown_result' | 'success' | 'failure'
26+
27+
export type ListAuthenticationEventsRequestOrderBy =
28+
| 'recorded_at_desc'
29+
| 'recorded_at_asc'
430

531
export type ListEventsRequestOrderBy = 'recorded_at_desc' | 'recorded_at_asc'
632

@@ -138,14 +164,6 @@ export interface SecretManagerSecretVersionInfo {
138164
revision: number
139165
}
140166

141-
export interface EventPrincipal {
142-
id: string
143-
}
144-
145-
export interface EventSystem {
146-
name: string
147-
}
148-
149167
export interface Resource {
150168
id: string
151169
type: ResourceType
@@ -284,11 +302,70 @@ export interface Resource {
284302
loadBalancerCertificateInfo?: LoadBalancerCertificateInfo
285303
}
286304

305+
export interface EventPrincipal {
306+
id: string
307+
}
308+
309+
export interface EventSystem {
310+
name: string
311+
}
312+
287313
export interface ProductService {
288314
name: string
289315
methods: string[]
290316
}
291317

318+
export interface AuthenticationEvent {
319+
/**
320+
* ID of the event.
321+
*/
322+
id: string
323+
/**
324+
* Timestamp of the event.
325+
*/
326+
recordedAt?: Date
327+
/**
328+
* Organization ID containing the event.
329+
*/
330+
organizationId: string
331+
/**
332+
* IP address at the origin of the event.
333+
*/
334+
sourceIp: string
335+
/**
336+
* User Agent at the origin of the event.
337+
*/
338+
userAgent?: string
339+
/**
340+
* Resources attached to the event.
341+
*/
342+
resources: Resource[]
343+
/**
344+
* Result of the authentication attempt.
345+
*/
346+
result: AuthenticationEventResult
347+
/**
348+
* (Optional) Reason for authentication failure.
349+
*/
350+
failureReason?: AuthenticationEventFailureReason
351+
/**
352+
* (Optional) ISO 3166-1 alpha-2 country code of the source IP.
353+
*/
354+
countryCode?: StdCountryCode
355+
/**
356+
* Authentication method used.
357+
*/
358+
method: AuthenticationEventMethod
359+
/**
360+
* Origin of the authentication attempt.
361+
*/
362+
origin: AuthenticationEventOrigin
363+
/**
364+
* (Optional) MFA type used for the authentication attempt.
365+
*/
366+
mfaType?: AuthenticationEventMFAType
367+
}
368+
292369
export interface Event {
293370
/**
294371
* ID of the event.
@@ -375,6 +452,24 @@ export interface Product {
375452
services: ProductService[]
376453
}
377454

455+
export type ListAuthenticationEventsRequest = {
456+
/**
457+
* Region to target. If none is passed will use default region from the config.
458+
*/
459+
region?: ScwRegion
460+
organizationId?: string
461+
recordedAfter?: Date
462+
recordedBefore?: Date
463+
orderBy?: ListAuthenticationEventsRequestOrderBy
464+
pageSize?: number
465+
pageToken?: string
466+
}
467+
468+
export interface ListAuthenticationEventsResponse {
469+
events: AuthenticationEvent[]
470+
nextPageToken?: string
471+
}
472+
378473
export type ListEventsRequest = {
379474
/**
380475
* Region to target. If none is passed will use default region from the config.

packages_generated/audit_trail/src/v1alpha1/validation-rules.gen.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// This file was automatically generated. DO NOT EDIT.
22
// If you have any remark or suggestion do not hesitate to open an issue.
33

4+
export const ListAuthenticationEventsRequest = {
5+
pageSize: {
6+
greaterThanOrEqual: 1,
7+
lessThanOrEqual: 1000,
8+
},
9+
}
10+
411
export const ListEventsRequest = {
512
methodName: {
613
pattern: /^[a-zA-Z][a-zA-Z0-9_]*$/,
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
// This file was automatically generated. DO NOT EDIT.
22
// If you have any remark or suggestion do not hesitate to open an issue.
3-
export type { LanguageCode } from './types.gen'
3+
export type {
4+
CountryCode,
5+
LanguageCode,
6+
} from './types.gen'

0 commit comments

Comments
 (0)