Skip to content

Commit 75c27c9

Browse files
authored
Merge pull request #37 from jupyter-naas/30-implement-the-interface-for-the-secrets
feat: interface for secrets
2 parents 9184168 + 58c120f commit 75c27c9

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

naas_python/domains/secret/adaptors/primary/TyperSecretAdaptor.py

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
ISecretDomain,
2121
ISecretInvoker,
2222
SecretConflictError,
23+
Secret
2324
)
2425
# from naas_python.domains.secret.SecretSchema import SecrettryConflictError
2526
from naas_python.utils.cicd import Pipeline
@@ -53,6 +54,7 @@ def __init__(self, domain: ISecretDomain):
5354
# Include all commands
5455
self.app.command()(self.list)
5556
self.app.command()(self.create)
57+
self.app.command()(self.bulk_create)
5658
self.app.command()(self.get)
5759
self.app.command()(self.delete)
5860

@@ -96,6 +98,20 @@ def create(
9698

9799
if secret is None:
98100
print('Secret Successfully created')
101+
102+
def bulk_create(
103+
self,
104+
secrets: str = typer.Option(..., "--secrets", help="List of secrets"),
105+
106+
):
107+
print("\ntyper_list:",json.dumps(secrets))
108+
"""Create Secrets with the given specifications"""
109+
secrets = self.domain.bulk_create(
110+
secrets_list=secrets,
111+
)
112+
113+
if secrets is None:
114+
print('Secret Successfully created')
99115

100116
def get(
101117
self,

naas_python/utils/domains_base/secondary/BaseAPIAdaptor.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ServiceStatusError(NaasException):
2222

2323
class BaseAPIAdaptor(NaasSpaceAuthenticatorAdapter):
2424
host = os.environ.get("NAAS_PYTHON_API_BASE_URL", "https://api.naas.ai")
25-
# host = os.environ.get("NAAS_PYTHON_API_BASE_URL", "http://localhost:8000")
25+
#host = os.environ.get("NAAS_PYTHON_API_BASE_URL", "http://localhost:8000")
2626
# Cache name is the name of the calling module
2727
cache_name = __name__
2828
cache_expire_after = 60 # Cache expires after 60 seconds
@@ -89,8 +89,8 @@ def make_api_request(
8989
return api_response
9090

9191
except requests.exceptions.HTTPError as e:
92+
_response = api_response.json()
9293
if api_response.status_code == 401:
93-
_response = api_response.json()
9494
_message = ""
9595
if "error_message" in _response:
9696
_message = _response["error_message"]
@@ -103,7 +103,13 @@ def make_api_request(
103103
e,
104104
)
105105
elif api_response.status_code == 500:
106-
_message = "Internal Server Error"
106+
_message = ""
107+
if "error_message" in _response:
108+
_message = _response["error_message"]
109+
elif "detail" in _response:
110+
_message = _response["detail"]
111+
else:
112+
_message = "Internal Server Error"
107113
raise ServiceStatusError(_message, e)
108114
else:
109115
# Other status codes will be handled by the calling method

0 commit comments

Comments
 (0)