Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge in new tags, updated tfsdk generation script #24

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions configurationapi/model_authorization_server_settings.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion configurationapi/model_idp_browser_sso.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion configurationapi/model_idp_connection.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion configurationapi/model_ldap_data_store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion configurationapi/model_open_id_connect_policy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 28 additions & 15 deletions scripts/generateTfsdkTags.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@
modelFiles = glob.glob('model_*.go')
jsonRegex = re.compile('`json:\"([0-9A-Za-z]*)[\",]')

def removeUnderscoresFromGroup(group) -> str:
return re.sub(r'_', '', group)

def buildAttributeValue(attribute) -> str:
underscoreAttribute = ""
match = re.findall(r'[0-9A-Z]', attribute)
if match != None:
underscoreAttribute = re.sub(r'([A-Z])', r'_\g<0>', attribute).lower()
fourUpperChars = re.findall(r'[A-Z]{4,4}', attribute)
threeUpperChars = re.findall(r'[A-Z]{3,3}', attribute)
twoUpperChars = re.findall(r'[A-Z]{2,2}', attribute)
if len(fourUpperChars) > 0:
underscoreAttribute = re.sub(r'_[a-z]_[a-z]_[a-z]_[a-z]', lambda m: "_" + removeUnderscoresFromGroup(m.group()) + "_", underscoreAttribute).lower()
elif len(threeUpperChars) > 0:
underscoreAttribute = re.sub(r'_[a-z]_[a-z]_[a-z]', lambda m: "_" + removeUnderscoresFromGroup(m.group()) + "_", underscoreAttribute).lower()
elif len(twoUpperChars) > 0 :
underscoreAttribute = re.sub(r'_[a-z]_[a-z]', lambda m: "_" + removeUnderscoresFromGroup(m.group()), underscoreAttribute).lower()
underscoreAttribute = underscoreAttribute.replace("__", "_")
else:
underscoreAttribute = attribute
if underscoreAttribute.endswith("_"):
underscoreAttribute = underscoreAttribute[:-1]
return underscoreAttribute

for modelFile in modelFiles:
updatedLines = []
with open(modelFile, 'r') as model:
Expand All @@ -16,23 +40,12 @@
# Ensure we don't add tfsdk tags to a line that already has one
if match != None and "tfsdk:" not in line:
# Get the attribute name from the json tag
attribute = match.group(1)
# Create a tfsdk tag for the attribute
underscoreAttribute = ""
i = 0
lastCharUpper = False
while i < len(attribute):
if i > 0 and attribute[i].isupper() != attribute[i - 1].isupper():
underscoreAttribute += "_"
underscoreAttribute += attribute[i].lower()
i += 1
if i < len(attribute):
underscoreAttribute += attribute[i].lower()
i += 1
attribute = str(match.group(1))
finalAttribute = buildAttributeValue(attribute)
# Add the tfsdk tag to the line
line = line.replace("\"`", "\" tfsdk:\"{}\"`".format(underscoreAttribute))
line = line.replace("\"`", "\" tfsdk:\"{}\"`".format(finalAttribute))
updatedLines.append(line)
# Rewrite the file
with open(modelFile, 'w') as model:
for line in updatedLines:
model.write(line)
model.write(line)
16 changes: 0 additions & 16 deletions text.txt

This file was deleted.