@clisma/config 0.1.0 → 0.1.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/dist/config.d.ts CHANGED
@@ -4,10 +4,16 @@ export type MigrationConfig = {
4
4
  replication_path?: string;
5
5
  vars?: Record<string, unknown>;
6
6
  };
7
+ export type TlsConfig = {
8
+ ca_file: string;
9
+ cert_file?: string;
10
+ key_file?: string;
11
+ };
7
12
  export type EnvConfig = {
8
13
  url: string;
9
14
  exclude?: string[];
10
15
  cluster_name?: string;
16
+ tls?: TlsConfig;
11
17
  migrations: MigrationConfig;
12
18
  };
13
19
  export type VariableConfig = {
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,eAAe,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CAC3C,CAAC;AA2BF;;GAEG;AACH,eAAO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vB,CAAC"}
package/dist/config.js CHANGED
@@ -68,12 +68,37 @@ export const parseConfig = async (content, env = {}, vars = {}, envName, sourceN
68
68
  ? resolveValue(extractValue(envBlock.cluster_name, ""), env, variables)
69
69
  : "";
70
70
  const clusterName = clusterNameValue || undefined;
71
+ const tlsBlock = envBlock.tls?.[0];
72
+ let tls;
73
+ if (tlsBlock) {
74
+ const caFile = tlsBlock.ca_file
75
+ ? resolveValue(extractValue(tlsBlock.ca_file, ""), env, variables)
76
+ : "";
77
+ const certFile = tlsBlock.cert_file
78
+ ? resolveValue(extractValue(tlsBlock.cert_file, ""), env, variables)
79
+ : "";
80
+ const keyFile = tlsBlock.key_file
81
+ ? resolveValue(extractValue(tlsBlock.key_file, ""), env, variables)
82
+ : "";
83
+ if (!caFile) {
84
+ throw new Error(`TLS block in environment "${targetEnv}" requires ca_file`);
85
+ }
86
+ if ((certFile && !keyFile) || (!certFile && keyFile)) {
87
+ throw new Error(`TLS block in environment "${targetEnv}" requires both cert_file and key_file for mTLS`);
88
+ }
89
+ tls = {
90
+ ca_file: caFile,
91
+ cert_file: certFile || undefined,
92
+ key_file: keyFile || undefined,
93
+ };
94
+ }
71
95
  // Parse exclude patterns (optional)
72
96
  const excludePatterns = extractList(envBlock.exclude, []);
73
97
  return {
74
98
  url: resolveValue(url, env, variables),
75
99
  exclude: excludePatterns,
76
100
  cluster_name: clusterName,
101
+ tls,
77
102
  migrations: {
78
103
  dir: resolveValue(migrationDir, env, variables),
79
104
  table_name: tableName,
@@ -44,6 +44,13 @@ export declare const clismaSchema: {
44
44
  };
45
45
  readonly description: "Optional glob patterns to exclude tables.";
46
46
  };
47
+ readonly tls: {
48
+ readonly type: "array";
49
+ readonly items: {
50
+ readonly $ref: "#/$defs/tlsBlock";
51
+ };
52
+ readonly description: "Optional TLS settings for custom CA and mutual TLS client certificates.";
53
+ };
47
54
  readonly migrations: {
48
55
  readonly type: "array";
49
56
  readonly items: {
@@ -78,6 +85,25 @@ export declare const clismaSchema: {
78
85
  };
79
86
  };
80
87
  };
88
+ readonly tlsBlock: {
89
+ readonly type: "object";
90
+ readonly additionalProperties: false;
91
+ readonly required: readonly ["ca_file"];
92
+ readonly properties: {
93
+ readonly ca_file: {
94
+ readonly type: "string";
95
+ readonly description: "Path to CA certificate file (PEM) used to verify the server certificate.";
96
+ };
97
+ readonly cert_file: {
98
+ readonly type: "string";
99
+ readonly description: "Path to client certificate file (PEM) for mutual TLS.";
100
+ };
101
+ readonly key_file: {
102
+ readonly type: "string";
103
+ readonly description: "Path to client private key file (PEM) for mutual TLS.";
104
+ };
105
+ };
106
+ };
81
107
  readonly variableBlock: {
82
108
  readonly type: "object";
83
109
  readonly additionalProperties: false;
@@ -1 +1 @@
1
- {"version":3,"file":"hcl-schema.d.ts","sourceRoot":"","sources":["../src/hcl-schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwGf,CAAC;AAEX,eAAO,MAAM,cAAc,QAAO,OAAO,YAExC,CAAC"}
1
+ {"version":3,"file":"hcl-schema.d.ts","sourceRoot":"","sources":["../src/hcl-schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqIf,CAAC;AAEX,eAAO,MAAM,cAAc,QAAO,OAAO,YAExC,CAAC"}
@@ -44,6 +44,13 @@ export const clismaSchema = {
44
44
  },
45
45
  description: "Optional glob patterns to exclude tables.",
46
46
  },
47
+ tls: {
48
+ type: "array",
49
+ items: {
50
+ $ref: "#/$defs/tlsBlock",
51
+ },
52
+ description: "Optional TLS settings for custom CA and mutual TLS client certificates.",
53
+ },
47
54
  migrations: {
48
55
  type: "array",
49
56
  items: {
@@ -78,6 +85,25 @@ export const clismaSchema = {
78
85
  },
79
86
  },
80
87
  },
88
+ tlsBlock: {
89
+ type: "object",
90
+ additionalProperties: false,
91
+ required: ["ca_file"],
92
+ properties: {
93
+ ca_file: {
94
+ type: "string",
95
+ description: "Path to CA certificate file (PEM) used to verify the server certificate.",
96
+ },
97
+ cert_file: {
98
+ type: "string",
99
+ description: "Path to client certificate file (PEM) for mutual TLS.",
100
+ },
101
+ key_file: {
102
+ type: "string",
103
+ description: "Path to client private key file (PEM) for mutual TLS.",
104
+ },
105
+ },
106
+ },
81
107
  variableBlock: {
82
108
  type: "object",
83
109
  additionalProperties: false,
@@ -21,6 +21,21 @@ variable "ttl_days" {
21
21
  default = "30"
22
22
  }
23
23
  `;
24
+ const SAMPLE_HCL_WITH_TLS = `
25
+ env "prod" {
26
+ url = "https://default:password@localhost:8443/default"
27
+
28
+ tls {
29
+ ca_file = env("TLS_CA_FILE")
30
+ cert_file = "certs/client.pem"
31
+ key_file = "certs/client.key"
32
+ }
33
+
34
+ migrations {
35
+ dir = "migrations"
36
+ }
37
+ }
38
+ `;
24
39
  test("parseConfig resolves env() and var.* values", async () => {
25
40
  const config = await parseConfig(SAMPLE_HCL, {
26
41
  CLICKHOUSE_URL: "lol",
@@ -31,3 +46,27 @@ test("parseConfig resolves env() and var.* values", async () => {
31
46
  assert.equal(config.migrations.vars?.ttl_static, "var.ttl_days");
32
47
  assert.equal(config.migrations.vars?.ttl_unexisting, "");
33
48
  });
49
+ test("parseConfig resolves TLS block and validates mTLS fields", async () => {
50
+ const config = await parseConfig(SAMPLE_HCL_WITH_TLS, {
51
+ TLS_CA_FILE: "certs/ca.pem",
52
+ }, {}, "prod");
53
+ assert.equal(config.tls?.ca_file, "certs/ca.pem");
54
+ assert.equal(config.tls?.cert_file, "certs/client.pem");
55
+ assert.equal(config.tls?.key_file, "certs/client.key");
56
+ });
57
+ test("parseConfig throws when only one mTLS file is provided", async () => {
58
+ await assert.rejects(() => parseConfig(`
59
+ env "prod" {
60
+ url = "https://default:password@localhost:8443/default"
61
+
62
+ tls {
63
+ ca_file = "certs/ca.pem"
64
+ cert_file = "certs/client.pem"
65
+ }
66
+
67
+ migrations {
68
+ dir = "migrations"
69
+ }
70
+ }
71
+ `, {}, {}, "prod"), /requires both cert_file and key_file/);
72
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clisma/config",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Configuration parsing and schema generation for clisma",
5
5
  "type": "module",
6
6
  "main": "dist/config.js",
@@ -8,6 +8,10 @@
8
8
  "files": [
9
9
  "dist"
10
10
  ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/StopMakingThatBigFace/clisma.git"
14
+ },
11
15
  "dependencies": {
12
16
  "@cdktf/hcl2json": "^0.21.0"
13
17
  },
package/dist/schema.d.ts DELETED
@@ -1,96 +0,0 @@
1
- export declare const clismaSchema: {
2
- readonly $schema: "https://json-schema.org/draft/2020-12/schema";
3
- readonly title: "clisma.hcl";
4
- readonly type: "object";
5
- readonly additionalProperties: false;
6
- readonly properties: {
7
- readonly env: {
8
- readonly type: "object";
9
- readonly additionalProperties: {
10
- readonly type: "array";
11
- readonly items: {
12
- readonly $ref: "#/$defs/envBlock";
13
- };
14
- };
15
- };
16
- readonly variable: {
17
- readonly type: "object";
18
- readonly additionalProperties: {
19
- readonly type: "array";
20
- readonly items: {
21
- readonly $ref: "#/$defs/variableBlock";
22
- };
23
- };
24
- };
25
- };
26
- readonly $defs: {
27
- readonly envBlock: {
28
- readonly type: "object";
29
- readonly additionalProperties: false;
30
- readonly required: readonly ["url", "migration"];
31
- readonly properties: {
32
- readonly url: {
33
- readonly type: "string";
34
- readonly description: "ClickHouse connection string.";
35
- };
36
- readonly exclude: {
37
- readonly type: "array";
38
- readonly items: {
39
- readonly type: "string";
40
- };
41
- readonly description: "Optional glob patterns to exclude tables.";
42
- };
43
- readonly migration: {
44
- readonly type: "array";
45
- readonly items: {
46
- readonly $ref: "#/$defs/migrationBlock";
47
- };
48
- };
49
- };
50
- };
51
- readonly migrationBlock: {
52
- readonly type: "object";
53
- readonly additionalProperties: false;
54
- readonly required: readonly ["dir"];
55
- readonly properties: {
56
- readonly dir: {
57
- readonly type: "string";
58
- readonly description: "Path to migrations directory.";
59
- };
60
- readonly table_name: {
61
- readonly type: "string";
62
- readonly description: "Custom table name for migration tracking.";
63
- };
64
- readonly vars: {
65
- readonly type: "object";
66
- readonly description: "Variables for Handlebars templates.";
67
- readonly additionalProperties: {
68
- readonly $ref: "#/$defs/variableValue";
69
- };
70
- };
71
- };
72
- };
73
- readonly variableBlock: {
74
- readonly type: "object";
75
- readonly additionalProperties: false;
76
- readonly required: readonly ["type"];
77
- readonly properties: {
78
- readonly type: {
79
- readonly type: "string";
80
- readonly description: "Variable type.";
81
- readonly enum: readonly ["string", "number", "bool", "any"];
82
- };
83
- readonly default: {
84
- readonly $ref: "#/$defs/variableValue";
85
- };
86
- readonly description: {
87
- readonly type: "string";
88
- };
89
- };
90
- };
91
- readonly variableValue: {
92
- readonly type: readonly ["string", "number", "boolean", "object", "array", "null"];
93
- };
94
- };
95
- };
96
- //# sourceMappingURL=schema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Ff,CAAC"}
package/dist/schema.js DELETED
@@ -1,95 +0,0 @@
1
- export const clismaSchema = {
2
- $schema: "https://json-schema.org/draft/2020-12/schema",
3
- title: "clisma.hcl",
4
- type: "object",
5
- additionalProperties: false,
6
- properties: {
7
- env: {
8
- type: "object",
9
- additionalProperties: {
10
- type: "array",
11
- items: {
12
- $ref: "#/$defs/envBlock",
13
- },
14
- },
15
- },
16
- variable: {
17
- type: "object",
18
- additionalProperties: {
19
- type: "array",
20
- items: {
21
- $ref: "#/$defs/variableBlock",
22
- },
23
- },
24
- },
25
- },
26
- $defs: {
27
- envBlock: {
28
- type: "object",
29
- additionalProperties: false,
30
- required: ["url", "migration"],
31
- properties: {
32
- url: {
33
- type: "string",
34
- description: "ClickHouse connection string.",
35
- },
36
- exclude: {
37
- type: "array",
38
- items: {
39
- type: "string",
40
- },
41
- description: "Optional glob patterns to exclude tables.",
42
- },
43
- migration: {
44
- type: "array",
45
- items: {
46
- $ref: "#/$defs/migrationBlock",
47
- },
48
- },
49
- },
50
- },
51
- migrationBlock: {
52
- type: "object",
53
- additionalProperties: false,
54
- required: ["dir"],
55
- properties: {
56
- dir: {
57
- type: "string",
58
- description: "Path to migrations directory.",
59
- },
60
- table_name: {
61
- type: "string",
62
- description: "Custom table name for migration tracking.",
63
- },
64
- vars: {
65
- type: "object",
66
- description: "Variables for Handlebars templates.",
67
- additionalProperties: {
68
- $ref: "#/$defs/variableValue",
69
- },
70
- },
71
- },
72
- },
73
- variableBlock: {
74
- type: "object",
75
- additionalProperties: false,
76
- required: ["type"],
77
- properties: {
78
- type: {
79
- type: "string",
80
- description: "Variable type.",
81
- enum: ["string", "number", "bool", "any"],
82
- },
83
- default: {
84
- $ref: "#/$defs/variableValue",
85
- },
86
- description: {
87
- type: "string",
88
- },
89
- },
90
- },
91
- variableValue: {
92
- type: ["string", "number", "boolean", "object", "array", "null"],
93
- },
94
- },
95
- };