Add initial implementation of DevOps client and harvester script
This commit is contained in:
26
devops.py
Normal file
26
devops.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import requests
|
||||||
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
|
DEVOPS_SCOPE = "https://app.vssps.visualstudio.com/.default"
|
||||||
|
DEVOPS_API_VERSION = "7.1"
|
||||||
|
|
||||||
|
class Client:
|
||||||
|
def __init__(self, org_url: str, token: str, api_version: str = DEVOPS_API_VERSION):
|
||||||
|
self._org_url = org_url
|
||||||
|
self._token = token
|
||||||
|
self._api_version = api_version
|
||||||
|
|
||||||
|
def get(self, url: str, params: dict = {}):
|
||||||
|
p = {
|
||||||
|
"api-version": self._api_version,
|
||||||
|
**params
|
||||||
|
}
|
||||||
|
r = requests.get(url=urljoin(self._org_url, url), params=p, headers={
|
||||||
|
"Authorization": f"Bearer {self._token}"
|
||||||
|
})
|
||||||
|
return r
|
||||||
|
|
||||||
|
def get_projects(self):
|
||||||
|
r = self.get("_apis/projects")
|
||||||
|
r.raise_for_status()
|
||||||
|
return r.json()
|
||||||
14
harvester.py
Executable file
14
harvester.py
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from devops import Client, DEVOPS_SCOPE
|
||||||
|
from azure.identity import DefaultAzureCredential
|
||||||
|
from json import dumps
|
||||||
|
|
||||||
|
def main():
|
||||||
|
token = DefaultAzureCredential().get_token(DEVOPS_SCOPE).token
|
||||||
|
client = Client("https://dev.azure.com/mcovsandbox/", token)
|
||||||
|
projects = client.get_projects()
|
||||||
|
print(dumps(projects, indent=2))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
azure-identity
|
||||||
Reference in New Issue
Block a user