Skip to content

Commit

Permalink
fix: add tests + delimiter global + removal of pycache from gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
DerTiedemann committed Oct 9, 2024
1 parent bc8eae6 commit fb6867c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
tmp*
auto-doc*
./test*
**/__pycache__/
9 changes: 5 additions & 4 deletions actions/parse-secrets-definitions/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import re

DELIMITER = "!!!"

# CAVEAT: will only work for one project at a time
# might be problematic if we want to inject secrets from multiple projects

Expand All @@ -10,7 +12,7 @@
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
def set_github_action_output(output_name, output_value, delim=''):
f = open(os.path.abspath(os.environ["GITHUB_OUTPUT"]), "a")
f.write(f'{output_name}<<!!!\n{output_value}!!!\n') # ATTENTION: this might lead to problems if the output value contains the delimiter, which will not happen in this program but dont just copy this and expect it to work
f.write(f'{output_name}<<{DELIMITER}\n{output_value}{DELIMITER}\n') # ATTENTION: this might lead to problems if the output value contains the delimiter, which will not happen in this program but dont just copy this and expect it to work
f.close()


Expand All @@ -19,7 +21,7 @@ def set_github_action_output(output_name, output_value, delim=''):
# if the secret would end in an underscore, remove it
# format: SECRET_NAME:PROJECT_NAME/SECRET_NAME/VERSION
def parse_secret(secret, project_name):
if "!!!" in secret:
if DELIMITER in secret:
raise ValueError("Invalid secret definition: !!! is a reserved keyword")
components = secret.split("/")

Expand All @@ -45,5 +47,4 @@ def main():


if __name__ == "__main__":
main()
# print(parse_secret("alksdjoioe4j####@!@#!1123asdlolw!!asd!!print(/1", "project"))
main()
17 changes: 17 additions & 0 deletions actions/parse-secrets-definitions/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest

from main import parse_secret

class TestParseSecret(unittest.TestCase):
def test_parse_secret(self):
self.assertEqual(parse_secret("secret_name", "project_name"), "SECRET_NAME:project_name/secret_name")
self.assertEqual(parse_secret("secret_name/version", "project_name"), "SECRET_NAME:project_name/secret_name/version")
self.assertEqual(parse_secret("123-456", "project_name"), "123_456:project_name/123-456")
self.assertEqual(parse_secret("123___123___123", "project_name"), "123_123_123:project_name/123___123___123")

def test_parse_secret_special(self):
# FIXME: this test is failing and i dont know why
self.assertEqual(parse_secret("123&&123()123__123*__*_123", "project_name"), "123_123_123_123:project_name/123&&123()123__123*__*_123")

if __name__ == '__main__':
unittest.main()

0 comments on commit fb6867c

Please sign in to comment.