-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateYAMLs.py
More file actions
50 lines (44 loc) · 1.82 KB
/
GenerateYAMLs.py
File metadata and controls
50 lines (44 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import base64
import secrets
import re
TEMPLATE_PATH = "YAMLs/1b-defcon-badge-00.yaml"
OUTPUT_DIR = "YAMLs"
START = 1
END = 49
def generate_key():
return base64.b64encode(secrets.token_bytes(32)).decode()
with open(TEMPLATE_PATH, "r") as f:
template = f.read()
for i in range(START, END + 1):
num = f"{i:02d}"
name = f"1b-defcon-badge-{num}"
key = generate_key()
yaml = template
yaml = yaml.replace("name: 1b-defcon-badge-00", f"name: {name}")
yaml = yaml.replace('friendly_name: 1B DefCon Badge 00', f'friendly_name: 1B DefCon Badge {num}')
# yaml = yaml.replace('ssid: !secret wifi_ssid', 'ssid: !secret defcon_ssid')
# yaml = yaml.replace('password: !secret wifi_password', 'password: !secret defcon_password')
yaml = yaml.replace('ssid: "1B-Defcon-Badge-00"', f'ssid: "1B-Defcon-Badge-{num}"')
# yaml = yaml.replace('key: ".*"', f'key: "{key}"')
yaml = re.sub(r'key: ".*?"', f'key: "{key}"', yaml)
yaml = yaml.replace('1b-defcon-badge-00.yaml', f'{name}.yaml')
out_path = os.path.join(OUTPUT_DIR, f"{name}.yaml")
with open(out_path, "w") as out:
out.write(yaml)
START = 50
END = 99
for i in range(START, END + 1):
num = f"{i:02d}"
name = f"1b-defcon-badge-{num}"
key = generate_key()
yaml = template
yaml = yaml.replace("name: 1b-defcon-badge-00", f"name: {name}")
yaml = yaml.replace('friendly_name: 1B DefCon Badge 00', f'friendly_name: 1B DefCon Badge {num}')
yaml = yaml.replace('ssid: "1B-Defcon-Badge-00"', f'ssid: "1B-Defcon-Badge-{num}"')
# yaml = yaml.replace('key: ".*"', f'key: "{key}"')
yaml = re.sub(r'key: ".*?"', f'key: "{key}"', yaml)
yaml = yaml.replace('1b-defcon-badge-00.yaml', f'{name}.yaml')
out_path = os.path.join(OUTPUT_DIR, f"{name}.yaml")
with open(out_path, "w") as out:
out.write(yaml)