Skip to content

Commit 474f97d

Browse files
committed
client_subnet_authority non-strict mode
- `generator/client_subnet_authority`: Add `nonstrict` mode to skip bad data
1 parent 2070f5b commit 474f97d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

dsc_datatool/generator/client_subnet_authority.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
class client_subnet_authority(Generator):
3838
auth = None
39+
nonstrict = False
3940

4041

4142
def _read(self, input):
@@ -89,6 +90,9 @@ def __init__(self, opts):
8990
csvs = opts.get('csv', None)
9091
urlv4 = opts.get('urlv4', 'https://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.csv')
9192
urlv6 = opts.get('urlv6', 'https://www.iana.org/assignments/ipv6-unicast-address-assignments/ipv6-unicast-address-assignments.csv')
93+
if opts.get('nonstrict', False):
94+
self.nonstrict = True
95+
9296
if csvs:
9397
if not isinstance(csvs, list):
9498
csvs = [ csvs ]
@@ -130,7 +134,12 @@ def process(self, datasets):
130134

131135
auth = {}
132136
for subnet in subnets:
133-
ip = ipaddress.ip_address(subnet)
137+
try:
138+
ip = ipaddress.ip_address(subnet)
139+
except Exception as e:
140+
if not self.nonstrict:
141+
raise e
142+
continue
134143
if ip.version == 4:
135144
idx = ipaddress.ip_network('%s/8' % ip, strict=False)
136145
ip = ipaddress.ip_network('%s/32' % ip)

man/man7/dsc-datatool-generator-client_subnet_authority.7

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ URL for IANA IPv4 address space registry, default to
3434
.BR urlv6 =url
3535
URL for IANA IPv6 address space registry, default to
3636
.IR https://www.iana.org/assignments/ipv6-unicast-address-assignments/ipv6-unicast-address-assignments.csv .
37+
.TP
38+
.BR nonstrict =<value>
39+
If set (to any value) then a non-strict mode is enabled which will disregard
40+
any bad data in the dataset, skipping it completely.
41+
Default is strict mode.
3742
.LP
3843
.SH "SEE ALSO"
3944
.BR dsc-datatool (1)

0 commit comments

Comments
 (0)