Skip to content

Commit f527341

Browse files
authored
Merge pull request #112 from bwrsandman/base64-private-key
auth: Allow private key for apps to be base64
2 parents 5d848bc + d51789b commit f527341

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

post/clang_tidy_review/clang_tidy_review/__init__.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# See LICENSE for more information
55

66
import argparse
7+
import base64
78
import fnmatch
89
import itertools
910
import json
@@ -63,13 +64,23 @@ def add_auth_arguments(parser: argparse.ArgumentParser):
6364
# Token
6465
parser.add_argument("--token", help="github auth token")
6566
# App
66-
group_app = parser.add_argument_group("github app installation auth")
67+
group_app = parser.add_argument_group(
68+
"""Github app installation authentication
69+
Permissions required: Contents (Read) and Pull requests (Read and Write)"""
70+
)
6771
group_app.add_argument("--app-id", type=int, help="app ID")
6872
group_app.add_argument(
6973
"--private-key", type=str, help="app private key as a string"
7074
)
7175
group_app.add_argument(
72-
"--private-key-file-path", type=str, help="app private key .pom file path"
76+
"--private-key-base64",
77+
type=str,
78+
help="app private key as a string encoded as base64",
79+
)
80+
group_app.add_argument(
81+
"--private-key-file-path",
82+
type=pathlib.Path,
83+
help="app private key .pom file path",
7384
)
7485
group_app.add_argument("--installation-id", type=int, help="app installation ID")
7586

@@ -80,11 +91,13 @@ def get_auth_from_arguments(args: argparse.Namespace) -> Auth:
8091

8192
if (
8293
args.app_id
83-
and (args.private_key or args.private_key_file_path)
94+
and (args.private_key or args.private_key_file_path or args.private_key_base64)
8495
and args.installation_id
8596
):
8697
if args.private_key:
8798
private_key = args.private_key
99+
elif args.private_key_base64:
100+
private_key = base64.b64decode(args.private_key_base64).decode("ascii")
88101
else:
89102
private_key = open(args.private_key_file_path).read()
90103
return Auth.AppAuth(args.app_id, private_key).get_installation_auth(
@@ -94,11 +107,12 @@ def get_auth_from_arguments(args: argparse.Namespace) -> Auth:
94107
args.app_id
95108
or args.private_key
96109
or args.private_key_file_path
110+
or args.private_key_base64
97111
or args.installation_id
98112
):
99113
raise argparse.ArgumentError(
100114
None,
101-
"--app-id, --private-key[-file-path] and --installation-id must be supplied together",
115+
"--app-id, --private-key[-file-path|-base64] and --installation-id must be supplied together",
102116
)
103117

104118
raise argparse.ArgumentError(None, "authentication method not supplied")

0 commit comments

Comments
 (0)