@fabrika/provider-zerops 0.2.0 → 0.3.2

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.
Files changed (83) hide show
  1. package/package.json +18 -5
  2. package/src/api/client.ts +522 -0
  3. package/src/api/errors.ts +50 -0
  4. package/src/api/polling.ts +59 -0
  5. package/src/api/readers.ts +185 -0
  6. package/src/api/service-env-response.ts +34 -0
  7. package/src/api/types.ts +602 -0
  8. package/src/api.ts +29 -1378
  9. package/src/authoring.ts +7 -10
  10. package/src/cli-args.ts +2 -6
  11. package/src/cli.ts +3 -28
  12. package/src/collaborators.ts +2 -4
  13. package/src/compile.ts +3 -1
  14. package/src/control.ts +203 -450
  15. package/src/descriptor.ts +179 -0
  16. package/src/index.ts +23 -127
  17. package/src/installation/admin-options.ts +100 -0
  18. package/src/installation/admin.ts +123 -0
  19. package/src/installation/deploy-options.ts +127 -0
  20. package/src/installation/deploy.ts +668 -0
  21. package/src/installation/generated/platform-console-schema.ts +41 -0
  22. package/src/installation/generated/platform-proxy-manifest.ts +72 -0
  23. package/src/installation/hosts.ts +117 -0
  24. package/src/installation/index.ts +390 -0
  25. package/src/installation/init-options.ts +148 -0
  26. package/src/installation/init.ts +394 -0
  27. package/src/installation/install-collaborators.ts +27 -0
  28. package/src/installation/install-environment.ts +193 -0
  29. package/src/installation/install-options.ts +156 -0
  30. package/src/installation/install-project.ts +201 -0
  31. package/src/installation/install-provisioning.ts +185 -0
  32. package/src/installation/install.ts +262 -0
  33. package/src/installation/installation-source.ts +42 -0
  34. package/src/installation/log.ts +77 -0
  35. package/src/installation/machine-key.ts +65 -0
  36. package/src/installation/manifest.ts +95 -0
  37. package/src/installation/placement-options.ts +33 -0
  38. package/src/installation/platform-source.ts +106 -0
  39. package/src/installation/platform-upload.ts +34 -0
  40. package/src/installation/proxy-manifest.ts +113 -0
  41. package/src/installation/secrets.ts +79 -0
  42. package/src/installation/sidecar.ts +125 -0
  43. package/src/installation/source-options.ts +12 -0
  44. package/src/installation/templates/README.md +116 -0
  45. package/src/installation/templates/fabrika.ref +1 -0
  46. package/src/installation/templates/gitignore +3 -0
  47. package/src/installation/templates/platform.yml +144 -0
  48. package/src/installation/topology/artifacts.ts +141 -0
  49. package/src/installation/topology/index.ts +13 -0
  50. package/src/installation/topology/installation-schemas.ts +225 -0
  51. package/src/installation/topology/invariants.ts +86 -0
  52. package/src/installation/topology/setups.ts +442 -0
  53. package/src/installation/topology/topology.ts +501 -0
  54. package/src/installation/topology/validate.ts +26 -0
  55. package/src/installation/upgrade-options.ts +99 -0
  56. package/src/installation/upgrade-output.ts +31 -0
  57. package/src/installation/upgrade.ts +373 -0
  58. package/src/managed-env.ts +113 -0
  59. package/src/manifest.ts +194 -344
  60. package/src/namespace/claims.ts +77 -0
  61. package/src/namespace/codec.ts +179 -0
  62. package/src/namespace/constants.ts +30 -0
  63. package/src/namespace/errors.ts +60 -0
  64. package/src/namespace/manifest.ts +28 -0
  65. package/src/namespace/operator.ts +151 -0
  66. package/src/namespace/provisioning.ts +482 -0
  67. package/src/namespace/proxy-attempt.ts +220 -0
  68. package/src/namespace/proxy-source.ts +22 -0
  69. package/src/namespace/topology.ts +115 -0
  70. package/src/namespace/types.ts +114 -0
  71. package/src/namespace.ts +34 -1271
  72. package/src/plan.ts +21 -23
  73. package/src/provider.ts +266 -241
  74. package/src/source/constants.ts +11 -0
  75. package/src/source/port.ts +49 -0
  76. package/src/source/types.ts +4 -0
  77. package/src/source/validation.ts +72 -0
  78. package/src/source.ts +2 -1220
  79. package/src/types.ts +8 -7
  80. package/src/version-attempt.ts +18 -0
  81. package/src/codec.ts +0 -108
  82. package/src/namespace-command.ts +0 -209
  83. package/src/source-connection.ts +0 -344
@@ -0,0 +1,127 @@
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 { describeArgument, readEnv, requiredSetting, setting } from '@fabrika/installation-init'
16
+ import { parsePlatformHosts, parsePlatformScheme } from './placement-options'
17
+ import { readInstallationSourceDir } from './source-options'
18
+
19
+ /** How the project this installation lives in is named. */
20
+ export type ZeropsProjectSelector =
21
+ | { readonly kind: 'id'; readonly projectId: string }
22
+ | { readonly kind: 'name'; readonly clientId: string; readonly name: string }
23
+
24
+ /** Every input `deployPlatform` takes from the operator. */
25
+ export interface PlatformDeployInput {
26
+ readonly project: ZeropsProjectSelector
27
+ /** Zerops personal or integration access token. Environment only. */
28
+ readonly accessToken: string
29
+ /** Region API base, when the installation is not on the default one. */
30
+ readonly apiBaseUrl?: string
31
+ /** The name this installation calls itself — written to every platform service as `ENVIRONMENT`. */
32
+ readonly environment: string
33
+ /** All three or none: none derives them from the proxy's Zerops subdomains. */
34
+ readonly hosts?: { readonly iam: string; readonly control: string; readonly operations: string }
35
+ /** The scheme a browser speaks to this installation. `https` unless a local composition says otherwise. */
36
+ readonly scheme: 'http' | 'https'
37
+ readonly sourceDir: string
38
+ /** IAM-issued `px_` admin key, used only to reconcile the console's schema. Environment only. */
39
+ readonly iamAdminKey: string
40
+ /** Read everything, write nothing, trigger nothing. */
41
+ readonly dryRun: boolean
42
+ }
43
+
44
+ const FLAGS = [
45
+ '--project-id',
46
+ '--project-name',
47
+ '--client-id',
48
+ '--env',
49
+ '--iam-host',
50
+ '--console-host',
51
+ '--operations-host',
52
+ '--scheme',
53
+ '--source-dir',
54
+ ] as const
55
+
56
+ const assertKnownArguments = (argv: readonly string[]): void => {
57
+ for (const arg of argv) {
58
+ if (arg === '--dry-run') {
59
+ continue
60
+ }
61
+ const name = arg.split('=')[0] ?? arg
62
+ if (!FLAGS.some((flag) => flag === name) || !arg.includes('=')) {
63
+ throw new Error(
64
+ `unexpected argument ${describeArgument(arg)}. Credentials are read from the environment and have no flag; run `
65
+ + '`fabrika platform deploy --provider=zerops --help` for the surface',
66
+ )
67
+ }
68
+ }
69
+ }
70
+
71
+ const readHosts = (
72
+ argv: readonly string[],
73
+ env: Record<string, string | undefined>,
74
+ ): PlatformDeployInput['hosts'] => {
75
+ const iam = setting(argv, env, '--iam-host', 'FABRIKA_PLATFORM_IAM_HOST')
76
+ const control = setting(argv, env, '--console-host', 'FABRIKA_PLATFORM_CONSOLE_HOST')
77
+ const operations = setting(argv, env, '--operations-host', 'FABRIKA_PLATFORM_OPERATIONS_HOST')
78
+ return parsePlatformHosts({ iam, control, operations })
79
+ }
80
+
81
+ const readScheme = (argv: readonly string[], env: Record<string, string | undefined>): 'http' | 'https' => {
82
+ const raw = setting(argv, env, '--scheme', 'FABRIKA_PLATFORM_SCHEME')
83
+ return parsePlatformScheme(raw)
84
+ }
85
+
86
+ const readProject = (argv: readonly string[], env: Record<string, string | undefined>): ZeropsProjectSelector => {
87
+ const projectId = setting(argv, env, '--project-id', 'FABRIKA_ZEROPS_PROJECT_ID')
88
+ const name = setting(argv, env, '--project-name', 'FABRIKA_ZEROPS_PROJECT_NAME')
89
+ if (projectId !== undefined && name !== undefined) {
90
+ throw new Error('name the project by id or by name, not both')
91
+ }
92
+ if (projectId !== undefined) {
93
+ return { kind: 'id', projectId }
94
+ }
95
+ if (name === undefined) {
96
+ throw new Error('--project-id=<id> or FABRIKA_ZEROPS_PROJECT_ID is required (or --project-name with --client-id)')
97
+ }
98
+ const clientId = requiredSetting(setting(argv, env, '--client-id', 'FABRIKA_ZEROPS_CLIENT_ID'), '--client-id', 'FABRIKA_ZEROPS_CLIENT_ID')
99
+ return { kind: 'name', clientId, name }
100
+ }
101
+
102
+ /** Parse the command's arguments and environment into the one input `deployPlatform` takes. */
103
+ export const parsePlatformDeployArgs = (
104
+ argv: readonly string[],
105
+ env: Record<string, string | undefined>,
106
+ ): PlatformDeployInput => {
107
+ const sourceDir = readInstallationSourceDir(argv, env)
108
+ assertKnownArguments(argv)
109
+ const dryRun = argv.includes('--dry-run')
110
+ const hosts = readHosts(argv, env)
111
+ const apiBaseUrl = readEnv(env, 'FABRIKA_ZEROPS_API_URL')
112
+ return {
113
+ project: readProject(argv, env),
114
+ // A dry run reads, and reading still needs a token; it is the one credential it cannot do without.
115
+ accessToken: requiredSetting(readEnv(env, 'FABRIKA_ZEROPS_ACCESS_TOKEN'), '(no flag)', 'FABRIKA_ZEROPS_ACCESS_TOKEN'),
116
+ environment: requiredSetting(setting(argv, env, '--env', 'FABRIKA_PLATFORM_ENVIRONMENT'), '--env', 'FABRIKA_PLATFORM_ENVIRONMENT'),
117
+ // Not required for a dry run: it authenticates a write this mode never makes.
118
+ iamAdminKey: dryRun
119
+ ? readEnv(env, 'FABRIKA_IAM_PROVISIONING_KEY') ?? ''
120
+ : requiredSetting(readEnv(env, 'FABRIKA_IAM_PROVISIONING_KEY'), '(no flag)', 'FABRIKA_IAM_PROVISIONING_KEY'),
121
+ scheme: readScheme(argv, env),
122
+ dryRun,
123
+ ...(hosts === undefined ? {} : { hosts }),
124
+ sourceDir,
125
+ ...(apiBaseUrl === undefined ? {} : { apiBaseUrl }),
126
+ }
127
+ }