chore(realms): refactor modules
This commit is contained in:
25
plugins/module_utils/common.py
Normal file
25
plugins/module_utils/common.py
Normal file
@ -0,0 +1,25 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
import requests
|
||||
|
||||
API_BASE_PATH: str = "/api2/json"
|
||||
|
||||
|
||||
@dataclass()
|
||||
class ProxmoxAuthInfo:
|
||||
instance_url: str
|
||||
token_id: str
|
||||
secret: str
|
||||
verify_cert: bool = True
|
||||
|
||||
|
||||
def _get_token_from_auth_info(auth_info: ProxmoxAuthInfo) -> str:
|
||||
return f"PVEAPIToken={auth_info.token_id}={auth_info.secret}"
|
||||
|
||||
|
||||
def _proxmox_request(method: str, endpoint: str, auth_info: ProxmoxAuthInfo, **params):
|
||||
return requests.request(method,
|
||||
f"{auth_info.instance_url}{API_BASE_PATH}{endpoint}",
|
||||
headers={'Authorization': _get_token_from_auth_info(auth_info)},
|
||||
verify=auth_info.verify_cert,
|
||||
**params)
|
Reference in New Issue
Block a user