forked from mirrors/thatmattlove-hyperglass
improve hyperglass-agent certificate import
This commit is contained in:
parent
e3716784bc
commit
7d5734af83
2 changed files with 4 additions and 17 deletions
|
|
@ -180,7 +180,7 @@ async def import_certificate(encoded_request: EncodedRequest):
|
|||
secret=matched_device.credential.password.get_secret_value(),
|
||||
)
|
||||
except HyperglassError as decode_error:
|
||||
raise HTTPException(detail=str(decode_error), status_code=401)
|
||||
raise HTTPException(detail=str(decode_error), status_code=400)
|
||||
|
||||
try:
|
||||
# Write certificate to file
|
||||
|
|
@ -192,6 +192,7 @@ async def import_certificate(encoded_request: EncodedRequest):
|
|||
except RuntimeError as err:
|
||||
raise HyperglassError(str(err), level="danger")
|
||||
|
||||
log.info("Added public key for {}", encoded_request.device)
|
||||
return {
|
||||
"output": f"Added public key for {encoded_request.device}",
|
||||
"level": "success",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
"""Tasks to be executed from web API."""
|
||||
|
||||
# Standard Library
|
||||
import re
|
||||
from typing import Dict, Union
|
||||
from pathlib import Path
|
||||
|
||||
|
|
@ -12,20 +11,7 @@ from httpx import Headers
|
|||
def import_public_key(
|
||||
app_path: Union[Path, str], device_name: str, keystring: str
|
||||
) -> bool:
|
||||
"""Import a public key for hyperglass-agent.
|
||||
|
||||
Arguments:
|
||||
app_path {Path|str} -- hyperglass app path
|
||||
device_name {str} -- Device name
|
||||
keystring {str} -- Public key
|
||||
|
||||
Raises:
|
||||
RuntimeError: Raised if unable to create certs directory
|
||||
RuntimeError: Raised if written key does not match input
|
||||
|
||||
Returns:
|
||||
{bool} -- True if file was written
|
||||
"""
|
||||
"""Import a public key for hyperglass-agent."""
|
||||
if not isinstance(app_path, Path):
|
||||
app_path = Path(app_path)
|
||||
|
||||
|
|
@ -37,7 +23,7 @@ def import_public_key(
|
|||
if not cert_dir.exists():
|
||||
raise RuntimeError(f"Failed to create certs directory at {str(cert_dir)}")
|
||||
|
||||
filename = re.sub(r"[^A-Za-z0-9]", "_", device_name) + ".pem"
|
||||
filename = f"{device_name}.pem"
|
||||
cert_file = cert_dir / filename
|
||||
|
||||
with cert_file.open("w+") as file:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue