Skip to content

Script to delete organization #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
57 changes: 57 additions & 0 deletions delete_org_from_port_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import time
import requests

CLIENT_ID = ''
CLIENT_SECRET = ''

API_URL = 'https://api.getport.io/v1'
CREDS = {'clientId': CLIENT_ID, 'clientSecret': CLIENT_SECRET}

orgs = [
"asdf"
]

def poll_run_until_finished(run_id, access_token):
run_status_url = f"{API_URL}/actions/runs/{run_id}"
response = requests.get(
run_status_url,
headers={
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
).json()

if response['run']['status'] != 'IN_PROGRESS':
return response['run']['status']
else:
time.sleep(1)
print(f'Polling, status is {response["run"]["status"]}')
return poll_run_until_finished(run_id, access_token)

for org_id in orgs:
print(f'Deleting org {org_id}')
token_response = requests.post(f'{API_URL}/auth/access_token', json=CREDS)
access_token = token_response.json()['accessToken']
action_run_url = f"{API_URL}/blueprints/organization/entities/{org_id}/actions/delete_org/runs"
response = requests.post(
action_run_url,
headers={
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
},
json={
"properties": {
"reason": "Deleted by script"
}
}
).json()
print(f'Started run for org deletion {org_id}')
run_id = response['run']['id']
status = poll_run_until_finished(run_id, access_token)

if status != 'SUCCESS':
print(f'Org {org_id} failed to delete, visit https://app.getport.io/organization/run?runId={run_id} to see why')
exit(1)

print(f'Org {org_id} deleted successfully')