Skip to content
Snippets Groups Projects
Commit c7e57e99 authored by Ben Morrice's avatar Ben Morrice
Browse files

Update rhncheck to support downloading entitlements via a zipfile

- apparently Red Hat changed this from being json to a zip?
parent 49dd0d11
No related branches found
No related tags found
1 merge request!219Update rhncheck to support downloading entitlements via a zipfile
Pipeline #4706142 passed
......@@ -5,10 +5,12 @@ import json
import requests
import base64
import glob
import io
import os
import tempfile
import smtplib
import shutil
import zipfile
from time import sleep
from email.mime.base import MIMEBase
......@@ -46,7 +48,11 @@ def call_https_rhsm(url):
while retries <= 3:
result = requests.get(url, headers=headers, verify=False)
if result.status_code == requests.codes.ok:
return json.loads(result.content)
# Basically, here we will have a zip file of the entitlements
if 'content-disposition' in result.headers:
return io.BytesIO(result.content)
else:
return json.loads(result.content)
print('Failed ({}) to get {}'.format(result.status_code, url))
retries+=1
sleep(retries**3)
......@@ -61,13 +67,13 @@ def get_entitlements(directory, linuxsoft_uuid):
except:
print('failed to communicated to rhsm, exiting')
sys.exit(1)
for cert in certificates:
if not cert['serial']['revoked']:
print('Downloading rhn cert: %s' % str(cert['serial']['id']) + '.pem')
f = open(directory + '/' + str(cert['serial']['id']) + '.pem', 'w')
f.write(cert['cert'])
f.write(key)
f.close()
z = zipfile.ZipFile(certificates)
z.extractall(directory)
cz = zipfile.ZipFile(f"{directory}/consumer_export.zip")
cz.extractall(directory)
for cert in os.listdir(f"{directory}/export/entitlement_certificates"):
print(f"Downloading/Extracting rhn cert: {cert}")
shutil.move(f"{directory}/export/entitlement_certificates/{cert}", directory)
for existingcert in glob.glob('/certs/*pem'):
if 'rhn_entitlements.pem' not in existingcert and 'redhat-uep.pem' not in existingcert:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment