def test_get_project_id(data, expected_project_id): check_output_patch = mock.patch( 'subprocess.check_output', autospec=True, return_value=data) with check_output_patch as check_output: project_id = _cloud_sdk.get_project_id() assert project_id == expected_project_id assert check_output.called
def test_get_project_id_non_default_config(config_dir): active_config = config_dir.join('active_config') test_config = py.path.local( _cloud_sdk._get_config_file(str(config_dir), 'test')) # Create an active config file that points to the 'test' config. active_config.write('test', ensure=True) test_config.write(CLOUD_SDK_CONFIG_DATA, ensure=True) project_id = _cloud_sdk.get_project_id() assert project_id == 'example-project'
def test_get_project_id_windows(): check_output_patch = mock.patch('subprocess.check_output', autospec=True, return_value=CLOUD_SDK_CONFIG_FILE_DATA) with check_output_patch as check_output: project_id = _cloud_sdk.get_project_id() assert project_id == 'example-project' assert check_output.called # Make sure the executable is `gcloud.cmd`. args = check_output.call_args[0] command = args[0] executable = command[0] assert executable == 'gcloud.cmd'
def _get_gcloud_sdk_credentials(): """Gets the credentials and project ID from the Cloud SDK.""" from google.auth import _cloud_sdk # Check if application default credentials exist. credentials_filename = _cloud_sdk.get_application_default_credentials_path() if not os.path.isfile(credentials_filename): return None, None credentials, project_id = load_credentials_from_file(credentials_filename) if not project_id: project_id = _cloud_sdk.get_project_id() return credentials, project_id
def _get_gcloud_sdk_credentials(): """Gets the credentials and project ID from the Cloud SDK.""" from google.auth import _cloud_sdk # Check if application default credentials exist. credentials_filename = ( _cloud_sdk.get_application_default_credentials_path()) if not os.path.isfile(credentials_filename): return None, None credentials, project_id = _load_credentials_from_file( credentials_filename) if not project_id: project_id = _cloud_sdk.get_project_id() return credentials, project_id
def _get_gcloud_sdk_credentials(): """Gets the credentials and project ID from the Cloud SDK.""" from google.auth import _cloud_sdk _LOGGER.debug("Checking Cloud SDK credentials as part of auth process...") # Check if application default credentials exist. credentials_filename = _cloud_sdk.get_application_default_credentials_path() if not os.path.isfile(credentials_filename): _LOGGER.debug("Cloud SDK credentials not found on disk; not using them") return None, None credentials, project_id = load_credentials_from_file(credentials_filename) if not project_id: project_id = _cloud_sdk.get_project_id() return credentials, project_id
def _get_gcloud_sdk_credentials(): """Gets the credentials and project ID from the Cloud SDK.""" # Check if application default credentials exist. credentials_filename = ( _cloud_sdk.get_application_default_credentials_path()) if not os.path.isfile(credentials_filename): return None, None credentials, project_id = _load_credentials_from_file(credentials_filename) if not project_id: project_id = _cloud_sdk.get_project_id() if not project_id: _LOGGER.warning( 'No project ID could be determined from the Cloud SDK ' 'configuration. Consider running `gcloud config set project` or ' 'setting the %s environment variable', environment_vars.PROJECT) return credentials, project_id
def _get_gcloud_sdk_credentials(): """Gets the credentials and project ID from the Cloud SDK.""" from google.auth import _cloud_sdk # Check if application default credentials exist. credentials_filename = ( _cloud_sdk.get_application_default_credentials_path()) if not os.path.isfile(credentials_filename): return None, None credentials, project_id = _load_credentials_from_file( credentials_filename) if not project_id: project_id = _cloud_sdk.get_project_id() if not project_id: _LOGGER.warning( 'No project ID could be determined from the Cloud SDK ' 'configuration. Consider running `gcloud config set project` or ' 'setting the %s environment variable', environment_vars.PROJECT) return credentials, project_id
def test_get_project_id_no_section(config_file): config_file.write('[section]', ensure=True) project_id = _cloud_sdk.get_project_id() assert project_id is None
def test_get_project_id(check_output_mock): project_id = _cloud_sdk.get_project_id() assert project_id == 'example-project'
def test_get_project_id_non_existent(config_file): project_id = _cloud_sdk.get_project_id() assert project_id is None
def test_get_project_id(config_file): config_file.write(CLOUD_SDK_CONFIG_DATA, ensure=True) project_id = _cloud_sdk.get_project_id() assert project_id == 'example-project'
def test_get_project_id_missing_value(check_output_mock): project_id = _cloud_sdk.get_project_id() assert project_id is None
def test_get_project_id_bad_json(check_output_mock): project_id = _cloud_sdk.get_project_id() assert project_id is None
def test_get_project_id_bad_file(config_file): config_file.write('<<<badconfig', ensure=True) project_id = _cloud_sdk.get_project_id() assert project_id is None
def test_get_project_id_call_error(check_output): project_id = _cloud_sdk.get_project_id() assert project_id is None assert check_output.called
def project_id(self): proj = self._get_field('project') if not proj: proj = _cloud_sdk.get_project_id() return proj