refactor: split api into api, api-cli & api-plugin

This commit is contained in:
2023-06-02 16:41:25 +02:00
parent 495a63977c
commit b21833de40
205 changed files with 1981 additions and 1492 deletions

View File

@@ -34,7 +34,7 @@
"is-cidr": "4.0.2",
"mustache": "4.2.0",
"semver": "7.3.8",
"typescript": "4.8.4"
"typescript": "4.9.5"
},
"devDependencies": {
"@openstapps/eslint-config": "workspace:*",

View File

@@ -35,7 +35,6 @@ import PortScanner from './port-scanner.js';
/**
* Checks if a ContainerInfo matches a name and version regex
*
* @param name Name to check
* @param versionRegex Version regex to check
* @param container Container info for check
@@ -61,7 +60,6 @@ export function containerMatchesRegex(
*
* Returns an empty String if there is no Gateway.
* This assumes that a backend runs in the container and it exposes one port.
*
* @param container Container info of which to get address from
*/
export async function getGatewayOfStAppsBackend(container: Dockerode.ContainerInfo): Promise<string> {
@@ -73,7 +71,7 @@ Please expose a port if the container should be accessible by NGINX.`);
}
// Basic Docker network
if (typeof container.Ports[0].IP !== 'undefined' && typeof container.Ports[0].PublicPort !== 'undefined') {
if (container.Ports[0].IP !== undefined && container.Ports[0].PublicPort !== undefined) {
// ip:port
return `${container.Ports[0].IP}:${container.Ports[0].PublicPort}`;
}
@@ -81,8 +79,8 @@ Please expose a port if the container should be accessible by NGINX.`);
// Docker Swarm network
if (
/* istanbul ignore next */
typeof container.NetworkSettings?.Networks?.ingress?.IPAddress !== 'undefined' &&
typeof container.Ports[0].PrivatePort !== 'undefined'
container.NetworkSettings?.Networks?.ingress?.IPAddress !== undefined &&
container.Ports[0].PrivatePort !== undefined
) {
const port = container.Ports[0].PrivatePort;
@@ -108,7 +106,6 @@ Please expose a port if the container should be accessible by NGINX.`);
* Generates an upstream map
*
* It maps all stapps-backend-containers to an gateway.
*
* @param activeVersions List of active versions
* @param outdatedVersions List of outdated versions
* @param containers List of container infos
@@ -131,7 +128,7 @@ export async function generateUpstreamMap(
result += (
await Promise.all(
activeVersions.map(async activeVersionRegex => {
const upstreamName = activeVersionRegex.replace(/[\\|.+]/g, '_');
const upstreamName = activeVersionRegex.replaceAll(/[\\|.+]/g, '_');
let activeBackends = containers.filter(container => {
return containerMatchesRegex('backend', new RegExp(activeVersionRegex), container);
@@ -205,14 +202,14 @@ export function generateListener(sslFilePaths: SSLFilePaths) {
let listener = '';
if (
typeof sslFilePaths !== 'undefined' &&
typeof sslFilePaths.certificate !== 'undefined' &&
sslFilePaths !== undefined &&
sslFilePaths.certificate !== undefined &&
isFileType(sslFilePaths.certificate, 'crt') &&
typeof sslFilePaths.certificateChain !== 'undefined' &&
sslFilePaths.certificateChain !== undefined &&
isFileType(sslFilePaths.certificateChain, 'crt') &&
typeof sslFilePaths.certificateKey !== 'undefined' &&
sslFilePaths.certificateKey !== undefined &&
isFileType(sslFilePaths.certificateKey, 'key') &&
typeof sslFilePaths.dhparam !== 'undefined' &&
sslFilePaths.dhparam !== undefined &&
isFileType(sslFilePaths.dhparam, 'pem')
) {
// https listener
@@ -251,7 +248,6 @@ export async function generateMetricsServer(logFormat: string, enableMetrics?: b
/**
* Render a mustache template file with given view object
*
* @param path Path to template file
* @param view Data to render template with
*/
@@ -263,7 +259,6 @@ async function renderTemplate(path: string, view: unknown): Promise<string> {
/**
* Generate allow list entries in CIDR notation that pass thru rate limiting
*
* @param entries Allow list entries that should be in CIDR notation
*/
function generateRateLimitAllowList(entries: string[]): string {
@@ -275,7 +270,6 @@ function generateRateLimitAllowList(entries: string[]): string {
/**
* Returns view for nginx config file
*
* @param containers List of container info
*/
export async function getTemplateView(containers: Dockerode.ContainerInfo[]): Promise<TemplateView> {
@@ -321,7 +315,6 @@ export async function getTemplateView(containers: Dockerode.ContainerInfo[]): Pr
/**
* Read the list of docker containers
*
* @param pathToDockerSocket Path to docker socket
*/
export async function getContainers(