pmcf 1.87.3 → 1.87.4

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/dns.mjs +26 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.87.3",
3
+ "version": "1.87.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/dns.mjs CHANGED
@@ -41,6 +41,22 @@ const DNSServiceTypeDefinition = {
41
41
 
42
42
  const DNS_SERVICE_FILTER = { type: DNSServiceTypeDefinition.name };
43
43
 
44
+ function addressList(objects) {
45
+ return Array.from(objects).map(object =>
46
+ typeof object === "string" ? object : object.name
47
+ );
48
+ }
49
+
50
+ function addressesStatement(prefix, objects, generateEmpty = false) {
51
+ const body = addressList(objects).map(name => ` ${name};`);
52
+
53
+ if (body.length || generateEmpty) {
54
+ return [`${prefix} {`, body, "};"];
55
+ }
56
+
57
+ return [];
58
+ }
59
+
44
60
  export class DNSService extends Base {
45
61
  allowedUpdates = [];
46
62
  recordTTL = "1W";
@@ -146,11 +162,10 @@ export class DNSService extends Base {
146
162
  }
147
163
  };
148
164
 
149
- const options = [
150
- "forwarders {",
151
- ...serviceAddresses(this.source, DNS_SERVICE_FILTER).map(a => ` ${a};`),
152
- "};"
153
- ];
165
+ const options = addressesStatement(
166
+ "forwarders",
167
+ serviceAddresses(this.source, DNS_SERVICE_FILTER)
168
+ );
154
169
  if (options.length > 2) {
155
170
  await writeLines(
156
171
  join(p1, "etc/named/options"),
@@ -160,22 +175,15 @@ export class DNSService extends Base {
160
175
  }
161
176
 
162
177
  const acls = [
163
- "acl trusted {",
164
- ...Array.from(subnets(this.trusted)).map(subnet => ` ${subnet.name};`),
165
- "};",
166
- "",
167
- "acl protected {",
168
- ...Array.from(subnets(this.protected)).map(subnet => ` ${subnet.name};`),
169
- "};",
170
- "",
171
- "acl open {",
172
- "};"
173
- ];
178
+ addressesStatement("acl trusted", subnets(this.trusted)),
179
+ addressesStatement("acl protected", subnets(this.protected)),
180
+ addressesStatement("acl open", [], true)
181
+ ].flat();
174
182
 
175
- if (options.length > 8) {
183
+ if (acls.length) {
176
184
  await writeLines(join(p1, "etc/named"), `0-acl-${name}.conf`, acls);
177
185
  }
178
- if (options.length > 2 || acls.length > 8) {
186
+ if (options.length || acls.length) {
179
187
  yield packageData;
180
188
  }
181
189