55
66
77class GitYaml :
8- def __init__ (self , dom : str ):
8+ def __init__ (self , dom : str , prefix : str ):
99 self .pattern : str = "^(.*)-(.*)-(.*)"
1010 self .dom : str = dom
1111 self .git_ref : str = (
1212 f"https://api.github.com/repos/epics-containers/{ dom } -services/git/refs"
1313 )
14+ self .prefix : re .Match [str ] | None = re .match (self .pattern , prefix )
15+ assert self .prefix is not None , "Empty Prefix"
1416
1517 def re_group (self , component : str ) -> str | None :
1618 match : re .Match [str ] | None = re .match (self .pattern , component )
17-
1819 if match :
1920 return match .group (1 )
2021
@@ -30,20 +31,19 @@ def get_json_from_url(self, url: str) -> dict | None:
3031 return err .response .json ()
3132
3233 def get_yaml (self , url ) -> str | None :
33- data : dict | None = self .get_json_from_url (url )
34- if data is not None :
35- base64_content = data ["content" ]
36- decoded_content = base64 .b64decode (base64_content ).decode ("utf-8" )
34+ config_json : dict | None = self .get_json_from_url (url )
35+ assert config_json is not None , "Could not fetch config json tree"
3736
38- return decoded_content
37+ ioc_yaml_url = self .fetch_matches (config_json , "ioc_yaml" )
38+ if ioc_yaml_url is not None :
39+ data : dict | None = self .get_json_from_url (ioc_yaml_url )
40+ if data is not None :
41+ base64_content = data ["content" ]
42+ decoded_content = base64 .b64decode (base64_content ).decode ("utf-8" )
3943
40- def fetch_matches (
41- self ,
42- tree : dict ,
43- task : str ,
44- prefix : str = "" ,
45- option : str = "" ,
46- ) -> str | None :
44+ return decoded_content
45+
46+ def fetch_matches (self , tree : dict , task : str ) -> str | None :
4747 if task == "ref" :
4848 matching_refs = [
4949 item
@@ -58,19 +58,21 @@ def fetch_matches(
5858 for item in tree
5959 if isinstance (item , dict ) and item .get ("path" ) == "services"
6060 ]
61- print (f"DEBUG1:{ matching_url } " )
6261 return matching_url [0 ]["url" ]
6362
6463 elif task == "subfolder" :
6564 tree = tree ["tree" ]
66- matching_folders = [
67- item
68- for item in tree
69- if isinstance (item , dict )
70- and self .re_group (str (item .get ("path" ))) == prefix .lower ()
71- ]
72- if matching_folders :
73- return matching_folders [0 ]["url" ]
65+ if self .prefix :
66+ print (f"DEBUG1:{ self .prefix .group (1 ).lower ()} " )
67+ matching_folders = [
68+ item
69+ for item in tree
70+ if isinstance (item , dict )
71+ and self .re_group (str (item .get ("path" )))
72+ == self .prefix .group (1 ).lower ()
73+ ]
74+ if matching_folders :
75+ return matching_folders [0 ]["url" ]
7476
7577 elif task == "config" :
7678 tree = tree ["tree" ]
@@ -80,22 +82,23 @@ def fetch_matches(
8082 if isinstance (item , dict ) and item .get ("path" ) == "config"
8183 ]
8284 return config [0 ]["url" ]
83-
84- else :
85- answer = [
85+ elif task == "iocyaml" :
86+ tree = tree [ "tree" ]
87+ ioc_url = [
8688 item
8789 for item in tree
88- if isinstance (item , dict ) and item .get (option ) == task
90+ if isinstance (item , dict ) and item .get ("path" ) == "ioc.yaml"
8991 ]
90- return answer [0 ]["url" ]
92+ return ioc_url [0 ]["url" ]
9193
9294 def fetch_ioc_yaml (
9395 self ,
9496 ):
9597 commit_hashes : dict | None = self .get_json_from_url (self .git_ref )
9698
9799 assert commit_hashes is not None , "Could not pull commit hashes"
98- if commit_hashes ["message" ]:
100+ if len (commit_hashes ) < 3 :
101+ print (f"{ commit_hashes ['message' ]} " )
99102 return
100103
101104 main_hash = self .fetch_matches (commit_hashes , "ref" )
0 commit comments