Skip to content
Closed
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: 4 additions & 0 deletions changed_files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
A custom-integrations/config.json
M custom-integrations/delete_assets.star
A custom-integrations/test.star
A temp.txt
1 change: 1 addition & 0 deletions custom-integrations/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"test": "test"}
4 changes: 2 additions & 2 deletions custom-integrations/delete_assets.star
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def delete_assets(assets, headers):
# verify the delete worked
if delete.status_code == 204:
print(
f"Deleted all assets matching this search: {}".format())
"Deleted all assets matching this search: {}".format())
else:
print(f"Failed to delete assets. Please try again.")
print("Failed to delete assets. Please try again.")


def main(*args, **kwargs):
Expand Down
43 changes: 43 additions & 0 deletions custom-integrations/test.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
load('runzero.types', 'ImportAsset', 'NetworkInterface')
load('json', json_encode='encode', json_decode='decode')
load('net', 'ip_address')
load('http', http_post='post', http_get='get', http_delete='delete', 'url_encode')

BASE_URL = "https://console.runZero.com/api/v1.0"
SEARCH = "alive:f"

def get_delete_ids(headers):
# get assets to delete
assets = []
url = BASE_URL + "/export/org/assets.json"
get_assets = http_get(url=url, headers=headers, body=bytes(url_encode({"search": SEARCH, "fields": "id"})))
assets_json = json_decode(get_assets.body)

# if you got assets, return them as a list of asset IDs
if get_assets.status_code == 200:
assets = [x["id"] for x in assets_json]
return assets
else:
return None


def delete_assets(assets, headers):

# delete assets
url = BASE_URL + "/org/assets/bulk/delete"
delete = http_delete(url, headers=headers, body=bytes(json_encode({"asset_ids": assets})))

# verify the delete worked
if delete.status_code == 204:
print(
"Deleted all assets matching this search: {}".format())
else:
print("Failed to delete assets. Please try again.")


def main(*args, **kwargs):
rz_org_token = kwargs['access_secret']
headers = {"Authorization": "Bearer {}".format(rz_org_token)}
assets = get_delete_ids(headers=headers)
if assets:
delete_assets(assets=assets)
1 change: 1 addition & 0 deletions temp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testing workflow
Loading