def testGetDefaultConfigPath(self): self.mock_bin_check = self.StartObjectPatch( bin_ops, 'CheckForInstalledBinary', return_value='/usr/bin/kubectl-anthos') self.mock_expandvars.side_effect = self._MockExpandVar expected = { 'LINUX': os.path.join(self.home_path, '.config/google/anthos/' 'kubectl-anthos-config.yaml'), 'MACOSX': os.path.join( self.home_path, 'Library/Preferences/google/anthos/' 'kubectl-anthos-config.yaml'), } command_executor = anthoscli_backend.AnthosAuthWrapper() for os_id in anthoscli_backend.DEFAULT_LOGIN_CONFIG_PATH: if os_id == platforms.OperatingSystem.WINDOWS.id: continue self.StartObjectPatch( platforms.OperatingSystem, 'Current', return_value=platforms.OperatingSystem.FromId(os_id)) self.assertEqual(expected[os_id], command_executor.default_config_path)
def Run(self, args): command_executor = anthoscli_backend.AnthosAuthWrapper() response = command_executor( command='version', show_exec_error=args.show_exec_error, env=anthoscli_backend.GetEnvArgsForCommand()) return self._DefaultOperationResponseHandler(response)
def Run(self, args): command_executor = anthoscli_backend.AnthosAuthWrapper() response = command_executor( command='create-login-config', kube_config=args.kubeconfig, output_file=args.output, merge_from=args.merge_from, show_exec_error=args.show_exec_error, env=anthoscli_backend.GetEnvArgsForCommand()) return anthoscli_backend.LoginResponseHandler(response)
def Run(self, args): command_executor = anthoscli_backend.AnthosAuthWrapper() log.status.Print(self._LOGIN_CONFIG_MESSAGE) response = command_executor( command='login', cluster=args.cluster, kube_config=args.kubeconfig, user=args.user, login_config=args.login_config, login_config_cert=args.login_config_cert, dry_run=args.dry_run, show_exec_error=args.show_exec_error, env=anthoscli_backend.GetEnvArgsForCommand()) return self._LoginResponseHandler(response)
def Run(self, args): command_executor = anthoscli_backend.AnthosAuthWrapper() with progress_tracker.ProgressTracker( 'Configuring Anthos authentication.', interruptable=True): response = command_executor( command='login', cluster=args.cluster, kube_config=args.kubeconfig, user=args.user, login_config=args.login_config, login_config_cert=args.login_config_cert, dry_run=args.dry_run, show_exec_error=args.show_exec_error, env=anthoscli_backend.GetEnvArgsForCommand()) return self._DefaultOperationResponseHandler(response)
def testGetDefaultConfigPathWindows(self): self.mock_bin_check = self.StartObjectPatch( bin_ops, 'CheckForInstalledBinary', return_value='/usr/bin/kubectl-anthos') self.StartEnvPatch({'APPDATA': 'APP_DATA_DIR'}) self.mock_expandvars.side_effect = self._MockExpandVar expected = { 'WINDOWS': os.path.join('APP_DATA_DIR', 'google', 'anthos', 'kubectl-anthos-config.yaml') } command_executor = anthoscli_backend.AnthosAuthWrapper() self.StartObjectPatch(platforms.OperatingSystem, 'Current', return_value=platforms.OperatingSystem.WINDOWS) self.assertEqual(expected[platforms.OperatingSystem.WINDOWS.id], command_executor.default_config_path)
def Run(self, args): cluster = args.CLUSTER config_file = args.login_config force_update = args.set_preferred_auth anthoscli_backend.GetPreferredAuthForCluster(cluster, config_file, force_update) command_executor = anthoscli_backend.AnthosAuthWrapper() log.status.Print(self._LOGIN_CONFIG_MESSAGE) response = command_executor( command='login', cluster=cluster, kube_config=args.kubeconfig, user=args.user, login_config=config_file, login_config_cert=args.login_config_cert, dry_run=args.dry_run, show_exec_error=args.show_exec_error, env=anthoscli_backend.GetEnvArgsForCommand()) return self._LoginResponseHandler(response)
def Run(self, args): command_executor = anthoscli_backend.AnthosAuthWrapper() # Log and execute binary command with flags. response = command_executor( command="token", token_type=args.type, cluster=args.cluster, aws_sts_region=args.aws_sts_region, id_token=args.id_token, access_token=args.access_token, access_token_expiry=args.access_token_expiry, refresh_token=args.refresh_token, client_id=args.client_id, client_secret=args.client_secret, idp_certificate_authority_data=args.idp_certificate_authority_data, idp_issuer_url=args.idp_issuer_url, kubeconfig_path=args.kubeconfig_path, user=args.user, env=anthoscli_backend.GetEnvArgsForCommand()) return self._DefaultOperationResponseHandler(response)
def Run(self, args): command_executor = anthoscli_backend.AnthosAuthWrapper() cluster = args.CLUSTER # Get Default Path if flag not provided. login_config = args.login_config or command_executor.default_config_path # Get contents of config, parsing either URL or File. login_config, config_contents, is_url = anthoscli_backend.GetFileOrURL( login_config, args.login_config_cert) # Get Preferred Auth Method and handle prompting. force_update = args.set_preferred_auth authmethod, ldapuser, ldappass = anthoscli_backend.GetPreferredAuthForCluster( cluster=cluster, login_config=login_config, config_contents=config_contents, force_update=force_update, is_url=is_url) # Log and execute binary command with flags. log.status.Print(messages.LOGIN_CONFIG_MESSAGE) response = command_executor( command='login', cluster=cluster, kube_config=args.kubeconfig, user=args.user, login_config=login_config, login_config_cert=args.login_config_cert, dry_run=args.dry_run, show_exec_error=args.show_exec_error, ldap_user=ldapuser, ldap_pass=ldappass, preferred_auth=authmethod, env=anthoscli_backend.GetEnvArgsForCommand( extra_vars={'GCLOUD_AUTH_PLUGIN': 'true'})) return anthoscli_backend.LoginResponseHandler( response, list_clusters_only=(cluster is None))