Skip to content

Commit db32c98

Browse files
Distinguish between insecure and tis-verify (#98)
* Distingish between insecure (http or https) and tls-verify (check CA of registry) * add param tls_verify for docker_client * disable urllib3 warning in param tls_verify * bump version to 0.1.22 Signed-off-by: Marius Bertram <marius@brtrm.de>
1 parent 8b0cff6 commit db32c98

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
1414
The versions coincide with releases on pip. Only major versions will be released as tags on Github.
1515

1616
## [0.0.x](https://github.com/oras-project/oras-py/tree/main) (0.0.x)
17+
- add tls_verify to provider class for optional disable tls verification (0.1.22)
1718
- Allow to pull exactly to PWD (0.1.21)
1819
- Ensure insecure is passed to provider class (0.1.20)
1920
- patch fix for blob upload Windows, closes issue [93](https://github.com/oras-project/oras-py/issues/93) (0.1.19)

oras/client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(
3030
hostname: Optional[str] = None,
3131
registry: Optional[oras.provider.Registry] = None,
3232
insecure: bool = False,
33+
tls_verify: bool = True,
3334
):
3435
"""
3536
Create an ORAS client.
@@ -43,7 +44,7 @@ def __init__(
4344
:param insecure: use http instead of https
4445
:type insecure: bool
4546
"""
46-
self.remote = registry or oras.provider.Registry(hostname, insecure)
47+
self.remote = registry or oras.provider.Registry(hostname, insecure, tls_verify)
4748

4849
def __repr__(self) -> str:
4950
return str(self)
@@ -142,6 +143,7 @@ def login(
142143
password: str,
143144
password_stdin: bool = False,
144145
insecure: bool = False,
146+
tls_verify: bool = True,
145147
hostname: Optional[str] = None,
146148
config_path: Optional[List[str]] = None,
147149
) -> dict:
@@ -158,6 +160,8 @@ def login(
158160
:type password_stdin: bool
159161
:param insecure: use http instead of https
160162
:type insecure: bool
163+
:param tls_verify: verify tls
164+
:type tls_verify: bool
161165
:param hostname: the hostname to login to
162166
:type hostname: str
163167
:param config_path: list of config paths to add
@@ -170,7 +174,7 @@ def login(
170174
username=username,
171175
password=password,
172176
password_stdin=password_stdin,
173-
insecure=insecure,
177+
tls_verify=tls_verify,
174178
hostname=hostname,
175179
config_path=config_path, # type: ignore
176180
)
@@ -189,7 +193,7 @@ def _login(
189193
username: Optional[str] = None,
190194
password: Optional[str] = None,
191195
password_stdin: bool = False,
192-
insecure: bool = False,
196+
tls_verify: bool = True,
193197
hostname: Optional[str] = None,
194198
config_path: Optional[str] = None,
195199
) -> dict:
@@ -224,7 +228,7 @@ def _login(
224228
# Login
225229
# https://docker-py.readthedocs.io/en/stable/client.html?highlight=login#docker.client.DockerClient.login
226230
try:
227-
client = oras.utils.get_docker_client(insecure=insecure)
231+
client = oras.utils.get_docker_client(tls_verify=tls_verify)
228232
return client.login(
229233
username=username,
230234
password=password,

oras/provider.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,21 @@ class Registry:
3131
and the registry isn't necessarily the "remote" endpoint.
3232
"""
3333

34-
def __init__(self, hostname: Optional[str] = None, insecure: bool = False):
34+
def __init__(
35+
self,
36+
hostname: Optional[str] = None,
37+
insecure: bool = False,
38+
tls_verify: bool = True,
39+
):
3540
"""
3641
Create a new registry provider.
3742
3843
:param hostname: the registry hostname (optional)
3944
:type hostname: str
4045
:param insecure: use http instead of https
4146
:type insecure: bool
47+
:param tls_verify: verify TLS certificates
48+
:type tls_verify: bool
4249
"""
4350
self.hostname: Optional[str] = hostname
4451
self.headers: dict = {}
@@ -47,9 +54,9 @@ def __init__(self, hostname: Optional[str] = None, insecure: bool = False):
4754
self.token: Optional[str] = None
4855
self._auths: dict = {}
4956
self._basic_auth = None
50-
self._insecure = insecure
57+
self._tls_verify = tls_verify
5158

52-
if insecure:
59+
if not tls_verify:
5360
requests.packages.urllib3.disable_warnings() # type: ignore
5461

5562
def logout(self, hostname: str):
@@ -846,7 +853,7 @@ def do_request(
846853
json=json,
847854
headers=headers,
848855
stream=stream,
849-
verify=not self._insecure,
856+
verify=self._tls_verify,
850857
)
851858

852859
# A 401 response is a request for authentication

oras/utils/request.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ def append_url_params(url: str, params: dict) -> str:
5151
return urlparse.urlunparse(updated)
5252

5353

54-
def get_docker_client(insecure: bool = False, **kwargs):
54+
def get_docker_client(tls_verify: bool = True, **kwargs):
5555
"""
5656
Get a docker client.
5757
58-
:param tls : enable tls
59-
:type tls: bool
58+
:param tls_verify : enable tls
59+
:type tls_verify: bool
6060
"""
6161
import docker
6262

63-
return docker.DockerClient(tls=not insecure, **kwargs)
63+
return docker.DockerClient(tls=tls_verify, **kwargs)

oras/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__copyright__ = "Copyright The ORAS Authors."
33
__license__ = "Apache-2.0"
44

5-
__version__ = "0.1.21"
5+
__version__ = "0.1.22"
66
AUTHOR = "Vanessa Sochat"
77
EMAIL = "vsoch@users.noreply.github.com"
88
NAME = "oras"

0 commit comments

Comments
 (0)