def setUp(self): super(TestMetricsIntegrationTests, self).setUp() # Save the original state of the collector. self.original_collector_instance = MetricsCollector.GetCollector() # Set dummy attributes for the collector. MetricsCollector.StartTestCollector('https://example.com', 'user-agent-007', {'a': 'b', 'c': 'd'}) self.collector = MetricsCollector.GetCollector()
def testDisabling(self): """Tests enabling/disabling of metrics collection.""" self.assertEqual(self.collector, MetricsCollector.GetCollector()) # Test when gsutil is part of the Cloud SDK and the user opted in there. with mock.patch.dict(os.environ, values={'CLOUDSDK_WRAPPER': '1', 'GA_CID': '555'}): MetricsCollector._CheckAndSetDisabledCache() self.assertFalse(MetricsCollector._disabled_cache) self.assertEqual(self.collector, MetricsCollector.GetCollector()) # Test when gsutil is part of the Cloud SDK and the user did not opt in # there. with mock.patch.dict(os.environ, values={'CLOUDSDK_WRAPPER': '1', 'GA_CID': ''}): MetricsCollector._CheckAndSetDisabledCache() self.assertTrue(MetricsCollector._disabled_cache) self.assertEqual(None, MetricsCollector.GetCollector()) # Test when gsutil is not part of the Cloud SDK and there is no UUID file. with mock.patch.dict(os.environ, values={'CLOUDSDK_WRAPPER': ''}): with mock.patch('os.path.exists', return_value=False): MetricsCollector._CheckAndSetDisabledCache() self.assertTrue(MetricsCollector._disabled_cache) self.assertEqual(None, MetricsCollector.GetCollector()) # Test when gsutil is not part of the Cloud SDK and there is a UUID file. with mock.patch.dict(os.environ, values={'CLOUDSDK_WRAPPER': ''}): with mock.patch('os.path.exists', return_value=True): MetricsCollector._CheckAndSetDisabledCache() self.assertFalse(MetricsCollector._disabled_cache) self.assertEqual(self.collector, MetricsCollector.GetCollector())
def testDisabling(self): """Tests enabling/disabling of metrics collection.""" self.assertEqual(self.collector, MetricsCollector.GetCollector()) # Test when gsutil is part of the Cloud SDK and the user opted in there. with mock.patch.dict(os.environ, values={'CLOUDSDK_WRAPPER': '1', 'GA_CID': '555'}): MetricsCollector._CheckAndSetDisabledCache() self.assertFalse(MetricsCollector._disabled_cache) self.assertEqual(self.collector, MetricsCollector.GetCollector()) # Test when gsutil is part of the Cloud SDK and the user did not opt in # there. with mock.patch.dict(os.environ, values={'CLOUDSDK_WRAPPER': '1', 'GA_CID': ''}): MetricsCollector._CheckAndSetDisabledCache() self.assertTrue(MetricsCollector._disabled_cache) self.assertEqual(None, MetricsCollector.GetCollector()) # Test when gsutil is not part of the Cloud SDK and there is no UUID file. with mock.patch.dict(os.environ, values={'CLOUDSDK_WRAPPER': ''}): with mock.patch('os.path.exists', return_value=False): MetricsCollector._CheckAndSetDisabledCache() self.assertTrue(MetricsCollector._disabled_cache) self.assertEqual(None, MetricsCollector.GetCollector()) # Test when gsutil is not part of the Cloud SDK and there is a UUID file. with mock.patch.dict(os.environ, values={'CLOUDSDK_WRAPPER': ''}): with mock.patch('os.path.exists', return_value=True): # Mock the contents of the file. with mock.patch('__builtin__.open') as mock_open: mock_open.return_value.__enter__ = lambda s: s # Set the file.read() method to return the disabled text. mock_open.return_value.read.return_value = metrics._DISABLED_TEXT MetricsCollector._CheckAndSetDisabledCache() self.assertTrue(MetricsCollector._disabled_cache) self.assertEqual(None, MetricsCollector.GetCollector()) # Set the file.read() method to return a mock cid (analytics enabled). mock_open.return_value.read.return_value = 'mock_cid' MetricsCollector._CheckAndSetDisabledCache() self.assertFalse(MetricsCollector._disabled_cache) self.assertEqual(self.collector, MetricsCollector.GetCollector()) # Check that open/read was called twice. self.assertEqual(2, len(mock_open.call_args_list)) self.assertEqual(2, len(mock_open.return_value.read.call_args_list))
def setUp(self): super(TestMetricsUnitTests, self).setUp() # Save the original state of the collector. self.original_collector_instance = MetricsCollector.GetCollector() # Set dummy attributes for the collector. MetricsCollector.StartTestCollector('https://example.com', 'user-agent-007', {'a': 'b', 'c': 'd'}) self.collector = MetricsCollector.GetCollector() self.log_handler = MockLoggingHandler() # Use metrics logger to avoid impacting the root logger which may # interfere with other tests. logging.getLogger('metrics').setLevel(logging.DEBUG) logging.getLogger('metrics').addHandler(self.log_handler)
class PubsubV1(base_api.BaseApiClient): """Generated client library for service pubsub version v1.""" MESSAGES_MODULE = messages BASE_URL = u'https://pubsub.googleapis.com/' _PACKAGE = u'pubsub' _SCOPES = [u'https://www.googleapis.com/auth/cloud-platform', u'https://www.googleapis.com/auth/pubsub'] _VERSION = u'v1' _CLIENT_ID = 'nomatter' _CLIENT_SECRET = 'nomatter' _USER_AGENT = 'apitools gsutil/%s Python/%s (%s)' % ( gslib.VERSION, platform.python_version(), sys.platform) if system_util.InvokedViaCloudSdk(): _USER_AGENT += ' google-cloud-sdk' if system_util.CloudSdkVersion(): _USER_AGENT += '/%s' % system_util.CloudSdkVersion() if MetricsCollector.IsDisabled(): _USER_AGENT += ' analytics/disabled' else: _USER_AGENT += ' analytics/enabled' _CLIENT_CLASS_NAME = u'PubsubV1' _URL_VERSION = u'v1' _API_KEY = None def __init__(self, url='', credentials=None, get_credentials=True, http=None, model=None, log_request=False, log_response=False, credentials_args=None, default_global_params=None, additional_http_headers=None): """Create a new pubsub handle.""" url = url or self.BASE_URL super(PubsubV1, self).__init__( url, credentials=credentials, get_credentials=get_credentials, http=http, model=model, log_request=log_request, log_response=log_response, credentials_args=credentials_args, default_global_params=default_global_params, additional_http_headers=additional_http_headers) self.projects_snapshots = self.ProjectsSnapshotsService(self) self.projects_subscriptions = self.ProjectsSubscriptionsService(self) self.projects_topics_subscriptions = self.ProjectsTopicsSubscriptionsService(self) self.projects_topics = self.ProjectsTopicsService(self) self.projects = self.ProjectsService(self) class ProjectsSnapshotsService(base_api.BaseApiService): """Service class for the projects_snapshots resource.""" _NAME = u'projects_snapshots' def __init__(self, client): super(PubsubV1.ProjectsSnapshotsService, self).__init__(client) self._upload_configs = { } def GetIamPolicy(self, request, global_params=None): """Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set. Args: request: (PubsubProjectsSnapshotsGetIamPolicyRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Policy) The response message. """ config = self.GetMethodConfig('GetIamPolicy') return self._RunMethod( config, request, global_params=global_params) GetIamPolicy.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/snapshots/{snapshotsId}:getIamPolicy', http_method=u'GET', method_id=u'pubsub.projects.snapshots.getIamPolicy', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:getIamPolicy', request_field='', request_type_name=u'PubsubProjectsSnapshotsGetIamPolicyRequest', response_type_name=u'Policy', supports_download=False, ) def SetIamPolicy(self, request, global_params=None): """Sets the access control policy on the specified resource. Replaces any. existing policy. Args: request: (PubsubProjectsSnapshotsSetIamPolicyRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Policy) The response message. """ config = self.GetMethodConfig('SetIamPolicy') return self._RunMethod( config, request, global_params=global_params) SetIamPolicy.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/snapshots/{snapshotsId}:setIamPolicy', http_method=u'POST', method_id=u'pubsub.projects.snapshots.setIamPolicy', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:setIamPolicy', request_field=u'setIamPolicyRequest', request_type_name=u'PubsubProjectsSnapshotsSetIamPolicyRequest', response_type_name=u'Policy', supports_download=False, ) def TestIamPermissions(self, request, global_params=None): """Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error. Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning. Args: request: (PubsubProjectsSnapshotsTestIamPermissionsRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (TestIamPermissionsResponse) The response message. """ config = self.GetMethodConfig('TestIamPermissions') return self._RunMethod( config, request, global_params=global_params) TestIamPermissions.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/snapshots/{snapshotsId}:testIamPermissions', http_method=u'POST', method_id=u'pubsub.projects.snapshots.testIamPermissions', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:testIamPermissions', request_field=u'testIamPermissionsRequest', request_type_name=u'PubsubProjectsSnapshotsTestIamPermissionsRequest', response_type_name=u'TestIamPermissionsResponse', supports_download=False, ) class ProjectsSubscriptionsService(base_api.BaseApiService): """Service class for the projects_subscriptions resource.""" _NAME = u'projects_subscriptions' def __init__(self, client): super(PubsubV1.ProjectsSubscriptionsService, self).__init__(client) self._upload_configs = { } def Acknowledge(self, request, global_params=None): """Acknowledges the messages associated with the `ack_ids` in the. `AcknowledgeRequest`. The Pub/Sub system can remove the relevant messages from the subscription. Acknowledging a message whose ack deadline has expired may succeed, but such a message may be redelivered later. Acknowledging a message more than once will not result in an error. Args: request: (PubsubProjectsSubscriptionsAcknowledgeRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Empty) The response message. """ config = self.GetMethodConfig('Acknowledge') return self._RunMethod( config, request, global_params=global_params) Acknowledge.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/subscriptions/{subscriptionsId}:acknowledge', http_method=u'POST', method_id=u'pubsub.projects.subscriptions.acknowledge', ordered_params=[u'subscription'], path_params=[u'subscription'], query_params=[], relative_path=u'v1/{+subscription}:acknowledge', request_field=u'acknowledgeRequest', request_type_name=u'PubsubProjectsSubscriptionsAcknowledgeRequest', response_type_name=u'Empty', supports_download=False, ) def Create(self, request, global_params=None): """Creates a subscription to a given topic. If the subscription already exists, returns `ALREADY_EXISTS`. If the corresponding topic doesn't exist, returns `NOT_FOUND`. If the name is not provided in the request, the server will assign a random name for this subscription on the same project as the topic, conforming to the [resource name format](https://cloud.google.com/pubsub/docs/overview#names). The generated name is populated in the returned Subscription object. Note that for REST API requests, you must specify a name in the request. Args: request: (Subscription) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Subscription) The response message. """ config = self.GetMethodConfig('Create') return self._RunMethod( config, request, global_params=global_params) Create.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/subscriptions/{subscriptionsId}', http_method=u'PUT', method_id=u'pubsub.projects.subscriptions.create', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}', request_field='<request>', request_type_name=u'Subscription', response_type_name=u'Subscription', supports_download=False, ) def Delete(self, request, global_params=None): """Deletes an existing subscription. All messages retained in the subscription. are immediately dropped. Calls to `Pull` after deletion will return `NOT_FOUND`. After a subscription is deleted, a new one may be created with the same name, but the new one has no association with the old subscription or its topic unless the same topic is specified. Args: request: (PubsubProjectsSubscriptionsDeleteRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Empty) The response message. """ config = self.GetMethodConfig('Delete') return self._RunMethod( config, request, global_params=global_params) Delete.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/subscriptions/{subscriptionsId}', http_method=u'DELETE', method_id=u'pubsub.projects.subscriptions.delete', ordered_params=[u'subscription'], path_params=[u'subscription'], query_params=[], relative_path=u'v1/{+subscription}', request_field='', request_type_name=u'PubsubProjectsSubscriptionsDeleteRequest', response_type_name=u'Empty', supports_download=False, ) def Get(self, request, global_params=None): """Gets the configuration details of a subscription. Args: request: (PubsubProjectsSubscriptionsGetRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Subscription) The response message. """ config = self.GetMethodConfig('Get') return self._RunMethod( config, request, global_params=global_params) Get.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/subscriptions/{subscriptionsId}', http_method=u'GET', method_id=u'pubsub.projects.subscriptions.get', ordered_params=[u'subscription'], path_params=[u'subscription'], query_params=[], relative_path=u'v1/{+subscription}', request_field='', request_type_name=u'PubsubProjectsSubscriptionsGetRequest', response_type_name=u'Subscription', supports_download=False, ) def GetIamPolicy(self, request, global_params=None): """Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set. Args: request: (PubsubProjectsSubscriptionsGetIamPolicyRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Policy) The response message. """ config = self.GetMethodConfig('GetIamPolicy') return self._RunMethod( config, request, global_params=global_params) GetIamPolicy.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/subscriptions/{subscriptionsId}:getIamPolicy', http_method=u'GET', method_id=u'pubsub.projects.subscriptions.getIamPolicy', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:getIamPolicy', request_field='', request_type_name=u'PubsubProjectsSubscriptionsGetIamPolicyRequest', response_type_name=u'Policy', supports_download=False, ) def List(self, request, global_params=None): """Lists matching subscriptions. Args: request: (PubsubProjectsSubscriptionsListRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (ListSubscriptionsResponse) The response message. """ config = self.GetMethodConfig('List') return self._RunMethod( config, request, global_params=global_params) List.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/subscriptions', http_method=u'GET', method_id=u'pubsub.projects.subscriptions.list', ordered_params=[u'project'], path_params=[u'project'], query_params=[u'pageSize', u'pageToken'], relative_path=u'v1/{+project}/subscriptions', request_field='', request_type_name=u'PubsubProjectsSubscriptionsListRequest', response_type_name=u'ListSubscriptionsResponse', supports_download=False, ) def ModifyAckDeadline(self, request, global_params=None): """Modifies the ack deadline for a specific message. This method is useful. to indicate that more time is needed to process a message by the subscriber, or to make the message available for redelivery if the processing was interrupted. Note that this does not modify the subscription-level `ackDeadlineSeconds` used for subsequent messages. Args: request: (PubsubProjectsSubscriptionsModifyAckDeadlineRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Empty) The response message. """ config = self.GetMethodConfig('ModifyAckDeadline') return self._RunMethod( config, request, global_params=global_params) ModifyAckDeadline.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/subscriptions/{subscriptionsId}:modifyAckDeadline', http_method=u'POST', method_id=u'pubsub.projects.subscriptions.modifyAckDeadline', ordered_params=[u'subscription'], path_params=[u'subscription'], query_params=[], relative_path=u'v1/{+subscription}:modifyAckDeadline', request_field=u'modifyAckDeadlineRequest', request_type_name=u'PubsubProjectsSubscriptionsModifyAckDeadlineRequest', response_type_name=u'Empty', supports_download=False, ) def ModifyPushConfig(self, request, global_params=None): """Modifies the `PushConfig` for a specified subscription. This may be used to change a push subscription to a pull one (signified by an empty `PushConfig`) or vice versa, or change the endpoint URL and other attributes of a push subscription. Messages will accumulate for delivery continuously through the call regardless of changes to the `PushConfig`. Args: request: (PubsubProjectsSubscriptionsModifyPushConfigRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Empty) The response message. """ config = self.GetMethodConfig('ModifyPushConfig') return self._RunMethod( config, request, global_params=global_params) ModifyPushConfig.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/subscriptions/{subscriptionsId}:modifyPushConfig', http_method=u'POST', method_id=u'pubsub.projects.subscriptions.modifyPushConfig', ordered_params=[u'subscription'], path_params=[u'subscription'], query_params=[], relative_path=u'v1/{+subscription}:modifyPushConfig', request_field=u'modifyPushConfigRequest', request_type_name=u'PubsubProjectsSubscriptionsModifyPushConfigRequest', response_type_name=u'Empty', supports_download=False, ) def Pull(self, request, global_params=None): """Pulls messages from the server. Returns an empty list if there are no. messages available in the backlog. The server may return `UNAVAILABLE` if there are too many concurrent pull requests pending for the given subscription. Args: request: (PubsubProjectsSubscriptionsPullRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (PullResponse) The response message. """ config = self.GetMethodConfig('Pull') return self._RunMethod( config, request, global_params=global_params) Pull.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/subscriptions/{subscriptionsId}:pull', http_method=u'POST', method_id=u'pubsub.projects.subscriptions.pull', ordered_params=[u'subscription'], path_params=[u'subscription'], query_params=[], relative_path=u'v1/{+subscription}:pull', request_field=u'pullRequest', request_type_name=u'PubsubProjectsSubscriptionsPullRequest', response_type_name=u'PullResponse', supports_download=False, ) def SetIamPolicy(self, request, global_params=None): """Sets the access control policy on the specified resource. Replaces any. existing policy. Args: request: (PubsubProjectsSubscriptionsSetIamPolicyRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Policy) The response message. """ config = self.GetMethodConfig('SetIamPolicy') return self._RunMethod( config, request, global_params=global_params) SetIamPolicy.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/subscriptions/{subscriptionsId}:setIamPolicy', http_method=u'POST', method_id=u'pubsub.projects.subscriptions.setIamPolicy', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:setIamPolicy', request_field=u'setIamPolicyRequest', request_type_name=u'PubsubProjectsSubscriptionsSetIamPolicyRequest', response_type_name=u'Policy', supports_download=False, ) def TestIamPermissions(self, request, global_params=None): """Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error. Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning. Args: request: (PubsubProjectsSubscriptionsTestIamPermissionsRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (TestIamPermissionsResponse) The response message. """ config = self.GetMethodConfig('TestIamPermissions') return self._RunMethod( config, request, global_params=global_params) TestIamPermissions.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/subscriptions/{subscriptionsId}:testIamPermissions', http_method=u'POST', method_id=u'pubsub.projects.subscriptions.testIamPermissions', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:testIamPermissions', request_field=u'testIamPermissionsRequest', request_type_name=u'PubsubProjectsSubscriptionsTestIamPermissionsRequest', response_type_name=u'TestIamPermissionsResponse', supports_download=False, ) class ProjectsTopicsSubscriptionsService(base_api.BaseApiService): """Service class for the projects_topics_subscriptions resource.""" _NAME = u'projects_topics_subscriptions' def __init__(self, client): super(PubsubV1.ProjectsTopicsSubscriptionsService, self).__init__(client) self._upload_configs = { } def List(self, request, global_params=None): """Lists the name of the subscriptions for this topic. Args: request: (PubsubProjectsTopicsSubscriptionsListRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (ListTopicSubscriptionsResponse) The response message. """ config = self.GetMethodConfig('List') return self._RunMethod( config, request, global_params=global_params) List.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/topics/{topicsId}/subscriptions', http_method=u'GET', method_id=u'pubsub.projects.topics.subscriptions.list', ordered_params=[u'topic'], path_params=[u'topic'], query_params=[u'pageSize', u'pageToken'], relative_path=u'v1/{+topic}/subscriptions', request_field='', request_type_name=u'PubsubProjectsTopicsSubscriptionsListRequest', response_type_name=u'ListTopicSubscriptionsResponse', supports_download=False, ) class ProjectsTopicsService(base_api.BaseApiService): """Service class for the projects_topics resource.""" _NAME = u'projects_topics' def __init__(self, client): super(PubsubV1.ProjectsTopicsService, self).__init__(client) self._upload_configs = { } def Create(self, request, global_params=None): """Creates the given topic with the given name. Args: request: (Topic) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Topic) The response message. """ config = self.GetMethodConfig('Create') return self._RunMethod( config, request, global_params=global_params) Create.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/topics/{topicsId}', http_method=u'PUT', method_id=u'pubsub.projects.topics.create', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}', request_field='<request>', request_type_name=u'Topic', response_type_name=u'Topic', supports_download=False, ) def Delete(self, request, global_params=None): """Deletes the topic with the given name. Returns `NOT_FOUND` if the topic. does not exist. After a topic is deleted, a new topic may be created with the same name; this is an entirely new topic with none of the old configuration or subscriptions. Existing subscriptions to this topic are not deleted, but their `topic` field is set to `_deleted-topic_`. Args: request: (PubsubProjectsTopicsDeleteRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Empty) The response message. """ config = self.GetMethodConfig('Delete') return self._RunMethod( config, request, global_params=global_params) Delete.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/topics/{topicsId}', http_method=u'DELETE', method_id=u'pubsub.projects.topics.delete', ordered_params=[u'topic'], path_params=[u'topic'], query_params=[], relative_path=u'v1/{+topic}', request_field='', request_type_name=u'PubsubProjectsTopicsDeleteRequest', response_type_name=u'Empty', supports_download=False, ) def Get(self, request, global_params=None): """Gets the configuration of a topic. Args: request: (PubsubProjectsTopicsGetRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Topic) The response message. """ config = self.GetMethodConfig('Get') return self._RunMethod( config, request, global_params=global_params) Get.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/topics/{topicsId}', http_method=u'GET', method_id=u'pubsub.projects.topics.get', ordered_params=[u'topic'], path_params=[u'topic'], query_params=[], relative_path=u'v1/{+topic}', request_field='', request_type_name=u'PubsubProjectsTopicsGetRequest', response_type_name=u'Topic', supports_download=False, ) def GetIamPolicy(self, request, global_params=None): """Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set. Args: request: (PubsubProjectsTopicsGetIamPolicyRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Policy) The response message. """ config = self.GetMethodConfig('GetIamPolicy') return self._RunMethod( config, request, global_params=global_params) GetIamPolicy.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/topics/{topicsId}:getIamPolicy', http_method=u'GET', method_id=u'pubsub.projects.topics.getIamPolicy', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:getIamPolicy', request_field='', request_type_name=u'PubsubProjectsTopicsGetIamPolicyRequest', response_type_name=u'Policy', supports_download=False, ) def List(self, request, global_params=None): """Lists matching topics. Args: request: (PubsubProjectsTopicsListRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (ListTopicsResponse) The response message. """ config = self.GetMethodConfig('List') return self._RunMethod( config, request, global_params=global_params) List.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/topics', http_method=u'GET', method_id=u'pubsub.projects.topics.list', ordered_params=[u'project'], path_params=[u'project'], query_params=[u'pageSize', u'pageToken'], relative_path=u'v1/{+project}/topics', request_field='', request_type_name=u'PubsubProjectsTopicsListRequest', response_type_name=u'ListTopicsResponse', supports_download=False, ) def Publish(self, request, global_params=None): """Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic. does not exist. The message payload must not be empty; it must contain either a non-empty data field, or at least one attribute. Args: request: (PubsubProjectsTopicsPublishRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (PublishResponse) The response message. """ config = self.GetMethodConfig('Publish') return self._RunMethod( config, request, global_params=global_params) Publish.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/topics/{topicsId}:publish', http_method=u'POST', method_id=u'pubsub.projects.topics.publish', ordered_params=[u'topic'], path_params=[u'topic'], query_params=[], relative_path=u'v1/{+topic}:publish', request_field=u'publishRequest', request_type_name=u'PubsubProjectsTopicsPublishRequest', response_type_name=u'PublishResponse', supports_download=False, ) def SetIamPolicy(self, request, global_params=None): """Sets the access control policy on the specified resource. Replaces any. existing policy. Args: request: (PubsubProjectsTopicsSetIamPolicyRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Policy) The response message. """ config = self.GetMethodConfig('SetIamPolicy') return self._RunMethod( config, request, global_params=global_params) SetIamPolicy.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/topics/{topicsId}:setIamPolicy', http_method=u'POST', method_id=u'pubsub.projects.topics.setIamPolicy', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:setIamPolicy', request_field=u'setIamPolicyRequest', request_type_name=u'PubsubProjectsTopicsSetIamPolicyRequest', response_type_name=u'Policy', supports_download=False, ) def TestIamPermissions(self, request, global_params=None): """Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error. Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning. Args: request: (PubsubProjectsTopicsTestIamPermissionsRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (TestIamPermissionsResponse) The response message. """ config = self.GetMethodConfig('TestIamPermissions') return self._RunMethod( config, request, global_params=global_params) TestIamPermissions.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/topics/{topicsId}:testIamPermissions', http_method=u'POST', method_id=u'pubsub.projects.topics.testIamPermissions', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:testIamPermissions', request_field=u'testIamPermissionsRequest', request_type_name=u'PubsubProjectsTopicsTestIamPermissionsRequest', response_type_name=u'TestIamPermissionsResponse', supports_download=False, ) class ProjectsService(base_api.BaseApiService): """Service class for the projects resource.""" _NAME = u'projects' def __init__(self, client): super(PubsubV1.ProjectsService, self).__init__(client) self._upload_configs = { }
class CloudkmsV1(base_api.BaseApiClient): """Generated client library for service cloudkms version v1.""" MESSAGES_MODULE = messages BASE_URL = u'https://cloudkms.googleapis.com/' _PACKAGE = u'cloudkms' _SCOPES = [u'https://www.googleapis.com/auth/cloud-platform'] _VERSION = u'v1' _CLIENT_ID = 'nomatter' _CLIENT_SECRET = 'nomatter' _USER_AGENT = 'apitools gsutil/%s Python/%s (%s)' % ( gslib.VERSION, platform.python_version(), sys.platform) if os.environ.get('CLOUDSDK_WRAPPER') == '1': _USER_AGENT += ' google-cloud-sdk' if os.environ.get('CLOUDSDK_VERSION'): _USER_AGENT += '/%s' % os.environ.get('CLOUDSDK_VERSION') if MetricsCollector.IsDisabled(): _USER_AGENT += ' analytics/disabled' else: _USER_AGENT += ' analytics/enabled' _CLIENT_CLASS_NAME = u'CloudkmsV1' _URL_VERSION = u'v1' _API_KEY = None def __init__(self, url='', credentials=None, get_credentials=True, http=None, model=None, log_request=False, log_response=False, credentials_args=None, default_global_params=None, additional_http_headers=None): """Create a new cloudkms handle.""" url = url or self.BASE_URL super(CloudkmsV1, self).__init__(url, credentials=credentials, get_credentials=get_credentials, http=http, model=model, log_request=log_request, log_response=log_response, credentials_args=credentials_args, default_global_params=default_global_params, additional_http_headers=additional_http_headers) self.projects_locations_keyRings_cryptoKeys_cryptoKeyVersions = self.ProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsService( self) self.projects_locations_keyRings_cryptoKeys = self.ProjectsLocationsKeyRingsCryptoKeysService( self) self.projects_locations_keyRings = self.ProjectsLocationsKeyRingsService( self) self.projects_locations = self.ProjectsLocationsService(self) self.projects = self.ProjectsService(self) class ProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsService( base_api.BaseApiService): """Service class for the projects_locations_keyRings_cryptoKeys_cryptoKeyVersions resource.""" _NAME = u'projects_locations_keyRings_cryptoKeys_cryptoKeyVersions' def __init__(self, client): super( CloudkmsV1. ProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsService, self).__init__(client) self._upload_configs = {} def Create(self, request, global_params=None): """Create a new CryptoKeyVersion in a CryptoKey. The server will assign the next sequential id. If unset, state will be set to ENABLED. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsCreateRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (CryptoKeyVersion) The response message. """ config = self.GetMethodConfig('Create') return self._RunMethod(config, request, global_params=global_params) Create.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}/cryptoKeyVersions', http_method=u'POST', method_id= u'cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.create', ordered_params=[u'parent'], path_params=[u'parent'], query_params=[], relative_path=u'v1/{+parent}/cryptoKeyVersions', request_field=u'cryptoKeyVersion', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsCreateRequest', response_type_name=u'CryptoKeyVersion', supports_download=False, ) def Destroy(self, request, global_params=None): """Schedule a CryptoKeyVersion for destruction. Upon calling this method, CryptoKeyVersion.state will be set to DESTROY_SCHEDULED and destroy_time will be set to a time 24 hours in the future, at which point the state will be changed to DESTROYED, and the key material will be irrevocably destroyed. Before the destroy_time is reached, RestoreCryptoKeyVersion may be called to reverse the process. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsDestroyRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (CryptoKeyVersion) The response message. """ config = self.GetMethodConfig('Destroy') return self._RunMethod(config, request, global_params=global_params) Destroy.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}/cryptoKeyVersions/{cryptoKeyVersionsId}:destroy', http_method=u'POST', method_id= u'cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.destroy', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}:destroy', request_field=u'destroyCryptoKeyVersionRequest', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsDestroyRequest', response_type_name=u'CryptoKeyVersion', supports_download=False, ) def Get(self, request, global_params=None): """Returns metadata for a given CryptoKeyVersion. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsGetRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (CryptoKeyVersion) The response message. """ config = self.GetMethodConfig('Get') return self._RunMethod(config, request, global_params=global_params) Get.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}/cryptoKeyVersions/{cryptoKeyVersionsId}', http_method=u'GET', method_id= u'cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.get', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}', request_field='', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsGetRequest', response_type_name=u'CryptoKeyVersion', supports_download=False, ) def List(self, request, global_params=None): """Lists CryptoKeyVersions. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsListRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (ListCryptoKeyVersionsResponse) The response message. """ config = self.GetMethodConfig('List') return self._RunMethod(config, request, global_params=global_params) List.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}/cryptoKeyVersions', http_method=u'GET', method_id= u'cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.list', ordered_params=[u'parent'], path_params=[u'parent'], query_params=[u'pageSize', u'pageToken'], relative_path=u'v1/{+parent}/cryptoKeyVersions', request_field='', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsListRequest', response_type_name=u'ListCryptoKeyVersionsResponse', supports_download=False, ) def Patch(self, request, global_params=None): """Update a CryptoKeyVersion's metadata. state may be changed between ENABLED and DISABLED using this method. See DestroyCryptoKeyVersion and RestoreCryptoKeyVersion to move between other states. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsPatchRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (CryptoKeyVersion) The response message. """ config = self.GetMethodConfig('Patch') return self._RunMethod(config, request, global_params=global_params) Patch.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}/cryptoKeyVersions/{cryptoKeyVersionsId}', http_method=u'PATCH', method_id= u'cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.patch', ordered_params=[u'name'], path_params=[u'name'], query_params=[u'updateMask'], relative_path=u'v1/{+name}', request_field=u'cryptoKeyVersion', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsPatchRequest', response_type_name=u'CryptoKeyVersion', supports_download=False, ) def Restore(self, request, global_params=None): """Restore a CryptoKeyVersion in the. DESTROY_SCHEDULED, state. Upon restoration of the CryptoKeyVersion, state will be set to DISABLED, and destroy_time will be cleared. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsRestoreRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (CryptoKeyVersion) The response message. """ config = self.GetMethodConfig('Restore') return self._RunMethod(config, request, global_params=global_params) Restore.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}/cryptoKeyVersions/{cryptoKeyVersionsId}:restore', http_method=u'POST', method_id= u'cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.restore', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}:restore', request_field=u'restoreCryptoKeyVersionRequest', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsRestoreRequest', response_type_name=u'CryptoKeyVersion', supports_download=False, ) class ProjectsLocationsKeyRingsCryptoKeysService(base_api.BaseApiService): """Service class for the projects_locations_keyRings_cryptoKeys resource.""" _NAME = u'projects_locations_keyRings_cryptoKeys' def __init__(self, client): super(CloudkmsV1.ProjectsLocationsKeyRingsCryptoKeysService, self).__init__(client) self._upload_configs = {} def Create(self, request, global_params=None): """Create a new CryptoKey within a KeyRing. CryptoKey.purpose is required. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysCreateRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (CryptoKey) The response message. """ config = self.GetMethodConfig('Create') return self._RunMethod(config, request, global_params=global_params) Create.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys', http_method=u'POST', method_id= u'cloudkms.projects.locations.keyRings.cryptoKeys.create', ordered_params=[u'parent'], path_params=[u'parent'], query_params=[u'cryptoKeyId'], relative_path=u'v1/{+parent}/cryptoKeys', request_field=u'cryptoKey', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysCreateRequest', response_type_name=u'CryptoKey', supports_download=False, ) def Decrypt(self, request, global_params=None): """Decrypts data that was protected by Encrypt. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysDecryptRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (DecryptResponse) The response message. """ config = self.GetMethodConfig('Decrypt') return self._RunMethod(config, request, global_params=global_params) Decrypt.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}:decrypt', http_method=u'POST', method_id= u'cloudkms.projects.locations.keyRings.cryptoKeys.decrypt', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}:decrypt', request_field=u'decryptRequest', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysDecryptRequest', response_type_name=u'DecryptResponse', supports_download=False, ) def Encrypt(self, request, global_params=None): """Encrypts data, so that it can only be recovered by a call to Decrypt. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysEncryptRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (EncryptResponse) The response message. """ config = self.GetMethodConfig('Encrypt') return self._RunMethod(config, request, global_params=global_params) Encrypt.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}:encrypt', http_method=u'POST', method_id= u'cloudkms.projects.locations.keyRings.cryptoKeys.encrypt', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}:encrypt', request_field=u'encryptRequest', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysEncryptRequest', response_type_name=u'EncryptResponse', supports_download=False, ) def Get(self, request, global_params=None): """Returns metadata for a given CryptoKey, as well as its. primary CryptoKeyVersion. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysGetRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (CryptoKey) The response message. """ config = self.GetMethodConfig('Get') return self._RunMethod(config, request, global_params=global_params) Get.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}', http_method=u'GET', method_id=u'cloudkms.projects.locations.keyRings.cryptoKeys.get', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}', request_field='', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysGetRequest', response_type_name=u'CryptoKey', supports_download=False, ) def GetIamPolicy(self, request, global_params=None): """Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysGetIamPolicyRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Policy) The response message. """ config = self.GetMethodConfig('GetIamPolicy') return self._RunMethod(config, request, global_params=global_params) GetIamPolicy.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}:getIamPolicy', http_method=u'GET', method_id= u'cloudkms.projects.locations.keyRings.cryptoKeys.getIamPolicy', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:getIamPolicy', request_field='', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysGetIamPolicyRequest', response_type_name=u'Policy', supports_download=False, ) def List(self, request, global_params=None): """Lists CryptoKeys. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysListRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (ListCryptoKeysResponse) The response message. """ config = self.GetMethodConfig('List') return self._RunMethod(config, request, global_params=global_params) List.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys', http_method=u'GET', method_id=u'cloudkms.projects.locations.keyRings.cryptoKeys.list', ordered_params=[u'parent'], path_params=[u'parent'], query_params=[u'pageSize', u'pageToken'], relative_path=u'v1/{+parent}/cryptoKeys', request_field='', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysListRequest', response_type_name=u'ListCryptoKeysResponse', supports_download=False, ) def Patch(self, request, global_params=None): """Update a CryptoKey. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysPatchRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (CryptoKey) The response message. """ config = self.GetMethodConfig('Patch') return self._RunMethod(config, request, global_params=global_params) Patch.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}', http_method=u'PATCH', method_id=u'cloudkms.projects.locations.keyRings.cryptoKeys.patch', ordered_params=[u'name'], path_params=[u'name'], query_params=[u'updateMask'], relative_path=u'v1/{+name}', request_field=u'cryptoKey', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysPatchRequest', response_type_name=u'CryptoKey', supports_download=False, ) def SetIamPolicy(self, request, global_params=None): """Sets the access control policy on the specified resource. Replaces any. existing policy. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysSetIamPolicyRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Policy) The response message. """ config = self.GetMethodConfig('SetIamPolicy') return self._RunMethod(config, request, global_params=global_params) SetIamPolicy.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}:setIamPolicy', http_method=u'POST', method_id= u'cloudkms.projects.locations.keyRings.cryptoKeys.setIamPolicy', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:setIamPolicy', request_field=u'setIamPolicyRequest', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysSetIamPolicyRequest', response_type_name=u'Policy', supports_download=False, ) def TestIamPermissions(self, request, global_params=None): """Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error. Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysTestIamPermissionsRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (TestIamPermissionsResponse) The response message. """ config = self.GetMethodConfig('TestIamPermissions') return self._RunMethod(config, request, global_params=global_params) TestIamPermissions.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}:testIamPermissions', http_method=u'POST', method_id= u'cloudkms.projects.locations.keyRings.cryptoKeys.testIamPermissions', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:testIamPermissions', request_field=u'testIamPermissionsRequest', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysTestIamPermissionsRequest', response_type_name=u'TestIamPermissionsResponse', supports_download=False, ) def UpdatePrimaryVersion(self, request, global_params=None): """Update the version of a CryptoKey that will be used in Encrypt. Args: request: (CloudkmsProjectsLocationsKeyRingsCryptoKeysUpdatePrimaryVersionRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (CryptoKey) The response message. """ config = self.GetMethodConfig('UpdatePrimaryVersion') return self._RunMethod(config, request, global_params=global_params) UpdatePrimaryVersion.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}/cryptoKeys/{cryptoKeysId}:updatePrimaryVersion', http_method=u'POST', method_id= u'cloudkms.projects.locations.keyRings.cryptoKeys.updatePrimaryVersion', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}:updatePrimaryVersion', request_field=u'updateCryptoKeyPrimaryVersionRequest', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCryptoKeysUpdatePrimaryVersionRequest', response_type_name=u'CryptoKey', supports_download=False, ) class ProjectsLocationsKeyRingsService(base_api.BaseApiService): """Service class for the projects_locations_keyRings resource.""" _NAME = u'projects_locations_keyRings' def __init__(self, client): super(CloudkmsV1.ProjectsLocationsKeyRingsService, self).__init__(client) self._upload_configs = {} def Create(self, request, global_params=None): """Create a new KeyRing in a given Project and Location. Args: request: (CloudkmsProjectsLocationsKeyRingsCreateRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (KeyRing) The response message. """ config = self.GetMethodConfig('Create') return self._RunMethod(config, request, global_params=global_params) Create.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings', http_method=u'POST', method_id=u'cloudkms.projects.locations.keyRings.create', ordered_params=[u'parent'], path_params=[u'parent'], query_params=[u'keyRingId'], relative_path=u'v1/{+parent}/keyRings', request_field=u'keyRing', request_type_name= u'CloudkmsProjectsLocationsKeyRingsCreateRequest', response_type_name=u'KeyRing', supports_download=False, ) def Get(self, request, global_params=None): """Returns metadata for a given KeyRing. Args: request: (CloudkmsProjectsLocationsKeyRingsGetRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (KeyRing) The response message. """ config = self.GetMethodConfig('Get') return self._RunMethod(config, request, global_params=global_params) Get.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}', http_method=u'GET', method_id=u'cloudkms.projects.locations.keyRings.get', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}', request_field='', request_type_name=u'CloudkmsProjectsLocationsKeyRingsGetRequest', response_type_name=u'KeyRing', supports_download=False, ) def GetIamPolicy(self, request, global_params=None): """Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set. Args: request: (CloudkmsProjectsLocationsKeyRingsGetIamPolicyRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Policy) The response message. """ config = self.GetMethodConfig('GetIamPolicy') return self._RunMethod(config, request, global_params=global_params) GetIamPolicy.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}:getIamPolicy', http_method=u'GET', method_id=u'cloudkms.projects.locations.keyRings.getIamPolicy', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:getIamPolicy', request_field='', request_type_name= u'CloudkmsProjectsLocationsKeyRingsGetIamPolicyRequest', response_type_name=u'Policy', supports_download=False, ) def List(self, request, global_params=None): """Lists KeyRings. Args: request: (CloudkmsProjectsLocationsKeyRingsListRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (ListKeyRingsResponse) The response message. """ config = self.GetMethodConfig('List') return self._RunMethod(config, request, global_params=global_params) List.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings', http_method=u'GET', method_id=u'cloudkms.projects.locations.keyRings.list', ordered_params=[u'parent'], path_params=[u'parent'], query_params=[u'pageSize', u'pageToken'], relative_path=u'v1/{+parent}/keyRings', request_field='', request_type_name=u'CloudkmsProjectsLocationsKeyRingsListRequest', response_type_name=u'ListKeyRingsResponse', supports_download=False, ) def SetIamPolicy(self, request, global_params=None): """Sets the access control policy on the specified resource. Replaces any. existing policy. Args: request: (CloudkmsProjectsLocationsKeyRingsSetIamPolicyRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Policy) The response message. """ config = self.GetMethodConfig('SetIamPolicy') return self._RunMethod(config, request, global_params=global_params) SetIamPolicy.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}:setIamPolicy', http_method=u'POST', method_id=u'cloudkms.projects.locations.keyRings.setIamPolicy', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:setIamPolicy', request_field=u'setIamPolicyRequest', request_type_name= u'CloudkmsProjectsLocationsKeyRingsSetIamPolicyRequest', response_type_name=u'Policy', supports_download=False, ) def TestIamPermissions(self, request, global_params=None): """Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error. Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning. Args: request: (CloudkmsProjectsLocationsKeyRingsTestIamPermissionsRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (TestIamPermissionsResponse) The response message. """ config = self.GetMethodConfig('TestIamPermissions') return self._RunMethod(config, request, global_params=global_params) TestIamPermissions.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/locations/{locationsId}/keyRings/{keyRingsId}:testIamPermissions', http_method=u'POST', method_id= u'cloudkms.projects.locations.keyRings.testIamPermissions', ordered_params=[u'resource'], path_params=[u'resource'], query_params=[], relative_path=u'v1/{+resource}:testIamPermissions', request_field=u'testIamPermissionsRequest', request_type_name= u'CloudkmsProjectsLocationsKeyRingsTestIamPermissionsRequest', response_type_name=u'TestIamPermissionsResponse', supports_download=False, ) class ProjectsLocationsService(base_api.BaseApiService): """Service class for the projects_locations resource.""" _NAME = u'projects_locations' def __init__(self, client): super(CloudkmsV1.ProjectsLocationsService, self).__init__(client) self._upload_configs = {} def Get(self, request, global_params=None): """Get information about a location. Args: request: (CloudkmsProjectsLocationsGetRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Location) The response message. """ config = self.GetMethodConfig('Get') return self._RunMethod(config, request, global_params=global_params) Get.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/locations/{locationsId}', http_method=u'GET', method_id=u'cloudkms.projects.locations.get', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}', request_field='', request_type_name=u'CloudkmsProjectsLocationsGetRequest', response_type_name=u'Location', supports_download=False, ) def List(self, request, global_params=None): """Lists information about the supported locations for this service. Args: request: (CloudkmsProjectsLocationsListRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (ListLocationsResponse) The response message. """ config = self.GetMethodConfig('List') return self._RunMethod(config, request, global_params=global_params) List.method_config = lambda: base_api.ApiMethodInfo( flat_path=u'v1/projects/{projectsId}/locations', http_method=u'GET', method_id=u'cloudkms.projects.locations.list', ordered_params=[u'name'], path_params=[u'name'], query_params=[u'filter', u'pageSize', u'pageToken'], relative_path=u'v1/{+name}/locations', request_field='', request_type_name=u'CloudkmsProjectsLocationsListRequest', response_type_name=u'ListLocationsResponse', supports_download=False, ) class ProjectsService(base_api.BaseApiService): """Service class for the projects resource.""" _NAME = u'projects' def __init__(self, client): super(CloudkmsV1.ProjectsService, self).__init__(client) self._upload_configs = {}
def tearDown(self): super(TestMetricsIntegrationTests, self).tearDown() # Reset to default collection settings. MetricsCollector.StopTestCollector( original_instance=self.original_collector_instance)
def testDisabling(self): """Tests enabling/disabling of metrics collection.""" self.assertEqual(self.collector, MetricsCollector.GetCollector()) # Test when gsutil is part of the Cloud SDK and the user opted in there. with mock.patch.dict(os.environ, values={ 'CLOUDSDK_WRAPPER': '1', 'GA_CID': '555' }): MetricsCollector._CheckAndSetDisabledCache() self.assertFalse(MetricsCollector._disabled_cache) self.assertEqual(self.collector, MetricsCollector.GetCollector()) # Test when gsutil is part of the Cloud SDK and the user did not opt in # there. with mock.patch.dict(os.environ, values={ 'CLOUDSDK_WRAPPER': '1', 'GA_CID': '' }): MetricsCollector._CheckAndSetDisabledCache() self.assertTrue(MetricsCollector._disabled_cache) self.assertEqual(None, MetricsCollector.GetCollector()) # Test when gsutil is not part of the Cloud SDK and there is no UUID file. with mock.patch.dict(os.environ, values={'CLOUDSDK_WRAPPER': ''}): with mock.patch('os.path.exists', return_value=False): MetricsCollector._CheckAndSetDisabledCache() self.assertTrue(MetricsCollector._disabled_cache) self.assertEqual(None, MetricsCollector.GetCollector()) # Test when gsutil is not part of the Cloud SDK and there is a UUID file. with mock.patch.dict(os.environ, values={'CLOUDSDK_WRAPPER': ''}): with mock.patch('os.path.exists', return_value=True): # Mock the contents of the file. with mock.patch('__builtin__.open') as mock_open: mock_open.return_value.__enter__ = lambda s: s # Set the file.read() method to return the disabled text. mock_open.return_value.read.return_value = metrics._DISABLED_TEXT MetricsCollector._CheckAndSetDisabledCache() self.assertTrue(MetricsCollector._disabled_cache) self.assertEqual(None, MetricsCollector.GetCollector()) # Set the file.read() method to return a mock cid (analytics enabled). mock_open.return_value.read.return_value = 'mock_cid' MetricsCollector._CheckAndSetDisabledCache() self.assertFalse(MetricsCollector._disabled_cache) self.assertEqual(self.collector, MetricsCollector.GetCollector()) # Check that open/read was called twice. self.assertEqual(2, len(mock_open.call_args_list)) self.assertEqual( 2, len(mock_open.return_value.read.call_args_list))
def testDisabling(self): """Tests enabling/disabling of metrics collection.""" self.assertEqual(self.collector, MetricsCollector.GetCollector()) # Test when gsutil is part of the Cloud SDK and the user opted in there. with mock.patch.dict(os.environ, values={ 'CLOUDSDK_WRAPPER': '1', 'GA_CID': '555' }): MetricsCollector._CheckAndSetDisabledCache() self.assertFalse(MetricsCollector._disabled_cache) self.assertEqual(self.collector, MetricsCollector.GetCollector()) # Test when gsutil is part of the Cloud SDK and the user did not opt in # there. with mock.patch.dict(os.environ, values={ 'CLOUDSDK_WRAPPER': '1', 'GA_CID': '' }): MetricsCollector._CheckAndSetDisabledCache() self.assertTrue(MetricsCollector._disabled_cache) self.assertEqual(None, MetricsCollector.GetCollector()) # Test when gsutil is not part of the Cloud SDK and there is no UUID file. with mock.patch.dict(os.environ, values={'CLOUDSDK_WRAPPER': ''}): with mock.patch('os.path.exists', return_value=False): MetricsCollector._CheckAndSetDisabledCache() self.assertTrue(MetricsCollector._disabled_cache) self.assertEqual(None, MetricsCollector.GetCollector()) # Test when gsutil is not part of the Cloud SDK and there is a UUID file. with mock.patch.dict(os.environ, values={'CLOUDSDK_WRAPPER': ''}): with mock.patch('os.path.exists', return_value=True): MetricsCollector._CheckAndSetDisabledCache() self.assertFalse(MetricsCollector._disabled_cache) self.assertEqual(self.collector, MetricsCollector.GetCollector())
class IamcredentialsV1(base_api.BaseApiClient): """Generated client library for service iamcredentials version v1.""" MESSAGES_MODULE = messages BASE_URL = u'https://iamcredentials.googleapis.com/' _PACKAGE = u'iamcredentials' _SCOPES = [u'https://www.googleapis.com/auth/cloud-platform'] _VERSION = u'v1' _CLIENT_ID = 'nomatter' _CLIENT_SECRET = 'nomatter' _USER_AGENT = 'apitools gsutil/%s Python/%s (%s)' % ( gslib.VERSION, platform.python_version(), sys.platform) if system_util.InvokedViaCloudSdk(): _USER_AGENT += ' google-cloud-sdk' if system_util.CloudSdkVersion(): _USER_AGENT += '/%s' % system_util.CloudSdkVersion() if MetricsCollector.IsDisabled(): _USER_AGENT += ' analytics/disabled' else: _USER_AGENT += ' analytics/enabled' _CLIENT_CLASS_NAME = u'IamcredentialsV1' _URL_VERSION = u'v1' _API_KEY = None def __init__(self, url='', credentials=None, get_credentials=True, http=None, model=None, log_request=False, log_response=False, credentials_args=None, default_global_params=None, additional_http_headers=None, response_encoding=None): """Create a new iamcredentials handle.""" url = url or self.BASE_URL super(IamcredentialsV1, self).__init__(url, credentials=credentials, get_credentials=get_credentials, http=http, model=model, log_request=log_request, log_response=log_response, credentials_args=credentials_args, default_global_params=default_global_params, additional_http_headers=additional_http_headers, response_encoding=response_encoding) self.projects_serviceAccounts = self.ProjectsServiceAccountsService( self) self.projects = self.ProjectsService(self) class ProjectsServiceAccountsService(base_api.BaseApiService): """Service class for the projects_serviceAccounts resource.""" _NAME = u'projects_serviceAccounts' def __init__(self, client): super(IamcredentialsV1.ProjectsServiceAccountsService, self).__init__(client) self._upload_configs = {} def GenerateAccessToken(self, request, global_params=None): """Generates an OAuth 2.0 access token for a service account. Args: request: (IamcredentialsProjectsServiceAccountsGenerateAccessTokenRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (GenerateAccessTokenResponse) The response message. """ config = self.GetMethodConfig('GenerateAccessToken') return self._RunMethod(config, request, global_params=global_params) GenerateAccessToken.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/serviceAccounts/{serviceAccountsId}:generateAccessToken', http_method=u'POST', method_id= u'iamcredentials.projects.serviceAccounts.generateAccessToken', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}:generateAccessToken', request_field=u'generateAccessTokenRequest', request_type_name= u'IamcredentialsProjectsServiceAccountsGenerateAccessTokenRequest', response_type_name=u'GenerateAccessTokenResponse', supports_download=False, ) def GenerateIdToken(self, request, global_params=None): r"""Generates an OpenID Connect ID token for a service account. Args: request: (IamcredentialsProjectsServiceAccountsGenerateIdTokenRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (GenerateIdTokenResponse) The response message. """ config = self.GetMethodConfig('GenerateIdToken') return self._RunMethod(config, request, global_params=global_params) GenerateIdToken.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/serviceAccounts/{serviceAccountsId}:generateIdToken', http_method=u'POST', method_id= u'iamcredentials.projects.serviceAccounts.generateIdToken', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}:generateIdToken', request_field=u'generateIdTokenRequest', request_type_name= u'IamcredentialsProjectsServiceAccountsGenerateIdTokenRequest', response_type_name=u'GenerateIdTokenResponse', supports_download=False, ) def SignBlob(self, request, global_params=None): r"""Signs a blob using a service account's system-managed private key. Args: request: (IamcredentialsProjectsServiceAccountsSignBlobRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (SignBlobResponse) The response message. """ config = self.GetMethodConfig('SignBlob') return self._RunMethod(config, request, global_params=global_params) SignBlob.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/serviceAccounts/{serviceAccountsId}:signBlob', http_method=u'POST', method_id=u'iamcredentials.projects.serviceAccounts.signBlob', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}:signBlob', request_field=u'signBlobRequest', request_type_name= u'IamcredentialsProjectsServiceAccountsSignBlobRequest', response_type_name=u'SignBlobResponse', supports_download=False, ) def SignJwt(self, request, global_params=None): r"""Signs a JWT using a service account's system-managed private key. Args: request: (IamcredentialsProjectsServiceAccountsSignJwtRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (SignJwtResponse) The response message. """ config = self.GetMethodConfig('SignJwt') return self._RunMethod(config, request, global_params=global_params) SignJwt.method_config = lambda: base_api.ApiMethodInfo( flat_path= u'v1/projects/{projectsId}/serviceAccounts/{serviceAccountsId}:signJwt', http_method=u'POST', method_id=u'iamcredentials.projects.serviceAccounts.signJwt', ordered_params=[u'name'], path_params=[u'name'], query_params=[], relative_path=u'v1/{+name}:signJwt', request_field=u'signJwtRequest', request_type_name= u'IamcredentialsProjectsServiceAccountsSignJwtRequest', response_type_name=u'SignJwtResponse', supports_download=False, ) class ProjectsService(base_api.BaseApiService): """Service class for the projects resource.""" _NAME = u'projects' def __init__(self, client): super(IamcredentialsV1.ProjectsService, self).__init__(client) self._upload_configs = {}