This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added delete and revoke token examples
- Loading branch information
michael.kumar
committed
May 15, 2019
1 parent
2f25679
commit d1c1e98
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# developed and tested with python 3.7.1 | ||
|
||
import sys | ||
import requests | ||
|
||
# CONFIGURATION | ||
secret = "xxxxx" #the token management token secret | ||
environment = "xxxxx" # your environment base url | ||
userSuffix = "ruxit.com" | ||
# END CONFIGURATION | ||
|
||
tokenBaseUrl = "https://" + environment + "/api/v1/tokens" | ||
|
||
tokenIds = requests.get(tokenBaseUrl + '?permissions=InstallerDownload&Api-Token=' + secret) | ||
|
||
#this should catch most wrong url/secret issues | ||
if tokenIds.status_code != 200: | ||
sys.exit('Request failed, error code: {}'.format(tokenIds.status_code)) | ||
|
||
for tokenId in tokenIds.json()['values']: | ||
tokenIdUrl = tokenBaseUrl + "/" + tokenId['id']+ "?Api-Token=" + secret | ||
tokenMetadata = requests.get(tokenIdUrl) | ||
jsonMetaData = tokenMetadata.json() | ||
|
||
if jsonMetaData['userId'].endswith(userSuffix): | ||
requests.delete(tokenIdUrl) | ||
print ('Deleted token with name {}, creator was {}'.format(jsonMetaData['name'], jsonMetaData['userId'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# developed and tested with python 3.7.1 | ||
|
||
import sys | ||
import requests | ||
|
||
# CONFIGURATION | ||
secret = "xxxxx" #the token management token secret | ||
environment = "xxxxx" # your environment base url | ||
userSuffix = "ruxit.com" | ||
# END CONFIGURATION | ||
|
||
tokenBaseUrl = "https://" + environment + "/api/v1/tokens" | ||
|
||
tokenIds = requests.get(tokenBaseUrl + '?permissions=InstallerDownload&Api-Token=' + secret) | ||
|
||
#this should catch most wrong url/secret issues | ||
if tokenIds.status_code != 200: | ||
sys.exit('Request failed, error code: {}'.format(tokenIds.status_code)) | ||
|
||
for tokenId in tokenIds.json()['values']: | ||
tokenIdUrl = tokenBaseUrl + "/" + tokenId['id']+ "?Api-Token=" + secret | ||
tokenMetadata = requests.get(tokenIdUrl) | ||
jsonMetaData = tokenMetadata.json() | ||
|
||
if jsonMetaData['userId'].endswith(userSuffix): | ||
requests.put(tokenIdUrl, json={'revoked':'true'}) | ||
print ('Revoked token with name {}, creator was {}'.format(jsonMetaData['name'], jsonMetaData['userId'])) |