Last active
April 24, 2020 13:43
-
-
Save immanuelpotter/ff0b3434374415d9ddbb803a23d3a7ab to your computer and use it in GitHub Desktop.
Testing out PAT tokens can hit required endpoints they need to get to in Azure DevOps.
This file contains hidden or 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
#!/usr/bin/env python | |
import requests | |
import sys | |
import pprint | |
import base64 | |
def encode_string(token): | |
to_encode_string = "Basic:" + token | |
encoded_str = base64.b64encode(to_encode_string.encode()).decode('utf-8') | |
return encoded_str | |
def send_request(endpoint, encoded_str): | |
try: | |
auth_header = 'Basic ' + encoded_str | |
r = requests.get(endpoint, headers={'Authorization' : auth_header}) | |
result = r.json() | |
if result: | |
print("Endpoint " + endpoint + " authorization successful.") | |
except: | |
print("Something failed sending request to endpoint " + url + ". Check your PAT token and api endpoints.") | |
def main(): | |
if len(sys.argv) == 2: | |
token = sys.argv[1] | |
encoded_str = encode_string(token) | |
# Add your required endpoints here. Projects is here as an example. | |
urls = [ | |
'https://dev.azure.com/{YOUR_ADO_ORGANISATION}/_apis/projects?api-version=5.1' | |
] | |
for url in urls: | |
try: | |
result = send_request(url, encoded_str) | |
except: | |
print("Something failed for endpoint " + url + ". Check the scope of the PAT token and available organisations.") | |
else: | |
print("Usage: python " + sys.argv[0] + " RAW_PAT_TOKEN") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment