skipped 233 lines 234 234 dest='extra_system_labels', 235 235 nargs='+', 236 236 help='extra labels that should be treated as system labels.') 237 + parser.add_argument('--config-folder', 238 + dest='config_folder', 239 + help='Optional: Alternate folder to store config and credentials', 240 + default=getProgPath()) 237 241 parser.add_argument('--version', 238 242 action='store_true', 239 243 dest='version', skipped 123 lines 363 367 "groupsmigration": QuotaBucket(10, 1, 10), 364 368 } 365 369 370 + def getConfigPath(): 371 + return options.config_folder 366 372 367 373 def getProgPath(): 368 374 if os.environ.get('STATICX_PROG_PATH', False): skipped 30 lines 399 405 400 406 def getOauth2TxtStorageCredentials(): 401 407 auth_as = options.use_admin if options.use_admin else options.email 402 - cfgFile = os.path.join(getProgPath (), '%s.cfg' % auth_as) 408 + cfgFile = os.path.join(getConfigPath (), '%s.cfg' % auth_as) 403 409 oauth_string = readFile(cfgFile, continueOnError=True, displayError=False) 404 410 if not oauth_string: 405 411 return skipped 15 lines 421 427 %s --action create-project --email %s 422 428 423 429 """ % (sys.argv[0], options.email) 424 - filename = os.path.join(getProgPath (), 'client_secrets.json') 430 + filename = os.path.join(getConfigPath (), 'client_secrets.json') 425 431 cs_data = readFile(filename, continueOnError=True, displayError=True) 426 432 if not cs_data: 427 433 systemErrorExit(14, MISSING_CLIENT_SECRETS_MESSAGE) skipped 81 lines 509 515 510 516 def writeCredentials(creds): 511 517 auth_as = options.use_admin if options.use_admin else options.email 512 - cfgFile = os.path.join(getProgPath (), '%s.cfg' % auth_as) 518 + cfgFile = os.path.join(getConfigPath (), '%s.cfg' % auth_as) 513 519 creds_data = { 514 520 'token': creds.token, 515 521 'refresh_token': creds.refresh_token, skipped 52 lines 568 574 def _LatestVersionNotAvailable(): 569 575 if forceCheck: 570 576 systemErrorExit(4, 'GYB Latest Version information not available') 571 - last_update_check_file = os.path.join(getProgPath (), 'lastcheck.txt') 577 + last_update_check_file = os.path.join(getConfigPath (), 'lastcheck.txt') 572 578 current_version = __version__ 573 579 now_time = calendar.timegm(time.gmtime()) 574 580 check_url = 'https://api.github.com/repos/jay0lee/got-your-back/releases' # includes pre-releases skipped 66 lines 641 647 httpc = google_auth_httplib2.AuthorizedHttp(credentials, _createHttpObj()) 642 648 if options.debug: 643 649 extra_args['prettyPrint'] = True 644 - if os.path.isfile(os.path.join(getProgPath (), 'extra-args.txt')): 650 + if os.path.isfile(os.path.join(getConfigPath (), 'extra-args.txt')): 645 651 config = configparser.ConfigParser() 646 652 config.optionxform = str 647 - config.read(os.path.join(getProgPath (), 'extra-args.txt')) 653 + config.read(os.path.join(getConfigPath (), 'extra-args.txt')) 648 654 extra_args.update(dict(config.items('extra-args'))) 649 655 version = getAPIVer(api) 650 656 try: skipped 4 lines 655 661 cache_discovery=False, 656 662 static_discovery=False) 657 663 except googleapiclient.errors.UnknownApiNameOrVersion: 658 - disc_file = os.path.join(getProgPath (), '%s-%s.json' % (api, version)) 664 + disc_file = os.path.join(getConfigPath (), '%s-%s.json' % (api, version)) 659 665 if os.path.isfile(disc_file): 660 666 f = file(disc_file, 'r') 661 667 discovery = f.read() skipped 12 lines 674 680 credentials = getSvcAcctCredentials(scopes, auth_as) 675 681 if options.debug: 676 682 extra_args['prettyPrint'] = True 677 - if os.path.isfile(os.path.join(getProgPath (), 'extra-args.txt')): 683 + if os.path.isfile(os.path.join(getConfigPath (), 'extra-args.txt')): 678 684 config = configparser.ConfigParser() 679 685 config.optionxform = str 680 686 config.read(getGamPath()+'extra-args.txt') skipped 180 lines 861 867 kwargs['login_hint'] = login_hint 862 868 # Needs to be set so oauthlib doesn't puke when Google changes our scopes 863 869 os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = 'true' 864 - if not os.path.isfile(os.path.join(getProgPath (), 'oauthbrowser.txt')): 870 + if not os.path.isfile(os.path.join(getConfigPath (), 'oauthbrowser.txt')): 865 871 flow.run_console( 866 872 authorization_prompt_message=MESSAGE_CONSOLE_AUTHORIZATION_PROMPT, 867 873 authorization_code_message=MESSAGE_CONSOLE_AUTHORIZATION_CODE, skipped 144 lines 1012 1018 "token_uri": "https://accounts.google.com/o/oauth2/token" 1013 1019 } 1014 1020 }''' % (client_id, client_secret, projectId) 1015 - client_secrets_file = os.path.join(getProgPath (), 'client_secrets.json') 1021 + client_secrets_file = os.path.join(getConfigPath (), 'client_secrets.json') 1016 1022 writeFile(client_secrets_file, cs_data, continueOnError=False) 1017 1023 1018 1024 PROJECTID_PATTERN = re.compile(r'^[a-z][a-z0-9-]{4,28}[a-z0-9]$') skipped 14 lines 1033 1039 sys.exit(3) 1034 1040 login_hint = getValidateLoginHint(login_hint) 1035 1041 crm, _ = getCRMService(login_hint) 1036 - client_secrets_file = os.path.join(getProgPath (), 'client_secrets.json') 1042 + client_secrets_file = os.path.join(getConfigPath (), 'client_secrets.json') 1037 1043 if pfilter == 'current': 1038 1044 cs_data = readFile(client_secrets_file, mode='rb', continueOnError=True, displayError=True, encoding=None) 1039 1045 if not cs_data: skipped 40 lines 1080 1086 pass 1081 1087 1082 1088 def doCreateProject(): 1083 - service_account_file = os.path.join(getProgPath (), 'oauth2service.json') 1084 - client_secrets_file = os.path.join(getProgPath (), 'client_secrets.json') 1089 + service_account_file = os.path.join(getConfigPath (), 'oauth2service.json') 1090 + client_secrets_file = os.path.join(getConfigPath (), 'client_secrets.json') 1085 1091 for a_file in [service_account_file, client_secrets_file]: 1086 1092 if os.path.exists(a_file): 1087 1093 print('File %s already exists. Please delete or rename it before attempting to create another project.' % a_file) skipped 117 lines 1205 1211 MESSAGE_INSTRUCTIONS_OAUTH2SERVICE_JSON = 'Please run\n\ngyb --action create-project\ngyb --action check-service-account\n\nto create and configure a service account.' 1206 1212 def getSvcAcctCredentials(scopes, act_as): 1207 1213 try: 1208 - json_string = readFile(os.path.join(getProgPath (), 'oauth2service.json'), continueOnError=True, displayError=True) 1214 + json_string = readFile(os.path.join(getConfigPath (), 'oauth2service.json'), continueOnError=True, displayError=True) 1209 1215 if not json_string: 1210 1216 print(MESSAGE_INSTRUCTIONS_OAUTH2SERVICE_JSON) 1211 1217 systemErrorExit(6, None) skipped 10 lines 1222 1228 1223 1229 def getSvcAccountClientId(): 1224 1230 try: 1225 - json_string = readFile(os.path.join(getProgPath (), 'oauth2service.json'), continueOnError=True, displayError=True) 1231 + json_string = readFile(os.path.join(getConfigPath (), 'oauth2service.json'), continueOnError=True, displayError=True) 1226 1232 if not json_string: 1227 1233 print(MESSAGE_INSTRUCTIONS_OAUTH2SERVICE_JSON) 1228 1234 systemErrorExit(6, None) skipped 190 lines 1419 1425 print("Error: you did not authorize the OAuth token in the browser with the \ 1420 1426 %s Google Account. Please make sure you are logged in to the correct account \ 1421 1427 when authorizing the token in the browser." % auth_as) 1422 - cfgFile = os.path.join(getProgPath (), '%s.cfg' % auth_as) 1428 + cfgFile = os.path.join(getConfigPath (), '%s.cfg' % auth_as) 1423 1429 os.remove(cfgFile) 1424 1430 return False 1425 1431 skipped 273 lines 1699 1705 if options.version: 1700 1706 print(getGYBVersion()) 1701 1707 print('Path: %s' % getProgPath()) 1708 + print('ConfigPath: %s' % getConfigPath()) 1702 1709 print(ssl.OPENSSL_VERSION) 1703 1710 anonhttpc = _createHttpObj() 1704 1711 headers = {'User-Agent': getGYBVersion(' | ')} skipped 670 lines 2375 2382 print('ERROR: --action revoke does not work with --service-account') 2376 2383 sys.exit(5) 2377 2384 auth_as = options.use_admin if options.use_admin else options.email 2378 - oauth2file = os.path.join(getProgPath (), '%s.cfg' % auth_as) 2385 + oauth2file = os.path.join(getConfigPath (), '%s.cfg' % auth_as) 2379 2386 credentials = getOauth2TxtStorageCredentials() 2380 2387 if credentials is None: 2381 2388 return skipped 77 lines