mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 01:57:13 +02:00
Improved support for private packages in PlatformIO Registry
This commit is contained in:
@ -11,6 +11,7 @@ PlatformIO Core 5
|
||||
5.2.5 (2021-12-??)
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
- Improved support for private packages in `PlatformIO Registry <https://registry.platformio.org/>`__
|
||||
|
||||
5.2.4 (2021-12-15)
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
@ -21,7 +21,7 @@ import requests.adapters
|
||||
from requests.packages.urllib3.util.retry import Retry # pylint:disable=import-error
|
||||
|
||||
from platformio import __check_internet_hosts__, __default_requests_timeout__, app, util
|
||||
from platformio.cache import ContentCache
|
||||
from platformio.cache import ContentCache, cleanup_content_cache
|
||||
from platformio.exception import PlatformioException, UserSideException
|
||||
|
||||
try:
|
||||
@ -134,6 +134,8 @@ class HTTPClient(object):
|
||||
raise HTTPClientError(str(e))
|
||||
|
||||
def fetch_json_data(self, method, path, **kwargs):
|
||||
if method != "get":
|
||||
cleanup_content_cache("http")
|
||||
cache_valid = kwargs.pop("cache_valid") if "cache_valid" in kwargs else None
|
||||
if not cache_valid:
|
||||
return self._parse_json_response(self.send_request(method, path, **kwargs))
|
||||
|
@ -23,6 +23,21 @@ class RegistryClient(HTTPClient):
|
||||
def __init__(self):
|
||||
super(RegistryClient, self).__init__(__registry_api__)
|
||||
|
||||
@staticmethod
|
||||
def allowed_private_packages():
|
||||
private_permissions = set(
|
||||
[
|
||||
"service.registry.publish-private-tool",
|
||||
"service.registry.publish-private-platform",
|
||||
"service.registry.publish-private-library",
|
||||
]
|
||||
)
|
||||
info = AccountClient().get_account_info() or {}
|
||||
for item in info.get("packages", []):
|
||||
if set(item.keys()) & private_permissions:
|
||||
return True
|
||||
return False
|
||||
|
||||
def send_auth_request(self, *args, **kwargs):
|
||||
headers = kwargs.get("headers", {})
|
||||
if "Authorization" not in headers:
|
||||
@ -116,13 +131,24 @@ class RegistryClient(HTTPClient):
|
||||
params = dict(query=" ".join(search_query))
|
||||
if page:
|
||||
params["page"] = int(page)
|
||||
return self.fetch_json_data(
|
||||
"get", "/v3/search", params=params, cache_valid="1h"
|
||||
return (
|
||||
self.send_auth_request
|
||||
if self.allowed_private_packages()
|
||||
else self.fetch_json_data
|
||||
)(
|
||||
"get",
|
||||
"/v3/search",
|
||||
params=params,
|
||||
cache_valid="1h",
|
||||
)
|
||||
|
||||
def get_package(self, type_, owner, name, version=None):
|
||||
try:
|
||||
return self.fetch_json_data(
|
||||
return (
|
||||
self.send_auth_request
|
||||
if self.allowed_private_packages()
|
||||
else self.fetch_json_data
|
||||
)(
|
||||
"get",
|
||||
"/v3/packages/{owner}/{type}/{name}".format(
|
||||
type=type_, owner=owner.lower(), name=name.lower()
|
||||
|
@ -134,6 +134,14 @@ def access_list(owner, urn_type, json_output):
|
||||
table_data = []
|
||||
table_data.append(("URN:", resource.get("urn")))
|
||||
table_data.append(("Owner:", resource.get("owner")))
|
||||
table_data.append(
|
||||
(
|
||||
"Access:",
|
||||
click.style("Private", fg="red")
|
||||
if resource.get("private", False)
|
||||
else "Public",
|
||||
)
|
||||
)
|
||||
table_data.append(
|
||||
(
|
||||
"Access level(s):",
|
||||
|
Reference in New Issue
Block a user