def main(): """Launches bq.""" version = bootstrapping.ReadFileContents('platform/bq', 'VERSION') bootstrapping.CommandStart('bq', version=version) blocked_commands = { 'init': 'To authenticate, run gcloud auth.', } argv = bootstrapping.GetDecodedArgv() bootstrapping.WarnAndExitOnBlockedCommand(argv, blocked_commands) cmd_args = [arg for arg in argv[1:] if not arg.startswith('-')] args = [] if cmd_args and cmd_args[0] not in ('version', 'help'): # Check for credentials only if they are needed. store.Load() # Checks if there are active credentials project, account = bootstrapping.GetActiveProjectAndAccount() adc_path = config.Paths().LegacyCredentialsAdcPath(account) single_store_path = config.Paths().LegacyCredentialsBqPath(account) gce_metadata = gce.Metadata() if gce_metadata and account in gce_metadata.Accounts(): args = ['--use_gce_service_account'] elif os.path.isfile(adc_path): args = ['--application_default_credential_file', adc_path, '--credential_file', single_store_path] else: p12_key_path = config.Paths().LegacyCredentialsP12KeyPath(account) if os.path.isfile(p12_key_path): args = ['--service_account', account, '--service_account_credential_file', single_store_path, '--service_account_private_key_file', p12_key_path] else: # Don't have any credentials we can pass. raise store.NoCredentialsForAccountException(account) use_client_cert = ( os.getenv('GOOGLE_API_USE_CLIENT_CERTIFICATE', 'false').upper() == 'TRUE') if use_client_cert: args.append('--mtls') _MaybeAddOption(args, 'project_id', project) bootstrapping.CheckUpdates('bq') proxy_params = properties.VALUES.proxy _MaybeAddOption(args, 'proxy_address', proxy_params.address.Get()) _MaybeAddOption(args, 'proxy_port', proxy_params.port.Get()) _MaybeAddOption(args, 'proxy_username', proxy_params.username.Get()) _MaybeAddOption(args, 'proxy_password', proxy_params.password.Get()) _MaybeAddOption(args, 'disable_ssl_validation', properties.VALUES.auth.disable_ssl_validation.GetBool()) _MaybeAddOption(args, 'ca_certificates_file', properties.VALUES.core.custom_ca_certs_file .Get()) bootstrapping.ExecutePythonTool( 'platform/bq', 'bq.py', *args)
def main(): """Launches the Schema Conversion Tool.""" bootstrapping.CommandStart(_COMPONENT_ID, component_id=_COMPONENT_ID) bootstrapping.CheckUpdates(_COMPONENT_ID) update_manager.UpdateManager.EnsureInstalledAndRestart([_COMPONENT_ID], command=__file__) try: java_bin = java.RequireJavaInstalled('Schema Conversion Tool', min_version=9) java_9plus = True except java.JavaVersionError: java_bin = java.RequireJavaInstalled('Schema Conversion Tool', min_version=8) java_9plus = False os.environ.setdefault('SCT_UPDATE_CHECK', 'false') jar_name = 'schema_conversion_gui.jar' main_jar = os.path.join(_JAR_DIR, jar_name) # Accept a platform-appropriate default added as 1st arg in sct.sh/sct.cmd. working_dir_default = bootstrapping.GetDecodedArgv()[1] flags = [ '-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager', '-Dspring.profiles.active=production', '-Dgcloud.component.dir={}'.format(_COMPONENT_DIR), '-Dsct.working.dir.default={}'.format(working_dir_default), '-jar', main_jar, ] if java_9plus: # Open modules to reflection explicitly to avoid Java 9+ warnings. flags = [ '--add-opens', 'java.base/java.io=ALL-UNNAMED', '--add-opens', 'java.base/java.lang=ALL-UNNAMED', '--add-opens', 'java.base/java.net=ALL-UNNAMED', '--add-opens', 'java.rmi/sun.rmi.transport=ALL-UNNAMED', ] + flags bootstrapping.ExecuteJarTool( java_bin, _JAR_DIR, jar_name, None, # No main classname for Springboot JAR. Use -jar flag instead. flags, '--server.address=127.0.0.1')
def ParseArgs(): """Parse args for the installer, so interactive prompts can be avoided.""" def Bool(s): return s.lower() in ['true', '1'] parser = argparse.ArgumentParser() parser.add_argument('--usage-reporting', default=None, type=Bool, help='(true/false) Disable anonymous usage reporting.') parser.add_argument('--rc-path', help=('Profile to update with PATH and completion. If' ' given without --command-completion or' ' --path-update in "quiet" mode, a line will be' ' added to this profile for both command completion' ' and path updating.')) parser.add_argument('--command-completion', '--bash-completion', default=None, type=Bool, help=('(true/false) Add a line for command completion in' ' the profile. In "quiet" mode, if True and you do' ' not provide--rc-path, the default profile' ' will be updated.')) parser.add_argument('--path-update', default=None, type=Bool, help=('(true/false) Add a line for path updating in the' ' profile. In "quiet" mode, if True and you do not' ' provide --rc-path, the default profile will be' ' updated.')) parser.add_argument('--disable-installation-options', action='store_true', help='DEPRECATED. This flag is no longer used.') parser.add_argument('--override-components', nargs='*', help='Override the components that would be installed by ' 'default and install these instead.') parser.add_argument('--additional-components', nargs='+', help='Additional components to install by default. These' ' components will either be added to the default install ' 'list, or to the override-components (if provided).') # Must have a None default so properties are not always overridden when the # arg is not provided. parser.add_argument('--quiet', '-q', default=None, action=actions.StoreConstProperty( properties.VALUES.core.disable_prompts, True), help='Disable all interactive prompts. If input is ' 'required, defaults will be used or an error will be ' 'raised') return parser.parse_args(bootstrapping.GetDecodedArgv()[1:])
_MaybeAddBotoOption(args, 'Boto', 'https_validate_certificates', None if disable_ssl is None else not disable_ssl) _MaybeAddBotoOption(args, 'Boto', 'ca_certificates_file', properties.VALUES.core.custom_ca_certs_file.Get()) # Note that the original args to gsutil will be appended after the args we've # supplied here. bootstrapping.ExecutePythonTool('platform/gsutil', 'gsutil', *args) if __name__ == '__main__': bootstrapping.DisallowPython3() try: version = bootstrapping.ReadFileContents('platform/gsutil', 'VERSION') bootstrapping.CommandStart('gsutil', version=version) blacklist = { 'update': 'To update, run: gcloud components update', } argv = bootstrapping.GetDecodedArgv() bootstrapping.CheckForBlacklistedCommand(argv, blacklist, warn=True, die=True) # Don't call bootstrapping.PreRunChecks because anonymous access is # supported for some endpoints. gsutil will output the appropriate # error message upon receiving an authentication error. bootstrapping.CheckUpdates('gsutil') main() except Exception as e: # pylint: disable=broad-except exceptions.HandleError(e, 'gsutil')