Skip to content

Commit

Permalink
fix: stop printing confnig
Browse files Browse the repository at this point in the history
  • Loading branch information
AJWurts committed Oct 24, 2024
1 parent f00e094 commit ab6eed4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
27 changes: 27 additions & 0 deletions generate_jwt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import time
import jwt
import json


def generate_jwt(signing_key, client_id) -> str:

payload = {
# Issued at time
"iat": int(time.time()),
# JWT expiration time (10 minutes maximum)
"exp": int(time.time()) + 600,
# GitHub App's client ID
"iss": client_id,
"alg": "RS256",
}

# Create JWT
encoded_jwt = jwt.encode(payload, signing_key, algorithm="RS256")
return encoded_jwt


if __name__ == "__main__":
with open("config.json", "r") as f:
config = json.load(f)

print(generate_jwt(config["signing_key"], config["client_id"]))
14 changes: 12 additions & 2 deletions tap_github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@

REQUIRED_CONFIG_KEYS = [
"start_date",
"repository",
] # access_token or installation_id required


GITHUB_ACCESS_TOKEN_KEYS = ["access_token", "start_date", "repository"]

GITHUB_APP_CONFIG_KEYS = [
"client_id",
"client_secret",
"signing_key",
"installation_id",
"start_date'",
]


def do_discover(client):
"""
Call the discovery function.
Expand All @@ -27,10 +37,10 @@ def main():
"""
Run discover mode or sync mode.
"""

args = singer.utils.parse_args(REQUIRED_CONFIG_KEYS)

config = args.config
print(config)

client = GithubClient(config)

Expand Down
21 changes: 20 additions & 1 deletion tap_github/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,31 @@ def extract_orgs_from_config(self):

return set(orgs_paths)

def get_selected_repos(self):
headers = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {self.token}",
"X-GitHub-Api-Version": "2022-11-28",
}
url = "https://api.github.com/installation/repositories"
response = requests.get(url, headers=headers)
if response.status_code == 200:
repos = response.json()["repositories"]
full_names = [repo["full_name"] for repo in repos]
return full_names
else:
response.raise_for_status()

def extract_repos_from_config(self):
"""
Extracts all repositories from the config and calls get_all_repos()
for organizations using the wildcard 'org/*' format.
"""
repo_paths = list(filter(None, self.config["repository"].split(" ")))
repo_paths: list[str] = []
if is_oauth_credentials(self.config):
repo_paths = self.get_selected_repos()
else:
repo_paths = list(filter(None, self.config["repository"].split(" ")))

unique_repos = set()
# Insert the duplicate repos found in the config repo_paths into duplicates
Expand Down

0 comments on commit ab6eed4

Please sign in to comment.