Skip to content
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
14 changes: 2 additions & 12 deletions resources/github.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import random
import string

from sh import gh
from robot.api.deco import keyword
from robot.api import logger


def randstring(size=6, chars=string.ascii_uppercase + string.digits):
return "".join(random.choice(chars) for _ in range(size)) # nosec B311


def randint():
return f"{random.randint(1000000, 9999999)}" # nosec B311
from resources import helpers


class GitHub:
Expand All @@ -20,7 +10,7 @@ def __init__(self):

@keyword
def random_repo_name(self, org, base_name):
return f"{org}/{base_name}-{randint()}"
return f"{org}/{base_name}-{helpers.randint()}"

@keyword
def a_copy_of_repo(self, repo_template, repo_name):
Expand Down
5 changes: 5 additions & 0 deletions resources/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import random
import yaml
from sh import minder

Expand All @@ -10,6 +11,10 @@
)


def randint():
return f"{random.randint(1000000, 9999999)}" # nosec B311


def _get_url_from_config(server_type):
"""Helper function to read config and return URL for a given server type."""
minder_config_path = os.getenv(MINDER_CONFIG)
Expand Down
2 changes: 1 addition & 1 deletion resources/minder_restapi_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def create_authorization_header(self):

Logs into Minder, extracts the Bearer token, and returns the Authorization header.
"""
log_into_minder()
log_into_minder() # TODO remove this, it should be ensured by the above layer
bearer_token = self._get_bearer_token()

# Return the Authorization header
Expand Down
15 changes: 8 additions & 7 deletions resources/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from robot.api.deco import keyword
from robot.libraries.BuiltIn import BuiltIn
import re
import hashlib
import os
from resources.minder_restapi_lib import MinderRestApiLib
from resources import helpers


class Projects:
Expand Down Expand Up @@ -132,11 +132,12 @@ def _convert_to_dns_safe_name(self, name):
if name[0].isdigit():
name = "p-" + name

# If the name is already 63 characters or less, return it as is
if len(name) <= 63:
return name
# If the name is already 63 - 8 characters or less, add random
# suffix and return it.
suffix = helpers.randint()
if len(name) <= 63 - 8:
return f"{name}-{suffix}"

# Otherwise, truncate and add suffix
suffix = hashlib.sha1(name.encode()).hexdigest()[:9] # nosec
truncated_name = name[:53]
# Otherwise truncate
truncated_name = name[:55]
return f"{truncated_name}-{suffix}"