def _GetApiDef(api_name, api_version): """Returns the APIDef for the specified API and version. Args: api_name: str, The API name (or the command surface name, if different). api_version: str, The version of the API. Raises: apis_util.UnknownAPIError: If api_name does not exist in the APIs map. apis_util.UnknownVersionError: If api_version does not exist for given api_name in the APIs map. Returns: APIDef, The APIDef for the specified API and version. """ api_name, api_name_alias = _GetApiNameAndAlias(api_name) if api_name not in apis_map.MAP: raise apis_util.UnknownAPIError(api_name) version_overrides = properties.VALUES.api_client_overrides.AllValues() version_override = version_overrides.get(api_name_alias, None) api_version = version_override or api_version api_versions = apis_map.MAP[api_name] if api_version is None or api_version not in api_versions: raise apis_util.UnknownVersionError(api_name, api_version) else: api_def = api_versions[api_version] return api_def
def testUnknownOsloginApiVarsion(self, oslogin_mock): # Should fall through to alternate authentication. properties.VALUES.core.account.Set('*****@*****.**') self.remote = ssh.Remote('23.251.133.75', user='******') oslogin_mock.side_effect = apis_util.UnknownVersionError( 'oslogin', 'v1') self.make_requests.side_effect = iter([ [INSTANCE_WITH_OSLOGIN_ENABLED], [self.project_resource], ]) self.Run(""" compute ssh instance-1 --zone zone-1 """) self.CheckRequests( [(self.compute.instances, 'Get', self.messages.ComputeInstancesGetRequest(instance='instance-1', project='my-project', zone='zone-1'))], [(self.compute.projects, 'Get', self.messages.ComputeProjectsGetRequest(project='my-project'))], ) # Require SSH keys self.ensure_keys.assert_called_once_with(self.keys, None, allow_passphrase=True) # SSH Command self.ssh_init.assert_called_once_with( mock_matchers.TypeMatcher(ssh.SSHCommand), remote=self.remote, identity_file=self.private_key_file, extra_flags=[], tty=None, options=dict(self.options, HostKeyAlias='compute.44444'), remote_command=None, iap_tunnel_args=None, remainder=[]) self.ssh_run.assert_called_once_with(mock_matchers.TypeMatcher( ssh.SSHCommand), self.env, force_connect=True)