Skip to content

Commit

Permalink
Merge for v0.8.2 release (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
hdm authored Apr 1, 2024
1 parent 61625c8 commit 30ff839
Show file tree
Hide file tree
Showing 11 changed files with 502 additions and 76 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/check_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pipx install poetry
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies
Expand All @@ -33,10 +33,10 @@ jobs:
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pipx install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
Expand All @@ -49,10 +49,10 @@ jobs:
test-integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pipx install poetry
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"
cache: "poetry"
Expand All @@ -72,10 +72,10 @@ jobs:
lints:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pipx install poetry
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"
cache: "poetry"
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pipx install poetry
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies
Expand All @@ -32,10 +32,10 @@ jobs:
# run integration tests against production before releasing new version of sdk
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"
cache: "poetry"
Expand Down Expand Up @@ -64,10 +64,10 @@ jobs:
# for OpenID Connect trusted publisher to pypi
id-token: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"
- name: Install dependencies
Expand All @@ -92,20 +92,20 @@ jobs:
pages: write
id-token: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"
- name: Build project documentation
uses: ./.github/actions/docsbuild
- name: Setup Pages
uses: actions/configure-pages@v3
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v3
with:
path: 'docs/build/html'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
48 changes: 48 additions & 0 deletions examples/bulk_update_custom_attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import datetime
import time
import uuid

import runzero
from runzero.api import CustomIntegrationsAdmin
from runzero.types import ImportAsset, Tag

# API keys are required for using the runZero sdk. See https://www.runzero.com/docs/leveraging-the-api/
MY_CLIENT_ID = "" # OAuth client id. See https://console.runzero.com/account/api/clients
MY_CLIENT_SECRET = "" # OAuth client secret. See https://console.runzero.com/account/api/clients
MY_ORG_ID = uuid.UUID("") # runZero organization ID. See https://console.runzero.com/organizations
MY_SITE_ID = uuid.UUID("") # runZero site ID. See https://console.runzero.com/sites
MY_INTEGRATION_ID = uuid.UUID("") # ID of the custom integration to use.


def main():
"""
The code below gives an example of how to update asset attributes in bulk.
"""

# create the runzero client
c = runzero.Client()

# try to log in using OAuth credentials
try:
c.oauth_login(MY_CLIENT_ID, MY_CLIENT_SECRET)
except runzero.AuthError as e:
print(f"login failed: {e}")
return
print("login successful")

integrations = CustomIntegrationsAdmin(client=c)
my_integration = integrations.get_asset_admin_handle(MY_INTEGRATION_ID)
count = my_integration.bulk_update_custom_attributes(
MY_ORG_ID,
search='hw:"superserver"',
site=MY_SITE_ID,
attributes={
"assetExamined": "true",
"machineType": "server-check",
},
)
print(f"updated {count} asset(s)")


if __name__ == "__main__":
main()
61 changes: 61 additions & 0 deletions examples/create_asset_in_custom_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import datetime
import time
import uuid

import runzero
from runzero.api import CustomIntegrationsAdmin
from runzero.types import ImportAsset, Tag

# API keys are required for using the runZero sdk. See https://www.runzero.com/docs/leveraging-the-api/
MY_CLIENT_ID = "" # OAuth client id. See https://console.runzero.com/account/api/clients
MY_CLIENT_SECRET = "" # OAuth client secret. See https://console.runzero.com/account/api/clients
MY_ORG_ID = uuid.UUID("") # runZero organization ID. See https://console.runzero.com/organizations
MY_SITE_ID = uuid.UUID("") # runZero site ID. See https://console.runzero.com/sites
MY_INTEGRATION_ID = uuid.UUID("") # ID of the custom integration to use.
MY_ASSET_ID = "custom-asset-1" # The "foreign ID" for the newly-created asset.


def main():
"""
The code below gives an example of how to create a new asset in a custom integration.
"""

# create the runzero client
c = runzero.Client()

# try to log in using OAuth credentials
try:
c.oauth_login(MY_CLIENT_ID, MY_CLIENT_SECRET)
except runzero.AuthError as e:
print(f"login failed: {e}")
return
print("login successful")

integrations = CustomIntegrationsAdmin(client=c)
my_integration = integrations.get_asset_admin_handle(MY_INTEGRATION_ID)
asset_id = my_integration.create_asset(
MY_ORG_ID,
MY_SITE_ID,
ImportAsset(
id=MY_ASSET_ID,
hostnames=["example-hostname-1", "example-hostname-2"],
domain="example.com",
first_seen_ts=datetime.datetime.now(),
os="Linux",
os_version="3.11",
manufacturer="Linux",
model="Super Server",
tags=[Tag("tag1=value1")],
device_type="Server",
custom_attributes={
"custom.attr1": "custom.value1",
"ipAddresses": "192.168.86.1\t10.10.10.1",
"ipAddressesExtra": "10.10.10.4",
},
),
)
print(f"created asset {asset_id}")


if __name__ == "__main__":
main()
49 changes: 49 additions & 0 deletions examples/update_custom_attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import datetime
import time
import uuid

import runzero
from runzero.api import CustomIntegrationsAdmin
from runzero.types import ImportAsset, Tag

# API keys are required for using the runZero sdk. See https://www.runzero.com/docs/leveraging-the-api/
MY_CLIENT_ID = "" # OAuth client id. See https://console.runzero.com/account/api/clients
MY_CLIENT_SECRET = "" # OAuth client secret. See https://console.runzero.com/account/api/clients
MY_ORG_ID = uuid.UUID("") # runZero organization ID. See https://console.runzero.com/organizations
MY_SITE_ID = uuid.UUID("") # runZero site ID. See https://console.runzero.com/sites
MY_INTEGRATION_ID = uuid.UUID("") # ID of the custom integration to use.
MY_ASSET_ID = uuid.UUID("") # the runZero ID of the asset to update.


def main():
"""
The code below gives an example of how to update asset attributes.
"""

# create the runzero client
c = runzero.Client()

# try to log in using OAuth credentials
try:
c.oauth_login(MY_CLIENT_ID, MY_CLIENT_SECRET)
except runzero.AuthError as e:
print(f"login failed: {e}")
return
print("login successful")

integrations = CustomIntegrationsAdmin(client=c)
my_integration = integrations.get_asset_admin_handle(MY_INTEGRATION_ID)
count = my_integration.update_custom_attributes(
MY_ORG_ID,
site=MY_SITE_ID,
asset_id=MY_ASSET_ID,
attributes={
"machineCheck": "super-server",
"attributeToDelete": "",
},
)
print(f"updated {count} asset(s)")


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

0 comments on commit 30ff839

Please sign in to comment.