Skip to content

Commit

Permalink
Switch all producers to create_headers()
Browse files Browse the repository at this point in the history
  • Loading branch information
redaxmedia committed Feb 13, 2022
1 parent 4b047b7 commit 4074083
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 171 deletions.
12 changes: 2 additions & 10 deletions chroma_feedback/producer/appveyor/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,9 @@ def fetch(host : str, slug : str, token : str) -> List[Producer]:
response = None

if host and slug and token:
response = request.get(host + '/api/projects/' + slug, headers =
{
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
})
response = request.get(host + '/api/projects/' + slug, headers = request.create_bearer_auth_headers(token))
elif host and token:
response = request.get(host + '/api/projects', headers =
{
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
})
response = request.get(host + '/api/projects', headers = request.create_bearer_auth_headers(token))

# process response

Expand Down
8 changes: 1 addition & 7 deletions chroma_feedback/producer/azure/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import base64
from argparse import ArgumentParser
from typing import List

Expand Down Expand Up @@ -32,12 +31,7 @@ def fetch(host : str, slug : str, token : str) -> List[Producer]:
response = None

if host and slug and token:
token = ':' + token
response = request.get(host + '/' + slug + '/_apis/build/builds?api-version=6.0', headers =
{
'Accept': 'application/json',
'Authorization': 'Basic ' + base64.b64encode(token.encode('utf-8')).decode('ascii')
})
response = request.get(host + '/' + slug + '/_apis/build/builds?api-version=6.0', headers = request.create_basic_auth_headers('', token))

# process response

Expand Down
6 changes: 1 addition & 5 deletions chroma_feedback/producer/bamboo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ def fetch(host : str, slug : str, token : str) -> List[Producer]:
response = None

if host and slug and token:
response = request.get(host + '/rest/api/latest/result/' + normalize_slug(slug), headers =
{
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
})
response = request.get(host + '/rest/api/latest/result/' + normalize_slug(slug), headers = request.create_bearer_auth_headers(token))

# process response

Expand Down
8 changes: 1 addition & 7 deletions chroma_feedback/producer/bitbucket/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import base64
from argparse import ArgumentParser
from typing import List

Expand Down Expand Up @@ -33,12 +32,7 @@ def fetch(host : str, slug : str, username : str, password : str) -> List[Produc
response = None

if host and slug and username and password:
username_password = username + ':' + password
response = request.get(host + '/2.0/repositories/' + slug + '/pipelines/', headers =
{
'Accept': 'application/json',
'Authorization': 'Basic ' + base64.b64encode(username_password.encode('utf-8')).decode('ascii')
})
response = request.get(host + '/2.0/repositories/' + slug + '/pipelines/', headers = request.create_basic_auth_headers(username, password))

# process response

Expand Down
12 changes: 2 additions & 10 deletions chroma_feedback/producer/buddy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ def fetch_projects(host : str, workspace : str, token : str) -> List[Dict[str, A
response = None

if host and workspace and token:
response = request.get(host + '/workspaces/' + workspace + '/projects', headers =
{
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
})
response = request.get(host + '/workspaces/' + workspace + '/projects', headers = request.create_bearer_auth_headers(token))

# process response

Expand All @@ -70,11 +66,7 @@ def fetch_pipelines(host: str, workspace: str, project : str, token: str) -> Lis
response = None

if host and workspace and project and token:
response = request.get(host + '/workspaces/' + workspace + '/projects/' + project + '/pipelines/', headers=
{
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
})
response = request.get(host + '/workspaces/' + workspace + '/projects/' + project + '/pipelines/', headers = request.create_bearer_auth_headers(token))

# process response

Expand Down
34 changes: 13 additions & 21 deletions chroma_feedback/producer/circle/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List

from chroma_feedback import helper, request
from chroma_feedback.typing import Producer
from chroma_feedback.typing import Headers, Producer
from .normalize import normalize_data

ARGS = None
Expand Down Expand Up @@ -36,23 +36,11 @@ def fetch(host : str, organization : str, slug : str, __filter__ : str, token :
response = None

if host and slug and __filter__ == 'mine' and token:
response = request.get(host + '/api/v2/project/' + slug + '/pipeline/mine', headers =
{
'Accept': 'application/json',
'Circle-Token': token
})
response = request.get(host + '/api/v2/project/' + slug + '/pipeline/mine', headers = _create_headers(token))
elif host and slug and token:
response = request.get(host + '/api/v2/project/' + slug + '/pipeline', headers =
{
'Accept': 'application/json',
'Circle-Token': token
})
response = request.get(host + '/api/v2/project/' + slug + '/pipeline', headers = _create_headers(token))
elif host and organization and token:
response = request.get(host + '/api/v2/pipeline?org-slug=' + organization, headers =
{
'Accept': 'application/json',
'Circle-Token': token
})
response = request.get(host + '/api/v2/pipeline?org-slug=' + organization, headers = _create_headers(token))

# process response

Expand All @@ -72,11 +60,7 @@ def fetch_workflows(host : str, pipeline_id : str, token : str) -> List[Producer
response = None

if host and pipeline_id and token:
response = request.get(host + '/api/v2/pipeline/' + pipeline_id + '/workflow', headers =
{
'Accept': 'application/json',
'Circle-Token': token
})
response = request.get(host + '/api/v2/pipeline/' + pipeline_id + '/workflow', headers = _create_headers(token))

# process response

Expand All @@ -88,3 +72,11 @@ def fetch_workflows(host : str, pipeline_id : str, token : str) -> List[Producer
if 'project_slug' in build and 'name' in build and 'status' in build:
result.append(normalize_data(build['project_slug'] + '/' + build['name'], build['status']))
return result


def _create_headers(token : str) -> Headers:
return \
{
'Accept': 'application/json',
'Circle-Token': token
}
20 changes: 3 additions & 17 deletions chroma_feedback/producer/codeship/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import base64
from argparse import ArgumentParser
from typing import Any, Dict, List

Expand Down Expand Up @@ -49,12 +48,7 @@ def fetch_auth(host : str, username : str, password : str) -> Dict[str, Any]:
response = None

if host and username and password:
username_password = username + ':' + password
response = request.post(host + '/v2/auth', headers =
{
'Accept': 'application/json',
'Authorization': 'Basic ' + base64.b64encode(username_password.encode('utf-8')).decode('ascii')
})
response = request.post(host + '/v2/auth', headers = request.create_basic_auth_headers(username, password))

# process response

Expand All @@ -72,11 +66,7 @@ def fetch_projects(host : str, organization_id : str, token : str) -> List[Dict[
response = None

if host and organization_id and token:
response = request.get(host + '/v2/organizations/' + organization_id + '/projects', headers =
{
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
})
response = request.get(host + '/v2/organizations/' + organization_id + '/projects', headers = request.create_bearer_auth_headers(token))

# process response

Expand All @@ -94,11 +84,7 @@ def fetch_builds(host : str, organization_id : str, slug : str, project_id : str
response = None

if host and organization_id and project_id and token:
response = request.get(host + '/v2/organizations/' + organization_id + '/projects/' + project_id + '/builds', headers =
{
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
})
response = request.get(host + '/v2/organizations/' + organization_id + '/projects/' + project_id + '/builds', headers = request.create_bearer_auth_headers(token))

# process response

Expand Down
14 changes: 9 additions & 5 deletions chroma_feedback/producer/custom/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List

from chroma_feedback import helper, request
from chroma_feedback.typing import Producer
from chroma_feedback.typing import Headers, Producer
from .normalize import normalize_data

ARGS = None
Expand Down Expand Up @@ -30,10 +30,7 @@ def fetch(host : str, slug : str) -> List[Producer]:
response = None

if host and slug:
response = request.get(host + '/statuses/' + slug, headers =
{
'Accept': 'application/json'
})
response = request.get(host + '/statuses/' + slug, headers = _create_headers())

# process response

Expand All @@ -44,3 +41,10 @@ def fetch(host : str, slug : str) -> List[Producer]:
if 'slug' in build and 'url' in build and 'status' in build:
result.append(normalize_data(build['slug'], build['url'], build['status']))
return result


def _create_headers() -> Headers:
return\
{
'Accept': 'application/json'
}
18 changes: 11 additions & 7 deletions chroma_feedback/producer/datadog/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List

from chroma_feedback import helper, request
from chroma_feedback.typing import Producer
from chroma_feedback.typing import Headers, Producer
from .normalize import normalize_data

ARGS = None
Expand Down Expand Up @@ -32,12 +32,7 @@ def fetch(host : str, slug : str, api_key : str, application_key : str) -> List[
response = None

if host and slug and api_key and application_key:
response = request.get(host + '/api/v1/monitor/' + slug, headers =
{
'Accept': 'application/json',
'DD-API-KEY': api_key,
'DD-APPLICATION-KEY': application_key
})
response = request.get(host + '/api/v1/monitor/' + slug, headers = _create_headers(api_key, application_key))

# process response

Expand All @@ -47,3 +42,12 @@ def fetch(host : str, slug : str, api_key : str, application_key : str) -> List[
if 'name' in data and 'overall_state' in data:
result.append(normalize_data(data['name'], data['overall_state']))
return result


def _create_headers(api_key : str, application_key : str) -> Headers:
return \
{
'Accept': 'application/json',
'DD-API-KEY': api_key,
'DD-APPLICATION-KEY': application_key
}
22 changes: 11 additions & 11 deletions chroma_feedback/producer/github/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any, Dict, List

from chroma_feedback import helper, request
from chroma_feedback.typing import Producer
from chroma_feedback.typing import Headers, Producer
from .normalize import normalize_data

ARGS = None
Expand Down Expand Up @@ -48,11 +48,7 @@ def fetch_repositories(host : str, username : str, token : str) -> List[Dict[str
response = None

if host and username and token:
response = request.get(host + '/users/' + username + '/repos', headers =
{
'Accept': 'application/vnd.github.v3+json',
'Authorization': 'Token ' + token
})
response = request.get(host + '/users/' + username + '/repos', headers = _create_headers(token))

# process response

Expand All @@ -69,11 +65,7 @@ def fetch_runs(host : str, slug : str, token : str) -> List[Producer]:
response = None

if host and slug and token:
response = request.get(host + '/repos/' + slug + '/actions/runs', headers =
{
'Accept': 'application/vnd.github.v3+json',
'Authorization': 'Token ' + token
})
response = request.get(host + '/repos/' + slug + '/actions/runs', headers = _create_headers(token))

# process response

Expand All @@ -86,3 +78,11 @@ def fetch_runs(host : str, slug : str, token : str) -> List[Producer]:
if build and 'repository' in build and 'full_name' in build['repository'] and 'html_url' in build and 'status' in build and 'conclusion' in build:
result.append(normalize_data(build['repository']['full_name'], build['html_url'], build['status'], build['conclusion']))
return result


def _create_headers(token : str) -> Headers:
return\
{
'Accept': 'application/vnd.github.v3+json',
'Authorization': 'Token ' + token
}
22 changes: 11 additions & 11 deletions chroma_feedback/producer/gitlab/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List

from chroma_feedback import helper, request
from chroma_feedback.typing import Producer
from chroma_feedback.typing import Headers, Producer
from .normalize import normalize_data

ARGS = None
Expand Down Expand Up @@ -31,11 +31,7 @@ def fetch(host : str, slug : str, token : str) -> List[Producer]:
response = None

if host and slug and token:
response = request.get(host + '/api/v4/projects/' + slug + '/pipelines', headers =
{
'Accept': 'application/json',
'Private-Token': token
})
response = request.get(host + '/api/v4/projects/' + slug + '/pipelines', headers = _create_headers(token))

# process response

Expand All @@ -55,11 +51,7 @@ def fetch_jobs(host : str, slug : str, pipeline_id : str, token : str) -> List[P
response = None

if host and slug and pipeline_id and token:
response = request.get(host + '/api/v4/projects/' + slug + '/pipelines/' + pipeline_id + '/jobs', headers =
{
'Accept': 'application/json',
'Private-Token': token
})
response = request.get(host + '/api/v4/projects/' + slug + '/pipelines/' + pipeline_id + '/jobs', headers = _create_headers(token))

# process response

Expand All @@ -70,3 +62,11 @@ def fetch_jobs(host : str, slug : str, pipeline_id : str, token : str) -> List[P
if 'name' in build and 'web_url' in build and 'status' in build:
result.append(normalize_data(slug + '/' + build['name'], build['web_url'], build['status']))
return result


def _create_headers(token : str) -> Headers:
return\
{
'Accept': 'application/json',
'Private-Token': token
}
6 changes: 3 additions & 3 deletions chroma_feedback/producer/heroku/core.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from argparse import ArgumentParser
from typing import Dict, List
from typing import List

from chroma_feedback import helper, request
from chroma_feedback.typing import Producer
from chroma_feedback.typing import Headers, Producer
from .normalize import normalize_data

ARGS = None
Expand Down Expand Up @@ -66,7 +66,7 @@ def fetch_slugs(host : str, token : str) -> List[str]:
return result


def _create_headers(token : str) -> Dict[str, str]:
def _create_headers(token : str) -> Headers:
return\
{
'Accept': 'application/vnd.heroku+json;version=3',
Expand Down

0 comments on commit 4074083

Please sign in to comment.