oras 0.2.2__tar.gz → 0.2.22__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. {oras-0.2.2/oras.egg-info → oras-0.2.22}/PKG-INFO +4 -2
  2. {oras-0.2.2 → oras-0.2.22}/README.md +3 -1
  3. {oras-0.2.2 → oras-0.2.22}/oras/auth/__init__.py +9 -3
  4. {oras-0.2.2 → oras-0.2.22}/oras/auth/token.py +13 -12
  5. {oras-0.2.2 → oras-0.2.22}/oras/auth/utils.py +3 -0
  6. {oras-0.2.2 → oras-0.2.22}/oras/decorator.py +5 -0
  7. {oras-0.2.2 → oras-0.2.22}/oras/provider.py +4 -2
  8. {oras-0.2.2 → oras-0.2.22}/oras/tests/test_provider.py +59 -6
  9. {oras-0.2.2 → oras-0.2.22}/oras/utils/fileio.py +3 -2
  10. {oras-0.2.2 → oras-0.2.22}/oras/version.py +1 -1
  11. {oras-0.2.2 → oras-0.2.22/oras.egg-info}/PKG-INFO +4 -2
  12. {oras-0.2.2 → oras-0.2.22}/LICENSE +0 -0
  13. {oras-0.2.2 → oras-0.2.22}/MANIFEST.in +0 -0
  14. {oras-0.2.2 → oras-0.2.22}/oras/__init__.py +0 -0
  15. {oras-0.2.2 → oras-0.2.22}/oras/auth/base.py +0 -0
  16. {oras-0.2.2 → oras-0.2.22}/oras/auth/basic.py +0 -0
  17. {oras-0.2.2 → oras-0.2.22}/oras/client.py +0 -0
  18. {oras-0.2.2 → oras-0.2.22}/oras/container.py +0 -0
  19. {oras-0.2.2 → oras-0.2.22}/oras/defaults.py +0 -0
  20. {oras-0.2.2 → oras-0.2.22}/oras/logger.py +0 -0
  21. {oras-0.2.2 → oras-0.2.22}/oras/main/__init__.py +0 -0
  22. {oras-0.2.2 → oras-0.2.22}/oras/main/login.py +0 -0
  23. {oras-0.2.2 → oras-0.2.22}/oras/oci.py +0 -0
  24. {oras-0.2.2 → oras-0.2.22}/oras/schemas.py +0 -0
  25. {oras-0.2.2 → oras-0.2.22}/oras/tests/__init__.py +0 -0
  26. {oras-0.2.2 → oras-0.2.22}/oras/tests/annotations.json +0 -0
  27. {oras-0.2.2 → oras-0.2.22}/oras/tests/artifact.txt +0 -0
  28. {oras-0.2.2 → oras-0.2.22}/oras/tests/conftest.py +0 -0
  29. {oras-0.2.2 → oras-0.2.22}/oras/tests/run_registry.sh +0 -0
  30. {oras-0.2.2 → oras-0.2.22}/oras/tests/test_oci.py +0 -0
  31. {oras-0.2.2 → oras-0.2.22}/oras/tests/test_oras.py +0 -0
  32. {oras-0.2.2 → oras-0.2.22}/oras/tests/test_utils.py +0 -0
  33. {oras-0.2.2 → oras-0.2.22}/oras/tests/upload_data/artifact.txt +0 -0
  34. {oras-0.2.2 → oras-0.2.22}/oras/types.py +0 -0
  35. {oras-0.2.2 → oras-0.2.22}/oras/utils/__init__.py +0 -0
  36. {oras-0.2.2 → oras-0.2.22}/oras/utils/request.py +0 -0
  37. {oras-0.2.2 → oras-0.2.22}/oras.egg-info/SOURCES.txt +0 -0
  38. {oras-0.2.2 → oras-0.2.22}/oras.egg-info/dependency_links.txt +0 -0
  39. {oras-0.2.2 → oras-0.2.22}/oras.egg-info/not-zip-safe +0 -0
  40. {oras-0.2.2 → oras-0.2.22}/oras.egg-info/requires.txt +0 -0
  41. {oras-0.2.2 → oras-0.2.22}/oras.egg-info/top_level.txt +0 -0
  42. {oras-0.2.2 → oras-0.2.22}/pyproject.toml +0 -0
  43. {oras-0.2.2 → oras-0.2.22}/setup.cfg +0 -0
  44. {oras-0.2.2 → oras-0.2.22}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oras
3
- Version: 0.2.2
3
+ Version: 0.2.22
4
4
  Summary: OCI Registry as Storage Python SDK
5
5
  Home-page: https://github.com/oras-project/oras-py
6
6
  Author: Vanessa Sochat
@@ -26,7 +26,7 @@ License-File: LICENSE
26
26
  # ORAS Python
27
27
 
28
28
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
29
- [![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors-)
29
+ [![All Contributors](https://img.shields.io/badge/all_contributors-24-orange.svg?style=flat-square)](#contributors-)
30
30
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
31
31
 
32
32
  ![ORAS Logo](https://raw.githubusercontent.com/oras-project/oras-www/main/static/img/oras.png)
@@ -81,6 +81,8 @@ tool to generate a contributors graphic below.
81
81
  </tr>
82
82
  <tr>
83
83
  <td align="center" valign="top" width="14.28%"><a href="crosscat.me"><img src="https://avatars.githubusercontent.com/u/39812919?v=4?s=100" width="100px;" alt="Isabella Basso"/><br /><sub><b>Isabella Basso</b></sub></a><br /><a href="https://github.com/oras-project/oras-py/commits?author=isinyaaa" title="Code">💻</a></td>
84
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/xarses"><img src="https://avatars.githubusercontent.com/u/2107834?v=4?s=100" width="100px;" alt="Andrew Woodward"/><br /><sub><b>Andrew Woodward</b></sub></a><br /><a href="https://github.com/oras-project/oras-py/commits?author=xarses" title="Code">💻</a></td>
85
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/ccronca"><img src="https://avatars.githubusercontent.com/u/1499184?v=4?s=100" width="100px;" alt="Camilo Cota"/><br /><sub><b>Camilo Cota</b></sub></a><br /><a href="https://github.com/oras-project/oras-py/commits?author=ccronca" title="Code">💻</a></td>
84
86
  </tr>
85
87
  </tbody>
86
88
  </table>
@@ -1,7 +1,7 @@
1
1
  # ORAS Python
2
2
 
3
3
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4
- [![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors-)
4
+ [![All Contributors](https://img.shields.io/badge/all_contributors-24-orange.svg?style=flat-square)](#contributors-)
5
5
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
6
6
 
7
7
  ![ORAS Logo](https://raw.githubusercontent.com/oras-project/oras-www/main/static/img/oras.png)
@@ -56,6 +56,8 @@ tool to generate a contributors graphic below.
56
56
  </tr>
57
57
  <tr>
58
58
  <td align="center" valign="top" width="14.28%"><a href="crosscat.me"><img src="https://avatars.githubusercontent.com/u/39812919?v=4?s=100" width="100px;" alt="Isabella Basso"/><br /><sub><b>Isabella Basso</b></sub></a><br /><a href="https://github.com/oras-project/oras-py/commits?author=isinyaaa" title="Code">💻</a></td>
59
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/xarses"><img src="https://avatars.githubusercontent.com/u/2107834?v=4?s=100" width="100px;" alt="Andrew Woodward"/><br /><sub><b>Andrew Woodward</b></sub></a><br /><a href="https://github.com/oras-project/oras-py/commits?author=xarses" title="Code">💻</a></td>
60
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/ccronca"><img src="https://avatars.githubusercontent.com/u/1499184?v=4?s=100" width="100px;" alt="Camilo Cota"/><br /><sub><b>Camilo Cota</b></sub></a><br /><a href="https://github.com/oras-project/oras-py/commits?author=ccronca" title="Code">💻</a></td>
59
61
  </tr>
60
62
  </tbody>
61
63
  </table>
@@ -1,17 +1,23 @@
1
1
  import requests
2
2
 
3
- from oras.logger import logger
4
-
5
3
  from .basic import BasicAuth
6
4
  from .token import TokenAuth
7
5
 
8
6
  auth_backends = {"token": TokenAuth, "basic": BasicAuth}
9
7
 
10
8
 
9
+ class AuthenticationException(Exception):
10
+ """
11
+ An exception to raise when Authentication errors are fatal
12
+ """
13
+
14
+ pass
15
+
16
+
11
17
  def get_auth_backend(name="token", session=None, **kwargs):
12
18
  backend = auth_backends.get(name)
13
19
  if not backend:
14
- logger.exit(f"Authentication backend {backend} is not known.")
20
+ raise ValueError(f"Authentication backend {backend} is not known.")
15
21
  backend = backend(**kwargs)
16
22
  backend.session = session or requests.Session()
17
23
  return backend
@@ -71,16 +71,16 @@ class TokenAuth(AuthBackend):
71
71
 
72
72
  h = auth_utils.parse_auth_header(authHeaderRaw)
73
73
 
74
- # First try to request an anonymous token
75
- logger.debug("No Authorization, requesting anonymous token")
76
- anon_token = self.request_anonymous_token(h)
77
- if anon_token:
78
- logger.debug("Successfully obtained anonymous token!")
79
- self.token = anon_token
80
- headers["Authorization"] = "Bearer %s" % self.token
81
- return headers, True
82
-
83
- # Next try for logged in token
74
+ # if no basic auth, try by request an anonymous token
75
+ if not hasattr(self, "_basic_auth"):
76
+ anon_token = self.request_anonymous_token(h)
77
+ if anon_token:
78
+ logger.debug("Successfully obtained anonymous token!")
79
+ self.token = anon_token
80
+ headers["Authorization"] = "Bearer %s" % self.token
81
+ return headers, True
82
+
83
+ # basic auth is available, try using auth token
84
84
  token = self.request_token(h)
85
85
  if token:
86
86
  self.token = token
@@ -95,7 +95,7 @@ class TokenAuth(AuthBackend):
95
95
 
96
96
  def request_token(self, h: auth_utils.authHeader) -> bool:
97
97
  """
98
- Request an authenticated token and save for later.s
98
+ Request an authenticated token and save for later.
99
99
  """
100
100
  params = {}
101
101
  headers = {}
@@ -124,6 +124,7 @@ class TokenAuth(AuthBackend):
124
124
  # Set Basic Auth to receive token
125
125
  headers["Authorization"] = "Basic %s" % self._basic_auth
126
126
 
127
+ logger.debug(f"Requesting auth token for: {h}")
127
128
  authResponse = self.session.get(h.realm, headers=headers, params=params) # type: ignore
128
129
 
129
130
  if authResponse.status_code != 200:
@@ -150,7 +151,7 @@ class TokenAuth(AuthBackend):
150
151
  if h.scope:
151
152
  params["scope"] = h.scope
152
153
 
153
- logger.debug(f"Final params are {params}")
154
+ logger.debug(f"Requesting anon token with params: {params}")
154
155
  response = self.session.request("GET", h.realm, params=params)
155
156
  if response.status_code != 200:
156
157
  logger.debug(f"Response for anon token failed: {response.text}")
@@ -65,6 +65,9 @@ class authHeader:
65
65
  if key in ["realm", "service", "scope"]:
66
66
  setattr(self, key, lookup[key])
67
67
 
68
+ def __repr__(self):
69
+ return f"authHeader(lookup={{'service': {repr(self.service)}, 'realm': {repr(self.realm)}, 'scope': {repr(self.scope)}}})"
70
+
68
71
 
69
72
  def parse_auth_header(authHeaderRaw: str) -> authHeader:
70
73
  """
@@ -5,6 +5,7 @@ __license__ = "Apache-2.0"
5
5
  import time
6
6
  from functools import partial, update_wrapper
7
7
 
8
+ import oras.auth
8
9
  from oras.logger import logger
9
10
 
10
11
 
@@ -52,6 +53,8 @@ class classretry(Decorator):
52
53
  while attempt < attempts:
53
54
  try:
54
55
  return self.func(cls, *args, **kwargs)
56
+ except oras.auth.AuthenticationException as e:
57
+ raise e
55
58
  except Exception as e:
56
59
  sleep = timeout + 3**attempt
57
60
  logger.info(f"Retrying in {sleep} seconds - error: {e}")
@@ -71,6 +74,8 @@ def retry(attempts, timeout=2):
71
74
  while attempt < attempts:
72
75
  try:
73
76
  return func(*args, **kwargs)
77
+ except oras.auth.AuthenticationException as e:
78
+ raise e
74
79
  except Exception as e:
75
80
  sleep = timeout + 3**attempt
76
81
  logger.info(f"Retrying in {sleep} seconds - error: {e}")
@@ -957,7 +957,9 @@ class Registry:
957
957
  :param stream: stream the responses
958
958
  :type stream: bool
959
959
  """
960
- # Make the request and return to calling function, unless requires auth
960
+ # Make the request and return to calling function, but attempt to use auth token if previously obtained
961
+ if headers is not None and isinstance(self.auth, oras.auth.TokenAuth):
962
+ headers.update(self.auth.get_auth_header())
961
963
  response = self.session.request(
962
964
  method,
963
965
  url,
@@ -975,7 +977,7 @@ class Registry:
975
977
  # Otherwise, authenticate the request and retry
976
978
  headers, changed = self.auth.authenticate_request(response, headers)
977
979
  if not changed:
978
- logger.exit("Cannot respond to request for authentication.")
980
+ raise ValueError("Cannot respond to request for authentication.")
979
981
  response = self.session.request(
980
982
  method,
981
983
  url,
@@ -63,6 +63,65 @@ def test_annotated_registry_push(tmp_path, registry, credentials, target):
63
63
  )
64
64
 
65
65
 
66
+ @pytest.mark.with_auth(False)
67
+ def test_file_contains_column(tmp_path, registry, credentials, target):
68
+ """
69
+ Test for file containing column symbol
70
+ """
71
+ client = oras.client.OrasClient(hostname=registry, insecure=True)
72
+ artifact = os.path.join(here, "artifact.txt")
73
+ assert os.path.exists(artifact)
74
+
75
+ # file containing `:`
76
+ try:
77
+ contains_column = here / "some:file"
78
+ with open(contains_column, "w") as f:
79
+ f.write("hello world some:file")
80
+
81
+ res = client.push(files=[contains_column], target=target)
82
+ assert res.status_code in [200, 201]
83
+
84
+ files = client.pull(target, outdir=tmp_path / "download")
85
+ download = str(tmp_path / "download/some:file")
86
+ assert download in files
87
+ assert oras.utils.get_file_hash(
88
+ str(contains_column)
89
+ ) == oras.utils.get_file_hash(download)
90
+ finally:
91
+ contains_column.unlink()
92
+
93
+ # file containing `:` as prefix, pushed with type
94
+ try:
95
+ contains_column = here / ":somefile"
96
+ with open(contains_column, "w") as f:
97
+ f.write("hello world :somefile")
98
+
99
+ res = client.push(files=[f"{contains_column}:text/plain"], target=target)
100
+ assert res.status_code in [200, 201]
101
+
102
+ files = client.pull(target, outdir=tmp_path / "download")
103
+ download = str(tmp_path / "download/:somefile")
104
+ assert download in files
105
+ assert oras.utils.get_file_hash(
106
+ str(contains_column)
107
+ ) == oras.utils.get_file_hash(download)
108
+ finally:
109
+ contains_column.unlink()
110
+
111
+ # error: file does not exist
112
+ with pytest.raises(FileNotFoundError):
113
+ client.push(files=[".doesnotexist"], target=target)
114
+
115
+ with pytest.raises(FileNotFoundError):
116
+ client.push(files=[":doesnotexist"], target=target)
117
+
118
+ with pytest.raises(FileNotFoundError, match=r".*does:not:exists .*"):
119
+ client.push(files=["does:not:exists:text/plain"], target=target)
120
+
121
+ with pytest.raises(FileNotFoundError, match=r".*does:not:exists .*"):
122
+ client.push(files=["does:not:exists:text/plain+ext"], target=target)
123
+
124
+
66
125
  @pytest.mark.with_auth(False)
67
126
  def test_chunked_push(tmp_path, registry, credentials, target):
68
127
  """
@@ -130,12 +189,6 @@ def test_parse_manifest(registry):
130
189
  assert ref == "path/to/config"
131
190
  assert content_type == "application/vnd.oci.image.config.v1+json"
132
191
 
133
- testref = "path/to/config:application/vnd.oci.image.config.v1+json:extra"
134
- remote = oras.provider.Registry(hostname=registry, insecure=True)
135
- ref, content_type = remote._parse_manifest_ref(testref)
136
- assert ref == "path/to/config"
137
- assert content_type == "application/vnd.oci.image.config.v1+json:extra"
138
-
139
192
  testref = "/dev/null:application/vnd.oci.image.manifest.v1+json"
140
193
  ref, content_type = remote._parse_manifest_ref(testref)
141
194
  assert ref == "/dev/null"
@@ -346,7 +346,8 @@ def split_path_and_content(ref: str) -> PathAndOptionalContent:
346
346
  : return: A Tuple of the path in the reference, and the content-type if one found,
347
347
  otherwise None.
348
348
  """
349
- if ":" not in ref:
349
+
350
+ if os.path.exists(ref) or ":" not in ref:
350
351
  return PathAndOptionalContent(ref, None)
351
352
 
352
353
  if pathlib.Path(ref).drive:
@@ -370,5 +371,5 @@ def split_path_and_content(ref: str) -> PathAndOptionalContent:
370
371
  )
371
372
  return PathAndOptionalContent(ref, None)
372
373
  else:
373
- path_content_list = ref.split(":", 1)
374
+ path_content_list = ref.rsplit(":", 1)
374
375
  return PathAndOptionalContent(path_content_list[0], path_content_list[1])
@@ -2,7 +2,7 @@ __author__ = "Vanessa Sochat"
2
2
  __copyright__ = "Copyright The ORAS Authors."
3
3
  __license__ = "Apache-2.0"
4
4
 
5
- __version__ = "0.2.2"
5
+ __version__ = "0.2.22"
6
6
  AUTHOR = "Vanessa Sochat"
7
7
  EMAIL = "vsoch@users.noreply.github.com"
8
8
  NAME = "oras"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oras
3
- Version: 0.2.2
3
+ Version: 0.2.22
4
4
  Summary: OCI Registry as Storage Python SDK
5
5
  Home-page: https://github.com/oras-project/oras-py
6
6
  Author: Vanessa Sochat
@@ -26,7 +26,7 @@ License-File: LICENSE
26
26
  # ORAS Python
27
27
 
28
28
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
29
- [![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors-)
29
+ [![All Contributors](https://img.shields.io/badge/all_contributors-24-orange.svg?style=flat-square)](#contributors-)
30
30
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
31
31
 
32
32
  ![ORAS Logo](https://raw.githubusercontent.com/oras-project/oras-www/main/static/img/oras.png)
@@ -81,6 +81,8 @@ tool to generate a contributors graphic below.
81
81
  </tr>
82
82
  <tr>
83
83
  <td align="center" valign="top" width="14.28%"><a href="crosscat.me"><img src="https://avatars.githubusercontent.com/u/39812919?v=4?s=100" width="100px;" alt="Isabella Basso"/><br /><sub><b>Isabella Basso</b></sub></a><br /><a href="https://github.com/oras-project/oras-py/commits?author=isinyaaa" title="Code">💻</a></td>
84
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/xarses"><img src="https://avatars.githubusercontent.com/u/2107834?v=4?s=100" width="100px;" alt="Andrew Woodward"/><br /><sub><b>Andrew Woodward</b></sub></a><br /><a href="https://github.com/oras-project/oras-py/commits?author=xarses" title="Code">💻</a></td>
85
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/ccronca"><img src="https://avatars.githubusercontent.com/u/1499184?v=4?s=100" width="100px;" alt="Camilo Cota"/><br /><sub><b>Camilo Cota</b></sub></a><br /><a href="https://github.com/oras-project/oras-py/commits?author=ccronca" title="Code">💻</a></td>
84
86
  </tr>
85
87
  </tbody>
86
88
  </table>
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes