Skip to content

Commit

Permalink
adds pypi logic (#53)
Browse files Browse the repository at this point in the history
* add github workflow for pypi

* fixes regrade logic
  • Loading branch information
dapplegatecp authored Apr 10, 2024
1 parent 65cea96 commit 995c72c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/ncm_pypi_package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: bump version

on:
push:
paths:
- "ncm/**"

jobs:
bump_version:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel twine build bump2version
git config --global user.email "[email protected]"
git config --global user.name "Github Action"
- name: Bump version
run: |
cd ncm && bump2version patch
- name: Push changes
run: |
git push
- name: Build package
run: cd ncm && python -m build --sdist --wheel
- name: Upload to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
cd ncm && twine upload dist/*
5 changes: 5 additions & 0 deletions ncm/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[bumpversion]
current_version = 0.0.33
commit = True

[bumpversion:file:setup.py]
19 changes: 10 additions & 9 deletions ncm/ncm/ncm.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
It also has native support for handling any number of "__in" filters
beyond Cradlepoint's limit of 100. The script automatically chunks
the list into groups of 100 and combines the results into a single array.
the list into groups of 100 and combines the results into a single array
"""

from requests import Session
Expand Down Expand Up @@ -2451,16 +2452,16 @@ def get_subscriptions(self, **kwargs):
params = self.__parse_kwargs(kwargs, allowed_params)
return self.__get_json(get_url, call_type, params=params)

def regrade(self, subscription_id, mac_or_serial_number=None):
def regrade(self, subscription_id, mac_or_serial_number, action="UPGRADE"):
"""
Applies a subscription to an asset.
:param subscription_id: ID of the subscription to apply. (see https://developer.cradlepoint.com/ for list of subscriptions)
:param asset_id: ID of the asset to apply the subscription to. If not provided, the MAC address must be provided. Can also be a list
:param mac: MAC address of the asset to apply the subscription to. If not provided, the asset_id must be provided. Can also be a list.
:param subscription_id: ID of the subscription to apply. See https://developer.cradlepoint.com/ for list of subscriptions.
:param mac_or_serial_number: MAC address or serial number of the asset to apply the subscription to. Can also be a list.
:param action: Action to take. Default is "UPGRADE". Can also be "DOWNGRADE".
"""

call_type = 'Subscription'
post_url = f'{self.base_url}/asset_endpoints/regrade'
post_url = f'{self.base_url}/asset_endpoints/regrades'

payload = {
"atomic:operations": []
Expand All @@ -2472,7 +2473,7 @@ def regrade(self, subscription_id, mac_or_serial_number=None):
"data": {
"type": "regrades",
"attributes": {
"action": "UPGRADE",
"action": action,
"subscription_type": subscription_id
}
}
Expand All @@ -2483,7 +2484,7 @@ def regrade(self, subscription_id, mac_or_serial_number=None):
data['data']['attributes']['mac_address'] = smac
else:
data['data']['attributes']['serial_number'] = smac
payload.append(data)
payload["atomic:operations"].append(data)

ncm = self.session.post(post_url, json=payload)
result = self._return_handler(ncm.status_code, ncm.json(), call_type)
Expand All @@ -2497,7 +2498,7 @@ def get_regrades(self, **kwargs):
:return: A list of regrades with details.
"""
call_type = 'Subscription'
get_url = f'{self.base_url}/asset_endpoints/regrade'
get_url = f'{self.base_url}/asset_endpoints/regrades'

allowed_params = ["id",
"action_id",
Expand Down

0 comments on commit 995c72c

Please sign in to comment.