A module for MrLou_AudioCodes API
Project description
AudioCodes
Overview
The AudioCodes
is a collection of Python packages that I keep re-using and thought would be good to share them
Contributing
If you would like to contribute to this project, please fork the repository and submit a pull request with your changes. Ensure that your code follows the existing style and includes appropriate tests.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Installation
You can install the package from PyPI using pip:
pip install MrLou_AudioCodes
User Guide for HTTPRequest Script
This script simplifies the process of making HTTP GET
, POST
, and PUT
requests to a server with Basic Authentication. It is structured with reusable classes and functions to handle various API endpoints.
This guide provides an overview of the classes, functions, and usage examples for interacting with a server using the requests
library. The functions facilitate API calls for common tasks such as fetching data, uploading certificates, and saving configurations.
Classes Overview
1. HTTPRequest
- A base class to handle HTTP requests.
- Attributes:
fqdn
: Fully Qualified Domain Name for the server.auth
: Basic authentication credentials (Base64 encoded).
- Methods:
_send_request(self, method, url, data=None, files=None)
: Sends an HTTP request (GET, POST, PUT) to the server and returns the response.
2. GETRequest(HTTPRequest)
- Inherits from
HTTPRequest
. Used to sendGET
requests. - Method:
send(self, url)
: Sends aGET
request to the specifiedurl
and returns the response.
3. POSTRequest(HTTPRequest)
- Inherits from
HTTPRequest
. Used to sendPOST
requests. - Method:
send(self, url, payload)
: Sends aPOST
request to the specifiedurl
withpayload
and returns the response.
4. PUTRequest(HTTPRequest)
- Inherits from
HTTPRequest
. Used to sendPUT
requests. - Method:
send(self, url, payload, files=None)
: Sends aPUT
request to the specifiedurl
withpayload
and optionalfiles
, returns the response.
Functions Overview
GET Requests
-
get_alarms(fqdn, auth)
- Sends a
GET
request to retrieve active alarms. - Input:
fqdn
: Server FQDN.auth
: Authentication string.
- Output: List of alarm descriptions, or an empty list if no alarms are found.
- Sends a
-
get_status(fqdn, auth)
- Sends a
GET
request to retrieve server status. - Input:
fqdn
: Server FQDN.auth
: Authentication string.
- Output: Server status response.
- Sends a
-
get_tls_contexts_list(fqdn, auth)
- Sends a
GET
request to retrieve a list of TLS contexts. - Input:
fqdn
: Server FQDN.auth
: Authentication string.
- Output: List of TLS contexts, or the response object.
- Sends a
-
get_device_certificate(fqdn, auth, tls_ctxt_id)
- Sends a
GET
request to retrieve the device certificate for the specified TLS context. - Input:
fqdn
: Server FQDN.auth
: Authentication string.tls_ctxt_id
: TLS context ID.
- Output: Device certificate as a string, or the response object.
- Sends a
POST Requests
save_configuration(fqdn, auth)
- Sends a
POST
request to save the server configuration. - Input:
fqdn
: Server FQDN.auth
: Authentication string.
- Output: Response status code.
- Sends a
PUT Requests
-
upload_trusted_root_certificates(fqdn, auth, tls_ctxt_id, cert_name, cert_file_path)
- Uploads trusted root certificates to the server for the specified TLS context.
- Input:
fqdn
: Server FQDN.auth
: Authentication string.tls_ctxt_id
: TLS context ID.cert_name
: Name of the certificate.cert_file_path
: File path to the certificate.
- Output: Upload response.
-
upload_key_certificate(fqdn, auth, tls_ctxt_id, cert_name, cert_file_path)
- Uploads a private key certificate to the server for the specified TLS context.
- Input:
fqdn
: Server FQDN.auth
: Authentication string.tls_ctxt_id
: TLS context ID.cert_name
: Name of the certificate.cert_file_path
: File path to the certificate.
- Output: Upload response.
-
upload_device_certificate(fqdn, auth, tls_ctxt_id, cert_name, cert_file_path)
- Uploads a device certificate to the server for the specified TLS context.
- Input:
fqdn
: Server FQDN.auth
: Authentication string.tls_ctxt_id
: TLS context ID.cert_name
: Name of the certificate.cert_file_path
: File path to the certificate.
- Output: Upload response.
-
upload_incremental_cli_script(fqdn, auth, cli_name, cli_file_path)
- Uploads an incremental CLI script.
- Input:
fqdn
: Server FQDN.auth
: Authentication string.cli_name
: the name of the cli script file.cli_file_path
: the location of the cli script file.
- Output: Upload response.
-
change_user_config(fqdn, auth, username, password, status, password_age
- Uploads an incremental CLI script.
- Input:
fqdn
: Server FQDN.auth
: Authentication string.username
: the user to change or create a new user.password
: the new password. The valid value is a string of 8 to 40 ASCII characters, and can't contain the following: Wide characters, Spaces, Backslashes ()status
: the status of the user. (New, Valid, Inactivity)password_age
: Defines the duration (in days) of the validity of the password. ( valid value is 0 to 10000)
- Output: Upload response.
Example Usage
GET Example: Retrieve Alarms
alarms = get_alarms('example.com', 'auth_string')
print(alarms)
POST Example: Save Configuration
response = save_configuration('example.com', 'auth_string')
print(response.status_code)
PUT Example: Upload Root Certificate
response = upload_trusted_root_certificates('example.com', 'auth_string', 'tls_id', 'cert_name', '/path/to/cert.pem')
print(response.text)
Error Handling
- The script prints HTTP errors (e.g.,
HTTPError
,Timeout
,ConnectionError
) when requests fail. - In case of JSON decoding errors or unexpected server responses, it prints appropriate messages and handles failures gracefully.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file MrLou_AudioCodes-0.2.0.tar.gz
.
File metadata
- Download URL: MrLou_AudioCodes-0.2.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35e8fe5eee194233b21f23ae2e475fbd0c5aab40ffdb8cf77df66a8c6921f56e |
|
MD5 | e5ac9d90292129dc967e8111734e6302 |
|
BLAKE2b-256 | 9b38cd20e201176a23cd4f53cbe0ff8526d5441be2c75ba8591a626cf487bd65 |
File details
Details for the file MrLou_AudioCodes-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: MrLou_AudioCodes-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 089b73824ff37614de6cccf48523513f55ca86c608332bcabfc08e8c1737b239 |
|
MD5 | ebe70b4f19adea8ee2bf76610c0c5d19 |
|
BLAKE2b-256 | fb44790a8fbb7600588c55f4329637c327937a142c9c0eb47b5cf16679c8eace |