cloudsmith-cli 1.20.0__py3-none-any.whl
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.
- cloudsmith_cli/__init__.py +10 -0
- cloudsmith_cli/__main__.py +8 -0
- cloudsmith_cli/cli/__init__.py +1 -0
- cloudsmith_cli/cli/command.py +160 -0
- cloudsmith_cli/cli/commands/__init__.py +33 -0
- cloudsmith_cli/cli/commands/auth.py +173 -0
- cloudsmith_cli/cli/commands/check.py +129 -0
- cloudsmith_cli/cli/commands/copy.py +98 -0
- cloudsmith_cli/cli/commands/credential_helper/__init__.py +39 -0
- cloudsmith_cli/cli/commands/credential_helper/docker.py +66 -0
- cloudsmith_cli/cli/commands/credential_helper/manage.py +299 -0
- cloudsmith_cli/cli/commands/delete.py +67 -0
- cloudsmith_cli/cli/commands/dependencies.py +108 -0
- cloudsmith_cli/cli/commands/docs.py +16 -0
- cloudsmith_cli/cli/commands/download.py +620 -0
- cloudsmith_cli/cli/commands/entitlements.py +819 -0
- cloudsmith_cli/cli/commands/help_.py +12 -0
- cloudsmith_cli/cli/commands/list_.py +317 -0
- cloudsmith_cli/cli/commands/login.py +99 -0
- cloudsmith_cli/cli/commands/logout.py +151 -0
- cloudsmith_cli/cli/commands/main.py +73 -0
- cloudsmith_cli/cli/commands/mcp.py +523 -0
- cloudsmith_cli/cli/commands/metadata.py +503 -0
- cloudsmith_cli/cli/commands/metrics/__init__.py +2 -0
- cloudsmith_cli/cli/commands/metrics/command.py +20 -0
- cloudsmith_cli/cli/commands/metrics/entitlements.py +148 -0
- cloudsmith_cli/cli/commands/metrics/packages.py +134 -0
- cloudsmith_cli/cli/commands/move.py +111 -0
- cloudsmith_cli/cli/commands/policy/__init__.py +3 -0
- cloudsmith_cli/cli/commands/policy/command.py +20 -0
- cloudsmith_cli/cli/commands/policy/deny.py +248 -0
- cloudsmith_cli/cli/commands/policy/license.py +335 -0
- cloudsmith_cli/cli/commands/policy/vulnerability.py +322 -0
- cloudsmith_cli/cli/commands/push.py +1323 -0
- cloudsmith_cli/cli/commands/quarantine.py +148 -0
- cloudsmith_cli/cli/commands/quota/__init__.py +2 -0
- cloudsmith_cli/cli/commands/quota/command.py +20 -0
- cloudsmith_cli/cli/commands/quota/history.py +122 -0
- cloudsmith_cli/cli/commands/quota/quota.py +107 -0
- cloudsmith_cli/cli/commands/repos.py +330 -0
- cloudsmith_cli/cli/commands/resync.py +90 -0
- cloudsmith_cli/cli/commands/status.py +92 -0
- cloudsmith_cli/cli/commands/tags.py +375 -0
- cloudsmith_cli/cli/commands/tokens.py +318 -0
- cloudsmith_cli/cli/commands/upstream.py +479 -0
- cloudsmith_cli/cli/commands/vulnerabilities.py +141 -0
- cloudsmith_cli/cli/commands/whoami.py +188 -0
- cloudsmith_cli/cli/config.py +635 -0
- cloudsmith_cli/cli/decorators.py +624 -0
- cloudsmith_cli/cli/exceptions.py +215 -0
- cloudsmith_cli/cli/metadata_common.py +146 -0
- cloudsmith_cli/cli/saml.py +109 -0
- cloudsmith_cli/cli/table.py +59 -0
- cloudsmith_cli/cli/types.py +14 -0
- cloudsmith_cli/cli/utils.py +267 -0
- cloudsmith_cli/cli/validators.py +378 -0
- cloudsmith_cli/cli/webserver.py +263 -0
- cloudsmith_cli/core/__init__.py +1 -0
- cloudsmith_cli/core/api/__init__.py +1 -0
- cloudsmith_cli/core/api/distros.py +31 -0
- cloudsmith_cli/core/api/entitlements.py +130 -0
- cloudsmith_cli/core/api/exceptions.py +57 -0
- cloudsmith_cli/core/api/files.py +131 -0
- cloudsmith_cli/core/api/init.py +109 -0
- cloudsmith_cli/core/api/metadata.py +217 -0
- cloudsmith_cli/core/api/metrics.py +78 -0
- cloudsmith_cli/core/api/orgs.py +201 -0
- cloudsmith_cli/core/api/packages.py +309 -0
- cloudsmith_cli/core/api/quota.py +64 -0
- cloudsmith_cli/core/api/rates.py +28 -0
- cloudsmith_cli/core/api/repos.py +81 -0
- cloudsmith_cli/core/api/status.py +27 -0
- cloudsmith_cli/core/api/upstreams.py +72 -0
- cloudsmith_cli/core/api/user.py +109 -0
- cloudsmith_cli/core/api/version.py +15 -0
- cloudsmith_cli/core/api/vulnerabilities.py +230 -0
- cloudsmith_cli/core/cache_utils.py +160 -0
- cloudsmith_cli/core/config.py +140 -0
- cloudsmith_cli/core/credentials/__init__.py +0 -0
- cloudsmith_cli/core/credentials/chain.py +69 -0
- cloudsmith_cli/core/credentials/models.py +44 -0
- cloudsmith_cli/core/credentials/oidc/__init__.py +6 -0
- cloudsmith_cli/core/credentials/oidc/cache.py +220 -0
- cloudsmith_cli/core/credentials/oidc/detectors/__init__.py +122 -0
- cloudsmith_cli/core/credentials/oidc/detectors/aws.py +85 -0
- cloudsmith_cli/core/credentials/oidc/detectors/azure_devops.py +70 -0
- cloudsmith_cli/core/credentials/oidc/detectors/base.py +26 -0
- cloudsmith_cli/core/credentials/oidc/detectors/bitbucket_pipelines.py +35 -0
- cloudsmith_cli/core/credentials/oidc/detectors/circleci.py +40 -0
- cloudsmith_cli/core/credentials/oidc/detectors/generic.py +42 -0
- cloudsmith_cli/core/credentials/oidc/detectors/github_actions.py +64 -0
- cloudsmith_cli/core/credentials/oidc/detectors/gitlab_ci.py +49 -0
- cloudsmith_cli/core/credentials/oidc/exchange.py +87 -0
- cloudsmith_cli/core/credentials/provider.py +17 -0
- cloudsmith_cli/core/credentials/providers/__init__.py +15 -0
- cloudsmith_cli/core/credentials/providers/cli_flag.py +24 -0
- cloudsmith_cli/core/credentials/providers/credentials_file.py +24 -0
- cloudsmith_cli/core/credentials/providers/env_var.py +24 -0
- cloudsmith_cli/core/credentials/providers/keyring_provider.py +59 -0
- cloudsmith_cli/core/credentials/providers/oidc_provider.py +115 -0
- cloudsmith_cli/core/download.py +594 -0
- cloudsmith_cli/core/keyring.py +171 -0
- cloudsmith_cli/core/mcp/__init__.py +0 -0
- cloudsmith_cli/core/mcp/data.py +17 -0
- cloudsmith_cli/core/mcp/server.py +786 -0
- cloudsmith_cli/core/pagination.py +131 -0
- cloudsmith_cli/core/ratelimits.py +88 -0
- cloudsmith_cli/core/rest.py +255 -0
- cloudsmith_cli/core/utils.py +95 -0
- cloudsmith_cli/core/version.py +20 -0
- cloudsmith_cli/credential_helpers/__init__.py +7 -0
- cloudsmith_cli/credential_helpers/backends.py +41 -0
- cloudsmith_cli/credential_helpers/common.py +111 -0
- cloudsmith_cli/credential_helpers/custom_domains.py +281 -0
- cloudsmith_cli/credential_helpers/docker/__init__.py +4 -0
- cloudsmith_cli/credential_helpers/docker/installer.py +349 -0
- cloudsmith_cli/credential_helpers/docker/runtime.py +117 -0
- cloudsmith_cli/credential_helpers/launchers.py +175 -0
- cloudsmith_cli/data/VERSION +1 -0
- cloudsmith_cli/data/config.ini +23 -0
- cloudsmith_cli/data/credentials.ini +14 -0
- cloudsmith_cli/templates/__init__.py +3 -0
- cloudsmith_cli/templates/auth_error.html +45 -0
- cloudsmith_cli/templates/auth_success.html +37 -0
- cloudsmith_cli-1.20.0.dist-info/METADATA +610 -0
- cloudsmith_cli-1.20.0.dist-info/RECORD +130 -0
- cloudsmith_cli-1.20.0.dist-info/WHEEL +5 -0
- cloudsmith_cli-1.20.0.dist-info/entry_points.txt +2 -0
- cloudsmith_cli-1.20.0.dist-info/licenses/LICENSE +201 -0
- cloudsmith_cli-1.20.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Cloudsmith API - Initialisation."""
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
from typing import TypeVar
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
import cloudsmith_api
|
|
8
|
+
|
|
9
|
+
from ..rest import RestClient
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def initialise_api(
|
|
13
|
+
debug=False,
|
|
14
|
+
host=None,
|
|
15
|
+
credential=None,
|
|
16
|
+
proxy=None,
|
|
17
|
+
ssl_verify=True,
|
|
18
|
+
user_agent=None,
|
|
19
|
+
headers=None,
|
|
20
|
+
rate_limit=True,
|
|
21
|
+
rate_limit_callback=None,
|
|
22
|
+
error_retry_max=None,
|
|
23
|
+
error_retry_backoff=None,
|
|
24
|
+
error_retry_codes=None,
|
|
25
|
+
error_retry_cb=None,
|
|
26
|
+
):
|
|
27
|
+
"""Initialise the cloudsmith_api.Configuration."""
|
|
28
|
+
# FIXME: pylint: disable=too-many-arguments
|
|
29
|
+
config = cloudsmith_api.Configuration()
|
|
30
|
+
config.debug = debug
|
|
31
|
+
config.host = host if host else config.host
|
|
32
|
+
config.proxy = proxy if proxy else config.proxy
|
|
33
|
+
config.user_agent = user_agent
|
|
34
|
+
config.headers = headers if headers else {}
|
|
35
|
+
config.rate_limit = rate_limit
|
|
36
|
+
config.rate_limit_callback = rate_limit_callback
|
|
37
|
+
config.error_retry_max = error_retry_max
|
|
38
|
+
config.error_retry_backoff = error_retry_backoff
|
|
39
|
+
config.error_retry_codes = error_retry_codes
|
|
40
|
+
config.error_retry_cb = error_retry_cb
|
|
41
|
+
config.verify_ssl = ssl_verify
|
|
42
|
+
config.client_side_validation = False
|
|
43
|
+
|
|
44
|
+
if credential:
|
|
45
|
+
if credential.auth_type == "bearer":
|
|
46
|
+
config.headers["Authorization"] = f"Bearer {credential.api_key}"
|
|
47
|
+
if config.debug:
|
|
48
|
+
click.echo("SSO access token config value set")
|
|
49
|
+
else:
|
|
50
|
+
config.api_key["X-Api-Key"] = credential.api_key
|
|
51
|
+
if config.debug:
|
|
52
|
+
click.echo("User API key config value set")
|
|
53
|
+
|
|
54
|
+
auth_header = headers and config.headers.get("Authorization")
|
|
55
|
+
if auth_header and " " in auth_header:
|
|
56
|
+
auth_type, encoded = auth_header.split(" ", 1)
|
|
57
|
+
if auth_type == "Basic":
|
|
58
|
+
decoded = base64.b64decode(encoded)
|
|
59
|
+
values = decoded.decode("utf-8")
|
|
60
|
+
config.username, config.password = values.split(":")
|
|
61
|
+
|
|
62
|
+
if config.debug:
|
|
63
|
+
click.echo("Username and password config values set")
|
|
64
|
+
|
|
65
|
+
# Important! Some of the attributes set above (e.g. error_retry_max) are not
|
|
66
|
+
# present in the cloudsmith_api.Configuration class declaration.
|
|
67
|
+
# By calling the set_default() method, we ensure that future instances of that
|
|
68
|
+
# class will include those attributes, and their (default) values.
|
|
69
|
+
cloudsmith_api.Configuration.set_default(config)
|
|
70
|
+
|
|
71
|
+
return config
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
T = TypeVar("T")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def get_api_client(cls: type[T]) -> T:
|
|
78
|
+
"""Get an API client (with configuration)."""
|
|
79
|
+
config = cloudsmith_api.Configuration()
|
|
80
|
+
client = cls()
|
|
81
|
+
client.config = config
|
|
82
|
+
client.api_client.rest_client = RestClient(
|
|
83
|
+
error_retry_cb=getattr(config, "error_retry_cb", None),
|
|
84
|
+
respect_retry_after_header=getattr(config, "rate_limit", True),
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
user_agent = getattr(config, "user_agent", None)
|
|
88
|
+
if user_agent:
|
|
89
|
+
client.api_client.user_agent = user_agent
|
|
90
|
+
|
|
91
|
+
headers = getattr(config, "headers", None)
|
|
92
|
+
if headers:
|
|
93
|
+
for k, v in headers.items():
|
|
94
|
+
client.api_client.set_default_header(k, v)
|
|
95
|
+
|
|
96
|
+
return client
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def unset_api_key():
|
|
100
|
+
"""Unset the API key."""
|
|
101
|
+
config = cloudsmith_api.Configuration()
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
del config.api_key["X-Api-Key"]
|
|
105
|
+
except KeyError:
|
|
106
|
+
pass
|
|
107
|
+
|
|
108
|
+
if hasattr(cloudsmith_api.Configuration, "set_default"):
|
|
109
|
+
cloudsmith_api.Configuration.set_default(config)
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"""API - Package metadata (v2) endpoints."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import cloudsmith_api
|
|
7
|
+
|
|
8
|
+
from .. import ratelimits, utils
|
|
9
|
+
from ..pagination import PageInfo
|
|
10
|
+
from ..rest import RestClient
|
|
11
|
+
from .exceptions import catch_raise_api_exception
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class _MetadataApi:
|
|
15
|
+
"""Small client for metadata endpoints not yet present in cloudsmith_api."""
|
|
16
|
+
|
|
17
|
+
def __init__(self):
|
|
18
|
+
self.config = cloudsmith_api.Configuration()
|
|
19
|
+
self.rest_client = RestClient(
|
|
20
|
+
error_retry_cb=getattr(self.config, "error_retry_cb", None),
|
|
21
|
+
respect_retry_after_header=getattr(self.config, "rate_limit", True),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def get_metadata_api():
|
|
26
|
+
"""Get the metadata API client."""
|
|
27
|
+
return _MetadataApi()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _build_url(config, *parts):
|
|
31
|
+
host = (config.host or "").rstrip("/")
|
|
32
|
+
suffix = "/".join(p.strip("/") for p in parts if p)
|
|
33
|
+
return f"{host}/v2/{suffix}/"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _build_headers(config):
|
|
37
|
+
"""Build request headers from the configured cloudsmith_api.Configuration.
|
|
38
|
+
|
|
39
|
+
Mirrors the auth resolution performed by core/api/init.py: an Authorization
|
|
40
|
+
header (SSO bearer or Basic) takes precedence; otherwise we fall back to
|
|
41
|
+
the X-Api-Key header.
|
|
42
|
+
"""
|
|
43
|
+
headers = {"Accept": "application/json", "Content-Type": "application/json"}
|
|
44
|
+
headers.update(getattr(config, "headers", None) or {})
|
|
45
|
+
|
|
46
|
+
user_agent = getattr(config, "user_agent", None)
|
|
47
|
+
if user_agent:
|
|
48
|
+
headers["User-Agent"] = user_agent
|
|
49
|
+
|
|
50
|
+
if headers.get("Authorization"):
|
|
51
|
+
headers.pop("X-Api-Key", None)
|
|
52
|
+
else:
|
|
53
|
+
api_key = (config.api_key or {}).get("X-Api-Key")
|
|
54
|
+
if api_key:
|
|
55
|
+
headers["X-Api-Key"] = api_key
|
|
56
|
+
|
|
57
|
+
return headers
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _request(client, method, *path_parts, query_params=None, body=None):
|
|
61
|
+
url = _build_url(client.config, *path_parts)
|
|
62
|
+
|
|
63
|
+
with catch_raise_api_exception():
|
|
64
|
+
response = client.rest_client.request(
|
|
65
|
+
method,
|
|
66
|
+
url,
|
|
67
|
+
query_params=query_params,
|
|
68
|
+
headers=_build_headers(client.config),
|
|
69
|
+
body=body,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
ratelimits.maybe_rate_limit(client, response.getheaders())
|
|
73
|
+
return response
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _response_json(response):
|
|
77
|
+
if not response.data:
|
|
78
|
+
return {}
|
|
79
|
+
return json.loads(response.data)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def list_metadata(
|
|
83
|
+
package_slug_perm: str,
|
|
84
|
+
*,
|
|
85
|
+
source_kind: str | None = None,
|
|
86
|
+
classification: str | None = None,
|
|
87
|
+
page: int | None = None,
|
|
88
|
+
page_size: int | None = None,
|
|
89
|
+
):
|
|
90
|
+
"""List metadata entries attached to a package.
|
|
91
|
+
|
|
92
|
+
`source_kind` and `classification` are sent as the lowercased enum name
|
|
93
|
+
the v2 API expects; the authoritative backend validates the value and
|
|
94
|
+
surfaces a 4xx for anything it does not recognise.
|
|
95
|
+
|
|
96
|
+
Returns a (results, PageInfo) tuple.
|
|
97
|
+
"""
|
|
98
|
+
client = get_metadata_api()
|
|
99
|
+
api_kwargs = {}
|
|
100
|
+
|
|
101
|
+
source_kind_value = str(source_kind).strip().lower() if source_kind else ""
|
|
102
|
+
if source_kind_value:
|
|
103
|
+
api_kwargs["source_kind"] = source_kind_value
|
|
104
|
+
classification_value = str(classification).strip().lower() if classification else ""
|
|
105
|
+
if classification_value:
|
|
106
|
+
api_kwargs["classification"] = classification_value
|
|
107
|
+
|
|
108
|
+
api_kwargs.update(utils.get_page_kwargs(page=page, page_size=page_size))
|
|
109
|
+
|
|
110
|
+
response = _request(
|
|
111
|
+
client,
|
|
112
|
+
"GET",
|
|
113
|
+
"metadata",
|
|
114
|
+
"packages",
|
|
115
|
+
package_slug_perm,
|
|
116
|
+
query_params=api_kwargs or None,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
payload = _response_json(response)
|
|
120
|
+
results = payload.get("results", payload) if isinstance(payload, dict) else payload
|
|
121
|
+
page_info = PageInfo.from_headers(response.getheaders())
|
|
122
|
+
return results, page_info
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def get_metadata(package_slug_perm: str, metadata_slug_perm: str):
|
|
126
|
+
"""Retrieve a single metadata entry attached to a package."""
|
|
127
|
+
client = get_metadata_api()
|
|
128
|
+
response = _request(
|
|
129
|
+
client,
|
|
130
|
+
"GET",
|
|
131
|
+
"metadata",
|
|
132
|
+
"packages",
|
|
133
|
+
package_slug_perm,
|
|
134
|
+
metadata_slug_perm,
|
|
135
|
+
)
|
|
136
|
+
return _response_json(response)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def create_metadata(
|
|
140
|
+
package_slug_perm: str,
|
|
141
|
+
*,
|
|
142
|
+
content: Any,
|
|
143
|
+
content_type: str,
|
|
144
|
+
source_identity: str,
|
|
145
|
+
):
|
|
146
|
+
"""Attach a new metadata entry to a package."""
|
|
147
|
+
client = get_metadata_api()
|
|
148
|
+
body = {
|
|
149
|
+
"content": content,
|
|
150
|
+
"content_type": content_type,
|
|
151
|
+
"source_identity": source_identity,
|
|
152
|
+
}
|
|
153
|
+
response = _request(
|
|
154
|
+
client, "POST", "metadata", "packages", package_slug_perm, body=body
|
|
155
|
+
)
|
|
156
|
+
return _response_json(response)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def update_metadata(
|
|
160
|
+
package_slug_perm: str,
|
|
161
|
+
metadata_slug_perm: str,
|
|
162
|
+
*,
|
|
163
|
+
content: Any = None,
|
|
164
|
+
source_identity: str | None = None,
|
|
165
|
+
):
|
|
166
|
+
"""Patch an existing customer-owned metadata entry.
|
|
167
|
+
|
|
168
|
+
Only `content` and `source_identity` are mutable; the v2 API rejects
|
|
169
|
+
attempts to change `content_type`. Fields left as None are omitted from
|
|
170
|
+
the patch body so existing values are preserved.
|
|
171
|
+
"""
|
|
172
|
+
client = get_metadata_api()
|
|
173
|
+
body = {}
|
|
174
|
+
if content is not None:
|
|
175
|
+
body["content"] = content
|
|
176
|
+
if source_identity is not None:
|
|
177
|
+
body["source_identity"] = source_identity
|
|
178
|
+
if not body:
|
|
179
|
+
raise ValueError(
|
|
180
|
+
"update_metadata requires at least one of content or source_identity"
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
response = _request(
|
|
184
|
+
client,
|
|
185
|
+
"PATCH",
|
|
186
|
+
"metadata",
|
|
187
|
+
"packages",
|
|
188
|
+
package_slug_perm,
|
|
189
|
+
metadata_slug_perm,
|
|
190
|
+
body=body,
|
|
191
|
+
)
|
|
192
|
+
return _response_json(response)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def delete_metadata(package_slug_perm: str, metadata_slug_perm: str):
|
|
196
|
+
"""Remove a customer-owned metadata entry from a package."""
|
|
197
|
+
client = get_metadata_api()
|
|
198
|
+
_request(
|
|
199
|
+
client,
|
|
200
|
+
"DELETE",
|
|
201
|
+
"metadata",
|
|
202
|
+
"packages",
|
|
203
|
+
package_slug_perm,
|
|
204
|
+
metadata_slug_perm,
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def validate_metadata(*, content: Any, content_type: str):
|
|
209
|
+
"""Validate a metadata payload against its content type schema.
|
|
210
|
+
|
|
211
|
+
Hits POST /v2/metadata/validate/ which checks shape and schema without
|
|
212
|
+
persisting. Server returns 200 on success and 422 on validation failure.
|
|
213
|
+
"""
|
|
214
|
+
client = get_metadata_api()
|
|
215
|
+
body = {"content": content, "content_type": content_type}
|
|
216
|
+
_request(client, "POST", "metadata", "validate", body=body)
|
|
217
|
+
return True
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""API - Metrics endpoints."""
|
|
2
|
+
|
|
3
|
+
import cloudsmith_api
|
|
4
|
+
|
|
5
|
+
from .. import ratelimits
|
|
6
|
+
from .exceptions import catch_raise_api_exception
|
|
7
|
+
from .init import get_api_client
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_metrics_api():
|
|
11
|
+
"""Get the repos API client."""
|
|
12
|
+
return get_api_client(cloudsmith_api.MetricsApi)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def get_namespace_entitlements_metrics(owner=None, **kwargs):
|
|
16
|
+
"""Get repository entitlements metrics."""
|
|
17
|
+
client = get_metrics_api()
|
|
18
|
+
|
|
19
|
+
api_kwargs = {}
|
|
20
|
+
api_kwargs.update(
|
|
21
|
+
{param: value for param, value in kwargs.items() if value is not None}
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
headers = []
|
|
25
|
+
res = None
|
|
26
|
+
|
|
27
|
+
if owner:
|
|
28
|
+
with catch_raise_api_exception():
|
|
29
|
+
res, _, headers = client.metrics_entitlements_account_list_with_http_info(
|
|
30
|
+
owner=owner, **api_kwargs
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
34
|
+
return res.tokens if res else {}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def get_repository_entitlements_metrics(owner=None, repo=None, **kwargs):
|
|
38
|
+
"""Get repository entitlements metrics."""
|
|
39
|
+
client = get_metrics_api()
|
|
40
|
+
|
|
41
|
+
api_kwargs = {}
|
|
42
|
+
api_kwargs.update(
|
|
43
|
+
{param: value for param, value in kwargs.items() if value is not None}
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
headers = []
|
|
47
|
+
res = None
|
|
48
|
+
|
|
49
|
+
if owner and repo:
|
|
50
|
+
with catch_raise_api_exception():
|
|
51
|
+
res, _, headers = client.metrics_entitlements_repo_list_with_http_info(
|
|
52
|
+
owner=owner, repo=repo, **api_kwargs
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
56
|
+
return res.tokens if res else {}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def get_repository_packages_metrics(owner=None, repo=None, **kwargs):
|
|
60
|
+
"""Get repository packages metrics."""
|
|
61
|
+
client = get_metrics_api()
|
|
62
|
+
|
|
63
|
+
api_kwargs = {}
|
|
64
|
+
api_kwargs.update(
|
|
65
|
+
{param: value for param, value in kwargs.items() if value is not None}
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
headers = []
|
|
69
|
+
res = None
|
|
70
|
+
|
|
71
|
+
if owner and repo:
|
|
72
|
+
with catch_raise_api_exception():
|
|
73
|
+
res, _, headers = client.metrics_packages_list_with_http_info(
|
|
74
|
+
owner=owner, repo=repo, **api_kwargs
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
78
|
+
return res.packages if res else {}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"""API - Packages endpoints."""
|
|
2
|
+
|
|
3
|
+
import cloudsmith_api
|
|
4
|
+
|
|
5
|
+
from .. import ratelimits
|
|
6
|
+
from ..pagination import PageInfo
|
|
7
|
+
from .exceptions import catch_raise_api_exception
|
|
8
|
+
from .init import get_api_client
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_orgs_api():
|
|
12
|
+
"""Get the orgs API client."""
|
|
13
|
+
return get_api_client(cloudsmith_api.OrgsApi)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def list_custom_domains(owner):
|
|
17
|
+
"""List custom domains for an organization (raw SDK model dicts)."""
|
|
18
|
+
client = get_orgs_api()
|
|
19
|
+
|
|
20
|
+
with catch_raise_api_exception():
|
|
21
|
+
(
|
|
22
|
+
domains,
|
|
23
|
+
_,
|
|
24
|
+
headers,
|
|
25
|
+
) = client.orgs_custom_domains_list_with_http_info( # pylint: disable=no-member
|
|
26
|
+
org=owner
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
30
|
+
return [domain.to_dict() for domain in domains]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def list_vulnerability_policies(owner, page, page_size):
|
|
34
|
+
"""List vulnerability policies in a namespace."""
|
|
35
|
+
client = get_orgs_api()
|
|
36
|
+
|
|
37
|
+
with catch_raise_api_exception():
|
|
38
|
+
policies, _, headers = client.orgs_vulnerability_policy_list_with_http_info(
|
|
39
|
+
org=owner, page=page, page_size=page_size
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
43
|
+
page_info = PageInfo.from_headers(headers)
|
|
44
|
+
return [policy.to_dict() for policy in policies], page_info
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def create_vulnerability_policy(owner, policy_config):
|
|
48
|
+
"""Create a vulnerability policy in a namespace."""
|
|
49
|
+
client = get_orgs_api()
|
|
50
|
+
|
|
51
|
+
with catch_raise_api_exception():
|
|
52
|
+
policy, _, headers = client.orgs_vulnerability_policy_create_with_http_info(
|
|
53
|
+
org=owner, data=policy_config
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
57
|
+
return policy.to_dict()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def update_vulnerability_policy(owner, slug_perm, policy_config):
|
|
61
|
+
"""Update a vulnerability policy in a namespace."""
|
|
62
|
+
client = get_orgs_api()
|
|
63
|
+
|
|
64
|
+
with catch_raise_api_exception():
|
|
65
|
+
(
|
|
66
|
+
data,
|
|
67
|
+
_,
|
|
68
|
+
headers,
|
|
69
|
+
) = client.orgs_vulnerability_policy_partial_update_with_http_info(
|
|
70
|
+
owner, slug_perm, data=policy_config
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
74
|
+
return data.to_dict()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def delete_vulnerability_policy(owner, slug_perm):
|
|
78
|
+
"""Delete a vulnerability_policy from a namespace."""
|
|
79
|
+
client = get_orgs_api()
|
|
80
|
+
|
|
81
|
+
with catch_raise_api_exception():
|
|
82
|
+
_, _, headers = client.orgs_vulnerability_policy_delete_with_http_info(
|
|
83
|
+
owner, slug_perm
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def list_license_policies(owner, page, page_size):
|
|
90
|
+
"""List license policies in a namespace."""
|
|
91
|
+
client = get_orgs_api()
|
|
92
|
+
|
|
93
|
+
with catch_raise_api_exception():
|
|
94
|
+
policies, _, headers = client.orgs_license_policy_list_with_http_info(
|
|
95
|
+
org=owner, page=page, page_size=page_size
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
99
|
+
page_info = PageInfo.from_headers(headers)
|
|
100
|
+
return [policy.to_dict() for policy in policies], page_info
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def create_license_policy(owner, policy_config):
|
|
104
|
+
"""Create a license policy in a namespace."""
|
|
105
|
+
client = get_orgs_api()
|
|
106
|
+
|
|
107
|
+
with catch_raise_api_exception():
|
|
108
|
+
policy, _, headers = client.orgs_license_policy_create_with_http_info(
|
|
109
|
+
org=owner, data=policy_config
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
113
|
+
return policy.to_dict()
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def update_license_policy(owner, slug_perm, policy_config):
|
|
117
|
+
"""Update a license policy in a namespace."""
|
|
118
|
+
client = get_orgs_api()
|
|
119
|
+
|
|
120
|
+
with catch_raise_api_exception():
|
|
121
|
+
policy, _, headers = client.orgs_license_policy_partial_update_with_http_info(
|
|
122
|
+
org=owner, slug_perm=slug_perm, data=policy_config
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
126
|
+
return policy.to_dict()
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def delete_license_policy(owner, slug_perm):
|
|
130
|
+
"""Delete a license policy from a namespace."""
|
|
131
|
+
client = get_orgs_api()
|
|
132
|
+
|
|
133
|
+
with catch_raise_api_exception():
|
|
134
|
+
_, _, headers = client.orgs_license_policy_delete_with_http_info(
|
|
135
|
+
owner, slug_perm
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def list_deny_policies(owner, page, page_size):
|
|
142
|
+
"""List deny policies in a namespace."""
|
|
143
|
+
client = get_orgs_api()
|
|
144
|
+
|
|
145
|
+
with catch_raise_api_exception():
|
|
146
|
+
policies, _, headers = client.orgs_deny_policy_list_with_http_info(
|
|
147
|
+
org=owner, page=page, page_size=page_size
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
151
|
+
page_info = PageInfo.from_headers(headers)
|
|
152
|
+
return [policy.to_dict() for policy in policies], page_info
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def create_deny_policy(owner, policy_config):
|
|
156
|
+
"""Create a deny policy in a namespace."""
|
|
157
|
+
client = get_orgs_api()
|
|
158
|
+
|
|
159
|
+
with catch_raise_api_exception():
|
|
160
|
+
policy, _, headers = client.orgs_deny_policy_create_with_http_info(
|
|
161
|
+
org=owner, data=policy_config
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
165
|
+
return policy.to_dict()
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def get_deny_policy(owner, slug_perm):
|
|
169
|
+
"""Get a deny policy from a namespace."""
|
|
170
|
+
client = get_orgs_api()
|
|
171
|
+
|
|
172
|
+
with catch_raise_api_exception():
|
|
173
|
+
policy, _, headers = client.orgs_deny_policy_read_with_http_info(
|
|
174
|
+
org=owner, slug_perm=slug_perm
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
178
|
+
return policy.to_dict()
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def update_deny_policy(owner, slug_perm, policy_config):
|
|
182
|
+
"""Update a deny policy in a namespace."""
|
|
183
|
+
client = get_orgs_api()
|
|
184
|
+
|
|
185
|
+
with catch_raise_api_exception():
|
|
186
|
+
policy, _, headers = client.orgs_deny_policy_partial_update_with_http_info(
|
|
187
|
+
org=owner, slug_perm=slug_perm, data=policy_config
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
ratelimits.maybe_rate_limit(client, headers)
|
|
191
|
+
return policy.to_dict()
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def delete_deny_policy(owner, slug_perm):
|
|
195
|
+
"""Delete a deny policy from a namespace."""
|
|
196
|
+
client = get_orgs_api()
|
|
197
|
+
|
|
198
|
+
with catch_raise_api_exception():
|
|
199
|
+
_, _, headers = client.orgs_deny_policy_delete_with_http_info(owner, slug_perm)
|
|
200
|
+
|
|
201
|
+
ratelimits.maybe_rate_limit(client, headers)
|