pmcf 6.62.1 → 6.63.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "6.62.1",
3
+ "version": "6.63.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/base.mjs CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  boolean_attribute_writable,
20
20
  default_attribute_writable
21
21
  } from "pacc";
22
- import { union } from "./utils.mjs";
22
+ import { union, writeLines } from "./utils.mjs";
23
23
  import { addType } from "./type.mjs";
24
24
  import { core } from "./core.mjs";
25
25
  import { owner_attribute, aliases_attribute } from "./common-attributes.mjs";
@@ -210,6 +210,30 @@ export class base extends core {
210
210
  return this.constructor.name;
211
211
  }
212
212
 
213
+ async writeSystemdCredentialConfig(dir, serviceName) {
214
+ let lines = [];
215
+
216
+ const seen = new Set();
217
+
218
+ for (const [credentialName, cred] of this.credentials) {
219
+ if (cred.tags.has(serviceName) && !seen.has(credentialName)) {
220
+ seen.add(credentialName);
221
+ lines.push(
222
+ `LoadCredentialEncrypted=${cred.localName}:/etc/credstore.encrypted/${credentialName}`
223
+ );
224
+ }
225
+ }
226
+
227
+ if (lines.length) {
228
+ await writeLines(
229
+ join(dir, `usr/lib/systemd/system/${serviceName}.d`),
230
+ `credentials.conf`,
231
+ "[Service]",
232
+ lines
233
+ );
234
+ }
235
+ }
236
+
213
237
  set content(value) {
214
238
  this._content = value;
215
239
  }
@@ -10,9 +10,7 @@ import {
10
10
  string_set_attribute_writable,
11
11
  number_attribute_writable,
12
12
  priority_attribute,
13
- default_collection_attribute_writable,
14
- asArray,
15
- boolean_attribute_writable_false
13
+ asArray
16
14
  } from "pacc";
17
15
  import {
18
16
  base,
@@ -22,12 +20,12 @@ import {
22
20
  HTTPEndpoint,
23
21
  unix_endpoint
24
22
  } from "pmcf";
25
- import { writeLines } from "./utils.mjs";
26
23
  import { addType } from "./type.mjs";
27
24
  import { FAMILY_UNIX, FAMILY_DNS } from "./constants.mjs";
28
25
  import {
29
26
  networkAddressAttributes,
30
- extends_attribute,credentials_attribute,
27
+ extends_attribute,
28
+ credentials_attribute,
31
29
  networkInterfaces_attribute,
32
30
  endpointAttributes
33
31
  } from "./common-attributes.mjs";
@@ -267,30 +265,6 @@ export class CoreService extends base {
267
265
  return serviceTypes(ServiceTypes[this.type]);
268
266
  }
269
267
 
270
- async writeSystemdCredentialConfig(dir, serviceName) {
271
- let lines = [];
272
-
273
- const seen = new Set();
274
-
275
- for (const [credentialName, cred] of this.credentials) {
276
- if (cred.tags.has(serviceName) && !seen.has(credentialName)) {
277
- seen.add(credentialName);
278
- lines.push(
279
- `LoadCredentialEncrypted=${credentialName}:/etc/credstore.encrypted/${credentialName}`
280
- );
281
- }
282
- }
283
-
284
- if (lines.length) {
285
- await writeLines(
286
- join(dir, `usr/lib/systemd/system/${serviceName}.d`),
287
- `credentials.conf`,
288
- "[Service]",
289
- lines
290
- );
291
- }
292
- }
293
-
294
268
  get systemdService() {
295
269
  return (
296
270
  this.attribute("_systemdService") ??
@@ -1,8 +1,21 @@
1
+ import { string_attribute_writable } from "pacc";
1
2
  import { base } from "./base.mjs";
2
3
  import { addType } from "./type.mjs";
3
4
 
4
5
  export class credential extends base {
6
+ static attributes = {
7
+ localName: { ...string_attribute_writable, name: "localName" }
8
+ };
9
+
5
10
  static {
6
11
  addType(this);
7
12
  }
13
+
14
+ get localName() {
15
+ return this._localName ?? this.name;
16
+ }
17
+
18
+ set localName(value) {
19
+ this._localName = value;
20
+ }
8
21
  }
@@ -2,9 +2,12 @@ import { join } from "node:path";
2
2
  import { duration_attribute_writable } from "pacc";
3
3
  import { addType } from "./type.mjs";
4
4
  import { cluster } from "./cluster.mjs";
5
+ import { credential } from "./credential.mjs";
5
6
  import { FAMILY_IPV4 } from "ip-utilties";
6
7
  import { serviceEndpoints } from "./core-service.mjs";
7
8
  import { PROTOCOL_TCP } from "./constants.mjs";
9
+ import { credentials_attribute } from "./common-attributes.mjs";
10
+
8
11
  import { writeLines } from "./utils.mjs";
9
12
 
10
13
  export class keepalived extends cluster {
@@ -14,7 +17,8 @@ export class keepalived extends cluster {
14
17
  ...duration_attribute_writable,
15
18
  name: "checkInterval",
16
19
  default: 60
17
- }
20
+ },
21
+ credentials: credentials_attribute
18
22
  };
19
23
 
20
24
  static {
@@ -22,6 +26,7 @@ export class keepalived extends cluster {
22
26
  }
23
27
 
24
28
  checkInterval = 60;
29
+ credentials = new Map();
25
30
 
26
31
  async *preparePackages(stagingDir) {
27
32
  for (const ni of [...this.owner.clusters.values()].reduce(
@@ -55,7 +60,6 @@ export class keepalived extends cluster {
55
60
  ""
56
61
  ];
57
62
 
58
- const credentials = new Map();
59
63
  for (const cluster of [...this.owner.clusters.values()].sort((a, b) =>
60
64
  a.name.localeCompare(b.name)
61
65
  )) {
@@ -87,16 +91,20 @@ export class keepalived extends cluster {
87
91
  reducedPrio = cluster.backups.indexOf(ni) + 5;
88
92
  }
89
93
 
90
- const credential = name.toUpperCase() + "_PASSWORD";
91
- credentials.set(credential, name);
94
+ const cred = new credential(this);
95
+ cred.name = `keepalived.${name}.password`;
96
+ cred.localName = name.toUpperCase() + "_PASSWORD";
97
+ cred._tags.add("keepalived.service");
98
+ this.credentials.set(cred.name, cred);
99
+
92
100
  cfg.push(` priority ${host.priority - reducedPrio}`);
93
101
  cfg.push(" smtp_alert");
94
102
  cfg.push(" advert_int 5");
95
103
  cfg.push(" authentication {");
96
104
  cfg.push(" auth_type PASS");
97
105
  cfg.push(" auth_pass pass1234");
98
- cfg.push(" # auth_pass ${_ENV " + credential + "}");
99
- cfg.push(" # auth_pass ${" + credential + "}");
106
+ cfg.push(" # auth_pass ${_ENV " + cred.localName + "}");
107
+ cfg.push(" # auth_pass ${" + cred.localName + "}");
100
108
  cfg.push(" }");
101
109
 
102
110
  cfg.push(
@@ -191,19 +199,7 @@ export class keepalived extends cluster {
191
199
  ]
192
200
  );
193
201
 
194
- await writeLines(
195
- join(packageStagingDir, "/usr/lib/systemd/system/keepalived.d"),
196
- "credentials.conf",
197
- [
198
- "[Service]",
199
- ...credentials
200
- .entries()
201
- .map(
202
- ([credName, instance]) =>
203
- `LoadCredentialEncrypted=${credName}:/etc/credstore.encrypted/keepalived.${instance}.password`
204
- )
205
- ]
206
- );
202
+ await this.writeSystemdCredentialConfig(packageStagingDir, "keepalived.service");
207
203
  }
208
204
 
209
205
  await writeLines(