-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding authenticated views, docstrings, and typing
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
- Loading branch information
Showing
22 changed files
with
690 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,83 @@ | ||
__author__ = "Vanessa Sochat" | ||
__copyright__ = "Copyright 2021-2022, Vanessa Sochat" | ||
__license__ = "MIT" | ||
__license__ = "Apache-2.0" | ||
|
||
import os | ||
import re | ||
import docker | ||
import base64 | ||
import oras.utils | ||
|
||
|
||
def get_basic_auth(username, password): | ||
def load_configs(configs: list[str] = None): | ||
""" | ||
Load one or more configs with credentials from the filesystem. | ||
Arguments | ||
--------- | ||
configs : list of configuration paths to load | ||
""" | ||
configs = configs or [] | ||
default_config = docker.context.config.find_config_file() | ||
|
||
# Add the default docker config | ||
if default_config: | ||
configs.append(default_config) | ||
configs = set(configs) | ||
|
||
# Load configs until we find our registry hostname | ||
auths = {} | ||
for config in configs: | ||
if not os.path.exists(config): | ||
logger.warning(f"{config} does not exist.") | ||
continue | ||
cfg = oras.utils.read_json(config) | ||
auths.update(cfg.get("auths", {})) | ||
return auths | ||
|
||
|
||
def get_basic_auth(username: str, password: str): | ||
""" | ||
Prepare basic auth from a username and password. | ||
Arguments | ||
--------- | ||
username : the user account name | ||
password : the user account password | ||
""" | ||
auth_str = "%s:%s" % (username, password) | ||
return base64.b64encode(auth_str.encode("utf-8")).decode("utf-8") | ||
|
||
|
||
def parse_auth_header(authHeaderRaw): | ||
class authHeader: | ||
def __init__(self, lookup: dict): | ||
""" | ||
Given a dictionary of values, match them to class attributes | ||
Arguments | ||
--------- | ||
lookup : dictionary of key,value pairs to parse into auth header | ||
""" | ||
self.service = None | ||
self.realm = None | ||
self.scope = None | ||
for key in lookup: | ||
if key in ["realm", "service", "scope"]: | ||
setattr(self, key, lookup[key]) | ||
|
||
|
||
def parse_auth_header(authHeaderRaw: str) -> authHeader: | ||
""" | ||
Parse authentication header into pieces | ||
Arguments | ||
--------- | ||
username : the user account name | ||
password : the user account password | ||
""" | ||
regex = re.compile('([a-zA-z]+)="(.+?)"') | ||
matches = regex.findall(authHeaderRaw) | ||
lookup = dict() | ||
for match in matches: | ||
lookup[match[0]] = match[1] | ||
return authHeader(lookup) | ||
|
||
|
||
class authHeader: | ||
def __init__(self, lookup): | ||
""" | ||
Given a dictionary of values, match them to class attributes | ||
""" | ||
for key in lookup: | ||
if key in ["realm", "service", "scope"]: | ||
setattr(self, key.capitalize(), lookup[key]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
__author__ = "Vanessa Sochat" | ||
__copyright__ = "Copyright 2021-2022, Vanessa Sochat" | ||
__license__ = "Apache-2.0" | ||
|
||
import oras.client | ||
|
||
|
||
def main(args, parser, extra, subparser): | ||
""" | ||
Main is a light wrapper around the logout command. | ||
""" | ||
client = oras.client.OrasClient() | ||
client.logout(args.hostname) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.