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

Distinguish between insecure and tis-verify #98

Merged
merged 6 commits into from
Jul 22, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
The versions coincide with releases on pip. Only major versions will be released as tags on Github.

## [0.0.x](https://github.com/oras-project/oras-py/tree/main) (0.0.x)
- add tls_verify to provider class for optional disable tls verification (0.1.22)
- Allow to pull exactly to PWD (0.1.21)
- Ensure insecure is passed to provider class (0.1.20)
- patch fix for blob upload Windows, closes issue [93](https://github.com/oras-project/oras-py/issues/93) (0.1.19)
Expand Down
12 changes: 8 additions & 4 deletions oras/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(
hostname: Optional[str] = None,
registry: Optional[oras.provider.Registry] = None,
insecure: bool = False,
tls_verify: bool = True,
):
"""
Create an ORAS client.
Expand All @@ -43,7 +44,7 @@ def __init__(
:param insecure: use http instead of https
:type insecure: bool
"""
self.remote = registry or oras.provider.Registry(hostname, insecure)
self.remote = registry or oras.provider.Registry(hostname, insecure, tls_verify)

def __repr__(self) -> str:
return str(self)
Expand Down Expand Up @@ -142,6 +143,7 @@ def login(
password: str,
password_stdin: bool = False,
insecure: bool = False,
tls_verify: bool = True,
hostname: Optional[str] = None,
config_path: Optional[List[str]] = None,
) -> dict:
Expand All @@ -158,6 +160,8 @@ def login(
:type password_stdin: bool
:param insecure: use http instead of https
:type insecure: bool
:param tls_verify: verify tls
:type tls_verify: bool
:param hostname: the hostname to login to
:type hostname: str
:param config_path: list of config paths to add
Expand All @@ -170,7 +174,7 @@ def login(
username=username,
password=password,
password_stdin=password_stdin,
insecure=insecure,
tls_verify=tls_verify,
hostname=hostname,
config_path=config_path, # type: ignore
)
Expand All @@ -189,7 +193,7 @@ def _login(
username: Optional[str] = None,
password: Optional[str] = None,
password_stdin: bool = False,
insecure: bool = False,
tls_verify: bool = True,
hostname: Optional[str] = None,
config_path: Optional[str] = None,
) -> dict:
Expand Down Expand Up @@ -224,7 +228,7 @@ def _login(
# Login
# https://docker-py.readthedocs.io/en/stable/client.html?highlight=login#docker.client.DockerClient.login
try:
client = oras.utils.get_docker_client(insecure=insecure)
client = oras.utils.get_docker_client(tls_verify=tls_verify)
return client.login(
username=username,
password=password,
Expand Down
15 changes: 11 additions & 4 deletions oras/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ class Registry:
and the registry isn't necessarily the "remote" endpoint.
"""

def __init__(self, hostname: Optional[str] = None, insecure: bool = False):
def __init__(
self,
hostname: Optional[str] = None,
insecure: bool = False,
tls_verify: bool = True,
):
"""
Create a new registry provider.

:param hostname: the registry hostname (optional)
:type hostname: str
:param insecure: use http instead of https
:type insecure: bool
:param tls_verify: verify TLS certificates
:type tls_verify: bool
"""
self.hostname: Optional[str] = hostname
self.headers: dict = {}
Expand All @@ -47,9 +54,9 @@ def __init__(self, hostname: Optional[str] = None, insecure: bool = False):
self.token: Optional[str] = None
self._auths: dict = {}
self._basic_auth = None
self._insecure = insecure
self._tls_verify = tls_verify

if insecure:
if not tls_verify:
requests.packages.urllib3.disable_warnings() # type: ignore

def logout(self, hostname: str):
Expand Down Expand Up @@ -846,7 +853,7 @@ def do_request(
json=json,
headers=headers,
stream=stream,
verify=not self._insecure,
verify=self._tls_verify,
)

# A 401 response is a request for authentication
Expand Down
8 changes: 4 additions & 4 deletions oras/utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def append_url_params(url: str, params: dict) -> str:
return urlparse.urlunparse(updated)


def get_docker_client(insecure: bool = False, **kwargs):
def get_docker_client(tls_verify: bool = True, **kwargs):
"""
Get a docker client.

:param tls : enable tls
:type tls: bool
:param tls_verify : enable tls
:type tls_verify: bool
"""
import docker

return docker.DockerClient(tls=not insecure, **kwargs)
return docker.DockerClient(tls=tls_verify, **kwargs)
2 changes: 1 addition & 1 deletion oras/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__copyright__ = "Copyright The ORAS Authors."
__license__ = "Apache-2.0"

__version__ = "0.1.21"
__version__ = "0.1.22"
AUTHOR = "Vanessa Sochat"
EMAIL = "[email protected]"
NAME = "oras"
Expand Down