@gebit/stax-cli 1.3.2 → 1.4.0

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/dist/validate.js CHANGED
@@ -2,7 +2,7 @@ import { readdirSync, statSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { isMap, isScalar, LineCounter, parseDocument } from "yaml";
4
4
  import { isRecord } from "./guards.js";
5
- import { schema, validateDeployConfig as validateSchema } from "./schema.js";
5
+ import { ajv, schema, validateDeployConfig as validateSchema } from "./schema.js";
6
6
  /** a-wf-deploy-levels runs dependency levels l0 to l13. */
7
7
  const MAX_LEVELS = 14;
8
8
  const KNOWN_KEYS = {
@@ -245,6 +245,61 @@ function checkPipelineRules(data, report) {
245
245
  }
246
246
  }
247
247
  }
248
+ const AWS_OPTION_DEFAULTS = {
249
+ aws_endpoint_url: "",
250
+ aws_endpoint_url_s3: "",
251
+ aws_endpoint_url_sts: "",
252
+ aws_endpoint_url_iam: "",
253
+ aws_s3_compatible: "false",
254
+ aws_skip_sts_check: "false",
255
+ state_use_lockfile: "true",
256
+ state_use_path_style: "false",
257
+ };
258
+ const ENDPOINT_FIELDS = ["aws_endpoint_url", "aws_endpoint_url_s3", "aws_endpoint_url_sts", "aws_endpoint_url_iam"];
259
+ function checkEndpointURLs(deployment, report) {
260
+ const endpointShape = ajv.getSchema(`${schema.$id}#/$defs/endpointUrl`);
261
+ if (!endpointShape)
262
+ throw new Error("endpointUrl schema definition is missing");
263
+ for (const field of ENDPOINT_FIELDS) {
264
+ const raw = deployment[field];
265
+ if (typeof raw !== "string" || !raw.trim() || !endpointShape(raw))
266
+ continue;
267
+ const value = raw.trim();
268
+ try {
269
+ new URL(value);
270
+ }
271
+ catch {
272
+ report.add("error", ["deployment", field], "must be a valid absolute URL with a hostname and valid port");
273
+ continue;
274
+ }
275
+ if (!value.startsWith("https://") && !/^http:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::[0-9]+)?(?:\/|$)/.test(value)) {
276
+ report.add("error", ["deployment", field], "must use https (http is only allowed for localhost / 127.0.0.1 / [::1])");
277
+ }
278
+ }
279
+ }
280
+ function deploymentText(value) {
281
+ return value === undefined || value === null ? "" : String(value).trim();
282
+ }
283
+ /** Mirrors the AWS option checks in .github/scripts/deployment-config.mjs and a-wf-setup-ci. */
284
+ function checkDeploymentRules(data, report) {
285
+ const deployment = data.deployment;
286
+ if (!isRecord(deployment))
287
+ return;
288
+ const cloud = deploymentText(deployment.cloud).toLowerCase();
289
+ checkEndpointURLs(deployment, report);
290
+ const changed = Object.entries(AWS_OPTION_DEFAULTS)
291
+ .filter(([field, fallback]) => {
292
+ const value = deploymentText(deployment[field]);
293
+ return value !== "" && value !== fallback;
294
+ })
295
+ .map(([field]) => field);
296
+ // An unset cloud may still resolve to aws from the CLOUD variable.
297
+ if (cloud !== "" && cloud !== "aws") {
298
+ for (const field of changed)
299
+ report.add("error", ["deployment", field], `only applies to cloud "aws" (cloud is "${cloud}")`);
300
+ return;
301
+ }
302
+ }
248
303
  /** Validates one deploy config. Findings are sorted by position. */
249
304
  export function validateConfigText(text) {
250
305
  const lineCounter = new LineCounter();
@@ -273,6 +328,7 @@ export function validateConfigText(text) {
273
328
  if (Array.isArray(data.stacks)) {
274
329
  data.stacks.forEach((stack, index) => checkUnknownKeys(stack, KNOWN_KEYS.stack, ["stacks", index], report));
275
330
  }
331
+ checkDeploymentRules(data, report);
276
332
  checkPipelineRules(data, report);
277
333
  return report.findings.sort((a, b) => a.line - b.line || a.column - b.column);
278
334
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gebit/stax-cli",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "description": "Scaffold, extend and validate projects for the stax stack framework",
5
5
  "type": "module",
6
6
  "license": "GPL-3.0-only",
@@ -31,6 +31,11 @@
31
31
  },
32
32
  "$defs": {
33
33
  "deploymentValue": { "type": ["string", "null"], "pattern": "^[^\\r\\n]*$" },
34
+ "deploymentFlag": { "type": ["boolean", "string", "null"], "pattern": "^(?:true|false|[^\\S\\r\\n]*)$" },
35
+ "endpointUrl": {
36
+ "type": ["string", "null"],
37
+ "pattern": "^(?:[^\\S\\r\\n]*(?:https://[^\\s@/?#\\\\]+(?:/[^\\s@?#\\\\]*)?|http://(?:localhost|127\\.0\\.0\\.1|\\[::1\\])(?::[0-9]+)?(?:/[^\\s@?#\\\\]*)?)[^\\S\\r\\n]*|[^\\S\\r\\n]*)$"
38
+ },
34
39
  "deployment": {
35
40
  "type": ["object", "null"],
36
41
  "additionalProperties": false,
@@ -48,7 +53,15 @@
48
53
  "state_container_name": { "description": "Azure state container; falls back to STATE_CONTAINER_NAME.", "$ref": "#/$defs/deploymentValue" },
49
54
  "state_resource_group_name": { "description": "Azure state resource group; falls back to STATE_RESOURCE_GROUP_NAME.", "$ref": "#/$defs/deploymentValue" },
50
55
  "state_bucket_name": { "description": "AWS state bucket; falls back to STATE_BUCKET_NAME.", "$ref": "#/$defs/deploymentValue" },
51
- "state_region": { "description": "AWS state region; falls back to STATE_REGION.", "$ref": "#/$defs/deploymentValue" }
56
+ "state_region": { "description": "AWS state region; falls back to STATE_REGION.", "$ref": "#/$defs/deploymentValue" },
57
+ "aws_endpoint_url": { "description": "AWS only: base endpoint for every AWS service, e.g. a MinIO server; falls back to AWS_ENDPOINT_URL. https, or http on localhost.", "$ref": "#/$defs/endpointUrl" },
58
+ "aws_endpoint_url_s3": { "description": "AWS only: S3 endpoint for the state backend and the AWS provider, e.g. https://s3.eu-central-2.wasabisys.com; falls back to AWS_ENDPOINT_URL_S3.", "$ref": "#/$defs/endpointUrl" },
59
+ "aws_endpoint_url_sts": { "description": "AWS only: STS endpoint; falls back to AWS_ENDPOINT_URL_STS. Not supported with OIDC_ENABLED.", "$ref": "#/$defs/endpointUrl" },
60
+ "aws_endpoint_url_iam": { "description": "AWS only: IAM endpoint; falls back to AWS_ENDPOINT_URL_IAM.", "$ref": "#/$defs/endpointUrl" },
61
+ "aws_s3_compatible": { "description": "AWS only: S3-compatible storage mode (checksums only when required, no region or account-id lookups); falls back to AWS_S3_COMPATIBLE. Default false.", "$ref": "#/$defs/deploymentFlag" },
62
+ "aws_skip_sts_check": { "description": "AWS only: skip the STS get-caller-identity check and backend credential validation; falls back to AWS_SKIP_STS_CHECK. Default false.", "$ref": "#/$defs/deploymentFlag" },
63
+ "state_use_lockfile": { "description": "AWS only: S3 native state locking (use_lockfile); falls back to STATE_USE_LOCKFILE. Default true; set false only for stores without conditional writes.", "$ref": "#/$defs/deploymentFlag" },
64
+ "state_use_path_style": { "description": "AWS only: path-style S3 addressing for the state backend; falls back to STATE_USE_PATH_STYLE. Default false.", "$ref": "#/$defs/deploymentFlag" }
52
65
  }
53
66
  },
54
67
  "externalRepo": {