4
4
# See LICENSE for more information
5
5
6
6
import argparse
7
+ import base64
7
8
import fnmatch
8
9
import itertools
9
10
import json
@@ -63,13 +64,23 @@ def add_auth_arguments(parser: argparse.ArgumentParser):
63
64
# Token
64
65
parser .add_argument ("--token" , help = "github auth token" )
65
66
# 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
+ )
67
71
group_app .add_argument ("--app-id" , type = int , help = "app ID" )
68
72
group_app .add_argument (
69
73
"--private-key" , type = str , help = "app private key as a string"
70
74
)
71
75
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" ,
73
84
)
74
85
group_app .add_argument ("--installation-id" , type = int , help = "app installation ID" )
75
86
@@ -80,11 +91,13 @@ def get_auth_from_arguments(args: argparse.Namespace) -> Auth:
80
91
81
92
if (
82
93
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 )
84
95
and args .installation_id
85
96
):
86
97
if args .private_key :
87
98
private_key = args .private_key
99
+ elif args .private_key_base64 :
100
+ private_key = base64 .b64decode (args .private_key_base64 ).decode ("ascii" )
88
101
else :
89
102
private_key = open (args .private_key_file_path ).read ()
90
103
return Auth .AppAuth (args .app_id , private_key ).get_installation_auth (
@@ -94,11 +107,12 @@ def get_auth_from_arguments(args: argparse.Namespace) -> Auth:
94
107
args .app_id
95
108
or args .private_key
96
109
or args .private_key_file_path
110
+ or args .private_key_base64
97
111
or args .installation_id
98
112
):
99
113
raise argparse .ArgumentError (
100
114
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" ,
102
116
)
103
117
104
118
raise argparse .ArgumentError (None , "authentication method not supplied" )
0 commit comments