improve on gam enable apis

This commit is contained in:
Jay Lee
2023-02-17 22:07:36 +00:00
parent ed0ed8d7fc
commit b0626dd37a

View File

@ -7168,18 +7168,32 @@ def getGAMProjectFile(filepath):
return c.decode(UTF8) return c.decode(UTF8)
def signjwt_enable_apis(): def enable_apis():
try:
creds, project_id = google.auth.default()
except google.auth.exceptions.DefaultCredentialsError as e:
controlflow.system_error_exit(2, e)
httpObj = transport.AuthorizedHttp(
creds, transport.create_http(cache=GM_Globals[GM_CACHE_DIR]))
GAMProjectAPIs = getGAMProjectFile('project-apis.txt').splitlines() GAMProjectAPIs = getGAMProjectFile('project-apis.txt').splitlines()
enableGAMProjectAPIs(GAMProjectAPIs, try:
httpObj, _, projectId = google.auth.default()
projectId=project_id, except google.auth.exceptions.DefaultCredentialsError as e:
checkEnabled=True) projectId = input('Please enter your project ID: ')
while True:
a_or_m = input('Do you want to enable projects [a]utomatically or [m]anually? (a/m): ').strip().lower()
if a_or_m in ['a', 'm']:
break
else:
print('Please enter A or M....')
if a_or_m == 'a':
login_hint = _getValidateLoginHint()
_, httpObj = getCRMService(login_hint)
enableGAMProjectAPIs(GAMProjectAPIs,
httpObj,
projectId=projectId,
checkEnabled=True)
else:
chunk_size = 20
print('Using an account with project access, please use ALL of these URLs to enable 20 APIs at a time:\n\n')
for chunk in range(0, len(GAMProjectAPIs), chunk_size):
apiid = ",".join(GAMProjectAPIs[chunk:chunk+chunk_size])
url = f'https://console.cloud.google.com/apis/enableflow?apiid={apiid}&project={projectId}'
print(f' {url}\n\n')
def enableGAMProjectAPIs(GAMProjectAPIs, def enableGAMProjectAPIs(GAMProjectAPIs,
@ -12149,7 +12163,7 @@ def ProcessGAMCommand(args):
elif command == 'enable': elif command == 'enable':
enable_what = sys.argv[2].lower().replace('_', '') enable_what = sys.argv[2].lower().replace('_', '')
if enable_what in ['api', 'apis']: if enable_what in ['api', 'apis']:
signjwt_enable_apis() enable_apis()
sys.exit(0) sys.exit(0)
users = getUsersToModify() users = getUsersToModify()
command = sys.argv[3].lower() command = sys.argv[3].lower()