Skip to content

Commit

Permalink
Make no-auth github exporter okay (#352)
Browse files Browse the repository at this point in the history
Public repos do not need authentication.
  • Loading branch information
KevinMGranger authored Feb 22, 2022
1 parent 4a11c5f commit eb8141d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
15 changes: 7 additions & 8 deletions exporters/committime/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python3
import logging
import os
import sys
import time
from distutils.util import strtobool

Expand All @@ -16,8 +16,6 @@

import pelorus

REQUIRED_CONFIG = ["GIT_USER", "GIT_TOKEN"]


class GitFactory:
@staticmethod
Expand Down Expand Up @@ -46,17 +44,18 @@ def getCollector(

if __name__ == "__main__":
pelorus.upgrade_legacy_vars()
if pelorus.missing_configs(REQUIRED_CONFIG):
print("This program will exit.")
sys.exit(1)

pelorus.load_kube_config()
k8s_config = client.Configuration()
k8s_client = client.api_client.ApiClient(configuration=k8s_config)
dyn_client = DynamicClient(k8s_client)

username = os.environ.get("GIT_USER")
token = os.environ.get("GIT_TOKEN")
username = os.environ.get("GIT_USER", "")
token = os.environ.get("GIT_TOKEN", "")
if not username and not token:
logging.info(
"No GIT_USER and no GIT_TOKEN given. This is okay for public repositories only."
)
git_api = os.environ.get("GIT_API")
git_provider = os.environ.get("GIT_PROVIDER", pelorus.DEFAULT_GIT)
tls_verify = bool(
Expand Down
10 changes: 5 additions & 5 deletions exporters/committime/collector_github.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import Optional

import requests

Expand All @@ -16,8 +17,8 @@ class GitHubCommitCollector(AbstractCommitCollector):
def __init__(
self,
kube_client,
username,
token,
username: Optional[str],
token: Optional[str],
namespaces,
apps,
git_api=None,
Expand Down Expand Up @@ -56,9 +57,8 @@ def get_commit_time(self, metric):
+ self._suffix
+ metric.commit_hash
)
response = requests.get(
url, auth=(self._username, self._token), verify=self._tls_verify
)
auth = (self._username, self._token) if self._username and self._token else None
response = requests.get(url, auth=auth, verify=self._tls_verify)
if response.status_code != 200:
# This will occur when trying to make an API call to non-Github
logging.warning(
Expand Down

0 comments on commit eb8141d

Please sign in to comment.