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