Skip to content

Commit

Permalink
Ny fiks for æøå
Browse files Browse the repository at this point in the history
  • Loading branch information
augustdahl committed Jun 26, 2024
1 parent 997a7bc commit f053cd6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
22 changes: 19 additions & 3 deletions scripts/dask_infrastructure.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import sys
import os
import json
import re

def replace_special_characters(s):
replacements = {
'æ': 'ae',
'Æ': 'Ae',
'ø': 'o',
'Ø': 'O',
'å': 'aa',
'Å': 'Aa'
}

def replace(match):
return replacements[match.group(0)]

return re.sub(r'æ|Æ|ø|Ø|å|Å', replace, s)

def edit_file(filepath, params):
team_name: str = params.get("team_name")
Expand All @@ -15,14 +30,15 @@ def edit_file(filepath, params):

append_content_to_end_of_file(filepath, new_team_data)

def generate_module_definition(ad_group_name: str, team_name: str, area_name: str, project_name: str, project_id_map: dict) -> str:
def generate_module_definition(ad_group_name: str, area_name: str, project_name: str, project_id_map: dict) -> str:
area_special_chars_replaced = replace_special_characters(area_name)
module = f'''
module "{project_name.lower()}" {{
source = "../dbx_team_resources"
ad_group_name = "AAD - TF - TEAM - {ad_group_name}"
team_name = "{project_name.lower()}"
area_name = "{area_name.lower()}"
area_name = "{area_special_chars_replaced.lower()}"
deploy_sa_map = {{
sandbox = "{project_name.lower()}-deploy@{project_id_map['sandbox']}.iam.gserviceaccount.com",
dev = "{project_name.lower()}-deploy@{project_id_map['dev']}.iam.gserviceaccount.com",
Expand Down
20 changes: 18 additions & 2 deletions scripts/iam.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import json
import sys
from typing import List

import re

def replace_special_characters(s):
replacements = {
'æ': 'ae',
'Æ': 'Ae',
'ø': 'o',
'Ø': 'O',
'å': 'aa',
'Å': 'Aa'
}

def replace(match):
return replacements[match.group(0)]

return re.sub(r'æ|Æ|ø|Ø|å|Å', replace, s)

def find_line_ref_local_teams(lines: List[str]) -> int:
for (row, idx) in zip(lines, range(len(lines))):
Expand All @@ -21,7 +36,8 @@ def edit_file(file_path, params):
file.close()

last_teams_ref_idx = find_line_ref_local_teams(lines)
ad_group_formatted = json.dumps(ad_group).replace(' ', '').replace('"', '').lower()
ad_replace_chars = replace_special_characters(ad_group)
ad_group_formatted = json.dumps(ad_replace_chars).replace(' ', '').replace('"', '').lower()
lines.insert(last_teams_ref_idx + 3, f'"{project_name}"= ["aad-tf-team-{ad_group_formatted}@kartverket.no", "[email protected]"]\n')

with open(file_path, 'w') as file:
Expand Down

0 comments on commit f053cd6

Please sign in to comment.