From f26bf0fb411232320ae8327e2777badfcef78b69 Mon Sep 17 00:00:00 2001 From: Nivedita Paul Date: Mon, 10 May 2021 17:21:14 +0100 Subject: [PATCH 1/3] fix for latest jwt that doesnt need decoding --- git_credential_github_app_auth/identity.py | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/git_credential_github_app_auth/identity.py b/git_credential_github_app_auth/identity.py index 614fa40..74d0830 100644 --- a/git_credential_github_app_auth/identity.py +++ b/git_credential_github_app_auth/identity.py @@ -9,6 +9,7 @@ logger = logging.getLogger(__name__) + @attr.s(frozen=True) class AppIdentity: """Manages a github app id/key pair and signed token generation. @@ -31,7 +32,9 @@ def _resolve_app_id(app_id: Optional[Union[int, str]] = None): app_id = os.getenv(AppIdentity.APP_ID_ENV_VAR) if app_id is None: - raise ValueError("Unable to resolve app_id from env: %s" % AppIdentity.APP_ID_ENV_VAR) + raise ValueError( + "Unable to resolve app_id from env: %s" % AppIdentity.APP_ID_ENV_VAR + ) logger.info("Resolved %s to app id: %s", AppIdentity.APP_ID_ENV_VAR, app_id) try: @@ -51,7 +54,10 @@ def _resolve_key(private_key: Optional[str] = None): logger.debug("Resolving private_key from env.") private_key = os.getenv(AppIdentity.PRIVATE_KEY_ENV_VAR) if private_key is None: - raise ValueError("Unable to resolve private_key from env: %s" % AppIdentity.PRIVATE_KEY_ENV_VAR) + raise ValueError( + "Unable to resolve private_key from env: %s" + % AppIdentity.PRIVATE_KEY_ENV_VAR + ) logger.info("Resolved %s to private key.", AppIdentity.PRIVATE_KEY_ENV_VAR) if "BEGIN RSA PRIVATE KEY" in private_key: @@ -63,14 +69,14 @@ def _resolve_key(private_key: Optional[str] = None): logger.info("Resolved private key.") return private_key - app_id : int = attr.attrib( + app_id: int = attr.attrib( converter=_resolve_app_id.__func__, - default = attr.Factory(lambda: AppIdentity._resolve_app_id()) + default=attr.Factory(lambda: AppIdentity._resolve_app_id()), ) - private_key : str = attr.attrib( + private_key: str = attr.attrib( repr=False, converter=_resolve_key.__func__, - default = attr.Factory(lambda: AppIdentity._resolve_key()) + default=attr.Factory(lambda: AppIdentity._resolve_key()), ) def jwt(self) -> str: @@ -81,11 +87,9 @@ def jwt(self) -> str: """ issue_time = time.time() - 1 payload = dict( - iat= int(issue_time), - exp= int(issue_time + (10 * 60)), - iss= self.app_id + iat=int(issue_time), exp=int(issue_time + (10 * 60)), iss=self.app_id ) logging.debug("Issuing app jwt: %s", payload) - return jwt.encode(payload, self.private_key, algorithm='RS256').decode() + return jwt.encode(payload, self.private_key, algorithm="RS256") From e2afb0a6c92345c239ce44b7f33344be6f93e727 Mon Sep 17 00:00:00 2001 From: Matthew McCulloch Date: Fri, 21 May 2021 13:25:51 +0100 Subject: [PATCH 2/3] fix line endings on windows --- git_credential_github_app_auth/cli.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/git_credential_github_app_auth/cli.py b/git_credential_github_app_auth/cli.py index 7a385a9..0bcd347 100644 --- a/git_credential_github_app_auth/cli.py +++ b/git_credential_github_app_auth/cli.py @@ -1,5 +1,6 @@ import logging import json +import sys import click @@ -66,16 +67,14 @@ def token(appidentity, account): @click.command(help="Credential storage helper implementation.") @pass_appidentity @click.argument('input', type=click.File('r'), default="-") -@click.argument('output', type=click.File('w'), default="-") -def get(appidentity, input, output): +def get(appidentity, input): # https://git-scm.com/docs/git-credential - logger.debug("get id: %s input: %s output: %s", appidentity, input, output) + logger.debug("get id: %s input: %s", appidentity, input) def token_for_account(account): return installation_token_for(account, appidentity)["token"] - output.write(credential_helper(input.read(), token_for_account)) - output.write("\n") + sys.stdout.write(credential_helper(input.read(), token_for_account)) @cli.command(help="no-op git-credential interface") From e2286c19bea998435a9a3b40bf23f9e55d8fe9ee Mon Sep 17 00:00:00 2001 From: Tom Dudley Date: Fri, 21 May 2021 13:39:35 +0100 Subject: [PATCH 3/3] Fix GitHub path --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d1529b..8a1a47b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ for the application. environment. ``` - pip install git+https://github.com/uw-ipd/git-credential-github-app-auth + pip install git+https://github.com/KPMG-UK/git-credential-github-app-auth ``` 3. Add `github-app-auth` as a git-credential helper and ensure that