mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 09:18:31 +02:00
Feat/auto schemas (#48)
* use auto generated schemas * go version bump and dependencies upgrade * clarify some error messages --------- Co-authored-by: yusing <yusing@6uo.me>
This commit is contained in:
1228
schemas/config.schema.json
Normal file
1228
schemas/config.schema.json
Normal file
File diff suppressed because it is too large
Load Diff
66
schemas/config/access_log.ts
Normal file
66
schemas/config/access_log.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { CIDR, HTTPHeader, HTTPMethod, StatusCodeRange, URI } from "../types";
|
||||
|
||||
export const ACCESS_LOG_FORMATS = ["combined", "common", "json"] as const;
|
||||
|
||||
export type AccessLogFormat = (typeof ACCESS_LOG_FORMATS)[number];
|
||||
|
||||
export type AccessLogConfig = {
|
||||
/**
|
||||
* The size of the buffer.
|
||||
*
|
||||
* @minimum 0
|
||||
* @default 65536
|
||||
* @TJS-type integer
|
||||
*/
|
||||
buffer_size?: number;
|
||||
/** The format of the access log.
|
||||
*
|
||||
* @default "combined"
|
||||
*/
|
||||
format?: AccessLogFormat;
|
||||
/* The path to the access log file. */
|
||||
path: URI;
|
||||
/* The access log filters. */
|
||||
filters?: AccessLogFilters;
|
||||
/* The access log fields. */
|
||||
fields?: AccessLogFields;
|
||||
};
|
||||
|
||||
export type AccessLogFilter<T> = {
|
||||
/** Whether the filter is negative.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
negative?: boolean;
|
||||
/* The values to filter. */
|
||||
values: T[];
|
||||
};
|
||||
|
||||
export type AccessLogFilters = {
|
||||
/* Status code filter. */
|
||||
status_code?: AccessLogFilter<StatusCodeRange>;
|
||||
/* Method filter. */
|
||||
method?: AccessLogFilter<HTTPMethod>;
|
||||
/* Host filter. */
|
||||
host?: AccessLogFilter<string>;
|
||||
/* Header filter. */
|
||||
headers?: AccessLogFilter<HTTPHeader>;
|
||||
/* CIDR filter. */
|
||||
cidr?: AccessLogFilter<CIDR>;
|
||||
};
|
||||
|
||||
export const ACCESS_LOG_FIELD_MODES = ["keep", "drop", "redact"] as const;
|
||||
export type AccessLogFieldMode = (typeof ACCESS_LOG_FIELD_MODES)[number];
|
||||
|
||||
export type AccessLogField = {
|
||||
default?: AccessLogFieldMode;
|
||||
config: {
|
||||
[key: string]: AccessLogFieldMode;
|
||||
};
|
||||
};
|
||||
|
||||
export type AccessLogFields = {
|
||||
header?: AccessLogField;
|
||||
query?: AccessLogField;
|
||||
cookie?: AccessLogField;
|
||||
};
|
||||
91
schemas/config/autocert.ts
Normal file
91
schemas/config/autocert.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { DomainOrWildcards as DomainsOrWildcards, Email } from "../types";
|
||||
|
||||
export const AUTOCERT_PROVIDERS = [
|
||||
"local",
|
||||
"cloudflare",
|
||||
"clouddns",
|
||||
"duckdns",
|
||||
"ovh",
|
||||
] as const;
|
||||
|
||||
export type AutocertProvider = (typeof AUTOCERT_PROVIDERS)[number];
|
||||
|
||||
export type AutocertConfig =
|
||||
| LocalOptions
|
||||
| CloudflareOptions
|
||||
| CloudDNSOptions
|
||||
| DuckDNSOptions
|
||||
| OVHOptionsWithAppKey
|
||||
| OVHOptionsWithOAuth2Config;
|
||||
|
||||
export interface AutocertConfigBase {
|
||||
/* ACME email */
|
||||
email: Email;
|
||||
/* ACME domains */
|
||||
domains: DomainsOrWildcards;
|
||||
/* ACME certificate path */
|
||||
cert_path?: string;
|
||||
/* ACME key path */
|
||||
key_path?: string;
|
||||
}
|
||||
|
||||
export interface LocalOptions extends AutocertConfigBase {
|
||||
provider: "local";
|
||||
}
|
||||
|
||||
export interface CloudflareOptions extends AutocertConfigBase {
|
||||
provider: "cloudflare";
|
||||
options: { auth_token: string };
|
||||
}
|
||||
|
||||
export interface CloudDNSOptions extends AutocertConfigBase {
|
||||
provider: "clouddns";
|
||||
options: {
|
||||
client_id: string;
|
||||
email: Email;
|
||||
password: string;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export interface DuckDNSOptions extends AutocertConfigBase {
|
||||
provider: "duckdns";
|
||||
options: {
|
||||
token: string;
|
||||
};
|
||||
}
|
||||
|
||||
export const OVH_ENDPOINTS = [
|
||||
"ovh-eu",
|
||||
"ovh-ca",
|
||||
"ovh-us",
|
||||
"kimsufi-eu",
|
||||
"kimsufi-ca",
|
||||
"soyoustart-eu",
|
||||
"soyoustart-ca",
|
||||
] as const;
|
||||
|
||||
export type OVHEndpoint = (typeof OVH_ENDPOINTS)[number];
|
||||
|
||||
export interface OVHOptionsWithAppKey extends AutocertConfigBase {
|
||||
provider: "ovh";
|
||||
options: {
|
||||
application_secret: string;
|
||||
consumer_key: string;
|
||||
api_endpoint?: OVHEndpoint;
|
||||
application_key: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface OVHOptionsWithOAuth2Config extends AutocertConfigBase {
|
||||
provider: "ovh";
|
||||
options: {
|
||||
application_secret: string;
|
||||
consumer_key: string;
|
||||
api_endpoint?: OVHEndpoint;
|
||||
oauth2_config: {
|
||||
client_id: string;
|
||||
client_secret: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
52
schemas/config/config.ts
Normal file
52
schemas/config/config.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { DomainNames } from "../types";
|
||||
import { AutocertConfig } from "./autocert";
|
||||
import { EntrypointConfig } from "./entrypoint";
|
||||
import { HomepageConfig } from "./homepage";
|
||||
import { Providers } from "./providers";
|
||||
|
||||
export type Config = {
|
||||
/** Optional autocert configuration
|
||||
*
|
||||
* @examples require(".").autocertExamples
|
||||
*/
|
||||
autocert?: AutocertConfig;
|
||||
/* Optional entrypoint configuration */
|
||||
entrypoint?: EntrypointConfig;
|
||||
/* Providers configuration (include file, docker, notification) */
|
||||
providers: Providers;
|
||||
/** Optional list of domains to match
|
||||
*
|
||||
* @minItems 1
|
||||
* @examples require(".").matchDomainsExamples
|
||||
*/
|
||||
match_domains?: DomainNames;
|
||||
/* Optional homepage configuration */
|
||||
homepage?: HomepageConfig;
|
||||
/**
|
||||
* Optional timeout before shutdown
|
||||
* @default 3
|
||||
* @minimum 1
|
||||
*/
|
||||
timeout_shutdown?: number;
|
||||
};
|
||||
|
||||
export const autocertExamples = [
|
||||
{ provider: "local" },
|
||||
{
|
||||
provider: "cloudflare",
|
||||
email: "abc@gmail",
|
||||
domains: ["example.com"],
|
||||
options: { auth_token: "c1234565789-abcdefghijklmnopqrst" },
|
||||
},
|
||||
{
|
||||
provider: "clouddns",
|
||||
email: "abc@gmail",
|
||||
domains: ["example.com"],
|
||||
options: {
|
||||
client_id: "c1234565789",
|
||||
email: "abc@gmail",
|
||||
password: "password",
|
||||
},
|
||||
},
|
||||
];
|
||||
export const matchDomainsExamples = ["example.com", "*.example.com"] as const;
|
||||
47
schemas/config/entrypoint.ts
Normal file
47
schemas/config/entrypoint.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { MiddlewareCompose } from "../middlewares/middleware_compose";
|
||||
import { AccessLogConfig } from "./access_log";
|
||||
|
||||
export type EntrypointConfig = {
|
||||
/** Entrypoint middleware configuration
|
||||
*
|
||||
* @examples require(".").middlewaresExamples
|
||||
*/
|
||||
middlewares: MiddlewareCompose;
|
||||
/** Entrypoint access log configuration
|
||||
*
|
||||
* @examples require(".").accessLogExamples
|
||||
*/
|
||||
access_log?: AccessLogConfig;
|
||||
};
|
||||
|
||||
export const accessLogExamples = [
|
||||
{
|
||||
path: "/var/log/access.log",
|
||||
format: "combined",
|
||||
filters: {
|
||||
status_codes: {
|
||||
values: ["200-299"],
|
||||
},
|
||||
},
|
||||
fields: {
|
||||
headers: {
|
||||
default: "keep",
|
||||
config: {
|
||||
foo: "redact",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
] as const;
|
||||
|
||||
export const middlewaresExamples = [
|
||||
{
|
||||
use: "RedirectHTTP",
|
||||
},
|
||||
{
|
||||
use: "CIDRWhitelist",
|
||||
allow: ["127.0.0.1", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"],
|
||||
status: 403,
|
||||
message: "Forbidden",
|
||||
},
|
||||
] as const;
|
||||
7
schemas/config/homepage.ts
Normal file
7
schemas/config/homepage.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export type HomepageConfig = {
|
||||
/**
|
||||
* Use default app categories (uses docker image name)
|
||||
* @default true
|
||||
*/
|
||||
use_default_categories: boolean;
|
||||
};
|
||||
67
schemas/config/notification.ts
Normal file
67
schemas/config/notification.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { URL } from "../types";
|
||||
|
||||
export const NOTIFICATION_PROVIDERS = ["webhook", "gotify"] as const;
|
||||
|
||||
export type NotificationProvider = (typeof NOTIFICATION_PROVIDERS)[number];
|
||||
|
||||
export type NotificationConfig = {
|
||||
/* Name of the notification provider */
|
||||
name: string;
|
||||
/* URL of the notification provider */
|
||||
url: URL;
|
||||
};
|
||||
|
||||
export interface GotifyConfig extends NotificationConfig {
|
||||
provider: "gotify";
|
||||
/* Gotify token */
|
||||
token: string;
|
||||
}
|
||||
|
||||
export const WEBHOOK_TEMPLATES = ["discord"] as const;
|
||||
export const WEBHOOK_METHODS = ["POST", "GET", "PUT"] as const;
|
||||
export const WEBHOOK_MIME_TYPES = [
|
||||
"application/json",
|
||||
"application/x-www-form-urlencoded",
|
||||
"text/plain",
|
||||
] as const;
|
||||
export const WEBHOOK_COLOR_MODES = ["hex", "dec"] as const;
|
||||
|
||||
export type WebhookTemplate = (typeof WEBHOOK_TEMPLATES)[number];
|
||||
export type WebhookMethod = (typeof WEBHOOK_METHODS)[number];
|
||||
export type WebhookMimeType = (typeof WEBHOOK_MIME_TYPES)[number];
|
||||
export type WebhookColorMode = (typeof WEBHOOK_COLOR_MODES)[number];
|
||||
|
||||
export interface WebhookConfig extends NotificationConfig {
|
||||
provider: "webhook";
|
||||
/**
|
||||
* Webhook template
|
||||
*
|
||||
* @default "discord"
|
||||
*/
|
||||
template?: WebhookTemplate;
|
||||
/* Webhook token */
|
||||
token?: string;
|
||||
/**
|
||||
* Webhook message (usally JSON),
|
||||
* required when template is not defined
|
||||
*/
|
||||
payload?: string;
|
||||
/**
|
||||
* Webhook method
|
||||
*
|
||||
* @default "POST"
|
||||
*/
|
||||
method?: WebhookMethod;
|
||||
/**
|
||||
* Webhook mime type
|
||||
*
|
||||
* @default "application/json"
|
||||
*/
|
||||
mime_type?: WebhookMimeType;
|
||||
/**
|
||||
* Webhook color mode
|
||||
*
|
||||
* @default "hex"
|
||||
*/
|
||||
color_mode?: WebhookColorMode;
|
||||
}
|
||||
46
schemas/config/providers.ts
Normal file
46
schemas/config/providers.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { URI, URL } from "../types";
|
||||
import { GotifyConfig, WebhookConfig } from "./notification";
|
||||
|
||||
export type Providers = {
|
||||
/** List of route definition files to include
|
||||
*
|
||||
* @minItems 1
|
||||
* @examples require(".").includeExamples
|
||||
* @items.pattern ^[\w\d\-_]+\.(yaml|yml)$
|
||||
*/
|
||||
include?: URI[];
|
||||
/** Name-value mapping of docker hosts to retrieve routes from
|
||||
*
|
||||
* @minProperties 1
|
||||
* @examples require(".").dockerExamples
|
||||
* @items.pattern ^((\w+://)[^\s]+)|\$DOCKER_HOST$
|
||||
*/
|
||||
docker?: { [name: string]: URL };
|
||||
/** List of notification providers
|
||||
*
|
||||
* @minItems 1
|
||||
* @examples require(".").notificationExamples
|
||||
*/
|
||||
notification?: (WebhookConfig | GotifyConfig)[];
|
||||
};
|
||||
|
||||
export const includeExamples = ["file1.yml", "file2.yml"] as const;
|
||||
export const dockerExamples = [
|
||||
{ local: "$DOCKER_HOST" },
|
||||
{ remote: "tcp://10.0.2.1:2375" },
|
||||
{ remote2: "ssh://root:1234@10.0.2.2" },
|
||||
] as const;
|
||||
export const notificationExamples = [
|
||||
{
|
||||
name: "gotify",
|
||||
provider: "gotify",
|
||||
url: "https://gotify.domain.tld",
|
||||
token: "abcd",
|
||||
},
|
||||
{
|
||||
name: "discord",
|
||||
provider: "webhook",
|
||||
template: "discord",
|
||||
url: "https://discord.com/api/webhooks/1234/abcd",
|
||||
},
|
||||
] as const;
|
||||
7
schemas/docker.ts
Normal file
7
schemas/docker.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { IdleWatcherConfig } from "./providers/idlewatcher";
|
||||
import { Route } from "./providers/routes";
|
||||
|
||||
//FIXME: fix this
|
||||
export type DockerRoutes = {
|
||||
[key: string]: Route & IdleWatcherConfig;
|
||||
};
|
||||
1198
schemas/docker_routes.schema.json
Normal file
1198
schemas/docker_routes.schema.json
Normal file
File diff suppressed because it is too large
Load Diff
364
schemas/middleware_compose.schema.json
Normal file
364
schemas/middleware_compose.schema.json
Normal file
@@ -0,0 +1,364 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"definitions": {
|
||||
"CIDR": {
|
||||
"anyOf": [
|
||||
{
|
||||
"pattern": "^[0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*$",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"pattern": "^.*:.*:.*:.*:.*:.*:.*:.*$",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"pattern": "^[0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*/[0-9]*$",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"pattern": "^::[0-9]*$",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"pattern": "^.*::/[0-9]*$",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"pattern": "^.*:.*::/[0-9]*$",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"MiddlewareComposeMap": {
|
||||
"anyOf": [
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"use": {
|
||||
"enum": [
|
||||
"CustomErrorPage",
|
||||
"ErrorPage",
|
||||
"customErrorPage",
|
||||
"custom_error_page",
|
||||
"errorPage",
|
||||
"error_page"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"use"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"use": {
|
||||
"enum": [
|
||||
"RedirectHTTP",
|
||||
"redirectHTTP",
|
||||
"redirect_http"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"use"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"use": {
|
||||
"enum": [
|
||||
"SetXForwarded",
|
||||
"setXForwarded",
|
||||
"set_x_forwarded"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"use"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"use": {
|
||||
"enum": [
|
||||
"HideXForwarded",
|
||||
"hideXForwarded",
|
||||
"hide_x_forwarded"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"use"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"allow": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/CIDR"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"message": {
|
||||
"default": "IP not allowed",
|
||||
"description": "Error message when blocked",
|
||||
"type": "string"
|
||||
},
|
||||
"status": {
|
||||
"$ref": "#/definitions/StatusCode",
|
||||
"default": 403,
|
||||
"description": "HTTP status code when blocked (alias of status_code)"
|
||||
},
|
||||
"status_code": {
|
||||
"$ref": "#/definitions/StatusCode",
|
||||
"default": 403,
|
||||
"description": "HTTP status code when blocked"
|
||||
},
|
||||
"use": {
|
||||
"enum": [
|
||||
"CIDRWhitelist",
|
||||
"cidrWhitelist",
|
||||
"cidr_whitelist"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"allow",
|
||||
"use"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"recursive": {
|
||||
"default": false,
|
||||
"description": "Recursively resolve the IP",
|
||||
"type": "boolean"
|
||||
},
|
||||
"use": {
|
||||
"enum": [
|
||||
"cloudflareRealIp",
|
||||
"cloudflare_real_ip"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"use"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"add_headers": {
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "Add HTTP headers",
|
||||
"type": "object"
|
||||
},
|
||||
"hide_headers": {
|
||||
"description": "Hide HTTP headers",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"set_headers": {
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "Set HTTP headers",
|
||||
"type": "object"
|
||||
},
|
||||
"use": {
|
||||
"enum": [
|
||||
"ModifyRequest",
|
||||
"Request",
|
||||
"modifyRequest",
|
||||
"modify_request",
|
||||
"request"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"use"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"add_headers": {
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "Add HTTP headers",
|
||||
"type": "object"
|
||||
},
|
||||
"hide_headers": {
|
||||
"description": "Hide HTTP headers",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"set_headers": {
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "Set HTTP headers",
|
||||
"type": "object"
|
||||
},
|
||||
"use": {
|
||||
"enum": [
|
||||
"ModifyResponse",
|
||||
"Response",
|
||||
"modifyResponse",
|
||||
"modify_response",
|
||||
"response"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"use"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"allowed_groups": {
|
||||
"description": "Allowed groups",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"minItems": 1,
|
||||
"type": "array"
|
||||
},
|
||||
"allowed_users": {
|
||||
"description": "Allowed users",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"minItems": 1,
|
||||
"type": "array"
|
||||
},
|
||||
"use": {
|
||||
"enum": [
|
||||
"OIDC",
|
||||
"oidc"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"use"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"average": {
|
||||
"description": "Average number of requests allowed in a period",
|
||||
"type": "number"
|
||||
},
|
||||
"burst": {
|
||||
"description": "Maximum number of requests allowed in a period",
|
||||
"type": "number"
|
||||
},
|
||||
"period": {
|
||||
"default": "1s",
|
||||
"description": "Duration of the rate limit",
|
||||
"pattern": "^([0-9]+(ms|s|m|h))+$",
|
||||
"type": "string"
|
||||
},
|
||||
"use": {
|
||||
"enum": [
|
||||
"RateLimit",
|
||||
"rateLimit",
|
||||
"rate_limit"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"average",
|
||||
"burst",
|
||||
"use"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"from": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/CIDR"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"header": {
|
||||
"default": "X-Real-IP",
|
||||
"description": "Header to get the client IP from",
|
||||
"pattern": "^[a-zA-Z0-9\\-]+$",
|
||||
"type": "string"
|
||||
},
|
||||
"recursive": {
|
||||
"default": false,
|
||||
"description": "Recursive resolve the IP",
|
||||
"type": "boolean"
|
||||
},
|
||||
"use": {
|
||||
"enum": [
|
||||
"RealIP",
|
||||
"realIP",
|
||||
"real_ip"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"from",
|
||||
"use"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
"StatusCode": {
|
||||
"anyOf": [
|
||||
{
|
||||
"pattern": "^[0-9]*$",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "number"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"items": {
|
||||
"$ref": "#/definitions/MiddlewareComposeMap"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
|
||||
3
schemas/middlewares/middleware_compose.ts
Normal file
3
schemas/middlewares/middleware_compose.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { MiddlewareComposeMap } from "./middlewares";
|
||||
|
||||
export type MiddlewareCompose = MiddlewareComposeMap[];
|
||||
149
schemas/middlewares/middlewares.ts
Normal file
149
schemas/middlewares/middlewares.ts
Normal file
@@ -0,0 +1,149 @@
|
||||
import * as types from "../types";
|
||||
|
||||
export type MiddlewareComposeObjectRef = `${string}@file`;
|
||||
|
||||
export type KeyOptMapping<T extends { use: string }> = {
|
||||
[key in T["use"]]: Omit<T, "use">;
|
||||
} | { use: MiddlewareComposeObjectRef };
|
||||
|
||||
export type MiddlewaresMap = (
|
||||
| KeyOptMapping<CustomErrorPage>
|
||||
| KeyOptMapping<RedirectHTTP>
|
||||
| KeyOptMapping<SetXForwarded>
|
||||
| KeyOptMapping<HideXForwarded>
|
||||
| KeyOptMapping<CIDRWhitelist>
|
||||
| KeyOptMapping<CloudflareRealIP>
|
||||
| KeyOptMapping<ModifyRequest>
|
||||
| KeyOptMapping<ModifyResponse>
|
||||
| KeyOptMapping<OIDC>
|
||||
| KeyOptMapping<RateLimit>
|
||||
| KeyOptMapping<RealIP>
|
||||
| { [key in MiddlewareComposeObjectRef]: types.NullOrEmptyMap }
|
||||
);
|
||||
|
||||
export type MiddlewareComposeMap = (
|
||||
| CustomErrorPage
|
||||
| RedirectHTTP
|
||||
| SetXForwarded
|
||||
| HideXForwarded
|
||||
| CIDRWhitelist
|
||||
| CloudflareRealIP
|
||||
| ModifyRequest
|
||||
| ModifyResponse
|
||||
| OIDC
|
||||
| RateLimit
|
||||
| RealIP
|
||||
);
|
||||
|
||||
export type CustomErrorPage = {
|
||||
use: "error_page" | "errorPage" | "ErrorPage" | "custom_error_page" | "customErrorPage" | "CustomErrorPage";
|
||||
};
|
||||
|
||||
export type RedirectHTTP = {
|
||||
use: "redirect_http" | "redirectHTTP" | "RedirectHTTP";
|
||||
};
|
||||
|
||||
export type SetXForwarded = {
|
||||
use: "set_x_forwarded" | "setXForwarded" | "SetXForwarded";
|
||||
};
|
||||
export type HideXForwarded = {
|
||||
use: "hide_x_forwarded" | "hideXForwarded" | "HideXForwarded";
|
||||
};
|
||||
|
||||
export type CIDRWhitelist = {
|
||||
use: "cidr_whitelist" | "cidrWhitelist" | "CIDRWhitelist";
|
||||
/* Allowed CIDRs/IPs */
|
||||
allow: types.CIDR[];
|
||||
/** HTTP status code when blocked
|
||||
*
|
||||
* @default 403
|
||||
*/
|
||||
status_code?: types.StatusCode;
|
||||
/** HTTP status code when blocked (alias of status_code)
|
||||
*
|
||||
* @default 403
|
||||
*/
|
||||
status?: types.StatusCode;
|
||||
/** Error message when blocked
|
||||
*
|
||||
* @default "IP not allowed"
|
||||
*/
|
||||
message?: string;
|
||||
};
|
||||
|
||||
export type CloudflareRealIP = {
|
||||
use: "cloudflare_real_ip" | "cloudflareRealIp" | "cloudflare_real_ip";
|
||||
/** Recursively resolve the IP
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
recursive?: boolean;
|
||||
};
|
||||
|
||||
export type ModifyRequest = {
|
||||
use: "request" | "Request" | "modify_request" | "modifyRequest" | "ModifyRequest";
|
||||
/** Set HTTP headers */
|
||||
set_headers?: { [key: types.HTTPHeader]: string };
|
||||
/** Add HTTP headers */
|
||||
add_headers?: { [key: types.HTTPHeader]: string };
|
||||
/** Hide HTTP headers */
|
||||
hide_headers?: types.HTTPHeader[];
|
||||
};
|
||||
|
||||
export type ModifyResponse = {
|
||||
use: "response" | "Response" | "modify_response" | "modifyResponse" | "ModifyResponse";
|
||||
/** Set HTTP headers */
|
||||
set_headers?: { [key: types.HTTPHeader]: string };
|
||||
/** Add HTTP headers */
|
||||
add_headers?: { [key: types.HTTPHeader]: string };
|
||||
/** Hide HTTP headers */
|
||||
hide_headers?: types.HTTPHeader[];
|
||||
};
|
||||
|
||||
export type OIDC = {
|
||||
use: "oidc" | "OIDC";
|
||||
/** Allowed users
|
||||
*
|
||||
* @minItems 1
|
||||
*/
|
||||
allowed_users?: string[];
|
||||
/** Allowed groups
|
||||
*
|
||||
* @minItems 1
|
||||
*/
|
||||
allowed_groups?: string[];
|
||||
};
|
||||
|
||||
export type RateLimit = {
|
||||
use: "rate_limit" | "rateLimit" | "RateLimit";
|
||||
/** Average number of requests allowed in a period
|
||||
*
|
||||
* @min 1
|
||||
*/
|
||||
average: number;
|
||||
/** Maximum number of requests allowed in a period
|
||||
*
|
||||
* @min 1
|
||||
*/
|
||||
burst: number;
|
||||
/** Duration of the rate limit
|
||||
*
|
||||
* @default 1s
|
||||
*/
|
||||
period?: types.Duration;
|
||||
};
|
||||
|
||||
export type RealIP = {
|
||||
use: "real_ip" | "realIP" | "RealIP";
|
||||
/** Header to get the client IP from
|
||||
*
|
||||
* @default "X-Real-IP"
|
||||
*/
|
||||
header?: types.HTTPHeader;
|
||||
from: types.CIDR[];
|
||||
/** Recursive resolve the IP
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
recursive?: boolean;
|
||||
};
|
||||
33
schemas/providers/healthcheck.ts
Normal file
33
schemas/providers/healthcheck.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Duration, URI } from "../types";
|
||||
|
||||
/**
|
||||
* @additionalProperties false
|
||||
*/
|
||||
export type HealthcheckConfig = {
|
||||
/** Disable healthcheck
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
disable?: boolean;
|
||||
/** Healthcheck path
|
||||
*
|
||||
* @default /
|
||||
*/
|
||||
path?: URI;
|
||||
/**
|
||||
* Use GET instead of HEAD
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
use_get?: boolean;
|
||||
/** Healthcheck interval
|
||||
*
|
||||
* @default 5s
|
||||
*/
|
||||
interval?: Duration;
|
||||
/** Healthcheck timeout
|
||||
*
|
||||
* @default 5s
|
||||
*/
|
||||
timeout?: Duration;
|
||||
};
|
||||
36
schemas/providers/homepage.ts
Normal file
36
schemas/providers/homepage.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { URL } from "../types";
|
||||
|
||||
/**
|
||||
* @additionalProperties false
|
||||
*/
|
||||
export type HomepageConfig = {
|
||||
/** Whether show in dashboard
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
show?: boolean;
|
||||
/* Display name on dashboard */
|
||||
name?: string;
|
||||
/* Display icon on dashboard */
|
||||
icon?: URL | WalkxcodeIcon | TargetRelativeIconPath;
|
||||
/* App description */
|
||||
description?: string;
|
||||
/* Override url */
|
||||
url?: URL;
|
||||
/* App category */
|
||||
category?: string;
|
||||
/* Widget config */
|
||||
widget_config?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @pattern ^(png|svg|webp)\\/[\\w\\d\\-_]+\\.\\1$
|
||||
*/
|
||||
export type WalkxcodeIcon = string;
|
||||
|
||||
/**
|
||||
* @pattern ^@target/.+$
|
||||
*/
|
||||
export type TargetRelativeIconPath = string;
|
||||
41
schemas/providers/idlewatcher.ts
Normal file
41
schemas/providers/idlewatcher.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Duration, URI } from "../types";
|
||||
|
||||
export const STOP_METHODS = ["pause", "stop", "kill"] as const;
|
||||
export type StopMethod = (typeof STOP_METHODS)[number];
|
||||
|
||||
export const STOP_SIGNALS = [
|
||||
"",
|
||||
"SIGINT",
|
||||
"SIGTERM",
|
||||
"SIGHUP",
|
||||
"SIGQUIT",
|
||||
"INT",
|
||||
"TERM",
|
||||
"HUP",
|
||||
"QUIT",
|
||||
] as const;
|
||||
export type Signal = (typeof STOP_SIGNALS)[number];
|
||||
|
||||
export type IdleWatcherConfig = {
|
||||
/* Idle timeout */
|
||||
idle_timeout?: Duration;
|
||||
/** Wake timeout
|
||||
*
|
||||
* @default 30s
|
||||
*/
|
||||
wake_timeout?: Duration;
|
||||
/** Stop timeout
|
||||
*
|
||||
* @default 10s
|
||||
*/
|
||||
stop_timeout?: Duration;
|
||||
/** Stop method
|
||||
*
|
||||
* @default stop
|
||||
*/
|
||||
stop_method?: StopMethod;
|
||||
/* Stop signal */
|
||||
stop_signal?: Signal;
|
||||
/* Start endpoint (any path can wake the container if not specified) */
|
||||
start_endpoint?: URI;
|
||||
};
|
||||
44
schemas/providers/loadbalance.ts
Normal file
44
schemas/providers/loadbalance.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { RealIP } from "../middlewares/middlewares";
|
||||
|
||||
export const LOAD_BALANCE_MODES = [
|
||||
"round_robin",
|
||||
"least_conn",
|
||||
"ip_hash",
|
||||
] as const;
|
||||
export type LoadBalanceMode = (typeof LOAD_BALANCE_MODES)[number];
|
||||
|
||||
export type LoadBalanceConfigBase = {
|
||||
/** Alias (subdomain or FDN) of load-balancer
|
||||
*
|
||||
* @minLength 1
|
||||
*/
|
||||
link: string;
|
||||
/** Load-balance weight (reserved for future use)
|
||||
*
|
||||
* @minimum 0
|
||||
* @maximum 100
|
||||
*/
|
||||
weight?: number;
|
||||
};
|
||||
|
||||
export type LoadBalanceConfig = LoadBalanceConfigBase &
|
||||
(
|
||||
| {} // linking other routes
|
||||
| RoundRobinLoadBalanceConfig
|
||||
| LeastConnLoadBalanceConfig
|
||||
| IPHashLoadBalanceConfig
|
||||
);
|
||||
|
||||
export type IPHashLoadBalanceConfig = {
|
||||
mode: "ip_hash";
|
||||
/** Real IP config, header to get client IP from */
|
||||
config: RealIP;
|
||||
};
|
||||
|
||||
export type LeastConnLoadBalanceConfig = {
|
||||
mode: "least_conn";
|
||||
};
|
||||
|
||||
export type RoundRobinLoadBalanceConfig = {
|
||||
mode: "round_robin";
|
||||
};
|
||||
114
schemas/providers/routes.ts
Normal file
114
schemas/providers/routes.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
import { AccessLogConfig } from "../config/access_log";
|
||||
import { accessLogExamples } from "../config/entrypoint";
|
||||
import { MiddlewaresMap } from "../middlewares/middlewares";
|
||||
import { Hostname, IPv4, IPv6, PathPattern, Port, StreamPort } from "../types";
|
||||
import { HealthcheckConfig } from "./healthcheck";
|
||||
import { HomepageConfig } from "./homepage";
|
||||
import { LoadBalanceConfig } from "./loadbalance";
|
||||
export const PROXY_SCHEMES = ["http", "https"] as const;
|
||||
export const STREAM_SCHEMES = ["tcp", "udp"] as const;
|
||||
|
||||
export type ProxyScheme = (typeof PROXY_SCHEMES)[number];
|
||||
export type StreamScheme = (typeof STREAM_SCHEMES)[number];
|
||||
|
||||
export type Route = ReverseProxyRoute | StreamRoute;
|
||||
export type Routes = {
|
||||
[key: string]: Route;
|
||||
};
|
||||
|
||||
export type ReverseProxyRoute = {
|
||||
/** Alias (subdomain or FDN)
|
||||
* @minLength 1
|
||||
*/
|
||||
alias?: string;
|
||||
/** Proxy scheme
|
||||
*
|
||||
* @default http
|
||||
*/
|
||||
scheme?: ProxyScheme;
|
||||
/** Proxy host
|
||||
*
|
||||
* @default localhost
|
||||
*/
|
||||
host?: Hostname | IPv4 | IPv6;
|
||||
/** Proxy port
|
||||
*
|
||||
* @default 80
|
||||
*/
|
||||
port?: Port;
|
||||
/** Skip TLS verification
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
no_tls_verify?: boolean;
|
||||
/** Path patterns (only patterns that match will be proxied).
|
||||
*
|
||||
* See https://pkg.go.dev/net/http#hdr-Patterns-ServeMux
|
||||
*/
|
||||
path_patterns?: PathPattern[];
|
||||
/** Healthcheck config */
|
||||
healthcheck?: HealthcheckConfig;
|
||||
/** Load balance config */
|
||||
load_balance?: LoadBalanceConfig;
|
||||
/** Middlewares */
|
||||
middlewares?: MiddlewaresMap;
|
||||
/** Homepage config
|
||||
*
|
||||
* @examples require(".").homepageExamples
|
||||
*/
|
||||
homepage?: HomepageConfig;
|
||||
/** Access log config
|
||||
*
|
||||
* @examples require(".").accessLogExamples
|
||||
*/
|
||||
access_log?: AccessLogConfig;
|
||||
};
|
||||
|
||||
export type StreamRoute = {
|
||||
/** Alias (subdomain or FDN)
|
||||
* @minLength 1
|
||||
*/
|
||||
alias?: string;
|
||||
/** Stream scheme
|
||||
*
|
||||
* @default tcp
|
||||
*/
|
||||
scheme: StreamScheme;
|
||||
/** Stream host
|
||||
*
|
||||
* @default localhost
|
||||
*/
|
||||
host?: Hostname | IPv4 | IPv6;
|
||||
/* Stream port */
|
||||
port: StreamPort;
|
||||
/** Healthcheck config */
|
||||
healthcheck?: HealthcheckConfig;
|
||||
};
|
||||
|
||||
export const homepageExamples = [
|
||||
{
|
||||
name: "Sonarr",
|
||||
icon: "png/sonarr.png",
|
||||
category: "Arr suite",
|
||||
},
|
||||
{
|
||||
name: "App",
|
||||
icon: "@target/favicon.ico",
|
||||
},
|
||||
];
|
||||
|
||||
export const loadBalanceExamples = [
|
||||
{
|
||||
link: "flaresolverr",
|
||||
mode: "round_robin",
|
||||
},
|
||||
{
|
||||
link: "service.domain.com",
|
||||
mode: "ip_hash",
|
||||
config: {
|
||||
header: "X-Real-IP",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export { accessLogExamples };
|
||||
1123
schemas/routes.schema.json
Normal file
1123
schemas/routes.schema.json
Normal file
File diff suppressed because it is too large
Load Diff
111
schemas/types.ts
Normal file
111
schemas/types.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* @type "null"
|
||||
*/
|
||||
export interface Null {}
|
||||
export type Nullable<T> = T | Null;
|
||||
export type NullOrEmptyMap = {} | Null;
|
||||
|
||||
export const HTTP_METHODS = [
|
||||
"GET",
|
||||
"POST",
|
||||
"PUT",
|
||||
"PATCH",
|
||||
"DELETE",
|
||||
"CONNECT",
|
||||
"HEAD",
|
||||
"OPTIONS",
|
||||
"TRACE",
|
||||
] as const;
|
||||
|
||||
export type HTTPMethod = (typeof HTTP_METHODS)[number];
|
||||
/**
|
||||
* HTTP Header
|
||||
* @pattern ^[a-zA-Z0-9\-]+$
|
||||
*/
|
||||
export type HTTPHeader = string;
|
||||
|
||||
/**
|
||||
* HTTP Query
|
||||
* @pattern ^[a-zA-Z0-9\-_]+$
|
||||
*/
|
||||
export type HTTPQuery = string;
|
||||
/**
|
||||
* HTTP Cookie
|
||||
* @pattern ^[a-zA-Z0-9\-_]+$
|
||||
*/
|
||||
export type HTTPCookie = string;
|
||||
|
||||
export type StatusCode = number | `${number}`;
|
||||
export type StatusCodeRange = number | `${number}` | `${number}-${number}`;
|
||||
|
||||
/**
|
||||
* @items.pattern ^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$
|
||||
*/
|
||||
export type DomainNames = string[];
|
||||
/**
|
||||
* @items.pattern ^(\*\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$
|
||||
*/
|
||||
export type DomainOrWildcards = string[];
|
||||
/**
|
||||
* @format hostname
|
||||
*/
|
||||
export type Hostname = string;
|
||||
/**
|
||||
* @format ipv4
|
||||
*/
|
||||
export type IPv4 = string;
|
||||
/**
|
||||
* @format ipv6
|
||||
*/
|
||||
export type IPv6 = string;
|
||||
|
||||
/* CIDR / IPv4 / IPv6 */
|
||||
export type CIDR =
|
||||
| `${number}.${number}.${number}.${number}`
|
||||
| `${string}:${string}:${string}:${string}:${string}:${string}:${string}:${string}`
|
||||
| `${number}.${number}.${number}.${number}/${number}`
|
||||
| `::${number}`
|
||||
| `${string}::/${number}`
|
||||
| `${string}:${string}::/${number}`;
|
||||
|
||||
/**
|
||||
* @type integer
|
||||
* @minimum 0
|
||||
* @maximum 65535
|
||||
*/
|
||||
export type Port = number;
|
||||
|
||||
/**
|
||||
* @pattern ^\d+:\d+$
|
||||
*/
|
||||
export type StreamPort = string;
|
||||
|
||||
/**
|
||||
* @format email
|
||||
*/
|
||||
export type Email = string;
|
||||
|
||||
/**
|
||||
* @format uri
|
||||
*/
|
||||
export type URL = string;
|
||||
|
||||
/**
|
||||
* @format uri-reference
|
||||
*/
|
||||
export type URI = string;
|
||||
|
||||
/**
|
||||
* @pattern ^(?:([A-Z]+) )?(?:([a-zA-Z0-9.-]+)\\/)?(\\/[^\\s]*)$
|
||||
*/
|
||||
export type PathPattern = string;
|
||||
|
||||
/**
|
||||
* @pattern ^([0-9]+(ms|s|m|h))+$
|
||||
*/
|
||||
export type Duration = string;
|
||||
|
||||
/**
|
||||
* @format date-time
|
||||
*/
|
||||
export type DateTime = string;
|
||||
Reference in New Issue
Block a user