ultra-rest-client


Nameultra-rest-client JSON
Version 2.2.1 PyPI version JSON
download
home_pageNone
SummaryA sample Python client for communicating with the UltraDNS REST API
upload_time2024-09-23 15:29:58
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseNone
keywords ultra_rest_client
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # UltraDNS REST API Client for Python

This is a Python client for communicating with the UltraDNS REST API. It provides a simple and intuitive interface for interacting with the UltraDNS services.

Jump To:

* [Getting Started](#Getting-Started)
* [Usage](#Usage)
* [Functionality](#Functionality)
* [API Reference](#API-Reference)
* [Contributing](#Contributing)
* [License](#License)
* [Questions](#Questions)

## Getting Started

### Dependencies and Installation

This sample code depends on the requests library, which can be found at: http://docs.python-requests.org/en/latest/

If you have pip installed, you can add the client and requests to your environment with:

```
pip install ultra_rest_client
```

Once installed, you can use the `ultra_rest_client` module in your Python scripts:

```python
from ultra_rest_client import RestApiClient
client = RestApiClient(args)
```

## Usage

### Authentication

#### Authenticating using Username and Password

```python
from ultra_rest_client import RestApiClient
import os

# Fetch credentials from environment variables
username = os.getenv('USERNAME')
password = os.getenv('PASSWORD')

# Check if credentials are available
if not username or not password:
    raise ValueError("Username and password must be set in environment variables.")

client = RestApiClient(your_username, your_password)

domain = "udns-python-rest-client-test.com."

# Get Zone Metadata
print(f"Get metadata for zone {domain}: {client.get_zone_metadata(domain)}")
```

#### Authenticating using Bearer Token and Refresh Token

```python
from ultra_rest_client import RestApiClient
import os

# Fetch tokens from environment variables
access_token = os.getenv('ACCESS_TOKEN')
refresh_token = os.getenv('REFRESH_TOKEN')

# Check if tokens are available
if not access_token or not refresh_token:
    raise ValueError("Access token and refresh token must be set in environment variables.")

client = RestApiClient(access_token, refresh_token, use_token=True)

domain = "udns-python-rest-client-test.com."

# Get Zone Metadata
print(f"Get metadata for zone {domain}: {client.get_zone_metadata(domain)}")
``` 

#### Authenticating using Bearer Token

```python
from ultra_rest_client import RestApiClient
import os

# Fetch token from environment variables
access_token = os.getenv('ACCESS_TOKEN')

# Check if token are available
if not access_token:
    raise ValueError("Access token must be set in environment variables.")

client = RestApiClient(access_token, use_token=True)

domain = "udns-python-rest-client-test.com."

# Get Zone Metadata
print(f"Get metadata for zone {domain}: {client.get_zone_metadata(domain)}")
```

### Quick Examples
This example shows a complete working python file which will create a primary zone in UltraDNS. This example highlights how to get services using client and make requests.

```python
#!/usr/bin/env python3

from ultra_rest_client import RestApiClient
import os

def create_zone(client, domain):
    """Create a zone in UltraDNS. This function will create a zone with the name specified in the domain argument.
    It uses the accounts API to get the account name. This is required to create a zone.

    Args:
    - client (RestApiClient): An instance of the RestApiClient class.
    - domain (str): The domain name to be created.

    Returns:
    - dict: The response body.
    """
    account_details = client.get_account_details()
    account_name = account_details['accounts'][0]['accountName']
    return client.create_primary_zone(account_name, domain)

def create_a_record(client, domain):
    """Create an A record in UltraDNS. This function will create an A record with the name specified in the domain

    Args:
    - client (RestApiClient): An instance of the RestApiClient class.
    - domain (str): The domain name.
    """
    return client.create_rrset(domain, "A", domain, 300, "192.0.2.1")


def create_cname_record(client, domain):
    """Create a CNAME record in UltraDNS. This function will create a CNAME record with the name specified in the domain

    Args:
    - client (RestApiClient): An instance of the RestApiClient class.
    - domain (str): The domain name.

    Returns:
    - dict: The response body.
    """
    return client.create_rrset(domain, "CNAME", f"www.{domain}", 300, [domain])

def delete_zone(client, domain):
    """Delete the zone from UltraDNS.

    Args:
    - client (RestApiClient): An instance of the RestApiClient class.
    - domain (str): The domain name.
    """
    client.delete_zone(domain)
    return "Zone deleted Successfully"

def main():
    """The main function. This is the entry point for the script. It parses the command line arguments and calls the
    create_zone, create_a_record, and create_cname_record functions."""

    # Fetch credentials from environment variables
    username = os.getenv('USERNAME')
    password = os.getenv('PASSWORD')
    domain = "ultra-rest-client-test.com."

    # Check if credentials are available
    if not username or not password:
        raise ValueError("Username and password must be set in environment variables.")

    # Create an instance of your client
    client = RestApiClient(username, password)

    # Create the domain
    print(f"Creating zone {domain}: {create_zone(client, domain)}")

    # Create an A record for the domain
    print(f"Creating an A record pointing to 192.0.2.1: {create_a_record(client, domain)}")

    # Create a CNAME record for the domain
    print(f"Creating a 'www' CNAME pointing to {domain}: {create_cname_record(client, domain)}")

    # Delete the domain
    print(f"Deleting zone {domain}: {delete_zone(client, domain)}")

if __name__ == "__main__":
    main()
```

To set the environment variables, use the following commands in your terminal:

```python
export USERNAME='your_username'
export PASSWORD='your_password'
```

## Functionality

The sample code does not attempt to implement a client for all available UltraDNS REST API functionality.  It provides access to basic functionality. Adding additional functionality should be relatively straightforward, and any contributions from the UltraDNS community would be greatly appreciated. See [sample.py](sample.py) for an example of how to use this library in your own code.

## API Reference

For detailed API reference, please refer to the UltraDNS API documentation.

## Contributing

Contributions are always welcome! Please open a pull request with your changes, or open an issue if you encounter any problems or have suggestions.

## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

## Questions

Please contact UltraDNS support if you have any questions or encounter any issues with this code.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ultra-rest-client",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "ultra_rest_client",
    "author": null,
    "author_email": "ultradns <ultrassp-oss@vercara.com>",
    "download_url": "https://files.pythonhosted.org/packages/c6/c0/4f86f3c8cfe1157d8337b4d5359ecff9fb804aa5e8834bcf61f80637da37/ultra_rest_client-2.2.1.tar.gz",
    "platform": null,
    "description": "# UltraDNS REST API Client for Python\n\nThis is a Python client for communicating with the UltraDNS REST API. It provides a simple and intuitive interface for interacting with the UltraDNS services.\n\nJump To:\n\n* [Getting Started](#Getting-Started)\n* [Usage](#Usage)\n* [Functionality](#Functionality)\n* [API Reference](#API-Reference)\n* [Contributing](#Contributing)\n* [License](#License)\n* [Questions](#Questions)\n\n## Getting Started\n\n### Dependencies and Installation\n\nThis sample code depends on the requests library, which can be found at: http://docs.python-requests.org/en/latest/\n\nIf you have pip installed, you can add the client and requests to your environment with:\n\n```\npip install ultra_rest_client\n```\n\nOnce installed, you can use the `ultra_rest_client` module in your Python scripts:\n\n```python\nfrom ultra_rest_client import RestApiClient\nclient = RestApiClient(args)\n```\n\n## Usage\n\n### Authentication\n\n#### Authenticating using Username and Password\n\n```python\nfrom ultra_rest_client import RestApiClient\nimport os\n\n# Fetch credentials from environment variables\nusername = os.getenv('USERNAME')\npassword = os.getenv('PASSWORD')\n\n# Check if credentials are available\nif not username or not password:\n    raise ValueError(\"Username and password must be set in environment variables.\")\n\nclient = RestApiClient(your_username, your_password)\n\ndomain = \"udns-python-rest-client-test.com.\"\n\n# Get Zone Metadata\nprint(f\"Get metadata for zone {domain}: {client.get_zone_metadata(domain)}\")\n```\n\n#### Authenticating using Bearer Token and Refresh Token\n\n```python\nfrom ultra_rest_client import RestApiClient\nimport os\n\n# Fetch tokens from environment variables\naccess_token = os.getenv('ACCESS_TOKEN')\nrefresh_token = os.getenv('REFRESH_TOKEN')\n\n# Check if tokens are available\nif not access_token or not refresh_token:\n    raise ValueError(\"Access token and refresh token must be set in environment variables.\")\n\nclient = RestApiClient(access_token, refresh_token, use_token=True)\n\ndomain = \"udns-python-rest-client-test.com.\"\n\n# Get Zone Metadata\nprint(f\"Get metadata for zone {domain}: {client.get_zone_metadata(domain)}\")\n``` \n\n#### Authenticating using Bearer Token\n\n```python\nfrom ultra_rest_client import RestApiClient\nimport os\n\n# Fetch token from environment variables\naccess_token = os.getenv('ACCESS_TOKEN')\n\n# Check if token are available\nif not access_token:\n    raise ValueError(\"Access token must be set in environment variables.\")\n\nclient = RestApiClient(access_token, use_token=True)\n\ndomain = \"udns-python-rest-client-test.com.\"\n\n# Get Zone Metadata\nprint(f\"Get metadata for zone {domain}: {client.get_zone_metadata(domain)}\")\n```\n\n### Quick Examples\nThis example shows a complete working python file which will create a primary zone in UltraDNS. This example highlights how to get services using client and make requests.\n\n```python\n#!/usr/bin/env python3\n\nfrom ultra_rest_client import RestApiClient\nimport os\n\ndef create_zone(client, domain):\n    \"\"\"Create a zone in UltraDNS. This function will create a zone with the name specified in the domain argument.\n    It uses the accounts API to get the account name. This is required to create a zone.\n\n    Args:\n    - client (RestApiClient): An instance of the RestApiClient class.\n    - domain (str): The domain name to be created.\n\n    Returns:\n    - dict: The response body.\n    \"\"\"\n    account_details = client.get_account_details()\n    account_name = account_details['accounts'][0]['accountName']\n    return client.create_primary_zone(account_name, domain)\n\ndef create_a_record(client, domain):\n    \"\"\"Create an A record in UltraDNS. This function will create an A record with the name specified in the domain\n\n    Args:\n    - client (RestApiClient): An instance of the RestApiClient class.\n    - domain (str): The domain name.\n    \"\"\"\n    return client.create_rrset(domain, \"A\", domain, 300, \"192.0.2.1\")\n\n\ndef create_cname_record(client, domain):\n    \"\"\"Create a CNAME record in UltraDNS. This function will create a CNAME record with the name specified in the domain\n\n    Args:\n    - client (RestApiClient): An instance of the RestApiClient class.\n    - domain (str): The domain name.\n\n    Returns:\n    - dict: The response body.\n    \"\"\"\n    return client.create_rrset(domain, \"CNAME\", f\"www.{domain}\", 300, [domain])\n\ndef delete_zone(client, domain):\n    \"\"\"Delete the zone from UltraDNS.\n\n    Args:\n    - client (RestApiClient): An instance of the RestApiClient class.\n    - domain (str): The domain name.\n    \"\"\"\n    client.delete_zone(domain)\n    return \"Zone deleted Successfully\"\n\ndef main():\n    \"\"\"The main function. This is the entry point for the script. It parses the command line arguments and calls the\n    create_zone, create_a_record, and create_cname_record functions.\"\"\"\n\n    # Fetch credentials from environment variables\n    username = os.getenv('USERNAME')\n    password = os.getenv('PASSWORD')\n    domain = \"ultra-rest-client-test.com.\"\n\n    # Check if credentials are available\n    if not username or not password:\n        raise ValueError(\"Username and password must be set in environment variables.\")\n\n    # Create an instance of your client\n    client = RestApiClient(username, password)\n\n    # Create the domain\n    print(f\"Creating zone {domain}: {create_zone(client, domain)}\")\n\n    # Create an A record for the domain\n    print(f\"Creating an A record pointing to 192.0.2.1: {create_a_record(client, domain)}\")\n\n    # Create a CNAME record for the domain\n    print(f\"Creating a 'www' CNAME pointing to {domain}: {create_cname_record(client, domain)}\")\n\n    # Delete the domain\n    print(f\"Deleting zone {domain}: {delete_zone(client, domain)}\")\n\nif __name__ == \"__main__\":\n    main()\n```\n\nTo set the environment variables, use the following commands in your terminal:\n\n```python\nexport USERNAME='your_username'\nexport PASSWORD='your_password'\n```\n\n## Functionality\n\nThe sample code does not attempt to implement a client for all available UltraDNS REST API functionality.  It provides access to basic functionality. Adding additional functionality should be relatively straightforward, and any contributions from the UltraDNS community would be greatly appreciated. See [sample.py](sample.py) for an example of how to use this library in your own code.\n\n## API Reference\n\nFor detailed API reference, please refer to the UltraDNS API documentation.\n\n## Contributing\n\nContributions are always welcome! Please open a pull request with your changes, or open an issue if you encounter any problems or have suggestions.\n\n## License\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n\n## Questions\n\nPlease contact UltraDNS support if you have any questions or encounter any issues with this code.\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A sample Python client for communicating with the UltraDNS REST API",
    "version": "2.2.1",
    "project_urls": {
        "Homepage": "https://github.com/ultradns/python_rest_api_client"
    },
    "split_keywords": [
        "ultra_rest_client"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0fb214bb88c5941be44b3a625cb8e1f62bc80b1787e2d21fa91fa52e5b91d56b",
                "md5": "9f99c5d236c09d9ca5ba0daf4b585d30",
                "sha256": "e552141a824b74bc35d61bb7995f759dd31d02da59bf4343365c8e27128945d7"
            },
            "downloads": -1,
            "filename": "ultra_rest_client-2.2.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9f99c5d236c09d9ca5ba0daf4b585d30",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 14890,
            "upload_time": "2024-09-23T15:29:57",
            "upload_time_iso_8601": "2024-09-23T15:29:57.070776Z",
            "url": "https://files.pythonhosted.org/packages/0f/b2/14bb88c5941be44b3a625cb8e1f62bc80b1787e2d21fa91fa52e5b91d56b/ultra_rest_client-2.2.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c6c04f86f3c8cfe1157d8337b4d5359ecff9fb804aa5e8834bcf61f80637da37",
                "md5": "ce8d1dd70da74b3d1811318ca27ec5ec",
                "sha256": "9945504086bea9909063837e6ade9408b975ee22158df40612de6ce14b1186b7"
            },
            "downloads": -1,
            "filename": "ultra_rest_client-2.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ce8d1dd70da74b3d1811318ca27ec5ec",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 13219,
            "upload_time": "2024-09-23T15:29:58",
            "upload_time_iso_8601": "2024-09-23T15:29:58.602904Z",
            "url": "https://files.pythonhosted.org/packages/c6/c0/4f86f3c8cfe1157d8337b4d5359ecff9fb804aa5e8834bcf61f80637da37/ultra_rest_client-2.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-23 15:29:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ultradns",
    "github_project": "python_rest_api_client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ultra-rest-client"
}
        
Elapsed time: 0.91835s