Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Engineering improvements #19

Merged
merged 12 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
steps:
-
name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
-
name: Setup Python environment
uses: actions/setup-python@v4
uses: actions/setup-python@v5
-
name: Install Dependencies
run: pip install requests
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ on:
- master
jobs:
Code_Analysis_Job:
if: ${{ ! github.event.pull_request.head.repo.fork }}
runs-on: ubuntu-latest
environment: test
steps:
-
name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
-
name: Setup Python environment
uses: actions/setup-python@v4
uses: actions/setup-python@v5
-
name: Install Dependencies
run: pip install requests
Expand Down Expand Up @@ -51,6 +52,6 @@ jobs:
run: hatch build
-
name: Publishing python Package
uses: pypa/gh-action-pypi-publish@v1.5.1
uses: pypa/gh-action-pypi-publish@v1.10.1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion .plugin-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.1
v2.2.0
172 changes: 162 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
python_rest_api_client
======================
# UltraDNS REST API Client for Python

A sample Python client for communicating with the UltraDNS REST API
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.

Dependencies and Installation
========================
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/

Expand All @@ -14,13 +24,155 @@ If you have pip installed, you can add the client and requests to your environme
pip install ultra_rest_client
```

Functionality
=============
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

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

client = RestApiClient(your_bearer_token, your_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

client = RestApiClient(your_bearer_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 sys

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."""

username = sys.argv[1]
password = sys.argv[2]
domain = "ultra-rest-client-test.com."

# 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()
```

## 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.

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 for an example of how to use this library in your own code.
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

Questions
=========
## Questions

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

Loading