Skip to content
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
12 changes: 7 additions & 5 deletions libs/backend-apisix-standalone/src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,18 @@ export const toADC = (input: typing.APISIXStandalone) => {
id: ssl.id,
labels: ssl.labels,
type: ssl.type,
snis: ssl.snis!,
snis: ssl.snis,
certificates: [
{
certificate: ssl.cert,
key: ssl.key,
},
...(ssl.certs ?? []).map((cert, idx) => ({
certificate: cert,
key: ssl.keys![idx],
})),
...(ssl.certs && ssl.keys
? ssl.certs.map((cert, idx) => ({
certificate: cert,
key: ssl.keys?.[idx],
}))
: []),
] as Array<ADCSDK.SSLCertificate>,
client: ssl.client,
ssl_protocols: ssl.ssl_protocols,
Expand Down
6 changes: 4 additions & 2 deletions libs/backend-apisix-standalone/src/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const SSLSchema = z
labels: Metadata.labels,

type: z.union([z.literal('server'), z.literal('client')]).optional(),
snis: z.array(z.string()).min(1).optional(),
snis: z.array(z.string()).min(1),
cert: z.string(),
key: z.string(),
certs: z.array(z.string()).optional(),
Expand All @@ -224,7 +224,9 @@ const SSLSchema = z
skip_mtls_uri_regex: z.array(z.string()).optional(),
})
.optional(),
ssl_protocols: z.array(z.string()).optional(),
ssl_protocols: z
.array(z.enum(['TLSv1.1', 'TLSv1.2', 'TLSv1.3']))
.optional(),
status: Status.optional(),
})
.extend(ModifiedIndex);
Expand Down
270 changes: 36 additions & 234 deletions libs/sdk/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,175 +1,44 @@
import { ResourceType } from './resource';
import {
Consumer,
ConsumerCredential,
GlobalRule,
Labels,
PluginMetadata,
Plugins,
Route,
SSL,
Service,
StreamRoute,
Upstream,
} from './schema';

export * from './differ';
export * from './resource';

export type Labels = Record<string, string | Array<string>>;
export type Plugin = Record<string, unknown>;
export type Plugins = Record<string, Plugin>;
export type Expr = Array<unknown>;

export interface Route {
id?: string;
name: string;
description?: string;
labels?: Labels;

hosts?: Array<string>;
uris: Array<string>;
priority?: number;
timeout?: UpstreamTimeout;
vars?: Expr;
methods?: Array<string>;
enable_websocket?: boolean;
remote_addrs?: Array<string>;
plugins?: Plugins;
filter_func?: string;
service_id?: string;

metadata?: ResourceMetadata;
}

export interface Service {
id?: string;
name: string;
description?: string;
labels?: Labels;

upstream?: Upstream;
upstreams?: Array<Upstream>;
plugins?: Plugins;
path_prefix?: string;
strip_path_prefix?: boolean;
hosts?: Array<string>;

routes?: Array<Route>;
stream_routes?: Array<StreamRoute>;

metadata?: ResourceMetadata;
}

export type UpstreamBalancer = 'roundrobin' | 'chash' | 'least_conn' | 'ewma';
export type UpstreamScheme =
| 'grpc'
| 'grpcs'
| 'http'
| 'https'
| 'tcp'
| 'tls'
| 'udp'
| 'kafka';
export type UpstreamPassHost = 'pass' | 'node' | 'rewrite';
export interface UpstreamNode {
host: string;
port: number;
weight: number;
priority?: number;
metadata?: { [key: string]: unknown };
}
export interface UpstreamTimeout {
connect: number;
send: number;
read: number;
}
export interface UpstreamClientTLS {
client_cert?: string;
client_key?: string;
client_cert_id?: string;
verify?: boolean;
}
export interface UpstreamKeepalivePool {
size: number;
idle_timeout: number;
requests: number;
}
export interface UpstreamHealthCheck {
active?: UpstreamHealthCheckActive;
passive?: UpstreamHealthCheckPassive;
}
export interface UpstreamHealthCheckActive {
type?: 'http' | 'https' | 'tcp';
timeout?: number;
concurrency?: number;
host?: string;
port?: number;
http_path?: string;
https_verify_cert?: boolean;
http_request_headers?: Array<string>;
healthy?: UpstreamHealthCheckActiveHealthy;
unhealthy?: UpstreamHealthCheckActiveUnhealthy;
}
export interface UpstreamHealthCheckPassive {
type?: 'http' | 'https' | 'tcp';
healthy?: UpstreamHealthCheckPassiveHealthy;
unhealthy?: UpstreamHealthCheckPassiveUnhealthy;
}
export interface UpstreamHealthCheckPassiveHealthy {
http_statuses?: Array<number>;
successes?: number;
}
export interface UpstreamHealthCheckPassiveUnhealthy {
http_statuses?: Array<number>;
http_failures?: number;
tcp_failures?: number;
timeouts?: number;
}

export type UpstreamHealthCheckActiveHealthy = {
interval: number;
} & UpstreamHealthCheckPassiveHealthy;
export type UpstreamHealthCheckActiveUnhealthy = {
interval: number;
} & UpstreamHealthCheckPassiveUnhealthy;

export interface Upstream {
id?: string;
name?: string;
description?: string;
labels?: Labels;

type?: UpstreamBalancer;
hash_on?: string;
key?: string;
checks?: UpstreamHealthCheck;
nodes?: Array<UpstreamNode>;
scheme?: UpstreamScheme;
retries?: number;
retry_timeout?: number;
timeout?: UpstreamTimeout;
tls?: UpstreamClientTLS;
keepalive_pool?: UpstreamKeepalivePool;
pass_host?: UpstreamPassHost;
upstream_host?: string;

service_name?: string;
discovery_type?: string;
discovery_args?: Record<string, unknown>;

metadata?: ResourceMetadata;
}

export type SSLType = 'server' | 'client';
export interface SSLClientMTLS {
ca: string;
depth: number;
skip_mtls_uri_regex?: Array<string>;
}
export interface SSLCertificate {
certificate: string;
key: string;
}
export interface SSL {
id?: string;
labels?: Labels;

type?: SSLType;
snis: Array<string>;
certificates: Array<SSLCertificate>;
client?: SSLClientMTLS;
ssl_protocols?: Array<string>;

metadata?: ResourceMetadata;
}
export type {
Labels,
Plugin,
Plugins,
Expr,
Route,
Service,
UpstreamBalancer,
UpstreamScheme,
UpstreamPassHost,
UpstreamNode,
UpstreamTimeout,
Upstream,
SSLCertificate,
SSL,
GlobalRule,
PluginMetadata,
ConsumerCredential,
Consumer,
StreamRoute,
Configuration,
InternalConfiguration,
} from './schema';

export interface PluginConfig {
id?: string;
Expand All @@ -178,34 +47,6 @@ export interface PluginConfig {
labels?: Labels;

plugins: Plugins;

metadata?: ResourceMetadata;
}

export type GlobalRule = Record<string, unknown>;

export type PluginMetadata = Record<string, unknown>;

export interface ConsumerCredential {
id?: string;
name: string;
description?: string;
labels?: Labels;

type: 'key-auth' | 'basic-auth' | 'jwt-auth' | 'hmac-auth';

config: Plugin;

metadata?: ResourceMetadata;
}

export interface Consumer {
username: string;
description?: string;
labels?: Labels;

plugins?: Plugins;
credentials?: Array<ConsumerCredential>;
}

export interface ConsumerGroup {
Expand All @@ -217,45 +58,6 @@ export interface ConsumerGroup {
plugins: Plugins;

consumers?: Array<Consumer>;

metadata?: ResourceMetadata;
}

export interface StreamRoute {
id?: string;
name: string;
description?: string;
labels?: Labels;

plugins?: Plugins;

remote_addr?: string;
server_addr?: string;
server_port?: number;
sni?: string;

metadata?: ResourceMetadata;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ResourceMetadata {}

export interface Configuration {
services?: Array<Service>;
ssls?: Array<SSL>;
consumers?: Array<Consumer>;

// object format resources
global_rules?: Record<string, GlobalRule>;
plugin_metadata?: Record<string, PluginMetadata>;

// internal use only
routes?: Array<Route>;
stream_routes?: Array<StreamRoute>;
consumer_credentials?: Array<ConsumerCredential>;
upstreams?: Array<Upstream>;
/* consumer_groups?: Array<ConsumerGroup>;
plugin_configs?: Array<PluginConfig>; */
}

export type ResourceFor<T extends ResourceType> = T extends ResourceType.SERVICE
Expand Down
Loading
Loading