Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support private quay instance #171

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion operatorcourier/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -74,6 +75,13 @@ 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) 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

Expand Down
16 changes: 12 additions & 4 deletions operatorcourier/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@ 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.
:param namespace: Namespace that contains the repository for the application.
: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: 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just below this, don't you also need to update the call to _push_to_registry() to actually pass the new parameters along?

Expand All @@ -45,14 +51,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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to do this, rather than just support additional quay.io/cnr endpoints, why not just make the entire root path of the host to the API configurable? i.e.:

push_uri = 'https://%s/api/v1/packages/%s/%s' % (host, namespace,repository)

https://quay.io/cnr is the full arbitrary root path, the cnr is not part of the app-registry spec. Here's a full client implementation for reference: https://github.com/operator-framework/go-appr

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)
Expand Down