bundles: use a common metadata key for firewall restrictions, use repo.libs.tools.resolve_identifier()
All checks were successful
bundlewrap/pipeline/head This commit looks good
All checks were successful
bundlewrap/pipeline/head This commit looks good
This commit is contained in:
parent
9a2f9038c4
commit
5c1eba0d58
8 changed files with 92 additions and 49 deletions
|
@ -37,26 +37,34 @@ defaults = {
|
|||
'iptables/bundle_rules/transmission',
|
||||
)
|
||||
def iptables(metadata):
|
||||
interfaces = metadata.get('transmission/webinterface-on-interfaces', set())
|
||||
rules = []
|
||||
identifiers = metadata.get('transmission/restrict-to', set())
|
||||
rules = set()
|
||||
|
||||
rules.append('iptables_both -A INPUT -p udp --dport {} -j ACCEPT'.format(
|
||||
rules.add('iptables_both -A INPUT -p udp --dport {} -j ACCEPT'.format(
|
||||
metadata.get('transmission/config/peer-port'),
|
||||
))
|
||||
rules.append('iptables_both -A INPUT -p tcp --dport {} -j ACCEPT'.format(
|
||||
rules.add('iptables_both -A INPUT -p tcp --dport {} -j ACCEPT'.format(
|
||||
metadata.get('transmission/config/peer-port'),
|
||||
))
|
||||
|
||||
for iface in sorted(interfaces):
|
||||
rules.append('iptables_both -A INPUT -i {} -p tcp --dport {} -j ACCEPT'.format(
|
||||
iface,
|
||||
if identifiers:
|
||||
for identifier in sorted(identifiers):
|
||||
resolved = repo.libs.tools.resolve_identifier(repo, identifier)
|
||||
|
||||
for address in resolved['ipv4']:
|
||||
rules.add('iptables -A INPUT -p tcp -s {} --dport {} -j ACCEPT'.format(
|
||||
address,
|
||||
metadata.get('transmission/config/rpc-port'),
|
||||
))
|
||||
else:
|
||||
rules.add('iptables -A INPUT -p tcp --dport {} -j ACCEPT'.format(
|
||||
metadata.get('transmission/config/rpc-port'),
|
||||
))
|
||||
|
||||
return {
|
||||
'iptables': {
|
||||
'bundle_rules': {
|
||||
'transmission': rules,
|
||||
'transmission': list(sorted(rules)),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue