Skip to content

Commit

Permalink
Merge pull request #21 from ultradns/documentation_updates
Browse files Browse the repository at this point in the history
updated docs and scripts to align with security best practice
  • Loading branch information
stevedejong authored Sep 23, 2024
2 parents e5f5626 + 82843c0 commit d1418b8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
48 changes: 43 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ client = RestApiClient(args)

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

Expand All @@ -52,8 +61,17 @@ print(f"Get metadata for zone {domain}: {client.get_zone_metadata(domain)}")

```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')

client = RestApiClient(your_bearer_token, your_refresh_token, use_token=True)
# 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."

Expand All @@ -65,8 +83,16 @@ print(f"Get metadata for zone {domain}: {client.get_zone_metadata(domain)}")

```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(your_bearer_token, use_token=True)
client = RestApiClient(access_token, use_token=True)

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

Expand All @@ -81,7 +107,7 @@ This example shows a complete working python file which will create a primary zo
#!/usr/bin/env python3

from ultra_rest_client import RestApiClient
import sys
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.
Expand Down Expand Up @@ -134,10 +160,15 @@ 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]
# 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)

Expand All @@ -157,6 +188,13 @@ 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.
Expand Down
22 changes: 14 additions & 8 deletions sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@
from ultra_rest_client import RestApiClient
import sys
import time
import os

if len(sys.argv) != 6 and len(sys.argv) != 3:
raise Exception("Expected use: python sample.py username password [use_token use_http host:port]")
if len(sys.argv) != 4 and len(sys.argv) != 1:
raise Exception("Expected use: python sample.py [use_token use_http host:port]")

username = sys.argv[1]
password = sys.argv[2]
# Fetch credentials from environment variables
username = os.getenv('USERNAME')
password = os.getenv('PASSWORD')
use_http = 'False'
use_token = 'False'
domain = 'api.ultradns.com'

if len(sys.argv) == 6:
use_token = sys.argv[3]
use_http = sys.argv[4]
domain = sys.argv[5]
# Check if credentials are available
if not username or not password:
raise ValueError("Username and password must be set in environment variables.")

if len(sys.argv) == 4:
use_token = sys.argv[1]
use_http = sys.argv[2]
domain = sys.argv[3]

test_zone_name='udns-python-rest-client-test.com.'

Expand Down

0 comments on commit d1418b8

Please sign in to comment.