@fabrika/provider-zerops 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +18 -5
- package/src/api/client.ts +522 -0
- package/src/api/errors.ts +50 -0
- package/src/api/polling.ts +59 -0
- package/src/api/readers.ts +185 -0
- package/src/api/service-env-response.ts +34 -0
- package/src/api/types.ts +602 -0
- package/src/api.ts +29 -1378
- package/src/authoring.ts +7 -10
- package/src/cli-args.ts +0 -5
- package/src/cli.ts +3 -28
- package/src/collaborators.ts +2 -4
- package/src/compile.ts +3 -1
- package/src/control.ts +203 -450
- package/src/descriptor.ts +135 -0
- package/src/index.ts +23 -127
- package/src/installation/admin-options.ts +128 -0
- package/src/installation/admin.ts +123 -0
- package/src/installation/deploy-options.ts +155 -0
- package/src/installation/deploy.ts +668 -0
- package/src/installation/generated/platform-console-schema.ts +41 -0
- package/src/installation/generated/platform-proxy-manifest.ts +72 -0
- package/src/installation/hosts.ts +117 -0
- package/src/installation/index.ts +366 -0
- package/src/installation/init.ts +521 -0
- package/src/installation/install-collaborators.ts +28 -0
- package/src/installation/install-environment.ts +193 -0
- package/src/installation/install-options.ts +193 -0
- package/src/installation/install-project.ts +201 -0
- package/src/installation/install-provisioning.ts +185 -0
- package/src/installation/install.ts +286 -0
- package/src/installation/installation-source.ts +42 -0
- package/src/installation/log.ts +77 -0
- package/src/installation/machine-key.ts +65 -0
- package/src/installation/manifest.ts +95 -0
- package/src/installation/placement-options.ts +33 -0
- package/src/installation/platform-source.ts +106 -0
- package/src/installation/platform-upload.ts +34 -0
- package/src/installation/proxy-manifest.ts +113 -0
- package/src/installation/secrets.ts +79 -0
- package/src/installation/sidecar.ts +122 -0
- package/src/installation/source-options.ts +12 -0
- package/src/installation/templates/README.md +116 -0
- package/src/installation/templates/fabrika.ref +1 -0
- package/src/installation/templates/gitignore +3 -0
- package/src/installation/templates/platform.yml +144 -0
- package/src/installation/topology/artifacts.ts +141 -0
- package/src/installation/topology/index.ts +13 -0
- package/src/installation/topology/installation-schemas.ts +225 -0
- package/src/installation/topology/invariants.ts +86 -0
- package/src/installation/topology/setups.ts +442 -0
- package/src/installation/topology/topology.ts +501 -0
- package/src/installation/topology/validate.ts +26 -0
- package/src/installation/upgrade-options.ts +108 -0
- package/src/installation/upgrade-output.ts +31 -0
- package/src/installation/upgrade.ts +373 -0
- package/src/managed-env.ts +105 -0
- package/src/manifest.ts +191 -344
- package/src/namespace/claims.ts +77 -0
- package/src/namespace/codec.ts +179 -0
- package/src/namespace/constants.ts +30 -0
- package/src/namespace/errors.ts +60 -0
- package/src/namespace/manifest.ts +28 -0
- package/src/namespace/operator.ts +151 -0
- package/src/namespace/provisioning.ts +482 -0
- package/src/namespace/proxy-attempt.ts +220 -0
- package/src/namespace/proxy-source.ts +22 -0
- package/src/namespace/topology.ts +115 -0
- package/src/namespace/types.ts +114 -0
- package/src/namespace.ts +34 -1271
- package/src/plan.ts +21 -23
- package/src/provider.ts +266 -241
- package/src/source/constants.ts +11 -0
- package/src/source/port.ts +49 -0
- package/src/source/types.ts +4 -0
- package/src/source/validation.ts +72 -0
- package/src/source.ts +2 -1220
- package/src/types.ts +8 -7
- package/src/version-attempt.ts +18 -0
- package/src/codec.ts +0 -108
- package/src/namespace-command.ts +0 -209
- package/src/source-connection.ts +0 -344
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// The CLI surface of `fabrika platform deploy --provider=zerops`, parsed once.
|
|
2
|
+
//
|
|
3
|
+
// ── Two rules the shape enforces ──────────────────────────────────────────────────────────────────
|
|
4
|
+
//
|
|
5
|
+
// 1. **Every CREDENTIAL comes from the environment and only from the environment.** There is no
|
|
6
|
+
// `--token` and no `--admin-key`, and an unknown flag is an error, so a credential cannot be put
|
|
7
|
+
// on the command line by mistake — where it would land in a CI log, a process listing and the
|
|
8
|
+
// shell history of whoever reproduced the run.
|
|
9
|
+
// 2. **Everything else may come from a flag OR the environment, flag first.** A generated workflow
|
|
10
|
+
// writes the environment; a human debugging one overrides a single value without editing it.
|
|
11
|
+
//
|
|
12
|
+
// The command is unattended by construction: nothing here prompts, and a missing required value is an
|
|
13
|
+
// error naming both the flag and the variable that would supply it.
|
|
14
|
+
|
|
15
|
+
import { parsePlatformHosts, parsePlatformScheme } from './placement-options'
|
|
16
|
+
import { readInstallationSourceDir } from './source-options'
|
|
17
|
+
|
|
18
|
+
/** How the project this installation lives in is named. */
|
|
19
|
+
export type ZeropsProjectSelector =
|
|
20
|
+
| { readonly kind: 'id'; readonly projectId: string }
|
|
21
|
+
| { readonly kind: 'name'; readonly clientId: string; readonly name: string }
|
|
22
|
+
|
|
23
|
+
/** Every input `deployPlatform` takes from the operator. */
|
|
24
|
+
export interface PlatformDeployInput {
|
|
25
|
+
readonly project: ZeropsProjectSelector
|
|
26
|
+
/** Zerops personal or integration access token. Environment only. */
|
|
27
|
+
readonly accessToken: string
|
|
28
|
+
/** Region API base, when the installation is not on the default one. */
|
|
29
|
+
readonly apiBaseUrl?: string
|
|
30
|
+
/** The name this installation calls itself — written to every platform service as `ENVIRONMENT`. */
|
|
31
|
+
readonly environment: string
|
|
32
|
+
/** All three or none: none derives them from the proxy's Zerops subdomains. */
|
|
33
|
+
readonly hosts?: { readonly iam: string; readonly control: string; readonly operations: string }
|
|
34
|
+
/** The scheme a browser speaks to this installation. `https` unless a local composition says otherwise. */
|
|
35
|
+
readonly scheme: 'http' | 'https'
|
|
36
|
+
readonly sourceDir: string
|
|
37
|
+
/** IAM-issued `px_` admin key, used only to reconcile the console's schema. Environment only. */
|
|
38
|
+
readonly iamAdminKey: string
|
|
39
|
+
/** Read everything, write nothing, trigger nothing. */
|
|
40
|
+
readonly dryRun: boolean
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const FLAGS = [
|
|
44
|
+
'--project-id',
|
|
45
|
+
'--project-name',
|
|
46
|
+
'--client-id',
|
|
47
|
+
'--env',
|
|
48
|
+
'--iam-host',
|
|
49
|
+
'--console-host',
|
|
50
|
+
'--operations-host',
|
|
51
|
+
'--scheme',
|
|
52
|
+
'--source-dir',
|
|
53
|
+
] as const
|
|
54
|
+
|
|
55
|
+
const readFlag = (argv: readonly string[], name: string): string | undefined => {
|
|
56
|
+
const prefix = `${name}=`
|
|
57
|
+
const matches = argv.filter((arg) => arg.startsWith(prefix))
|
|
58
|
+
if (matches.length > 1) {
|
|
59
|
+
throw new Error(`${name} was given more than once`)
|
|
60
|
+
}
|
|
61
|
+
const value = matches[0]?.slice(prefix.length)
|
|
62
|
+
return value === undefined || value.trim() === '' ? undefined : value.trim()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const readEnv = (env: Record<string, string | undefined>, name: string): string | undefined => {
|
|
66
|
+
const value = env[name]
|
|
67
|
+
return value === undefined || value.trim() === '' ? undefined : value.trim()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const setting = (
|
|
71
|
+
argv: readonly string[],
|
|
72
|
+
env: Record<string, string | undefined>,
|
|
73
|
+
flag: string,
|
|
74
|
+
variable: string,
|
|
75
|
+
): string | undefined => readFlag(argv, flag) ?? readEnv(env, variable)
|
|
76
|
+
|
|
77
|
+
const required = (value: string | undefined, flag: string, variable: string): string => {
|
|
78
|
+
if (value === undefined) {
|
|
79
|
+
throw new Error(`${flag}=<value> or ${variable} is required`)
|
|
80
|
+
}
|
|
81
|
+
return value
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const assertKnownArguments = (argv: readonly string[]): void => {
|
|
85
|
+
for (const arg of argv) {
|
|
86
|
+
if (arg === '--dry-run') {
|
|
87
|
+
continue
|
|
88
|
+
}
|
|
89
|
+
const name = arg.split('=')[0] ?? arg
|
|
90
|
+
if (!FLAGS.some((flag) => flag === name) || !arg.includes('=')) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`unexpected argument \`${arg}\`. Credentials are read from the environment and have no flag; run `
|
|
93
|
+
+ '`fabrika platform deploy --provider=zerops --help` for the surface',
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const readHosts = (
|
|
100
|
+
argv: readonly string[],
|
|
101
|
+
env: Record<string, string | undefined>,
|
|
102
|
+
): PlatformDeployInput['hosts'] => {
|
|
103
|
+
const iam = setting(argv, env, '--iam-host', 'FABRIKA_PLATFORM_IAM_HOST')
|
|
104
|
+
const control = setting(argv, env, '--console-host', 'FABRIKA_PLATFORM_CONSOLE_HOST')
|
|
105
|
+
const operations = setting(argv, env, '--operations-host', 'FABRIKA_PLATFORM_OPERATIONS_HOST')
|
|
106
|
+
return parsePlatformHosts({ iam, control, operations })
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const readScheme = (argv: readonly string[], env: Record<string, string | undefined>): 'http' | 'https' => {
|
|
110
|
+
const raw = setting(argv, env, '--scheme', 'FABRIKA_PLATFORM_SCHEME')
|
|
111
|
+
return parsePlatformScheme(raw)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const readProject = (argv: readonly string[], env: Record<string, string | undefined>): ZeropsProjectSelector => {
|
|
115
|
+
const projectId = setting(argv, env, '--project-id', 'FABRIKA_ZEROPS_PROJECT_ID')
|
|
116
|
+
const name = setting(argv, env, '--project-name', 'FABRIKA_ZEROPS_PROJECT_NAME')
|
|
117
|
+
if (projectId !== undefined && name !== undefined) {
|
|
118
|
+
throw new Error('name the project by id or by name, not both')
|
|
119
|
+
}
|
|
120
|
+
if (projectId !== undefined) {
|
|
121
|
+
return { kind: 'id', projectId }
|
|
122
|
+
}
|
|
123
|
+
if (name === undefined) {
|
|
124
|
+
throw new Error('--project-id=<id> or FABRIKA_ZEROPS_PROJECT_ID is required (or --project-name with --client-id)')
|
|
125
|
+
}
|
|
126
|
+
const clientId = required(setting(argv, env, '--client-id', 'FABRIKA_ZEROPS_CLIENT_ID'), '--client-id', 'FABRIKA_ZEROPS_CLIENT_ID')
|
|
127
|
+
return { kind: 'name', clientId, name }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Parse the command's arguments and environment into the one input `deployPlatform` takes. */
|
|
131
|
+
export const parsePlatformDeployArgs = (
|
|
132
|
+
argv: readonly string[],
|
|
133
|
+
env: Record<string, string | undefined>,
|
|
134
|
+
): PlatformDeployInput => {
|
|
135
|
+
const sourceDir = readInstallationSourceDir(argv, env)
|
|
136
|
+
assertKnownArguments(argv)
|
|
137
|
+
const dryRun = argv.includes('--dry-run')
|
|
138
|
+
const hosts = readHosts(argv, env)
|
|
139
|
+
const apiBaseUrl = readEnv(env, 'FABRIKA_ZEROPS_API_URL')
|
|
140
|
+
return {
|
|
141
|
+
project: readProject(argv, env),
|
|
142
|
+
// A dry run reads, and reading still needs a token; it is the one credential it cannot do without.
|
|
143
|
+
accessToken: required(readEnv(env, 'FABRIKA_ZEROPS_ACCESS_TOKEN'), '(no flag)', 'FABRIKA_ZEROPS_ACCESS_TOKEN'),
|
|
144
|
+
environment: required(setting(argv, env, '--env', 'FABRIKA_PLATFORM_ENVIRONMENT'), '--env', 'FABRIKA_PLATFORM_ENVIRONMENT'),
|
|
145
|
+
// Not required for a dry run: it authenticates a write this mode never makes.
|
|
146
|
+
iamAdminKey: dryRun
|
|
147
|
+
? readEnv(env, 'FABRIKA_IAM_PROVISIONING_KEY') ?? ''
|
|
148
|
+
: required(readEnv(env, 'FABRIKA_IAM_PROVISIONING_KEY'), '(no flag)', 'FABRIKA_IAM_PROVISIONING_KEY'),
|
|
149
|
+
scheme: readScheme(argv, env),
|
|
150
|
+
dryRun,
|
|
151
|
+
...(hosts === undefined ? {} : { hosts }),
|
|
152
|
+
sourceDir,
|
|
153
|
+
...(apiBaseUrl === undefined ? {} : { apiBaseUrl }),
|
|
154
|
+
}
|
|
155
|
+
}
|