Esempio n. 1
0
 def test_construct_settings_override(self):
     _override = {
         'interfaces': {
             _SERVICE_NAME: {
                 'methods': {
                     'PageStreamingMethod': None,
                     'BundlingMethod': {
                         'timeout_millis': 8000,
                         'bundling': None
                     }
                 }
             }
         }
     }
     defaults = api_callable.construct_settings(
         _SERVICE_NAME, _A_CONFIG, _override, _RETRY_DICT,
         bundle_descriptors=_BUNDLE_DESCRIPTORS,
         page_descriptors=_PAGE_DESCRIPTORS)
     settings = defaults['bundling_method']
     self.assertAlmostEqual(settings.timeout, 8.0)
     self.assertIsNone(settings.bundler)
     self.assertIsNone(settings.page_descriptor)
     settings = defaults['page_streaming_method']
     self.assertAlmostEqual(settings.timeout, 12.0)
     self.assertIsInstance(settings.page_descriptor, PageDescriptor)
     self.assertIsNone(settings.retry)
Esempio n. 2
0
 def test_construct_settings_override(self):
     _override = {
         'interfaces': {
             _SERVICE_NAME: {
                 'methods': {
                     'PageStreamingMethod': None,
                     'BundlingMethod': {
                         'timeout_millis': 8000,
                         'bundling': None
                     }
                 }
             }
         }
     }
     defaults = api_callable.construct_settings(
         _SERVICE_NAME,
         _A_CONFIG,
         _override,
         _RETRY_DICT,
         bundle_descriptors=_BUNDLE_DESCRIPTORS,
         page_descriptors=_PAGE_DESCRIPTORS)
     settings = defaults['bundling_method']
     self.assertAlmostEqual(settings.timeout, 8.0)
     self.assertIsNone(settings.bundler)
     self.assertIsNone(settings.page_descriptor)
     settings = defaults['page_streaming_method']
     self.assertAlmostEqual(settings.timeout, 12.0)
     self.assertIsInstance(settings.page_descriptor, PageDescriptor)
     self.assertIsNone(settings.retry)
Esempio n. 3
0
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 metadata_transformer=None,
                 ssl_creds=None,
                 scopes=None,
                 client_config=None,
                 app_name='gax',
                 app_version=_GAX_VERSION):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.beta.implementations.Channel`): A ``Channel``
            object through which to make calls.
          ssl_creds (:class:`grpc.beta.implementations.ClientCredentials`):
            A `ClientCredentials` for use with an SSL-enabled channel.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          metadata_transformer (Callable[[], list]): A function that creates
             the metadata for requests.
          app_name (string): The codename of the calling service.
          app_version (string): The version of the calling service.

        Returns:
          A ImageAnnotatorApi object.
        """
        if scopes is None:
            scopes = self._ALL_SCOPES
        if client_config is None:
            client_config = {}
        goog_api_client = '{}/{} {} gax/{} python/{}'.format(
            app_name, app_version, self._CODE_GEN_NAME_VERSION,
            self._GAX_VERSION, platform.python_version())
        metadata = [('x-goog-api-client', goog_api_client)]
        default_client_config = json.loads(
            pkg_resources.resource_string(
                __name__, 'image_annotator_client_config.json').decode())
        defaults = api_callable.construct_settings(
            'google.cloud.vision.v1.ImageAnnotator',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            kwargs={'metadata': metadata})
        self.stub = config.create_stub(
            image_annotator_pb2.beta_create_ImageAnnotator_stub,
            service_path,
            port,
            ssl_creds=ssl_creds,
            channel=channel,
            metadata_transformer=metadata_transformer,
            scopes=scopes)
        self._batch_annotate_images = api_callable.create_api_call(
            self.stub.BatchAnnotateImages,
            settings=defaults['batch_annotate_images'])
Esempio n. 4
0
    def test_construct_settings(self):
        defaults = api_callable.construct_settings(
            _SERVICE_NAME,
            _A_CONFIG,
            dict(),
            _RETRY_DICT,
            bundle_descriptors=_BUNDLE_DESCRIPTORS,
            page_descriptors=_PAGE_DESCRIPTORS,
            kwargs={'key1': 'value1'})

        # Check values of the bundling method settings.
        settings = defaults['bundling_method']
        self.assertAlmostEqual(settings.timeout, 25.0)
        self.assertIsInstance(settings.bundler, bundling.Executor)
        self.assertIsInstance(settings.bundle_descriptor, BundleDescriptor)
        self.assertIsNone(settings.page_descriptor)

        # Check values of the page streaming method settings.
        settings = defaults['page_streaming_method']
        self.assertAlmostEqual(settings.timeout, 12.0)
        self.assertIsNone(settings.bundler)
        self.assertIsNone(settings.bundle_descriptor)
        self.assertIsInstance(settings.page_descriptor, PageDescriptor)

        # Check values that should be the same in both method settings.
        for settings in defaults.values():
            self.assertIsInstance(settings.retry, RetryOptions)
            self.assertEqual(settings.kwargs['key1'], 'value1')
            self.assertIn('metadata', settings.kwargs)
            metadata = settings.kwargs['metadata'][0][1]
            self.assertIn('gl-python/%s' % platform.python_version(), metadata)
            self.assertIn('gax/%s' % GAX_VERSION, metadata)
            self.assertIn('grpc/%s' % GRPC_VERSION, metadata)
Esempio n. 5
0
    def test_construct_settings_override2(self):
        _override = {
            'interfaces': {
                _SERVICE_NAME: {
                    'retry_codes': {
                        'bar_retry': [],
                        'baz_retry': ['code_a']
                    },
                    'retry_params': {
                        'default': {
                            'initial_retry_delay_millis': 1000,
                            'retry_delay_multiplier': 1.2,
                            'max_retry_delay_millis': 10000,
                            'initial_rpc_timeout_millis': 3000,
                            'rpc_timeout_multiplier': 1.3,
                            'max_rpc_timeout_millis': 30000,
                            'total_timeout_millis': 300000
                        },
                    },
                    'methods': {
                        'BundlingMethod': {
                            'retry_params_name': 'default',
                            'retry_codes_name': 'baz_retry',
                        },
                    },
                }
            }
        }
        defaults = api_callable.construct_settings(
            _SERVICE_NAME,
            _A_CONFIG,
            _override,
            _RETRY_DICT,
            bundle_descriptors=_BUNDLE_DESCRIPTORS,
            page_descriptors=_PAGE_DESCRIPTORS)
        settings = defaults['bundling_method']
        backoff = settings.retry.backoff_settings
        self.assertEqual(backoff.initial_retry_delay_millis, 1000)
        self.assertEqual(settings.retry.retry_codes, [_RETRY_DICT['code_a']])
        self.assertIsInstance(settings.bundler, bundling.Executor)
        self.assertIsInstance(settings.bundle_descriptor, BundleDescriptor)

        # page_streaming_method is unaffected because it's not specified in
        # overrides. 'bar_retry' or 'default' definitions in overrides should
        # not affect the methods which are not in the overrides.
        settings = defaults['page_streaming_method']
        backoff = settings.retry.backoff_settings
        self.assertEqual(backoff.initial_retry_delay_millis, 100)
        self.assertEqual(backoff.retry_delay_multiplier, 1.2)
        self.assertEqual(backoff.max_retry_delay_millis, 1000)
        self.assertEqual(settings.retry.retry_codes, [_RETRY_DICT['code_c']])
Esempio n. 6
0
 def test_construct_settings_override(self):
     _bundling_override = {'bundling_method': None}
     _retry_override = {'page_streaming_method': None}
     defaults = api_callable.construct_settings(
         _SERVICE_NAME, _A_CONFIG, _bundling_override, _retry_override,
         _RETRY_DICT, 30, bundle_descriptors=_BUNDLE_DESCRIPTORS,
         page_descriptors=_PAGE_DESCRIPTORS)
     settings = defaults['bundling_method']
     self.assertEquals(settings.timeout, 30)
     self.assertIsNone(settings.bundler)
     self.assertIsNone(settings.page_descriptor)
     settings = defaults['page_streaming_method']
     self.assertEquals(settings.timeout, 30)
     self.assertIsInstance(settings.page_descriptor, PageDescriptor)
     self.assertIsNone(settings.retry)
Esempio n. 7
0
 def test_construct_settings_override(self):
     _bundling_override = {'bundling_method': None}
     _retry_override = {'page_streaming_method': None}
     defaults = api_callable.construct_settings(
         _SERVICE_NAME, _A_CONFIG, _bundling_override, _retry_override,
         _RETRY_DICT, 30, bundle_descriptors=_BUNDLE_DESCRIPTORS,
         page_descriptors=_PAGE_DESCRIPTORS)
     settings = defaults['bundling_method']
     self.assertEquals(settings.timeout, 30)
     self.assertIsNone(settings.bundler)
     self.assertIsNone(settings.page_descriptor)
     settings = defaults['page_streaming_method']
     self.assertEquals(settings.timeout, 30)
     self.assertIsInstance(settings.page_descriptor, PageDescriptor)
     self.assertIsNone(settings.retry)
Esempio n. 8
0
    def test_construct_with_explicit_metadata(self):
        defaults = api_callable.construct_settings(
            _SERVICE_NAME, _A_CONFIG, dict(), _RETRY_DICT,
            bundle_descriptors=_BUNDLE_DESCRIPTORS,
            page_descriptors=_PAGE_DESCRIPTORS,
            kwargs={'metadata': [('x-goog-api-client', 'foo/1.2.3')]})
        settings = defaults['bundling_method']
        metadata = settings.kwargs['metadata'][0][1]

        # Ensure that the metadata string contains items that GAX adds,
        # but not the original header.
        self.assertNotIn('foo/1.2.3', metadata)
        self.assertIn('gl-python/%s' % platform.python_version(), metadata)
        self.assertIn('gax/%s' % GAX_VERSION, metadata)
        self.assertIn('grpc/%s' % GRPC_VERSION, metadata)
Esempio n. 9
0
    def test_construct_settings_override2(self):
        _override = {
            'interfaces': {
                _SERVICE_NAME: {
                    'retry_codes': {
                        'bar_retry': [],
                        'baz_retry': ['code_a']
                    },
                    'retry_params': {
                        'default': {
                            'initial_retry_delay_millis': 1000,
                            'retry_delay_multiplier': 1.2,
                            'max_retry_delay_millis': 10000,
                            'initial_rpc_timeout_millis': 3000,
                            'rpc_timeout_multiplier': 1.3,
                            'max_rpc_timeout_millis': 30000,
                            'total_timeout_millis': 300000
                        },
                    },
                    'methods': {
                        'BundlingMethod': {
                            'retry_params_name': 'default',
                            'retry_codes_name': 'baz_retry',
                        },
                    },
                }
            }
        }
        defaults = api_callable.construct_settings(
            _SERVICE_NAME, _A_CONFIG, _override, _RETRY_DICT,
            bundle_descriptors=_BUNDLE_DESCRIPTORS,
            page_descriptors=_PAGE_DESCRIPTORS)
        settings = defaults['bundling_method']
        backoff = settings.retry.backoff_settings
        self.assertEqual(backoff.initial_retry_delay_millis, 1000)
        self.assertEqual(settings.retry.retry_codes, [_RETRY_DICT['code_a']])
        self.assertIsInstance(settings.bundler, bundling.Executor)
        self.assertIsInstance(settings.bundle_descriptor, BundleDescriptor)

        # page_streaming_method is unaffected because it's not specified in
        # overrides. 'bar_retry' or 'default' definitions in overrides should
        # not affect the methods which are not in the overrides.
        settings = defaults['page_streaming_method']
        backoff = settings.retry.backoff_settings
        self.assertEqual(backoff.initial_retry_delay_millis, 100)
        self.assertEqual(backoff.retry_delay_multiplier, 1.2)
        self.assertEqual(backoff.max_retry_delay_millis, 1000)
        self.assertEqual(settings.retry.retry_codes, [_RETRY_DICT['code_c']])
Esempio n. 10
0
 def test_construct_settings(self):
     defaults = api_callable.construct_settings(
         _SERVICE_NAME, _A_CONFIG, dict(), dict(), _RETRY_DICT, 30,
         bundle_descriptors=_BUNDLE_DESCRIPTORS,
         page_descriptors=_PAGE_DESCRIPTORS)
     settings = defaults['bundling_method']
     self.assertEquals(settings.timeout, 30)
     self.assertIsInstance(settings.bundler, bundling.Executor)
     self.assertIsInstance(settings.bundle_descriptor, BundleDescriptor)
     self.assertIsNone(settings.page_descriptor)
     self.assertIsInstance(settings.retry, RetryOptions)
     settings = defaults['page_streaming_method']
     self.assertEquals(settings.timeout, 30)
     self.assertIsNone(settings.bundler)
     self.assertIsNone(settings.bundle_descriptor)
     self.assertIsInstance(settings.page_descriptor, PageDescriptor)
     self.assertIsInstance(settings.retry, RetryOptions)
Esempio n. 11
0
 def test_construct_settings(self):
     defaults = api_callable.construct_settings(
         _SERVICE_NAME, _A_CONFIG, dict(), dict(), _RETRY_DICT, 30,
         bundle_descriptors=_BUNDLE_DESCRIPTORS,
         page_descriptors=_PAGE_DESCRIPTORS)
     settings = defaults['bundling_method']
     self.assertEquals(settings.timeout, 30)
     self.assertIsInstance(settings.bundler, bundling.Executor)
     self.assertIsInstance(settings.bundle_descriptor, BundleDescriptor)
     self.assertIsNone(settings.page_descriptor)
     self.assertIsInstance(settings.retry, RetryOptions)
     settings = defaults['page_streaming_method']
     self.assertEquals(settings.timeout, 30)
     self.assertIsNone(settings.bundler)
     self.assertIsNone(settings.bundle_descriptor)
     self.assertIsInstance(settings.page_descriptor, PageDescriptor)
     self.assertIsInstance(settings.retry, RetryOptions)
Esempio n. 12
0
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 metadata_transformer=None,
                 ssl_creds=None,
                 scopes=None,
                 client_config=None,
                 app_name='gax',
                 app_version=_GAX_VERSION):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.Channel`): A ``Channel`` instance through
            which to make calls.
          ssl_creds (:class:`grpc.ChannelCredentials`): A
            ``ChannelCredentials`` instance for use with an SSL-enabled
            channel.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          metadata_transformer (Callable[[], list]): A function that creates
             the metadata for requests.
          app_name (string): The codename of the calling service.
          app_version (string): The version of the calling service.

        Returns:
          A IAMApi object.
        """
        if scopes is None:
            scopes = self._ALL_SCOPES
        if client_config is None:
            client_config = {}
        goog_api_client = '{}/{} {} gax/{} python/{}'.format(
            app_name, app_version, self._CODE_GEN_NAME_VERSION,
            self._GAX_VERSION, platform.python_version())
        metadata = [('x-goog-api-client', goog_api_client)]
        default_client_config = json.loads(
            pkg_resources.resource_string(__name__,
                                          'iam_client_config.json').decode())
        defaults = api_callable.construct_settings(
            'google.iam.admin.v1.IAM',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            kwargs={'metadata': metadata},
            page_descriptors=self._PAGE_DESCRIPTORS)
        self.iam_stub = config.create_stub(
            iam_pb2.IAMStub,
            service_path,
            port,
            ssl_creds=ssl_creds,
            channel=channel,
            metadata_transformer=metadata_transformer,
            scopes=scopes)

        self._list_service_accounts = api_callable.create_api_call(
            self.iam_stub.ListServiceAccounts,
            settings=defaults['list_service_accounts'])
        self._get_service_account = api_callable.create_api_call(
            self.iam_stub.GetServiceAccount,
            settings=defaults['get_service_account'])
        self._create_service_account = api_callable.create_api_call(
            self.iam_stub.CreateServiceAccount,
            settings=defaults['create_service_account'])
        self._update_service_account = api_callable.create_api_call(
            self.iam_stub.UpdateServiceAccount,
            settings=defaults['update_service_account'])
        self._delete_service_account = api_callable.create_api_call(
            self.iam_stub.DeleteServiceAccount,
            settings=defaults['delete_service_account'])
        self._list_service_account_keys = api_callable.create_api_call(
            self.iam_stub.ListServiceAccountKeys,
            settings=defaults['list_service_account_keys'])
        self._get_service_account_key = api_callable.create_api_call(
            self.iam_stub.GetServiceAccountKey,
            settings=defaults['get_service_account_key'])
        self._create_service_account_key = api_callable.create_api_call(
            self.iam_stub.CreateServiceAccountKey,
            settings=defaults['create_service_account_key'])
        self._delete_service_account_key = api_callable.create_api_call(
            self.iam_stub.DeleteServiceAccountKey,
            settings=defaults['delete_service_account_key'])
        self._sign_blob = api_callable.create_api_call(
            self.iam_stub.SignBlob, settings=defaults['sign_blob'])
        self._get_iam_policy = api_callable.create_api_call(
            self.iam_stub.GetIamPolicy, settings=defaults['get_iam_policy'])
        self._set_iam_policy = api_callable.create_api_call(
            self.iam_stub.SetIamPolicy, settings=defaults['set_iam_policy'])
        self._test_iam_permissions = api_callable.create_api_call(
            self.iam_stub.TestIamPermissions,
            settings=defaults['test_iam_permissions'])
        self._query_grantable_roles = api_callable.create_api_call(
            self.iam_stub.QueryGrantableRoles,
            settings=defaults['query_grantable_roles'])
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 credentials=None,
                 ssl_credentials=None,
                 scopes=None,
                 client_config=None,
                 app_name=None,
                 app_version='',
                 lib_name=None,
                 lib_version='',
                 metrics_headers=()):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.Channel`): A ``Channel`` instance through
            which to make calls.
          credentials (object): The authorization credentials to attach to
            requests. These credentials identify this application to the
            service.
          ssl_credentials (:class:`grpc.ChannelCredentials`): A
            ``ChannelCredentials`` instance for use with an SSL-enabled
            channel.
          scopes (list[string]): A list of OAuth2 scopes to attach to requests.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          app_name (string): The name of the application calling
            the service. Recommended for analytics purposes.
          app_version (string): The version of the application calling
            the service. Recommended for analytics purposes.
          lib_name (string): The API library software used for calling
            the service. (Unless you are writing an API client itself,
            leave this as default.)
          lib_version (string): The API library software version used
            for calling the service. (Unless you are writing an API client
            itself, leave this as default.)
          metrics_headers (dict): A dictionary of values for tracking
            client library metrics. Ultimately serializes to a string
            (e.g. 'foo/1.2.3 bar/3.14.1'). This argument should be
            considered private.

        Returns:
          A SubscriberClient object.
        """
        # Unless the calling application specifically requested
        # OAuth scopes, request everything.
        if scopes is None:
            scopes = self._ALL_SCOPES

        # Initialize an empty client config, if none is set.
        if client_config is None:
            client_config = {}

        # Initialize metrics_headers as an ordered dictionary
        # (cuts down on cardinality of the resulting string slightly).
        metrics_headers = collections.OrderedDict(metrics_headers)
        metrics_headers['gl-python'] = platform.python_version()

        # The library may or may not be set, depending on what is
        # calling this client. Newer client libraries set the library name
        # and version.
        if lib_name:
            metrics_headers[lib_name] = lib_version

        # Finally, track the GAPIC package version.
        metrics_headers['gapic'] = pkg_resources.get_distribution(
            'gapic-google-cloud-pubsub-v1', ).version

        # Load the configuration defaults.
        default_client_config = json.loads(
            pkg_resources.resource_string(
                __name__, 'subscriber_client_config.json').decode())
        defaults = api_callable.construct_settings(
            'google.pubsub.v1.Subscriber',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            metrics_headers=metrics_headers,
            page_descriptors=self._PAGE_DESCRIPTORS, )
        self.iam_policy_stub = config.create_stub(
            iam_policy_pb2.IAMPolicyStub,
            channel=channel,
            service_path=service_path,
            service_port=port,
            credentials=credentials,
            scopes=scopes,
            ssl_credentials=ssl_credentials)
        self.subscriber_stub = config.create_stub(
            pubsub_pb2.SubscriberStub,
            channel=channel,
            service_path=service_path,
            service_port=port,
            credentials=credentials,
            scopes=scopes,
            ssl_credentials=ssl_credentials)

        self._create_subscription = api_callable.create_api_call(
            self.subscriber_stub.CreateSubscription,
            settings=defaults['create_subscription'])
        self._get_subscription = api_callable.create_api_call(
            self.subscriber_stub.GetSubscription,
            settings=defaults['get_subscription'])
        self._update_subscription = api_callable.create_api_call(
            self.subscriber_stub.UpdateSubscription,
            settings=defaults['update_subscription'])
        self._list_subscriptions = api_callable.create_api_call(
            self.subscriber_stub.ListSubscriptions,
            settings=defaults['list_subscriptions'])
        self._delete_subscription = api_callable.create_api_call(
            self.subscriber_stub.DeleteSubscription,
            settings=defaults['delete_subscription'])
        self._modify_ack_deadline = api_callable.create_api_call(
            self.subscriber_stub.ModifyAckDeadline,
            settings=defaults['modify_ack_deadline'])
        self._acknowledge = api_callable.create_api_call(
            self.subscriber_stub.Acknowledge, settings=defaults['acknowledge'])
        self._pull = api_callable.create_api_call(
            self.subscriber_stub.Pull, settings=defaults['pull'])
        self._streaming_pull = api_callable.create_api_call(
            self.subscriber_stub.StreamingPull,
            settings=defaults['streaming_pull'])
        self._modify_push_config = api_callable.create_api_call(
            self.subscriber_stub.ModifyPushConfig,
            settings=defaults['modify_push_config'])
        self._list_snapshots = api_callable.create_api_call(
            self.subscriber_stub.ListSnapshots,
            settings=defaults['list_snapshots'])
        self._create_snapshot = api_callable.create_api_call(
            self.subscriber_stub.CreateSnapshot,
            settings=defaults['create_snapshot'])
        self._delete_snapshot = api_callable.create_api_call(
            self.subscriber_stub.DeleteSnapshot,
            settings=defaults['delete_snapshot'])
        self._seek = api_callable.create_api_call(
            self.subscriber_stub.Seek, settings=defaults['seek'])
        self._set_iam_policy = api_callable.create_api_call(
            self.iam_policy_stub.SetIamPolicy,
            settings=defaults['set_iam_policy'])
        self._get_iam_policy = api_callable.create_api_call(
            self.iam_policy_stub.GetIamPolicy,
            settings=defaults['get_iam_policy'])
        self._test_iam_permissions = api_callable.create_api_call(
            self.iam_policy_stub.TestIamPermissions,
            settings=defaults['test_iam_permissions'])
Esempio n. 14
0
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 credentials=None,
                 ssl_credentials=None,
                 scopes=None,
                 client_config=None,
                 app_name='gax',
                 app_version=_GAX_VERSION):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.Channel`): A ``Channel`` instance through
            which to make calls.
          credentials (object): The authorization credentials to attach to
            requests. These credentials identify this application to the
            service.
          ssl_credentials (:class:`grpc.ChannelCredentials`): A
            ``ChannelCredentials`` instance for use with an SSL-enabled
            channel.
          scopes (list[string]): A list of OAuth2 scopes to attach to requests.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          app_name (string): The codename of the calling service.
          app_version (string): The version of the calling service.

        Returns:
          A MetricsServiceV2Client object.
        """
        if scopes is None:
            scopes = self._ALL_SCOPES
        if client_config is None:
            client_config = {}
        goog_api_client = '{}/{} {} gax/{} python/{}'.format(
            app_name, app_version, self._CODE_GEN_NAME_VERSION,
            self._GAX_VERSION, platform.python_version())
        metadata = [('x-goog-api-client', goog_api_client)]
        default_client_config = json.loads(
            pkg_resources.resource_string(
                __name__, 'metrics_service_v2_client_config.json').decode())
        defaults = api_callable.construct_settings(
            'google.logging.v2.MetricsServiceV2',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            kwargs={'metadata': metadata},
            page_descriptors=self._PAGE_DESCRIPTORS)
        self.metrics_service_v2_stub = config.create_stub(
            logging_metrics_pb2.MetricsServiceV2Stub,
            channel=channel,
            service_path=service_path,
            service_port=port,
            credentials=credentials,
            scopes=scopes,
            ssl_credentials=ssl_credentials)

        self._list_log_metrics = api_callable.create_api_call(
            self.metrics_service_v2_stub.ListLogMetrics,
            settings=defaults['list_log_metrics'])
        self._get_log_metric = api_callable.create_api_call(
            self.metrics_service_v2_stub.GetLogMetric,
            settings=defaults['get_log_metric'])
        self._create_log_metric = api_callable.create_api_call(
            self.metrics_service_v2_stub.CreateLogMetric,
            settings=defaults['create_log_metric'])
        self._update_log_metric = api_callable.create_api_call(
            self.metrics_service_v2_stub.UpdateLogMetric,
            settings=defaults['update_log_metric'])
        self._delete_log_metric = api_callable.create_api_call(
            self.metrics_service_v2_stub.DeleteLogMetric,
            settings=defaults['delete_log_metric'])
Esempio n. 15
0
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 credentials=None,
                 ssl_credentials=None,
                 scopes=None,
                 client_config=None,
                 app_name='gax',
                 app_version=_GAX_VERSION):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.Channel`): A ``Channel`` instance through
            which to make calls.
          credentials (object): The authorization credentials to attach to
            requests. These credentials identify this application to the
            service.
          ssl_credentials (:class:`grpc.ChannelCredentials`): A
            ``ChannelCredentials`` instance for use with an SSL-enabled
            channel.
          scopes (list[string]): A list of OAuth2 scopes to attach to requests.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          app_name (string): The codename of the calling service.
          app_version (string): The version of the calling service.

        Returns:
          A SpeechClient object.
        """
        if scopes is None:
            scopes = self._ALL_SCOPES
        if client_config is None:
            client_config = {}
        goog_api_client = '{}/{} {} gax/{} python/{}'.format(
            app_name, app_version, self._CODE_GEN_NAME_VERSION,
            self._GAX_VERSION, platform.python_version())
        metadata = [('x-goog-api-client', goog_api_client)]
        default_client_config = json.loads(
            pkg_resources.resource_string(
                __name__, 'speech_client_config.json').decode())
        defaults = api_callable.construct_settings(
            'google.cloud.speech.v1beta1.Speech',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            kwargs={'metadata': metadata})
        self.speech_stub = config.create_stub(
            cloud_speech_pb2.SpeechStub,
            channel=channel,
            service_path=service_path,
            service_port=port,
            credentials=credentials,
            scopes=scopes,
            ssl_credentials=ssl_credentials)

        self._sync_recognize = api_callable.create_api_call(
            self.speech_stub.SyncRecognize,
            settings=defaults['sync_recognize'])
        self._async_recognize = api_callable.create_api_call(
            self.speech_stub.AsyncRecognize,
            settings=defaults['async_recognize'])
        self._streaming_recognize = api_callable.create_api_call(
            self.speech_stub.StreamingRecognize,
            settings=defaults['streaming_recognize'])
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 credentials=None,
                 ssl_credentials=None,
                 scopes=None,
                 client_config=None,
                 app_name=None,
                 app_version='',
                 lib_name=None,
                 lib_version='',
                 metrics_headers=()):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.Channel`): A ``Channel`` instance through
            which to make calls.
          credentials (object): The authorization credentials to attach to
            requests. These credentials identify this application to the
            service.
          ssl_credentials (:class:`grpc.ChannelCredentials`): A
            ``ChannelCredentials`` instance for use with an SSL-enabled
            channel.
          scopes (list[string]): A list of OAuth2 scopes to attach to requests.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          app_name (string): The name of the application calling
            the service. Recommended for analytics purposes.
          app_version (string): The version of the application calling
            the service. Recommended for analytics purposes.
          lib_name (string): The API library software used for calling
            the service. (Unless you are writing an API client itself,
            leave this as default.)
          lib_version (string): The API library software version used
            for calling the service. (Unless you are writing an API client
            itself, leave this as default.)
          metrics_headers (dict): A dictionary of values for tracking
            client library metrics. Ultimately serializes to a string
            (e.g. 'foo/1.2.3 bar/3.14.1'). This argument should be
            considered private.

        Returns:
          A SubscriberClient object.
        """
        # Unless the calling application specifically requested
        # OAuth scopes, request everything.
        if scopes is None:
            scopes = self._ALL_SCOPES

        # Initialize an empty client config, if none is set.
        if client_config is None:
            client_config = {}

        # Initialize metrics_headers as an ordered dictionary
        # (cuts down on cardinality of the resulting string slightly).
        metrics_headers = collections.OrderedDict(metrics_headers)
        metrics_headers['gl-python'] = platform.python_version()

        # The library may or may not be set, depending on what is
        # calling this client. Newer client libraries set the library name
        # and version.
        if lib_name:
            metrics_headers[lib_name] = lib_version

        # Finally, track the GAPIC package version.
        metrics_headers['gapic'] = pkg_resources.get_distribution(
            'google-cloud-pubsub', ).version

        # Load the configuration defaults.
        default_client_config = json.loads(
            pkg_resources.resource_string(
                __name__, 'subscriber_client_config.json').decode())
        defaults = api_callable.construct_settings(
            'google.pubsub.v1.Subscriber',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            metrics_headers=metrics_headers,
            page_descriptors=self._PAGE_DESCRIPTORS,
        )
        self.iam_policy_stub = config.create_stub(
            iam_policy_pb2.IAMPolicyStub,
            channel=channel,
            service_path=service_path,
            service_port=port,
            credentials=credentials,
            scopes=scopes,
            ssl_credentials=ssl_credentials)
        self.subscriber_stub = config.create_stub(
            pubsub_pb2.SubscriberStub,
            channel=channel,
            service_path=service_path,
            service_port=port,
            credentials=credentials,
            scopes=scopes,
            ssl_credentials=ssl_credentials)

        self._create_subscription = api_callable.create_api_call(
            self.subscriber_stub.CreateSubscription,
            settings=defaults['create_subscription'])
        self._get_subscription = api_callable.create_api_call(
            self.subscriber_stub.GetSubscription,
            settings=defaults['get_subscription'])
        self._update_subscription = api_callable.create_api_call(
            self.subscriber_stub.UpdateSubscription,
            settings=defaults['update_subscription'])
        self._list_subscriptions = api_callable.create_api_call(
            self.subscriber_stub.ListSubscriptions,
            settings=defaults['list_subscriptions'])
        self._delete_subscription = api_callable.create_api_call(
            self.subscriber_stub.DeleteSubscription,
            settings=defaults['delete_subscription'])
        self._modify_ack_deadline = api_callable.create_api_call(
            self.subscriber_stub.ModifyAckDeadline,
            settings=defaults['modify_ack_deadline'])
        self._acknowledge = api_callable.create_api_call(
            self.subscriber_stub.Acknowledge, settings=defaults['acknowledge'])
        self._pull = api_callable.create_api_call(self.subscriber_stub.Pull,
                                                  settings=defaults['pull'])
        self._streaming_pull = api_callable.create_api_call(
            self.subscriber_stub.StreamingPull,
            settings=defaults['streaming_pull'])
        self._modify_push_config = api_callable.create_api_call(
            self.subscriber_stub.ModifyPushConfig,
            settings=defaults['modify_push_config'])
        self._list_snapshots = api_callable.create_api_call(
            self.subscriber_stub.ListSnapshots,
            settings=defaults['list_snapshots'])
        self._create_snapshot = api_callable.create_api_call(
            self.subscriber_stub.CreateSnapshot,
            settings=defaults['create_snapshot'])
        self._delete_snapshot = api_callable.create_api_call(
            self.subscriber_stub.DeleteSnapshot,
            settings=defaults['delete_snapshot'])
        self._seek = api_callable.create_api_call(self.subscriber_stub.Seek,
                                                  settings=defaults['seek'])
        self._set_iam_policy = api_callable.create_api_call(
            self.iam_policy_stub.SetIamPolicy,
            settings=defaults['set_iam_policy'])
        self._get_iam_policy = api_callable.create_api_call(
            self.iam_policy_stub.GetIamPolicy,
            settings=defaults['get_iam_policy'])
        self._test_iam_permissions = api_callable.create_api_call(
            self.iam_policy_stub.TestIamPermissions,
            settings=defaults['test_iam_permissions'])
    def __init__(self,
                 channel=None,
                 credentials=None,
                 ssl_credentials=None,
                 scopes=None,
                 client_config=None,
                 lib_name=None,
                 lib_version='',
                 metrics_headers=()):
        """Constructor.

        Args:
            channel (~grpc.Channel): A ``Channel`` instance through
                which to make calls.
            credentials (~google.auth.credentials.Credentials): The authorization
                credentials to attach to requests. These credentials identify this
                application to the service.
            ssl_credentials (~grpc.ChannelCredentials): A
                ``ChannelCredentials`` instance for use with an SSL-enabled
                channel.
            scopes (Sequence[str]): A list of OAuth2 scopes to attach to requests.
            client_config (dict):
                A dictionary for call options for each method. See
                :func:`google.gax.construct_settings` for the structure of
                this data. Falls back to the default config if not specified
                or the specified config is missing data points.
            lib_name (str): The API library software used for calling
                the service. (Unless you are writing an API client itself,
                leave this as default.)
            lib_version (str): The API library software version used
                for calling the service. (Unless you are writing an API client
                itself, leave this as default.)
            metrics_headers (dict): A dictionary of values for tracking
                client library metrics. Ultimately serializes to a string
                (e.g. 'foo/1.2.3 bar/3.14.1'). This argument should be
                considered private.
        """
        # Unless the calling application specifically requested
        # OAuth scopes, request everything.
        if scopes is None:
            scopes = self._ALL_SCOPES

        # Initialize an empty client config, if none is set.
        if client_config is None:
            client_config = {}

        # Initialize metrics_headers as an ordered dictionary
        # (cuts down on cardinality of the resulting string slightly).
        metrics_headers = collections.OrderedDict(metrics_headers)
        metrics_headers['gl-python'] = platform.python_version()

        # The library may or may not be set, depending on what is
        # calling this client. Newer client libraries set the library name
        # and version.
        if lib_name:
            metrics_headers[lib_name] = lib_version

        # Finally, track the GAPIC package version.
        metrics_headers['gapic'] = pkg_resources.get_distribution(
            'google-cloud-videointelligence', ).version

        # Load the configuration defaults.
        defaults = api_callable.construct_settings(
            'google.cloud.videointelligence.v1beta1.VideoIntelligenceService',
            video_intelligence_service_client_config.config,
            client_config,
            config.STATUS_CODE_NAMES,
            metrics_headers=metrics_headers, )
        self.video_intelligence_service_stub = config.create_stub(
            video_intelligence_pb2.VideoIntelligenceServiceStub,
            channel=channel,
            service_path=self.SERVICE_ADDRESS,
            service_port=self.DEFAULT_SERVICE_PORT,
            credentials=credentials,
            scopes=scopes,
            ssl_credentials=ssl_credentials)

        self.operations_client = operations_client.OperationsClient(
            service_path=self.SERVICE_ADDRESS,
            channel=channel,
            credentials=credentials,
            ssl_credentials=ssl_credentials,
            scopes=scopes,
            client_config=client_config,
            metrics_headers=metrics_headers, )

        self._annotate_video = api_callable.create_api_call(
            self.video_intelligence_service_stub.AnnotateVideo,
            settings=defaults['annotate_video'])
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 metadata_transformer=None,
                 ssl_creds=None,
                 scopes=None,
                 client_config=None,
                 timeout=_DEFAULT_TIMEOUT,
                 app_name='gax',
                 app_version=_GAX_VERSION):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.beta.implementations.Channel`): A ``Channel``
            object through which to make calls.
          ssl_creds (:class:`grpc.beta.implementations.ClientCredentials`):
            A `ClientCredentials` for use with an SSL-enabled channel.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          metadata_transformer (Callable[[], list]): A function that creates
             the metadata for requests.
          timeout (int): The default timeout, in seconds, for calls made
            through this client
          app_name (string): The codename of the calling service.
          app_version (string): The version of the calling service.

        Returns:
          A ConfigServiceV2Api object.
        """
        if scopes is None:
            scopes = self._ALL_SCOPES
        if client_config is None:
            client_config = {}
        goog_api_client = '{}/{} {} gax/{} python/{}'.format(
            app_name, app_version, self._CODE_GEN_NAME_VERSION,
            self._GAX_VERSION, platform.python_version())
        metadata = [('x-goog-api-client', goog_api_client)]
        default_client_config = json.loads(
            pkg_resources.resource_string(
                __name__, 'config_service_v2_client_config.json'))
        defaults = api_callable.construct_settings(
            'google.logging.v2.ConfigServiceV2',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            timeout,
            kwargs={'metadata': metadata},
            page_descriptors=self._PAGE_DESCRIPTORS)
        self.stub = config.create_stub(
            logging_config_pb2.beta_create_ConfigServiceV2_stub,
            service_path,
            port,
            ssl_creds=ssl_creds,
            channel=channel,
            metadata_transformer=metadata_transformer,
            scopes=scopes)
        self._list_sinks = api_callable.create_api_call(
            self.stub.ListSinks, settings=defaults['list_sinks'])
        self._get_sink = api_callable.create_api_call(
            self.stub.GetSink, settings=defaults['get_sink'])
        self._create_sink = api_callable.create_api_call(
            self.stub.CreateSink, settings=defaults['create_sink'])
        self._update_sink = api_callable.create_api_call(
            self.stub.UpdateSink, settings=defaults['update_sink'])
        self._delete_sink = api_callable.create_api_call(
            self.stub.DeleteSink, settings=defaults['delete_sink'])
Esempio n. 19
0
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 metadata_transformer=None,
                 ssl_creds=None,
                 scopes=None,
                 client_config=None,
                 app_name='gax',
                 app_version=_GAX_VERSION):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.Channel`): A ``Channel`` instance through
            which to make calls.
          ssl_creds (:class:`grpc.ChannelCredentials`): A
            ``ChannelCredentials`` instance for use with an SSL-enabled
            channel.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          metadata_transformer (Callable[[], list]): A function that creates
             the metadata for requests.
          app_name (string): The codename of the calling service.
          app_version (string): The version of the calling service.

        Returns:
          A BigtableApi object.
        """
        if scopes is None:
            scopes = self._ALL_SCOPES
        if client_config is None:
            client_config = {}
        goog_api_client = '{}/{} {} gax/{} python/{}'.format(
            app_name, app_version, self._CODE_GEN_NAME_VERSION,
            self._GAX_VERSION, platform.python_version())
        metadata = [('x-goog-api-client', goog_api_client)]
        default_client_config = json.loads(
            pkg_resources.resource_string(
                __name__, 'bigtable_client_config.json').decode())
        defaults = api_callable.construct_settings(
            'google.bigtable.v2.Bigtable',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            kwargs={'metadata': metadata})
        self.bigtable_stub = config.create_stub(
            bigtable_pb2.BigtableStub,
            service_path,
            port,
            ssl_creds=ssl_creds,
            channel=channel,
            metadata_transformer=metadata_transformer,
            scopes=scopes)

        self._read_rows = api_callable.create_api_call(
            self.bigtable_stub.ReadRows, settings=defaults['read_rows'])
        self._sample_row_keys = api_callable.create_api_call(
            self.bigtable_stub.SampleRowKeys,
            settings=defaults['sample_row_keys'])
        self._mutate_row = api_callable.create_api_call(
            self.bigtable_stub.MutateRow, settings=defaults['mutate_row'])
        self._mutate_rows = api_callable.create_api_call(
            self.bigtable_stub.MutateRows, settings=defaults['mutate_rows'])
        self._check_and_mutate_row = api_callable.create_api_call(
            self.bigtable_stub.CheckAndMutateRow,
            settings=defaults['check_and_mutate_row'])
        self._read_modify_write_row = api_callable.create_api_call(
            self.bigtable_stub.ReadModifyWriteRow,
            settings=defaults['read_modify_write_row'])
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 metadata_transformer=None,
                 ssl_creds=None,
                 scopes=None,
                 client_config=None,
                 timeout=_DEFAULT_TIMEOUT,
                 app_name='gax',
                 app_version=_GAX_VERSION):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.beta.implementations.Channel`): A ``Channel``
            object through which to make calls.
          ssl_creds (:class:`grpc.beta.implementations.ClientCredentials`):
            A `ClientCredentials` for use with an SSL-enabled channel.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          metadata_transformer (Callable[[], list]): A function that creates
             the metadata for requests.
          timeout (int): The default timeout, in seconds, for calls made
            through this client
          app_name (string): The codename of the calling service.
          app_version (string): The version of the calling service.

        Returns:
          A MetricsServiceV2Api object.
        """
        if scopes is None:
            scopes = self._ALL_SCOPES
        if client_config is None:
            client_config = {}
        goog_api_client = '{}/{} {} gax/{} python/{}'.format(
            app_name, app_version, self._CODE_GEN_NAME_VERSION,
            self._GAX_VERSION, platform.python_version())
        metadata = [('x-goog-api-client', goog_api_client)]
        default_client_config = json.loads(pkg_resources.resource_string(
            __name__, 'metrics_service_v2_client_config.json'))
        defaults = api_callable.construct_settings(
            'google.logging.v2.MetricsServiceV2',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            timeout,
            kwargs={'metadata': metadata},
            page_descriptors=self._PAGE_DESCRIPTORS)
        self.stub = config.create_stub(
            logging_metrics_pb2.beta_create_MetricsServiceV2_stub,
            service_path,
            port,
            ssl_creds=ssl_creds,
            channel=channel,
            metadata_transformer=metadata_transformer,
            scopes=scopes)
        self._list_log_metrics = api_callable.create_api_call(
            self.stub.ListLogMetrics,
            settings=defaults['list_log_metrics'])
        self._get_log_metric = api_callable.create_api_call(
            self.stub.GetLogMetric,
            settings=defaults['get_log_metric'])
        self._create_log_metric = api_callable.create_api_call(
            self.stub.CreateLogMetric,
            settings=defaults['create_log_metric'])
        self._update_log_metric = api_callable.create_api_call(
            self.stub.UpdateLogMetric,
            settings=defaults['update_log_metric'])
        self._delete_log_metric = api_callable.create_api_call(
            self.stub.DeleteLogMetric,
            settings=defaults['delete_log_metric'])
Esempio n. 21
0
    def __init__(self,
                 channel=None,
                 credentials=None,
                 ssl_credentials=None,
                 scopes=None,
                 client_config=None,
                 lib_name=None,
                 lib_version='',
                 metrics_headers=()):
        """Constructor.

        Args:
            channel (~grpc.Channel): A ``Channel`` instance through
                which to make calls.
            credentials (~google.auth.credentials.Credentials): The authorization
                credentials to attach to requests. These credentials identify this
                application to the service.
            ssl_credentials (~grpc.ChannelCredentials): A
                ``ChannelCredentials`` instance for use with an SSL-enabled
                channel.
            scopes (Sequence[str]): A list of OAuth2 scopes to attach to requests.
            client_config (dict):
                A dictionary for call options for each method. See
                :func:`google.gax.construct_settings` for the structure of
                this data. Falls back to the default config if not specified
                or the specified config is missing data points.
            lib_name (str): The API library software used for calling
                the service. (Unless you are writing an API client itself,
                leave this as default.)
            lib_version (str): The API library software version used
                for calling the service. (Unless you are writing an API client
                itself, leave this as default.)
            metrics_headers (dict): A dictionary of values for tracking
                client library metrics. Ultimately serializes to a string
                (e.g. 'foo/1.2.3 bar/3.14.1'). This argument should be
                considered private.
        """
        # Unless the calling application specifically requested
        # OAuth scopes, request everything.
        if scopes is None:
            scopes = self._ALL_SCOPES

        # Initialize an empty client config, if none is set.
        if client_config is None:
            client_config = {}

        # Initialize metrics_headers as an ordered dictionary
        # (cuts down on cardinality of the resulting string slightly).
        metrics_headers = collections.OrderedDict(metrics_headers)
        metrics_headers['gl-python'] = platform.python_version()

        # The library may or may not be set, depending on what is
        # calling this client. Newer client libraries set the library name
        # and version.
        if lib_name:
            metrics_headers[lib_name] = lib_version

        # Finally, track the GAPIC package version.
        metrics_headers['gapic'] = pkg_resources.get_distribution(
            'google-cloud-firestore', ).version

        # Load the configuration defaults.
        defaults = api_callable.construct_settings(
            'google.firestore.v1beta1.Firestore',
            firestore_client_config.config,
            client_config,
            config.STATUS_CODE_NAMES,
            metrics_headers=metrics_headers,
            page_descriptors=self._PAGE_DESCRIPTORS,
        )
        self.firestore_stub = config.create_stub(
            firestore_pb2.FirestoreStub,
            channel=channel,
            service_path=self.SERVICE_ADDRESS,
            service_port=self.DEFAULT_SERVICE_PORT,
            credentials=credentials,
            scopes=scopes,
            ssl_credentials=ssl_credentials)

        self._get_document = api_callable.create_api_call(
            self.firestore_stub.GetDocument, settings=defaults['get_document'])
        self._list_documents = api_callable.create_api_call(
            self.firestore_stub.ListDocuments,
            settings=defaults['list_documents'])
        self._create_document = api_callable.create_api_call(
            self.firestore_stub.CreateDocument,
            settings=defaults['create_document'])
        self._update_document = api_callable.create_api_call(
            self.firestore_stub.UpdateDocument,
            settings=defaults['update_document'])
        self._delete_document = api_callable.create_api_call(
            self.firestore_stub.DeleteDocument,
            settings=defaults['delete_document'])
        self._batch_get_documents = api_callable.create_api_call(
            self.firestore_stub.BatchGetDocuments,
            settings=defaults['batch_get_documents'])
        self._begin_transaction = api_callable.create_api_call(
            self.firestore_stub.BeginTransaction,
            settings=defaults['begin_transaction'])
        self._commit = api_callable.create_api_call(
            self.firestore_stub.Commit, settings=defaults['commit'])
        self._rollback = api_callable.create_api_call(
            self.firestore_stub.Rollback, settings=defaults['rollback'])
        self._run_query = api_callable.create_api_call(
            self.firestore_stub.RunQuery, settings=defaults['run_query'])
        self._write = api_callable.create_api_call(self.firestore_stub.Write,
                                                   settings=defaults['write'])
        self._listen = api_callable.create_api_call(
            self.firestore_stub.Listen, settings=defaults['listen'])
        self._list_collection_ids = api_callable.create_api_call(
            self.firestore_stub.ListCollectionIds,
            settings=defaults['list_collection_ids'])
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 credentials=None,
                 ssl_credentials=None,
                 scopes=None,
                 client_config=None,
                 app_name='gax',
                 app_version=_GAX_VERSION):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.Channel`): A ``Channel`` instance through
            which to make calls.
          credentials (object): The authorization credentials to attach to
            requests. These credentials identify this application to the
            service.
          ssl_credentials (:class:`grpc.ChannelCredentials`): A
            ``ChannelCredentials`` instance for use with an SSL-enabled
            channel.
          scopes (list[string]): A list of OAuth2 scopes to attach to requests.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          app_name (string): The codename of the calling service.
          app_version (string): The version of the calling service.

        Returns:
          A DatastoreClient object.
        """
        if scopes is None:
            scopes = self._ALL_SCOPES
        if client_config is None:
            client_config = {}
        goog_api_client = '{}/{} {} gax/{} python/{}'.format(
            app_name, app_version, self._CODE_GEN_NAME_VERSION,
            self._GAX_VERSION, platform.python_version())
        metadata = [('x-goog-api-client', goog_api_client)]
        default_client_config = json.loads(
            pkg_resources.resource_string(
                __name__, 'datastore_client_config.json').decode())
        defaults = api_callable.construct_settings(
            'google.datastore.v1.Datastore',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            kwargs={'metadata': metadata})
        self.datastore_stub = config.create_stub(
            datastore_pb2.DatastoreStub,
            channel=channel,
            service_path=service_path,
            service_port=port,
            credentials=credentials,
            scopes=scopes,
            ssl_credentials=ssl_credentials)

        self._lookup = api_callable.create_api_call(
            self.datastore_stub.Lookup, settings=defaults['lookup'])
        self._run_query = api_callable.create_api_call(
            self.datastore_stub.RunQuery, settings=defaults['run_query'])
        self._begin_transaction = api_callable.create_api_call(
            self.datastore_stub.BeginTransaction,
            settings=defaults['begin_transaction'])
        self._commit = api_callable.create_api_call(
            self.datastore_stub.Commit, settings=defaults['commit'])
        self._rollback = api_callable.create_api_call(
            self.datastore_stub.Rollback, settings=defaults['rollback'])
        self._allocate_ids = api_callable.create_api_call(
            self.datastore_stub.AllocateIds, settings=defaults['allocate_ids'])
Esempio n. 23
0
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 metadata_transformer=None,
                 ssl_creds=None,
                 scopes=None,
                 client_config=None,
                 app_name='gax',
                 app_version=_GAX_VERSION):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.Channel`): A ``Channel`` instance through
            which to make calls.
          ssl_creds (:class:`grpc.ChannelCredentials`): A
            ``ChannelCredentials`` instance for use with an SSL-enabled
            channel.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          metadata_transformer (Callable[[], list]): A function that creates
             the metadata for requests.
          app_name (string): The codename of the calling service.
          app_version (string): The version of the calling service.

        Returns:
          A PublisherApi object.
        """
        if scopes is None:
            scopes = self._ALL_SCOPES
        if client_config is None:
            client_config = {}
        goog_api_client = '{}/{} {} gax/{} python/{}'.format(
            app_name, app_version, self._CODE_GEN_NAME_VERSION,
            self._GAX_VERSION, platform.python_version())
        metadata = [('x-goog-api-client', goog_api_client)]
        default_client_config = json.loads(
            pkg_resources.resource_string(
                __name__, 'publisher_client_config.json').decode())
        defaults = api_callable.construct_settings(
            'google.pubsub.v1.Publisher',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            kwargs={'metadata': metadata},
            bundle_descriptors=self._BUNDLE_DESCRIPTORS,
            page_descriptors=self._PAGE_DESCRIPTORS)
        self.stub = config.create_stub(
            pubsub_pb2.PublisherStub,
            service_path,
            port,
            ssl_creds=ssl_creds,
            channel=channel,
            metadata_transformer=metadata_transformer,
            scopes=scopes)
        self._create_topic = api_callable.create_api_call(
            self.stub.CreateTopic, settings=defaults['create_topic'])
        self._publish = api_callable.create_api_call(
            self.stub.Publish, settings=defaults['publish'])
        self._get_topic = api_callable.create_api_call(
            self.stub.GetTopic, settings=defaults['get_topic'])
        self._list_topics = api_callable.create_api_call(
            self.stub.ListTopics, settings=defaults['list_topics'])
        self._list_topic_subscriptions = api_callable.create_api_call(
            self.stub.ListTopicSubscriptions,
            settings=defaults['list_topic_subscriptions'])
        self._delete_topic = api_callable.create_api_call(
            self.stub.DeleteTopic, settings=defaults['delete_topic'])
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 credentials=None,
                 ssl_credentials=None,
                 scopes=None,
                 client_config=None,
                 app_name=None,
                 app_version='',
                 lib_name=None,
                 lib_version='',
                 metrics_headers=()):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.Channel`): A ``Channel`` instance through
            which to make calls.
          credentials (object): The authorization credentials to attach to
            requests. These credentials identify this application to the
            service.
          ssl_credentials (:class:`grpc.ChannelCredentials`): A
            ``ChannelCredentials`` instance for use with an SSL-enabled
            channel.
          scopes (list[string]): A list of OAuth2 scopes to attach to requests.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          app_name (string): The name of the application calling
            the service. Recommended for analytics purposes.
          app_version (string): The version of the application calling
            the service. Recommended for analytics purposes.
          lib_name (string): The API library software used for calling
            the service. (Unless you are writing an API client itself,
            leave this as default.)
          lib_version (string): The API library software version used
            for calling the service. (Unless you are writing an API client
            itself, leave this as default.)
          metrics_headers (dict): A dictionary of values for tracking
            client library metrics. Ultimately serializes to a string
            (e.g. 'foo/1.2.3 bar/3.14.1'). This argument should be
            considered private.

        Returns:
          A OperationsClient object.
        """
        # Unless the calling application specifically requested
        # OAuth scopes, request everything.
        if scopes is None:
            scopes = self._ALL_SCOPES

        # Initialize an empty client config, if none is set.
        if client_config is None:
            client_config = {}

        # Initialize metrics_headers as an ordered dictionary
        # (cuts down on cardinality of the resulting string slightly).
        metrics_headers = collections.OrderedDict(metrics_headers)
        metrics_headers['gl-python'] = platform.python_version()

        # The library may or may not be set, depending on what is
        # calling this client. Newer client libraries set the library name
        # and version.
        if lib_name:
            metrics_headers[lib_name] = lib_version

        # Load the configuration defaults.
        default_client_config = json.loads(
            pkg_resources.resource_string(
                __name__, 'operations_client_config.json').decode())
        defaults = api_callable.construct_settings(
            'google.longrunning.Operations',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            metrics_headers=metrics_headers,
            page_descriptors=self._PAGE_DESCRIPTORS, )
        self.operations_stub = config.create_stub(
            operations_pb2.OperationsStub,
            channel=channel,
            service_path=service_path,
            service_port=port,
            credentials=credentials,
            scopes=scopes,
            ssl_credentials=ssl_credentials)

        self._get_operation = api_callable.create_api_call(
            self.operations_stub.GetOperation,
            settings=defaults['get_operation'])
        self._list_operations = api_callable.create_api_call(
            self.operations_stub.ListOperations,
            settings=defaults['list_operations'])
        self._cancel_operation = api_callable.create_api_call(
            self.operations_stub.CancelOperation,
            settings=defaults['cancel_operation'])
        self._delete_operation = api_callable.create_api_call(
            self.operations_stub.DeleteOperation,
            settings=defaults['delete_operation'])
Esempio n. 25
0
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 credentials=None,
                 ssl_credentials=None,
                 scopes=None,
                 client_config=None,
                 app_name=None,
                 app_version='',
                 lib_name=None,
                 lib_version='',
                 metrics_headers=()):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.Channel`): A ``Channel`` instance through
            which to make calls.
          credentials (object): The authorization credentials to attach to
            requests. These credentials identify this application to the
            service.
          ssl_credentials (:class:`grpc.ChannelCredentials`): A
            ``ChannelCredentials`` instance for use with an SSL-enabled
            channel.
          scopes (list[string]): A list of OAuth2 scopes to attach to requests.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          app_name (string): The name of the application calling
            the service. Recommended for analytics purposes.
          app_version (string): The version of the application calling
            the service. Recommended for analytics purposes.
          lib_name (string): The API library software used for calling
            the service. (Unless you are writing an API client itself,
            leave this as default.)
          lib_version (string): The API library software version used
            for calling the service. (Unless you are writing an API client
            itself, leave this as default.)
          metrics_headers (dict): A dictionary of values for tracking
            client library metrics. Ultimately serializes to a string
            (e.g. 'foo/1.2.3 bar/3.14.1'). This argument should be
            considered private.

        Returns:
          A OperationsClient object.
        """
        # Unless the calling application specifically requested
        # OAuth scopes, request everything.
        if scopes is None:
            scopes = self._ALL_SCOPES

        # Initialize an empty client config, if none is set.
        if client_config is None:
            client_config = {}

        # Initialize metrics_headers as an ordered dictionary
        # (cuts down on cardinality of the resulting string slightly).
        metrics_headers = collections.OrderedDict(metrics_headers)
        metrics_headers['gl-python'] = platform.python_version()

        # The library may or may not be set, depending on what is
        # calling this client. Newer client libraries set the library name
        # and version.
        if lib_name:
            metrics_headers[lib_name] = lib_version

        # Load the configuration defaults.
        default_client_config = json.loads(
            pkg_resources.resource_string(
                __name__, 'operations_client_config.json').decode())
        defaults = api_callable.construct_settings(
            'google.longrunning.Operations',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            metrics_headers=metrics_headers,
            page_descriptors=self._PAGE_DESCRIPTORS,
        )
        self.operations_stub = config.create_stub(
            operations_pb2.OperationsStub,
            channel=channel,
            service_path=service_path,
            service_port=port,
            credentials=credentials,
            scopes=scopes,
            ssl_credentials=ssl_credentials)

        self._get_operation = api_callable.create_api_call(
            self.operations_stub.GetOperation,
            settings=defaults['get_operation'])
        self._list_operations = api_callable.create_api_call(
            self.operations_stub.ListOperations,
            settings=defaults['list_operations'])
        self._cancel_operation = api_callable.create_api_call(
            self.operations_stub.CancelOperation,
            settings=defaults['cancel_operation'])
        self._delete_operation = api_callable.create_api_call(
            self.operations_stub.DeleteOperation,
            settings=defaults['delete_operation'])
    def __init__(self,
                 service_path=SERVICE_ADDRESS,
                 port=DEFAULT_SERVICE_PORT,
                 channel=None,
                 metadata_transformer=None,
                 ssl_creds=None,
                 scopes=None,
                 client_config=None,
                 app_name='gax',
                 app_version=_GAX_VERSION):
        """Constructor.

        Args:
          service_path (string): The domain name of the API remote host.
          port (int): The port on which to connect to the remote host.
          channel (:class:`grpc.beta.implementations.Channel`): A ``Channel``
            object through which to make calls.
          ssl_creds (:class:`grpc.beta.implementations.ClientCredentials`):
            A `ClientCredentials` for use with an SSL-enabled channel.
          client_config (dict):
            A dictionary for call options for each method. See
            :func:`google.gax.construct_settings` for the structure of
            this data. Falls back to the default config if not specified
            or the specified config is missing data points.
          metadata_transformer (Callable[[], list]): A function that creates
             the metadata for requests.
          app_name (string): The codename of the calling service.
          app_version (string): The version of the calling service.

        Returns:
          A SubscriberApi object.
        """
        if scopes is None:
            scopes = self._ALL_SCOPES
        if client_config is None:
            client_config = {}
        goog_api_client = '{}/{} {} gax/{} python/{}'.format(
            app_name, app_version, self._CODE_GEN_NAME_VERSION,
            self._GAX_VERSION, platform.python_version())
        metadata = [('x-goog-api-client', goog_api_client)]
        default_client_config = json.loads(pkg_resources.resource_string(
            __name__, 'subscriber_client_config.json'))
        defaults = api_callable.construct_settings(
            'google.pubsub.v1.Subscriber',
            default_client_config,
            client_config,
            config.STATUS_CODE_NAMES,
            kwargs={'metadata': metadata},
            page_descriptors=self._PAGE_DESCRIPTORS)
        self.stub = config.create_stub(
            pubsub_pb2.beta_create_Subscriber_stub,
            service_path,
            port,
            ssl_creds=ssl_creds,
            channel=channel,
            metadata_transformer=metadata_transformer,
            scopes=scopes)
        self._create_subscription = api_callable.create_api_call(
            self.stub.CreateSubscription,
            settings=defaults['create_subscription'])
        self._get_subscription = api_callable.create_api_call(
            self.stub.GetSubscription,
            settings=defaults['get_subscription'])
        self._list_subscriptions = api_callable.create_api_call(
            self.stub.ListSubscriptions,
            settings=defaults['list_subscriptions'])
        self._delete_subscription = api_callable.create_api_call(
            self.stub.DeleteSubscription,
            settings=defaults['delete_subscription'])
        self._modify_ack_deadline = api_callable.create_api_call(
            self.stub.ModifyAckDeadline,
            settings=defaults['modify_ack_deadline'])
        self._acknowledge = api_callable.create_api_call(
            self.stub.Acknowledge,
            settings=defaults['acknowledge'])
        self._pull = api_callable.create_api_call(self.stub.Pull,
                                                  settings=defaults['pull'])
        self._modify_push_config = api_callable.create_api_call(
            self.stub.ModifyPushConfig,
            settings=defaults['modify_push_config'])