diff --git a/splunk_matrix_update.py b/splunk_matrix_update.py index 9606597..b36fccd 100644 --- a/splunk_matrix_update.py +++ b/splunk_matrix_update.py @@ -17,12 +17,15 @@ def get_token(): def get_images_list(token): - headers = {"Authorization": f"Bearer {token}"} - splunk_image_list_url = "https://registry.hub.docker.com/v2/splunk/splunk/tags/list" - response = requests.get(splunk_image_list_url, headers=headers) - response.raise_for_status() - response_json = json.loads(response.text) - return response_json["tags"] + # headers = {"Authorization": f"Bearer {token}"} + # splunk_image_list_url = "https://registry.hub.docker.com/v2/splunk/splunk/tags/list" + # response = requests.get(splunk_image_list_url, headers=headers) + # response.raise_for_status() + # response_json = json.loads(response.text) + all_details = "https://hub.docker.com/v2/repositories/splunk/splunk/tags?page_size=100" + response = requests.get(all_details) + all_details = json.loads(response.content) + return all_details["results"] def get_latest_image(stanza, images): @@ -49,6 +52,10 @@ def filter_image_list(images_list): filter_images[i] = filter_images[i].replace("'", "") return filter_images +def get_build_number_1(token, latest_image_digest): + image_lists = get_images_list(token) + match_and_return_name = next((d['name'] for d in image_lists for image in d.get('images', []) if image['digest'] == latest_image_digest), None) + return match_and_return_name def get_image_digest(token, image): headers = { @@ -90,8 +97,9 @@ def update_splunk_version(token): config.optionxform = str config.read("config/splunk_matrix.conf") update_file = False - images_list = get_images_list(token) - filter_images = filter_image_list(images_list) + all_images = get_images_list(token) + # filter_images = filter_image_list(images_list) + images_list = [d['name'] for d in all_images] for stanza in config.sections(): if stanza != "GENERAL": latest_image_version = get_latest_image(stanza, images_list) @@ -100,9 +108,10 @@ def update_splunk_version(token): if check_image_version(latest_image_version, stanza_image_version): config.set(stanza, "VERSION", latest_image_version) latest_image_digest = get_image_digest(token, latest_image_version) - build_number = get_build_number( - token, filter_images, latest_image_digest - ) + # build_number = get_build_number( + # token, filter_images, latest_image_digest + # ) + build_number = get_build_number_1(token,latest_image_digest) config.set(stanza, "BUILD", build_number) update_file = True