File tree Expand file tree Collapse file tree 4 files changed +16
-20
lines changed Expand file tree Collapse file tree 4 files changed +16
-20
lines changed Original file line number Diff line number Diff line change 1- import random
2- import string
3-
41from sh import gh
52from robot .api .deco import keyword
63from robot .api import logger
7-
8-
9- def randstring (size = 6 , chars = string .ascii_uppercase + string .digits ):
10- return "" .join (random .choice (chars ) for _ in range (size )) # nosec B311
11-
12-
13- def randint ():
14- return f"{ random .randint (1000000 , 9999999 )} " # nosec B311
4+ from resources import helpers
155
166
177class GitHub :
@@ -20,7 +10,7 @@ def __init__(self):
2010
2111 @keyword
2212 def random_repo_name (self , org , base_name ):
23- return f"{ org } /{ base_name } -{ randint ()} "
13+ return f"{ org } /{ base_name } -{ helpers . randint ()} "
2414
2515 @keyword
2616 def a_copy_of_repo (self , repo_template , repo_name ):
Original file line number Diff line number Diff line change 11import os
2+ import random
23import yaml
34from sh import minder
45
1011)
1112
1213
14+ def randint ():
15+ return f"{ random .randint (1000000 , 9999999 )} " # nosec B311
16+
17+
1318def _get_url_from_config (server_type ):
1419 """Helper function to read config and return URL for a given server type."""
1520 minder_config_path = os .getenv (MINDER_CONFIG )
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ def create_authorization_header(self):
1818
1919 Logs into Minder, extracts the Bearer token, and returns the Authorization header.
2020 """
21- log_into_minder ()
21+ log_into_minder () # TODO remove this, it should be ensured by the above layer
2222 bearer_token = self ._get_bearer_token ()
2323
2424 # Return the Authorization header
Original file line number Diff line number Diff line change 22from robot .api .deco import keyword
33from robot .libraries .BuiltIn import BuiltIn
44import re
5- import hashlib
65import os
76from resources .minder_restapi_lib import MinderRestApiLib
7+ from resources import helpers
88
99
1010class Projects :
@@ -132,11 +132,12 @@ def _convert_to_dns_safe_name(self, name):
132132 if name [0 ].isdigit ():
133133 name = "p-" + name
134134
135- # If the name is already 63 characters or less, return it as is
136- if len (name ) <= 63 :
137- return name
135+ # If the name is already 63 - 8 characters or less, add random
136+ # suffix and return it.
137+ suffix = helpers .randint ()
138+ if len (name ) <= 63 - 8 :
139+ return f"{ name } -{ suffix } "
138140
139- # Otherwise, truncate and add suffix
140- suffix = hashlib .sha1 (name .encode ()).hexdigest ()[:9 ] # nosec
141- truncated_name = name [:53 ]
141+ # Otherwise truncate
142+ truncated_name = name [:55 ]
142143 return f"{ truncated_name } -{ suffix } "
You can’t perform that action at this time.
0 commit comments