Add typechecking.
This commit is contained in:
@@ -39,11 +39,14 @@ import random
|
||||
import base64
|
||||
from cryptography import x509
|
||||
from cryptography.hazmat.primitives.serialization import Encoding
|
||||
from dateutil.parser import parse
|
||||
from typeguard import typechecked
|
||||
|
||||
import requests
|
||||
import coloredlogs
|
||||
|
||||
def create_nonce(length: int=45):
|
||||
@typechecked
|
||||
def create_nonce(length: int=45) -> str:
|
||||
"""
|
||||
Generate a random nonce string.
|
||||
|
||||
@@ -72,7 +75,9 @@ def create_nonce(length: int=45):
|
||||
|
||||
return nonce
|
||||
|
||||
def get_bearer(hostname: str, verify: bool, username: str, password:str):
|
||||
|
||||
@typechecked
|
||||
def get_bearer(hostname: str, verify: bool, username: str, password:str) -> str:
|
||||
"""
|
||||
Retrieve an OAuth bearer token for authentication with a HP CDM server.
|
||||
|
||||
@@ -170,8 +175,10 @@ def get_bearer(hostname: str, verify: bool, username: str, password:str):
|
||||
|
||||
return bearer
|
||||
|
||||
|
||||
@typechecked
|
||||
def get_csr(hostname: str, verify: bool, username: str, password: str, ou: str, org: str, city:str,
|
||||
state: str, country: str, filename: str):
|
||||
state: str, country: str, filename: str) -> None:
|
||||
"""
|
||||
Generate a Certificate Signing Request (CSR) for a HP CDM server.
|
||||
|
||||
@@ -252,12 +259,16 @@ def get_csr(hostname: str, verify: bool, username: str, password: str, ou: str,
|
||||
finished = True
|
||||
|
||||
csr = csr['certificateData']
|
||||
print(csr)
|
||||
|
||||
logger.debug('CSR:\n %s', csr)
|
||||
|
||||
with open(filename, 'w+', encoding='utf-8') as f:
|
||||
f.write(csr)
|
||||
|
||||
def install_certificate(hostname, verify, username, password, filename, bearer=None):
|
||||
|
||||
@typechecked
|
||||
def install_certificate(hostname: str, verify: bool, username: str, password: str, filename:str,
|
||||
bearer=None) -> None:
|
||||
"""
|
||||
Install a certificate on a HP CDM server.
|
||||
|
||||
@@ -333,7 +344,10 @@ def install_certificate(hostname, verify, username, password, filename, bearer=N
|
||||
|
||||
logger.info('Certificate successfully installed.')
|
||||
|
||||
def get_certificates(hostname, verify, username, password, bearer=None):
|
||||
|
||||
@typechecked
|
||||
def get_certificates(hostname:str, verify:bool, username: str, password: str,
|
||||
bearer=None) -> dict[int, dict]:
|
||||
"""
|
||||
Retrieve a list of certificates from an HP CDM server.
|
||||
|
||||
@@ -386,6 +400,8 @@ def get_certificates(hostname, verify, username, password, bearer=None):
|
||||
|
||||
return res
|
||||
|
||||
|
||||
@typechecked
|
||||
def delete_certificate(hostname, verify, username, password, certificates, certid, bearer=None):
|
||||
"""
|
||||
Delete a certificate from an HP CDM server.
|
||||
|
||||
Reference in New Issue
Block a user