pmcf 1.87.2 → 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 +49 -36
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.87.2",
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,33 +162,28 @@ 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
- ];
154
- await writeLines(join(p1, "etc/named/options"), `forwarders.conf`, options);
155
-
156
- const category = [
157
- "acl trusted {",
158
- ...Array.from(subnets(this.trusted)).map(subnet => ` ${subnet.name};`),
159
- "};",
160
- "",
161
- "acl protected {",
162
- ...Array.from(subnets(this.protected)).map(subnet => ` ${subnet.name};`),
163
- "};",
164
- "",
165
- "acl open {",
166
- "};"
167
- ];
168
-
169
- await writeLines(
170
- join(p1, "etc/named"),
171
- `0-${name}.conf`,
172
- category
165
+ const options = addressesStatement(
166
+ "forwarders",
167
+ serviceAddresses(this.source, DNS_SERVICE_FILTER)
173
168
  );
169
+ if (options.length > 2) {
170
+ await writeLines(
171
+ join(p1, "etc/named/options"),
172
+ `forwarders.conf`,
173
+ options
174
+ );
175
+ }
176
+
177
+ const acls = [
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 > 2 || category.length > 8) {
183
+ if (acls.length) {
184
+ await writeLines(join(p1, "etc/named"), `0-acl-${name}.conf`, acls);
185
+ }
186
+ if (options.length || acls.length) {
176
187
  yield packageData;
177
188
  }
178
189
 
@@ -187,17 +198,19 @@ export class DNSService extends Base {
187
198
  };
188
199
 
189
200
  packageData.sources = [
190
- new FileContentProvider(p2 + "/", {
191
- mode: 0o644,
192
- owner: "named",
193
- group: "named"
194
- }, {
195
- mode: 0o755,
196
- owner: "named",
197
- group: "named"
198
- })[
199
- Symbol.asyncIterator
200
- ]()
201
+ new FileContentProvider(
202
+ p2 + "/",
203
+ {
204
+ mode: 0o644,
205
+ owner: "named",
206
+ group: "named"
207
+ },
208
+ {
209
+ mode: 0o755,
210
+ owner: "named",
211
+ group: "named"
212
+ }
213
+ )[Symbol.asyncIterator]()
201
214
  ];
202
215
 
203
216
  await generateZoneDefs(this, packageData);