Skip to content

Commit

Permalink
ci: enhancing script
Browse files Browse the repository at this point in the history
  • Loading branch information
harshilgajera-crest committed Aug 9, 2024
1 parent 9c5af74 commit a7481d0
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions splunk_matrix_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 = {
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit a7481d0

Please sign in to comment.