1
0
Fork 0

Add filter "short_key"

This commit is contained in:
Alex Kotov 2019-06-02 19:56:08 +05:00
parent 227623ff40
commit 0c8e686bcd
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 27 additions and 6 deletions

2
.gitignore vendored
View file

@ -1 +1,3 @@
/*.retry
__pycache__/

View file

@ -7,7 +7,7 @@ yggdrasil_peers:
- "tcp://146.185.176.36:12345"
- "tcp://[2a03:b0c0:0:1010::1a7:c001]:12345"
- "tcp://ams1.y.sota.sh:8080"
yggdrasil_encryption_public_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
yggdrasil_encryption_private_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
yggdrasil_signing_public_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
yggdrasil_encryption_public_key: "0000000000000000000000000000000000000000000000000000000000000000"
yggdrasil_encryption_private_key: "0000000000000000000000000000000000000000000000000000000000000000"
yggdrasil_signing_public_key: "0000000000000000000000000000000000000000000000000000000000000000"
yggdrasil_signing_private_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

View file

@ -0,0 +1,19 @@
import re
from ansible.errors import AnsibleFilterError
SHORT_KEY_RE = re.compile(r'^[0-9a-z]{64}$', re.IGNORECASE)
def short_key(s):
s = str(s)
if not SHORT_KEY_RE.match(s):
raise AnsibleFilterError('Invalid key: %s' % s)
return '"%s"' % s.lower()
class FilterModule:
'''Filters to validate and escape Yggdrasil configuration variables.'''
def filters(self):
return {
'short_key': short_key,
}

View file

@ -11,9 +11,9 @@
".*"
],
"AllowedEncryptionPublicKeys": [],
"EncryptionPublicKey": "{{ yggdrasil_encryption_public_key }}",
"EncryptionPrivateKey": "{{ yggdrasil_encryption_private_key }}",
"SigningPublicKey": "{{ yggdrasil_signing_public_key }}",
"EncryptionPublicKey": {{ yggdrasil_encryption_public_key | short_key }},
"EncryptionPrivateKey": {{ yggdrasil_encryption_private_key | short_key }},
"SigningPublicKey": {{ yggdrasil_signing_public_key | short_key }},
"SigningPrivateKey": "{{ yggdrasil_signing_private_key }}",
"LinkLocalTCPPort": 0,
"IfName": "auto",