Skip to content

Commit

Permalink
chore: avoid having to match with all keys
Browse files Browse the repository at this point in the history
Signed-off-by: guillaume <[email protected]>
  • Loading branch information
gruyaume committed Sep 25, 2024
1 parent 2410d91 commit f4389c4
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/notary.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ def login(self, username: str, password: str) -> LoginResponse | None:
login_params = LoginParams(username=username, password=password)
response = self._make_request("POST", "/login", data=asdict(login_params))
if response and response.result:
return LoginResponse(**response.result)
return LoginResponse(
token=response.result.get("token"),
)
return None

def token_is_valid(self, token: str) -> bool:
Expand All @@ -198,7 +200,10 @@ def get_status(self) -> StatusResponse | None:
"""Return if the Notary server is initialized."""
response = self._make_request("GET", "/status")
if response and response.result:
return StatusResponse(**response.result)
return StatusResponse(
initialized=response.result.get("initialized"),
version=response.result.get("version"),
)
return None

def create_first_user(self, username: str, password: str) -> CreateUserResponse | None:
Expand All @@ -208,7 +213,9 @@ def create_first_user(self, username: str, password: str) -> CreateUserResponse
"POST", f"/api/{self.API_VERSION}/accounts", data=asdict(create_user_params)
)
if response and response.result:
return CreateUserResponse(**response.result)
return CreateUserResponse(
id=response.result.get("id"),
)
return None

def list_certificate_requests(self, token: str) -> List[CertificateRequest]:
Expand Down Expand Up @@ -239,7 +246,9 @@ def create_certificate_request(
data=asdict(create_certificate_request_params),
)
if response and response.result:
return CreateCertificateRequestResponse(**response.result)
return CreateCertificateRequestResponse(
id=response.result.get("id"),
)
return None

def create_certificate(
Expand All @@ -262,7 +271,9 @@ def create_certificate(
data=asdict(create_certificate_params),
)
if response and response.result:
return CreateCertificateResponse(**response.result)
return CreateCertificateResponse(
id=response.result.get("id"),
)
return None


Expand Down

0 comments on commit f4389c4

Please sign in to comment.