pmcf 3.20.2 → 3.21.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": "3.20.2",
3
+ "version": "3.21.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -55,7 +55,7 @@
55
55
  "dependencies": {
56
56
  "ip-utilties": "^2.0.2",
57
57
  "npm-pkgbuild": "^19.1.3",
58
- "pacc": "^7.0.0",
58
+ "pacc": "^7.1.0",
59
59
  "package-directory": "^8.1.0"
60
60
  },
61
61
  "devDependencies": {
package/src/base.mjs CHANGED
@@ -6,6 +6,8 @@ import {
6
6
  parse,
7
7
  globals,
8
8
  expand,
9
+ toExternal,
10
+ filterPublic,
9
11
  attributeIterator,
10
12
  default_attribute,
11
13
  name_attribute_writable,
@@ -16,6 +18,7 @@ import {
16
18
  description_attribute_writable,
17
19
  boolean_attribute_writable
18
20
  } from "pacc";
21
+
19
22
  import { asArray } from "./utils.mjs";
20
23
 
21
24
  /**
@@ -282,8 +285,7 @@ export class Base {
282
285
  }*/
283
286
  }
284
287
 
285
- _applyExtends() {
286
- }
288
+ _applyExtends() {}
287
289
 
288
290
  set extends(value) {
289
291
  this._extends.push(value);
@@ -376,6 +378,35 @@ export class Base {
376
378
  return this._extendedProperty(propertyName, new Set());
377
379
  }
378
380
 
381
+ /**
382
+ * Retrive attribute values from an object.
383
+ * @return {Object} values
384
+ */
385
+ getProperties(filter = filterPublic) {
386
+ const result = {};
387
+
388
+ for (
389
+ let typeDefinition = this.constructor.typeDefinition;
390
+ typeDefinition;
391
+ typeDefinition = typeDefinition.extends
392
+ ) {
393
+ for (const [path, def] of attributeIterator(
394
+ typeDefinition.attributes,
395
+ filter
396
+ )) {
397
+ const name = path.join(".");
398
+
399
+ let value = this.extendedProperty(name);
400
+
401
+ if (value !== undefined) {
402
+ result[def.externalName ?? name] = toExternal(value, def);
403
+ }
404
+ }
405
+ }
406
+
407
+ return result;
408
+ }
409
+
379
410
  get root() {
380
411
  return this.owner.root;
381
412
  }
@@ -516,7 +547,7 @@ export class Base {
516
547
  }
517
548
 
518
549
  get isTemplate() {
519
- return this.name?.indexOf("*") >= 0 || this.owner?.isTemplate || false;
550
+ return this.name?.indexOf("*") >= 0 || this.owner?.isTemplate || false;
520
551
  }
521
552
 
522
553
  get properties() {
@@ -654,10 +685,10 @@ export function extractFrom(
654
685
  const json = {};
655
686
 
656
687
  do {
657
- for (const [path, def] of attributeIterator(typeDefinition.attributes)) {
658
- if (def.private) {
659
- continue;
660
- }
688
+ for (const [path, def] of attributeIterator(
689
+ typeDefinition.attributes,
690
+ filterPublic
691
+ )) {
661
692
  const name = path.join(".");
662
693
  let value = object[name];
663
694
 
@@ -1,10 +1,10 @@
1
1
  import {
2
- getAttributesJSON,
3
2
  addType,
4
3
  string_attribute_writable,
5
4
  boolean_attribute_writable
6
5
  } from "pacc";
7
6
  import { Service, ServiceTypeDefinition, addServiceType } from "pmcf";
7
+ import { filterConfigurable } from "../utils.mjs";
8
8
 
9
9
  const SystemdJournalRemoteServiceTypeDefinition = {
10
10
  name: "systemd-journal-remote",
@@ -14,59 +14,66 @@ const SystemdJournalRemoteServiceTypeDefinition = {
14
14
  key: "name",
15
15
  attributes: {
16
16
  Seal: {
17
- ...boolean_attribute_writable
17
+ ...boolean_attribute_writable,
18
+ configurable: true
18
19
  },
19
20
  SplitMode: {
20
21
  ...string_attribute_writable,
21
- values: [false, "host"]
22
+ values: [false, "host"],
23
+ configurable: true
22
24
  },
23
25
  ServerKeyFile: {
24
- ...string_attribute_writable
26
+ ...string_attribute_writable,
27
+ configurable: true
25
28
  // default: "/etc/ssl/private/journal-upload.pem"
26
29
  },
27
30
  ServerCertificateFile: {
28
- ...string_attribute_writable
31
+ ...string_attribute_writable,
32
+ configurable: true
29
33
  // default: "/etc/ssl/certs/journal-upload.pem"
30
34
  },
31
35
  TrustedCertificateFile: {
32
- ...string_attribute_writable
36
+ ...string_attribute_writable,
37
+ configurable: true
33
38
  // default: "/etc/ssl/ca/trusted.pem"
34
39
  },
35
40
  MaxUse: {
36
- ...string_attribute_writable
41
+ ...string_attribute_writable,
42
+ configurable: true
37
43
  },
38
44
  KeepFree: {
39
- ...string_attribute_writable
45
+ ...string_attribute_writable,
46
+ configurable: true
40
47
  },
41
48
  MaxFileSize: {
42
- ...string_attribute_writable
49
+ ...string_attribute_writable,
50
+ configurable: true
43
51
  },
44
52
  MaxFiles: {
45
- ...string_attribute_writable
53
+ ...string_attribute_writable,
54
+ configurable: true
46
55
  },
47
56
  Compression: {
48
- ...string_attribute_writable
57
+ ...string_attribute_writable,
58
+ configurable: true
49
59
  // default: "zstd lz4 xz"
50
60
  }
51
61
  },
52
-
53
62
  service: {
54
- services: {
55
- endpoints: [
56
- {
57
- family: "IPv4",
58
- port: 19532,
59
- protocol: "tcp",
60
- tls: false
61
- },
62
- {
63
- family: "IPv6",
64
- port: 19532,
65
- protocol: "tcp",
66
- tls: false
67
- }
68
- ]
69
- }
63
+ endpoints: [
64
+ {
65
+ family: "IPv4",
66
+ port: 19532,
67
+ protocol: "tcp",
68
+ tls: false
69
+ },
70
+ {
71
+ family: "IPv6",
72
+ port: 19532,
73
+ protocol: "tcp",
74
+ tls: false
75
+ }
76
+ ]
70
77
  }
71
78
  };
72
79
 
@@ -102,23 +109,7 @@ export class SystemdJournalRemoteService extends Service {
102
109
  {
103
110
  serviceName: "systemd-journal-remote.service",
104
111
  configFileName: `etc/systemd/journal-remote.conf.d/${name}.conf`,
105
- content: [
106
- "Remote",
107
- {
108
- ...getAttributesJSON(
109
- this,
110
- SystemdJournalRemoteServiceTypeDefinition.attributes
111
- ),
112
- // TODO extendet properties with getAttribute()
113
- ...Object.fromEntries(
114
- Object.entries(
115
- SystemdJournalRemoteServiceTypeDefinition.attributes
116
- )
117
- .map(([k, v]) => [k, this.extendedProperty(k)])
118
- .filter(([k, v]) => v !== undefined)
119
- )
120
- }
121
- ]
112
+ content: ["Remote", this.getProperties(filterConfigurable)]
122
113
  }
123
114
  ];
124
115
  }
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  string_attribute_writable,
3
3
  boolean_attribute_writable,
4
- addType,
5
- getAttributesJSON
4
+ addType
6
5
  } from "pacc";
7
6
  import { Service, ServiceTypeDefinition, addServiceType } from "pmcf";
7
+ import { filterConfigurable } from "../utils.mjs";
8
8
 
9
9
  const SystemdJournalUploadServiceTypeDefinition = {
10
10
  name: "systemd-journal-upload",
@@ -13,28 +13,34 @@ const SystemdJournalUploadServiceTypeDefinition = {
13
13
  owners: ServiceTypeDefinition.owners,
14
14
  key: "name",
15
15
  attributes: {
16
- URL: string_attribute_writable,
16
+ URL: { ...string_attribute_writable, configurable: true },
17
17
  ServerKeyFile: {
18
- ...string_attribute_writable
18
+ ...string_attribute_writable,
19
+ configurable: true
19
20
  // default: "/etc/ssl/private/journal-upload.pem"
20
21
  },
21
22
  ServerCertificateFile: {
22
- ...string_attribute_writable
23
+ ...string_attribute_writable,
24
+ configurable: true
23
25
  // default: "/etc/ssl/certs/journal-upload.pem"
24
26
  },
25
27
  TrustedCertificateFile: {
26
- ...string_attribute_writable
28
+ ...string_attribute_writable,
29
+ configurable: true
27
30
  // default: "/etc/ssl/ca/trusted.pem"
28
31
  },
29
32
  Compression: {
30
- ...string_attribute_writable
33
+ ...string_attribute_writable,
34
+ configurable: true
31
35
  // default: "zstd lz4 xz"
32
36
  },
33
37
  ForceCompression: {
34
- ...boolean_attribute_writable
38
+ ...boolean_attribute_writable,
39
+ configurable: true
35
40
  // default: false
36
41
  }
37
- }
42
+ },
43
+ service: {}
38
44
  };
39
45
 
40
46
  /**
@@ -69,21 +75,7 @@ export class SystemdJournalUploadService extends Service {
69
75
  return {
70
76
  serviceName: "systemd-journal-upload.service",
71
77
  configFileName: `etc/systemd/journal-upload.conf.d/${name}.conf`,
72
- content: [
73
- "Upload",
74
- {
75
- ...getAttributesJSON(
76
- this,
77
- SystemdJournalUploadServiceTypeDefinition.attributes
78
- ),
79
- // TODO extendet properties with getAttribute()
80
- ...Object.fromEntries(
81
- Object.entries(SystemdJournalUploadServiceTypeDefinition.attributes)
82
- .map(([k, v]) => [k, this.extendedProperty(k)])
83
- .filter(([k, v]) => v !== undefined)
84
- )
85
- }
86
- ]
78
+ content: ["Upload", this.getProperties(filterConfigurable)]
87
79
  };
88
80
  }
89
81
  }
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  addType,
3
- getAttributesJSON,
4
3
  string_attribute_writable,
5
4
  duration_attribute_writable
6
5
  } from "pacc";
7
- import { Service, ServiceTypeDefinition } from "pmcf";
6
+ import { Service, ServiceTypeDefinition, addServiceType } from "pmcf";
7
+ import { filterConfigurable } from "../utils.mjs";
8
8
 
9
9
  const SystemdJournalServiceTypeDefinition = {
10
10
  name: "systemd-journal",
@@ -14,80 +14,105 @@ const SystemdJournalServiceTypeDefinition = {
14
14
  key: "name",
15
15
  attributes: {
16
16
  Storage: {
17
- ...string_attribute_writable
17
+ ...string_attribute_writable,
18
+ configurable: true
18
19
  },
19
20
  Seal: {
20
- ...string_attribute_writable
21
+ ...string_attribute_writable,
22
+ configurable: true
21
23
  },
22
24
  SplitMode: {
23
- ...string_attribute_writable
25
+ ...string_attribute_writable,
26
+ configurable: true
24
27
  },
25
28
  SyncIntervalSec: {
26
- ...duration_attribute_writable
29
+ ...duration_attribute_writable,
30
+ configurable: true
27
31
  },
28
32
  RateLimitIntervalSec: {
29
- ...duration_attribute_writable
33
+ ...duration_attribute_writable,
34
+ configurable: true
30
35
  },
31
36
  RateLimitBurst: {
32
- ...string_attribute_writable
37
+ ...string_attribute_writable,
38
+ configurable: true
33
39
  },
34
40
  SystemMaxUse: {
35
- ...string_attribute_writable
41
+ ...string_attribute_writable,
42
+ configurable: true
36
43
  },
37
44
  SystemKeepFree: {
38
- ...string_attribute_writable
45
+ ...string_attribute_writable,
46
+ configurable: true
39
47
  },
40
48
  SystemMaxFileSize: {
41
- ...string_attribute_writable
49
+ ...string_attribute_writable,
50
+ configurable: true
42
51
  },
43
52
  SystemMaxFiles: {
44
- ...string_attribute_writable
53
+ ...string_attribute_writable,
54
+ configurable: true
45
55
  },
46
56
  RuntimeMaxUse: {
47
- ...string_attribute_writable
57
+ ...string_attribute_writable,
58
+ configurable: true
48
59
  },
49
60
  RuntimeKeepFree: {
50
- ...string_attribute_writable
61
+ ...string_attribute_writable,
62
+ configurable: true
51
63
  },
52
64
  RuntimeMaxFileSize: {
53
- ...string_attribute_writable
65
+ ...string_attribute_writable,
66
+ configurable: true
54
67
  },
55
68
  RuntimeMaxFiles: {
56
- ...string_attribute_writable
69
+ ...string_attribute_writable,
70
+ configurable: true
57
71
  },
58
72
  MaxRetentionSec: {
59
- ...duration_attribute_writable
73
+ ...duration_attribute_writable,
74
+ configurable: true
60
75
  },
61
76
  MaxFileSec: {
62
- ...duration_attribute_writable
77
+ ...duration_attribute_writable,
78
+ configurable: true
63
79
  },
64
80
  ForwardToSyslog: {
65
- ...string_attribute_writable
81
+ ...string_attribute_writable,
82
+ configurable: true
66
83
  },
67
84
  ForwardToKMsg: {
68
- ...string_attribute_writable
85
+ ...string_attribute_writable,
86
+ configurable: true
69
87
  },
70
88
  ForwardToConsole: {
71
- ...string_attribute_writable
89
+ ...string_attribute_writable,
90
+ configurable: true
72
91
  },
73
92
  ForwardToWall: {
74
- ...string_attribute_writable
93
+ ...string_attribute_writable,
94
+ configurable: true
75
95
  },
76
96
  TTYPath: {
77
- ...string_attribute_writable
97
+ ...string_attribute_writable,
98
+ configurable: true
78
99
  },
79
100
  MaxLevelStore: {
80
- ...string_attribute_writable
101
+ ...string_attribute_writable,
102
+ configurable: true
81
103
  },
82
104
  Compress: {
83
- ...string_attribute_writable
105
+ ...string_attribute_writable,
106
+ configurable: true
84
107
  }
85
- }
108
+ },
109
+ service: {}
86
110
  };
87
111
 
88
112
  export class SystemdJournalService extends Service {
89
113
  static {
90
114
  addType(this);
115
+ addServiceType(this.typeDefinition.service, this.typeDefinition.name);
91
116
  }
92
117
 
93
118
  static get typeDefinition() {
@@ -104,22 +129,9 @@ export class SystemdJournalService extends Service {
104
129
 
105
130
  systemdConfigs(name) {
106
131
  return {
107
- serviceName: "systemd-journald",
132
+ serviceName: "systemd-journald.service",
108
133
  configFileName: `etc/systemd/journal.conf.d/${name}.conf`,
109
- content: [
110
- "Journal",
111
- {
112
- ...getAttributesJSON(
113
- this,
114
- SystemdJournalServiceTypeDefinition.attributes
115
- ),
116
- ...Object.fromEntries(
117
- Object.entries(SystemdJournalServiceTypeDefinition.attributes)
118
- .map(([k, v]) => [k, this.extendedProperty(k)])
119
- .filter(([k, v]) => v !== undefined)
120
- )
121
- }
122
- ]
134
+ content: ["Journal", this.getProperties(filterConfigurable)]
123
135
  };
124
136
  }
125
137
  }
@@ -9,9 +9,10 @@ import {
9
9
  ExtraSourceService,
10
10
  ExtraSourceServiceTypeDefinition,
11
11
  ServiceTypeDefinition,
12
- serviceEndpoints
12
+ serviceEndpoints,
13
+ addServiceType
13
14
  } from "pmcf";
14
- import { yesno } from "../utils.mjs";
15
+ import { filterConfigurable, yesno } from "../utils.mjs";
15
16
 
16
17
  const SystemdResolvedServiceTypeDefinition = {
17
18
  name: "systemd-resolved",
@@ -20,27 +21,32 @@ const SystemdResolvedServiceTypeDefinition = {
20
21
  owners: ServiceTypeDefinition.owners,
21
22
  key: "name",
22
23
  attributes: {
23
- DNS: string_attribute_writable,
24
- FallbackDNS: string_attribute_writable,
25
- Domains: string_attribute_writable,
26
- MulticastDNS: boolean_attribute_writable,
27
- Cache: boolean_attribute_writable,
28
- CacheFromLocalhost: boolean_attribute_writable,
29
- DNSStubListener: boolean_attribute_writable,
30
- DNSStubListenerExtra: string_attribute_writable,
31
- ReadEtcHosts: boolean_attribute_writable,
32
- ResolveUnicastSingleLabel: boolean_attribute_writable,
33
- StaleRetentionSec: duration_attribute_writable,
34
- RefuseRecordTypes: string_attribute_writable,
35
- DNSSEC: yesno_attribute_writable,
36
- DNSOverTLS: yesno_attribute_writable,
37
- LLMNR: yesno_attribute_writable
38
- }
24
+ DNS: { ...string_attribute_writable, configurable: true },
25
+ FallbackDNS: { ...string_attribute_writable, configurable: true },
26
+ Domains: { ...string_attribute_writable, configurable: true },
27
+ MulticastDNS: { ...boolean_attribute_writable, configurable: true },
28
+ Cache: { ...boolean_attribute_writable, configurable: true },
29
+ CacheFromLocalhost: { ...boolean_attribute_writable, configurable: true },
30
+ DNSStubListener: { ...boolean_attribute_writable, configurable: true },
31
+ DNSStubListenerExtra: { ...string_attribute_writable, configurable: true },
32
+ ReadEtcHosts: { ...boolean_attribute_writable, configurable: true },
33
+ ResolveUnicastSingleLabel: {
34
+ ...boolean_attribute_writable,
35
+ configurable: true
36
+ },
37
+ StaleRetentionSec: { ...duration_attribute_writable, configurable: true },
38
+ RefuseRecordTypes: { ...string_attribute_writable, configurable: true },
39
+ DNSSEC: { ...yesno_attribute_writable, default: false, configurable: true },
40
+ DNSOverTLS: { ...yesno_attribute_writable, configurable: true },
41
+ LLMNR: { ...yesno_attribute_writable, configurable: true }
42
+ },
43
+ service: {}
39
44
  };
40
45
 
41
46
  export class SystemdResolvedService extends ExtraSourceService {
42
47
  static {
43
48
  addType(this);
49
+ addServiceType(this.typeDefinition.service, this.typeDefinition.name);
44
50
  }
45
51
 
46
52
  static get typeDefinition() {
@@ -79,17 +85,7 @@ export class SystemdResolvedService extends ExtraSourceService {
79
85
  FallbackDNS: serviceEndpoints(this, options(100, 199, 4)),
80
86
  Domains: [...this.localDomains].join(" "),
81
87
  MulticastDNS: yesno(this.network.multicastDNS),
82
-
83
- DNSSEC: yesno(this.DNSSEC),
84
-
85
- // TODO extendet properties with getAttribute()
86
- ...Object.fromEntries(
87
- Object.entries(SystemdResolvedServiceTypeDefinition.attributes)
88
- .map(([k, v]) => [k, this.extendedProperty(k)])
89
- .filter(([k, v]) => v !== undefined)
90
- ),
91
- LLMNR: yesno(this.LLMNR),
92
-
88
+ ...this.getProperties(filterConfigurable)
93
89
  }
94
90
  ]
95
91
  };
@@ -1,21 +1,39 @@
1
- import { addType } from "pacc";
1
+ import {
2
+ addType,
3
+ string_attribute_writable,
4
+ duration_attribute_writable
5
+ } from "pacc";
2
6
  import {
3
7
  ExtraSourceService,
4
8
  ExtraSourceServiceTypeDefinition,
5
9
  ServiceTypeDefinition,
6
- serviceEndpoints
10
+ serviceEndpoints,
11
+ addServiceType
7
12
  } from "pmcf";
13
+ import { filterConfigurable } from "../utils.mjs";
8
14
 
9
15
  const SystemdTimesyncdServiceTypeDefinition = {
10
16
  name: "systemd-timesyncd",
11
17
  extends: ExtraSourceServiceTypeDefinition,
12
18
  specializationOf: ServiceTypeDefinition,
13
19
  owners: ServiceTypeDefinition.owners,
20
+
21
+ attributes: {
22
+ NTP: {...string_attribute_writable, configurable: true },
23
+ FallbackNTP: {...string_attribute_writable, configurable: true },
24
+ RootDistanceMaxSec: {...duration_attribute_writable, configurable: true },
25
+ PollIntervalMinSec: {...duration_attribute_writable, configurable: true },
26
+ PollIntervalMaxSec: {...duration_attribute_writable, configurable: true },
27
+ ConnectionRetrySec: {...duration_attribute_writable, configurable: true },
28
+ SaveIntervalSec: {...duration_attribute_writable, configurable: true }
29
+ },
30
+ service: {}
14
31
  };
15
32
 
16
33
  export class SystemdTimesyncdService extends ExtraSourceService {
17
34
  static {
18
35
  addType(this);
36
+ addServiceType(this.typeDefinition.service, this.typeDefinition.name);
19
37
  }
20
38
 
21
39
  static get typeDefinition() {
@@ -49,7 +67,8 @@ export class SystemdTimesyncdService extends ExtraSourceService {
49
67
  "Time",
50
68
  {
51
69
  NTP: serviceEndpoints(this, options(300, 399)),
52
- FallbackNTP: serviceEndpoints(this, options(100, 199))
70
+ FallbackNTP: serviceEndpoints(this, options(100, 199)),
71
+ ...this.getProperties(filterConfigurable)
53
72
  }
54
73
  ]
55
74
  };
package/src/utils.mjs CHANGED
@@ -107,3 +107,6 @@ export function asIterator(value) {
107
107
 
108
108
  return asArray(value);
109
109
  }
110
+
111
+
112
+ export const filterConfigurable = (name, attribute) => !attribute.private & attribute.configurable;
package/types/base.d.mts CHANGED
@@ -69,6 +69,11 @@ export class Base {
69
69
  _extendedPropertyIterator(propertyName: any, seen: any): Generator<any, void, any>;
70
70
  _extendedProperty(propertyName: any, seen: any): any;
71
71
  extendedProperty(propertyName: any): any;
72
+ /**
73
+ * Retrive attribute values from an object.
74
+ * @return {Object} values
75
+ */
76
+ getProperties(filter?: typeof filterPublic): any;
72
77
  get root(): any;
73
78
  get location(): any;
74
79
  get host(): any;
@@ -131,3 +136,4 @@ export class Base {
131
136
  toString(): string;
132
137
  toJSON(): any;
133
138
  }
139
+ import { filterPublic } from "pacc";