Skip to content

Commit

Permalink
Merge pull request #13 from ultradns/hatch_deployment
Browse files Browse the repository at this point in the history
Hatch deployment
  • Loading branch information
stevedejong authored Nov 14, 2022
2 parents 404eb61 + a95f382 commit 5081964
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 1 deletion.
26 changes: 26 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Code_Analysis_Workflow
on:
pull_request:
branches:
- master
jobs:
Code_Analysis_Job:
runs-on: ubuntu-latest
environment: test
steps:
-
name: Check out repository code
uses: actions/checkout@v3
-
name: Setup Python environment
uses: actions/setup-python@v4
-
name: Install Dependencies
run: pip install requests
-
name: Running acceptace test
run: python test.py
env:
ULTRADNS_UNIT_TEST_USERNAME: ${{ secrets.ULTRADNS_UNIT_TEST_USERNAME }}
ULTRADNS_UNIT_TEST_PASSWORD: ${{ secrets.ULTRADNS_UNIT_TEST_PASSWORD }}
ULTRADNS_UNIT_TEST_HOST_URL: ${{ secrets.ULTRADNS_UNIT_TEST_HOST_URL }}
56 changes: 56 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Release_Workflow
on:
push:
branches:
- master
jobs:
Code_Analysis_Job:
runs-on: ubuntu-latest
environment: test
steps:
-
name: Check out repository code
uses: actions/checkout@v3
-
name: Setup Python environment
uses: actions/setup-python@v4
-
name: Install Dependencies
run: pip install requests
-
name: Running acceptace test
run: python test.py
env:
ULTRADNS_UNIT_TEST_USERNAME: ${{ secrets.ULTRADNS_UNIT_TEST_USERNAME }}
ULTRADNS_UNIT_TEST_PASSWORD: ${{ secrets.ULTRADNS_UNIT_TEST_PASSWORD }}
ULTRADNS_UNIT_TEST_HOST_URL: ${{ secrets.ULTRADNS_UNIT_TEST_HOST_URL }}
Release_Job:
runs-on: ubuntu-latest
needs: Code_Analysis_Job
environment: prod
steps:
-
name: Check out repository code
uses: actions/checkout@v3
-
name: Setup Python environment
uses: actions/setup-python@v4
-
name: Create Release Info
run: echo "RELEASE_VERSION=$(cat .plugin-version)" >> $GITHUB_ENV
-
name: Installing Dependencies
run: |
pip install requests
pip install hatch
-
name: Versioning the build
run: hatch version ${{ env.RELEASE_VERSION }}
-
name: Creating python Package
run: hatch build
-
name: Publishing python Package
uses: pypa/[email protected]
with:
password: ${{ secrets.PYPI_API_TOKEN }}
1 change: 1 addition & 0 deletions .plugin-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.0
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
35 changes: 35 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "ultra-rest-client"
dynamic = ["version"]
description = "A sample Python client for communicating with the UltraDNS REST API"
readme = "README.md"
license-files = { paths = ["LICENSE"] }
authors = [
{ name = "ultradns", email = "[email protected]" },
]
keywords = [
"ultra_rest_client",
]
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: Apache Software License",
"Topic :: Utilities",
]
dependencies = [
"requests",
]

[project.urls]
Homepage = "https://github.com/ultradns/python_rest_api_client"

[tool.hatch.version]
path = "ultra_rest_client/about.py"

[tool.hatch.build.targets.sdist]
include = [
"/ultra_rest_client",
]
84 changes: 84 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import ultra_rest_client
import os
import time

username = os.environ.get('ULTRADNS_UNIT_TEST_USERNAME')
password = os.environ.get('ULTRADNS_UNIT_TEST_PASSWORD')
domain = os.environ.get('ULTRADNS_UNIT_TEST_HOST_URL')

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

c = ultra_rest_client.RestApiClient(username, password, False, domain)
print('version %s' % c.version())
print('status %s' % c.status())
account_details = c.get_account_details()
account_name = account_details[u'accounts'][0][u'accountName']
print('account name %s' % account_name )
print('get zone metadata %s' % c.get_zone_metadata_v3(test_zone_name))
print('get first 5 primary zones with udns: %s' % c.get_zones_v3(limit=5, sort="NAME", reverse=False, q={"name":"udns", "zone_type":"PRIMARY"}))
print('\n')
print('get first 5 secondary zones: %s' % c.get_zones_v3(limit=5, sort="NAME", reverse=False, q={"zone_type":"SECONDARY"}))
print('\n')
print('get all zones with 25 zones per page. First page is returned by default: %s' % c.get_zones_v3(limit=25, q={"zone_status":"ALL"}))
print('\n')
print('get next page of zones with 25 zones per page. Cursor returned by above request is used: %s' % c.get_zones_v3(limit=25, cursor='MTY1NDUxNTM4MTczMXNiLXN1YnBvb2wtY3J1ZC0xLmNvbS46TkVYVA==', q={"zone_status":"ALL"}))
print('create primary zone result %s' % c.create_primary_zone(account_name, "foo.invalid."))
print('get zone metadata %s' % c.get_zone_metadata("foo.invalid."))
print('delete zone %s ' % c.delete_zone("foo.invalid."))
print('zone name %s ' % test_zone_name)
print('get_rrsets %s ' % c.get_rrsets(test_zone_name))
print('create_rrset %s ' % c.create_rrset(test_zone_name, "A", "foo", 300, "1.2.3.4"))
print('get_rrsets %s ' % c.get_rrsets(test_zone_name))
print('get_rrsets_by_type %s ' % c.get_rrsets_by_type(test_zone_name, "A"))
print('edit_rrset %s ' % c.edit_rrset(test_zone_name, "A", "foo", 100, ["10.20.30.40"]))
print('get_rrsets %s ' % c.get_rrsets(test_zone_name))
print('get_rrsets_by_type %s ' % c.get_rrsets_by_type(test_zone_name, "A"))
print('get_rrsets_by_type_owner %s ' % c.get_rrsets_by_type_owner(test_zone_name, "A", "foo"))
print('delete_rrset %s ' % c.delete_rrset(test_zone_name, "A", "foo"))
print('get_rrsets %s ' % c.get_rrsets(test_zone_name))
print('get_rrsets_by_type %s ' % c.get_rrsets_by_type(test_zone_name, "A"))
print('get_rrsets_by_type_owner %s ' % c.get_rrsets_by_type_owner(test_zone_name, "A", "foo"))
print('batch delete %s ' % c.batch([
{'method': 'DELETE', 'uri': '/v1/zones/' + test_zone_name + '/rrsets/A/foo2'},
{'method': 'DELETE', 'uri': '/v1/zones/' + test_zone_name + '/rrsets/A/foo3'},
]))

print('get_rrsets_by_type %s ' % c.get_rrsets_by_type(test_zone_name, "A"))
print('get_rrsets_by_type_owner %s ' % c.get_rrsets_by_type_owner(test_zone_name, "A", "foo2"))
print('batch create %s ' % c.batch([
{'method': 'POST', 'uri': '/v1/zones/' + test_zone_name + '/rrsets/A/foo2', 'body': {'ttl': 100, 'rdata': ['2.4.6.8']}},
{'method': 'POST', 'uri': '/v1/zones/' + test_zone_name + '/rrsets/A/foo3', 'body': {'ttl': 100, 'rdata': ['20.40.60.80']}},
]))
print('get_rrsets_by_type %s ' % c.get_rrsets_by_type(test_zone_name, "A"))
print('get_rrsets_by_type_owner %s ' % c.get_rrsets_by_type_owner(test_zone_name, "A", "foo2"))
print('batch delete %s ' % c.batch([
{'method': 'DELETE', 'uri': '/v1/zones/' + test_zone_name + '/rrsets/A/foo2'},
{'method': 'DELETE', 'uri': '/v1/zones/' + test_zone_name + '/rrsets/A/foo3'},
]))
print('get_rrsets_by_type %s ' % c.get_rrsets_by_type(test_zone_name, "A"))
print('get_rrsets_by_type_owner %s ' % c.get_rrsets_by_type_owner(test_zone_name, "A", "foo2"))

#getting zones with q, sort, offset, limit
print('get first 5 primary zones with j: %s' % c.get_zones(offset=0, limit=5, sort="NAME", reverse=False, q={"name":"j", "zone_type":"PRIMARY"}))

#creating a zone with upload
result = c.create_primary_zone_by_upload(account_name, 'sample.client.me.', './zone.txt')
print('create zone via upload: %s' % result)

# check the task status
while True:
task_status = c.get_task(result['task_id'])
print('task status: %s ' % c.get_task(result['task_id']))
if task_status['code'] != 'IN_PROCESS':
break
time.sleep(1)


#check all task status
print('all task status: %s ' % c.get_all_tasks())

#delete task status
print('delete task status: %s ' % c.clear_task(result['task_id']))

#delete the zone
print('delete zone: %s ' % c.delete_zone('sample.client.me.'))
5 changes: 5 additions & 0 deletions ultra_rest_client/about.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__version__="0.0.0"
__prefix__="udns-python-rest-client-"

def get_client_user_agent() :
return __prefix__+__version__
4 changes: 3 additions & 1 deletion ultra_rest_client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# store the URL and the access/refresh tokens as state
import requests
from .about import get_client_user_agent

class AuthError(Exception):
def __init__(self, message):
Expand Down Expand Up @@ -67,7 +68,8 @@ def _refresh(self):

def _build_headers(self, content_type):
result = {"Accept": "application/json",
"Authorization": "Bearer " + self.access_token}
"Authorization": "Bearer " + self.access_token,
"User-Agent": get_client_user_agent()}
if content_type != "":
result["Content-type"] = content_type
return result
Expand Down

0 comments on commit 5081964

Please sign in to comment.