From 9efab196716c356e1a98f56a2dba69c439622611 Mon Sep 17 00:00:00 2001 From: Jeeva kandasamy Date: Tue, 22 Oct 2019 12:31:04 +0530 Subject: [PATCH 1/2] support private quay instance --- operatorcourier/api.py | 7 ++++++- operatorcourier/push.py | 14 ++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/operatorcourier/api.py b/operatorcourier/api.py index 7057f1e..205b040 100644 --- a/operatorcourier/api.py +++ b/operatorcourier/api.py @@ -60,7 +60,8 @@ def build_and_verify(source_dir=None, yamls=None, ui_validate_io=False, def build_verify_and_push(namespace, repository, revision, token, source_dir=None, yamls=None, - validation_output=None): + validation_output=None, + quay_host='quay.io', verify_host=True): """Build verify and push constructs the operator bundle, verifies it, and pushes it to an external app registry. Currently the only supported app registry is the one @@ -74,6 +75,10 @@ def build_verify_and_push(namespace, repository, revision, token, :param source_dir: Path to local directory of yaml files to be read :param yamls: List of yaml strings to create bundle with :param validation_output: Path to optional output file for validation logs + :param quay_host: (optional) Supply this parameter if you use private quay instance. + Defaults to 'quay.io' + :param verify_host: (optional) ``quay_host`` TLS/CA verification. + Either a boolean or a string. Defaults to ``True`` :raises TypeError: When called with both source_dir and yamls specified diff --git a/operatorcourier/push.py b/operatorcourier/push.py index 068b065..537a77d 100644 --- a/operatorcourier/push.py +++ b/operatorcourier/push.py @@ -21,7 +21,8 @@ class PushCmd(): def __init__(self): pass - def push(self, bundle_dir, namespace, repository, release, auth_token): + def push(self, bundle_dir, namespace, repository, release, auth_token, + quay_host, verify_host): """Push takes a bundle and pushes it to the specified app registry repository. :param bundle_dir: Path to generated local directory that contains the bundle. @@ -29,6 +30,9 @@ def push(self, bundle_dir, namespace, repository, release, auth_token): :param repository: Repository name of the application described by the bundle. :param release: Release version of the bundle. :param auth_token: Authentication token used to push to Quay.io. + :param quay_host: Can be 'quay.io' or your private instance hostname. + :param verify_host: ``quay_host`` TLS/CA verification. + Either a boolean or a string. """ logger.info('Generating 64 bit bundle and pushing to app registry.') filterOutFiles(bundle_dir, BLACK_LIST) @@ -45,14 +49,16 @@ def _create_base64_bundle(self, bundle_dir, repository): result64 = base64.b64encode(result).decode("utf-8") return result64 - def _push_to_registry(self, namespace, repository, release, bundle, auth_token): - push_uri = 'https://quay.io/cnr/api/v1/packages/%s/%s' % (namespace, repository) + def _push_to_registry(self, namespace, repository, release, bundle, auth_token, + quay_host, verify_host): + push_uri = 'https://%s/cnr/api/v1/packages/%s/%s' % (quay_host, namespace, + repository) logger.info('Pushing bundle to %s' % push_uri) headers = {'Content-Type': 'application/json', 'Authorization': auth_token} json = {'blob': bundle, 'release': release, "media_type": "helm"} try: - r = requests.post(push_uri, json=json, headers=headers) + r = requests.post(push_uri, json=json, headers=headers, verify=verify_host) except requests.RequestException as e: msg = str(e) logger.error(msg) From 424a95f156ea9242b06446548e13b80ad409d103 Mon Sep 17 00:00:00 2001 From: Jeeva kandasamy Date: Tue, 22 Oct 2019 15:08:19 +0530 Subject: [PATCH 2/2] updaed detailed document --- operatorcourier/api.py | 7 +++++-- operatorcourier/push.py | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/operatorcourier/api.py b/operatorcourier/api.py index 205b040..494b89e 100644 --- a/operatorcourier/api.py +++ b/operatorcourier/api.py @@ -77,8 +77,11 @@ def build_verify_and_push(namespace, repository, revision, token, :param validation_output: Path to optional output file for validation logs :param quay_host: (optional) Supply this parameter if you use private quay instance. Defaults to 'quay.io' - :param verify_host: (optional) ``quay_host`` TLS/CA verification. - Either a boolean or a string. Defaults to ``True`` + :param verify_host: (optional) Either a boolean, in which case it controls + whether we verify the server's TLS certificate, or a string, + in which case it must be a path to a CA bundle to use. + Defaults to ``True``. For further details: + https://requests.kennethreitz.org/en/v3.0.0/api/#requests.request :raises TypeError: When called with both source_dir and yamls specified diff --git a/operatorcourier/push.py b/operatorcourier/push.py index 537a77d..4703b5d 100644 --- a/operatorcourier/push.py +++ b/operatorcourier/push.py @@ -31,8 +31,10 @@ def push(self, bundle_dir, namespace, repository, release, auth_token, :param release: Release version of the bundle. :param auth_token: Authentication token used to push to Quay.io. :param quay_host: Can be 'quay.io' or your private instance hostname. - :param verify_host: ``quay_host`` TLS/CA verification. - Either a boolean or a string. + :param verify_host: Either a boolean, in which case it controls whether we verify + the server's TLS certificate, or a string, in which case + it must be a path to a CA bundle to use. + Defaults to ``True``. """ logger.info('Generating 64 bit bundle and pushing to app registry.') filterOutFiles(bundle_dir, BLACK_LIST)