Skip to content

Commit e60bb9e

Browse files
authored
feat(lb): add redirect acl (#400)
1 parent c45a5d8 commit e60bb9e

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

packages/clients/src/api/lb/v1/index.gen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export * from './content.gen'
55
export type {
66
Acl,
77
AclAction,
8+
AclActionRedirect,
9+
AclActionRedirectRedirectType,
810
AclActionType,
911
AclHttpFilter,
1012
AclMatch,

packages/clients/src/api/lb/v1/marshalling.gen.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { DefaultValues } from '../../../bridge'
1111
import type {
1212
Acl,
1313
AclAction,
14+
AclActionRedirect,
1415
AclMatch,
1516
AclSpec,
1617
AddBackendServersRequest,
@@ -328,6 +329,20 @@ export const unmarshalLb = (data: unknown) => {
328329
} as Lb
329330
}
330331

332+
const unmarshalAclActionRedirect = (data: unknown) => {
333+
if (!isJSONObject(data)) {
334+
throw new TypeError(
335+
`Unmarshalling the type 'AclActionRedirect' failed as data isn't a dictionary.`,
336+
)
337+
}
338+
339+
return {
340+
code: data.code,
341+
target: data.target,
342+
type: data.type,
343+
} as AclActionRedirect
344+
}
345+
331346
export const unmarshalBackend = (data: unknown) => {
332347
if (!isJSONObject(data)) {
333348
throw new TypeError(
@@ -393,7 +408,12 @@ const unmarshalAclAction = (data: unknown) => {
393408
)
394409
}
395410

396-
return { type: data.type } as AclAction
411+
return {
412+
redirect: data.redirect
413+
? unmarshalAclActionRedirect(data.redirect)
414+
: undefined,
415+
type: data.type,
416+
} as AclAction
397417
}
398418

399419
const unmarshalAclMatch = (data: unknown) => {
@@ -738,10 +758,22 @@ export const unmarshalSetAclsResponse = (data: unknown) => {
738758
} as SetAclsResponse
739759
}
740760

761+
const marshalAclActionRedirect = (
762+
request: AclActionRedirect,
763+
defaults: DefaultValues,
764+
): Record<string, unknown> => ({
765+
code: request.code,
766+
target: request.target,
767+
type: request.type,
768+
})
769+
741770
const marshalAclAction = (
742771
request: AclAction,
743772
defaults: DefaultValues,
744773
): Record<string, unknown> => ({
774+
redirect: request.redirect
775+
? marshalAclActionRedirect(request.redirect, defaults)
776+
: undefined,
745777
type: request.type,
746778
})
747779

packages/clients/src/api/lb/v1/types.gen.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// If you have any remark or suggestion do not hesitate to open an issue.
33
import type { Region, Zone } from '../../../bridge'
44

5-
export type AclActionType = 'allow' | 'deny'
5+
export type AclActionRedirectRedirectType = 'location' | 'scheme'
6+
7+
export type AclActionType = 'allow' | 'deny' | 'redirect'
68

79
export type AclHttpFilter =
810
| 'acl_http_filter_none'
@@ -164,6 +166,33 @@ export interface Acl {
164166
export interface AclAction {
165167
/** The action type */
166168
type: AclActionType
169+
/** Redirect parameters when using an ACL with `redirect` action */
170+
redirect?: AclActionRedirect
171+
}
172+
173+
/** Acl action redirect */
174+
export interface AclActionRedirect {
175+
/** Redirect type */
176+
type: AclActionRedirectRedirectType
177+
/**
178+
* An URL can be used in case of a location redirect (e.g.
179+
* `https://scaleway.com` will redirect to this same URL). A scheme name (e.g.
180+
* `https`, `http`, `ftp`, `git`) will replace the request's original scheme.
181+
* This can be useful to implement HTTP to HTTPS redirects. Placeholders can
182+
* be used when using a `location` redirect in order to insert original
183+
* request's parts, these are:
184+
*
185+
* - `{{ host }}` for the current request's Host header
186+
* - `{{ query }}` for the current request's query string
187+
* - `{{ path }}` for the current request's URL path
188+
* - `{{ scheme }}` for the current request's scheme
189+
*/
190+
target: string
191+
/**
192+
* HTTP redirect code to use. Valid values are 301, 302, 303, 307 and 308.
193+
* Default value is 302
194+
*/
195+
code?: number
167196
}
168197

169198
/** Acl match */

0 commit comments

Comments
 (0)