Skip to main content

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 send GET requests.
  • Method:
    • send(self, url): Sends a GET request to the specified url and returns the response.

3. POSTRequest(HTTPRequest)

  • Inherits from HTTPRequest. Used to send POST requests.
  • Method:
    • send(self, url, payload): Sends a POST request to the specified url with payload and returns the response.

4. PUTRequest(HTTPRequest)

  • Inherits from HTTPRequest. Used to send PUT requests.
  • Method:
    • send(self, url, payload, files=None): Sends a PUT request to the specified url with payload and optional files, returns the response.

Functions Overview

GET Requests

  1. 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.
  2. get_status(fqdn, auth)

    • Sends a GET request to retrieve server status.
    • Input:
      • fqdn: Server FQDN.
      • auth: Authentication string.
    • Output: Server status response.
  3. 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.
  4. 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.

POST Requests

  1. save_configuration(fqdn, auth)
    • Sends a POST request to save the server configuration.
    • Input:
      • fqdn: Server FQDN.
      • auth: Authentication string.
    • Output: Response status code.

PUT Requests

  1. 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.
  2. 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.
  3. 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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MrLou_AudioCodes-0.1.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

MrLou_AudioCodes-0.1.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file MrLou_AudioCodes-0.1.2.tar.gz.

File metadata

  • Download URL: MrLou_AudioCodes-0.1.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.13

File hashes

Hashes for MrLou_AudioCodes-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d1864739cb824c8459419c701cafd1b9b9ac5860dd2f98646d075628779870d1
MD5 b200e14371f570aae4e98e6fbd273d81
BLAKE2b-256 6ce6d611b3edd2b2eaf4660d21ef060677cdf7688f2c473f5871f40474aeb2fc

See more details on using hashes here.

File details

Details for the file MrLou_AudioCodes-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for MrLou_AudioCodes-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5fc22dcdf7d6f1d2f0e164ea41ab3f2a14840032b5f93fdd79d67a94ca0654c1
MD5 21afd714293a5bd4facd136d9b90cc7f
BLAKE2b-256 84e8cd9306c95f7ffee428c4b684ac0f03815daf6fb632a6e21acfb939a53a45

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page