当前位置: 首页>>代码示例>>Python>>正文


Python credentials.Credentials方法代码示例

本文整理汇总了Python中google.auth.credentials.Credentials方法的典型用法代码示例。如果您正苦于以下问题:Python credentials.Credentials方法的具体用法?Python credentials.Credentials怎么用?Python credentials.Credentials使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.auth.credentials的用法示例。


在下文中一共展示了credentials.Credentials方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _make_client_document

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def _make_client_document(firestore_api, testcase):
    from google.cloud.firestore_v1beta1 import Client
    from google.cloud.firestore_v1beta1.client import DEFAULT_DATABASE
    import google.auth.credentials

    _, project, _, database, _, doc_path = testcase.doc_ref_path.split("/", 5)
    assert database == DEFAULT_DATABASE

    # Attach the fake GAPIC to a real client.
    credentials = mock.Mock(spec=google.auth.credentials.Credentials)

    with pytest.deprecated_call():
        client = Client(project=project, credentials=credentials)

    client._firestore_api_internal = firestore_api
    return client, client.document(doc_path) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:18,代码来源:test_cross_language.py

示例2: __init__

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def __init__(self, scopes=None, service_account_id=None):
        """
        Args:
            scopes (Sequence[str]): Scopes to request from the App Identity
                API.
            service_account_id (str): The service account ID passed into
                :func:`google.appengine.api.app_identity.get_access_token`.
                If not specified, the default application service account
                ID will be used.

        Raises:
            EnvironmentError: If the App Engine APIs are unavailable.
        """
        # pylint: disable=missing-raises-doc
        # Pylint rightfully thinks EnvironmentError is OSError, but doesn't
        # realize it's a valid alias.
        if app_identity is None:
            raise EnvironmentError("The App Engine APIs are not available.")

        super(Credentials, self).__init__()
        self._scopes = scopes
        self._service_account_id = service_account_id
        self._signer = Signer() 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:25,代码来源:app_engine.py

示例3: __init__

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def __init__(self, target_credentials, target_audience=None, include_email=False):
        """
        Args:
            target_credentials (google.auth.Credentials): The target
                credential used as to acquire the id tokens for.
            target_audience (string): Audience to issue the token for.
            include_email (bool): Include email in IdToken
        """
        super(IDTokenCredentials, self).__init__()

        if not isinstance(target_credentials, Credentials):
            raise exceptions.GoogleAuthError(
                "Provided Credential must be " "impersonated_credentials"
            )
        self._target_credentials = target_credentials
        self._target_audience = target_audience
        self._include_email = include_email 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:19,代码来源:impersonated_credentials.py

示例4: with_quota_project

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def with_quota_project(self, quota_project_id):
        """Returns a copy of these credentials with a modified quota project

        Args:
            quota_project_id (str): The project to use for quota and
            billing purposes

        Returns:
            google.oauth2.credentials.Credentials: A new credentials instance.
        """
        return self.__class__(
            self.token,
            refresh_token=self.refresh_token,
            id_token=self.id_token,
            token_uri=self.token_uri,
            client_id=self.client_id,
            client_secret=self.client_secret,
            scopes=self.scopes,
            quota_project_id=quota_project_id,
        ) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:22,代码来源:credentials.py

示例5: from_authorized_user_file

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def from_authorized_user_file(cls, filename, scopes=None):
        """Creates a Credentials instance from an authorized user json file.

        Args:
            filename (str): The path to the authorized user json file.
            scopes (Sequence[str]): Optional list of scopes to include in the
                credentials.

        Returns:
            google.oauth2.credentials.Credentials: The constructed
                credentials.

        Raises:
            ValueError: If the file is not in the expected format.
        """
        with io.open(filename, "r", encoding="utf-8") as json_file:
            data = json.load(json_file)
            return cls.from_authorized_user_info(data, scopes) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:20,代码来源:credentials.py

示例6: _from_signer_and_info

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def _from_signer_and_info(cls, signer, info, **kwargs):
        """Creates a Credentials instance from a signer and service account
        info.

        Args:
            signer (google.auth.crypt.Signer): The signer used to sign JWTs.
            info (Mapping[str, str]): The service account info.
            kwargs: Additional arguments to pass to the constructor.

        Returns:
            google.auth.jwt.Credentials: The constructed credentials.

        Raises:
            ValueError: If the info is not in the expected format.
        """
        return cls(
            signer,
            service_account_email=info["client_email"],
            token_uri=info["token_uri"],
            project_id=info.get("project_id"),
            **kwargs
        ) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:24,代码来源:service_account.py

示例7: from_service_account_info

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def from_service_account_info(cls, info, **kwargs):
        """Creates a Credentials instance from parsed service account info.

        Args:
            info (Mapping[str, str]): The service account info in Google
                format.
            kwargs: Additional arguments to pass to the constructor.

        Returns:
            google.auth.service_account.Credentials: The constructed
                credentials.

        Raises:
            ValueError: If the info is not in the expected format.
        """
        signer = _service_account_info.from_dict(
            info, require=["client_email", "token_uri"]
        )
        return cls._from_signer_and_info(signer, info, **kwargs) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:21,代码来源:service_account.py

示例8: with_subject

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def with_subject(self, subject):
        """Create a copy of these credentials with the specified subject.

        Args:
            subject (str): The subject claim.

        Returns:
            google.auth.service_account.Credentials: A new credentials
                instance.
        """
        return self.__class__(
            self._signer,
            service_account_email=self._service_account_email,
            scopes=self._scopes,
            token_uri=self._token_uri,
            subject=subject,
            project_id=self._project_id,
            quota_project_id=self._quota_project_id,
            additional_claims=self._additional_claims.copy(),
        ) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:22,代码来源:service_account.py

示例9: with_claims

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def with_claims(self, additional_claims):
        """Returns a copy of these credentials with modified claims.

        Args:
            additional_claims (Mapping[str, str]): Any additional claims for
                the JWT payload. This will be merged with the current
                additional claims.

        Returns:
            google.auth.service_account.Credentials: A new credentials
                instance.
        """
        new_additional_claims = copy.deepcopy(self._additional_claims)
        new_additional_claims.update(additional_claims or {})

        return self.__class__(
            self._signer,
            service_account_email=self._service_account_email,
            scopes=self._scopes,
            token_uri=self._token_uri,
            subject=self._subject,
            project_id=self._project_id,
            quota_project_id=self._quota_project_id,
            additional_claims=new_additional_claims,
        ) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:27,代码来源:service_account.py

示例10: __init__

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def __init__(self, credentials: credentials.Credentials):
        self._source_generator = source_generator.DjangoSourceFileGenerator()
        self._billing_client = billing.BillingClient.from_credentials(
            credentials)
        self._project_workflow = _project.ProjectWorkflow(credentials)
        self._database_workflow = _database.DatabaseWorkflow(credentials)
        self.deploy_workflow = deploy_workflow.DeployWorkflow(credentials)
        self._enable_service_workflow = _enable_service.EnableServiceWorkflow(
            credentials)
        self._service_account_workflow = (
            _service_account.ServiceAccountKeyGenerationWorkflow(credentials))
        self._static_content_workflow = (
            _static_content_serve.StaticContentServeWorkflow(credentials))
        self._file_bucket_workflow = (
            _file_bucket.FileBucketCreationWorkflow(credentials))
        self._console_io = io.ConsoleIO() 
开发者ID:GoogleCloudPlatform,项目名称:django-cloud-deploy,代码行数:18,代码来源:__init__.py

示例11: create_batch

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def create_batch(status=None, settings=types.BatchSettings()):
    """Create a batch object, which does not commit.

    Args:
        status (str): If provided, the batch's internal status will be set
            to the provided status.

    Returns:
        ~.pubsub_v1.publisher.batch.thread.Batch: The batch object
    """
    creds = mock.Mock(spec=credentials.Credentials)
    client = publisher.Client(credentials=creds)
    batch = Batch(client, "topic_name", settings)
    if status:
        batch._status = status
    return batch 
开发者ID:googleapis,项目名称:python-pubsub,代码行数:18,代码来源:test_base.py

示例12: test_publish_error_exceeding_flow_control_limits

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def test_publish_error_exceeding_flow_control_limits():
    creds = mock.Mock(spec=credentials.Credentials)
    publisher_options = types.PublisherOptions(
        flow_control=types.PublishFlowControl(
            message_limit=10,
            byte_limit=150,
            limit_exceeded_behavior=types.LimitExceededBehavior.ERROR,
        )
    )
    client = publisher.Client(credentials=creds, publisher_options=publisher_options)

    mock_batch = mock.Mock(spec=client._batch_class)
    topic = "topic/path"
    client._set_batch(topic, mock_batch)

    future1 = client.publish(topic, b"a" * 100)
    future2 = client.publish(topic, b"b" * 100)

    future1.result()  # no error, still within flow control limits
    with pytest.raises(exceptions.FlowControlLimitError):
        future2.result() 
开发者ID:googleapis,项目名称:python-pubsub,代码行数:23,代码来源:test_publisher_client.py

示例13: test_publish_attrs_bytestring

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def test_publish_attrs_bytestring():
    creds = mock.Mock(spec=credentials.Credentials)
    client = publisher.Client(credentials=creds)

    # Use a mock in lieu of the actual batch class.
    batch = mock.Mock(spec=client._batch_class)
    # Set the mock up to claim indiscriminately that it accepts all messages.

    topic = "topic/path"
    client._set_batch(topic, batch)

    # Begin publishing.
    future = client.publish(topic, b"foo", bar=b"baz")

    assert future is batch.publish.return_value

    # The attributes should have been sent as text.
    batch.publish.assert_called_once_with(
        types.PubsubMessage(data=b"foo", attributes={"bar": u"baz"})
    ) 
开发者ID:googleapis,项目名称:python-pubsub,代码行数:22,代码来源:test_publisher_client.py

示例14: test_stop

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def test_stop():
    creds = mock.Mock(spec=credentials.Credentials)
    client = publisher.Client(credentials=creds)

    batch1 = mock.Mock(spec=client._batch_class)
    topic = "topic/path"
    client._set_batch(topic, batch1)

    client.stop()

    assert batch1.commit.call_count == 1

    with pytest.raises(RuntimeError):
        client.publish("topic1", b"msg2")

    with pytest.raises(RuntimeError):
        client.resume_publish("topic", "ord_key")

    with pytest.raises(RuntimeError):
        client.stop() 
开发者ID:googleapis,项目名称:python-pubsub,代码行数:22,代码来源:test_publisher_client.py

示例15: test_commit_thread_created_on_publish

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import Credentials [as 别名]
def test_commit_thread_created_on_publish():
    creds = mock.Mock(spec=credentials.Credentials)
    # Max latency is not infinite so a commit thread is created.
    batch_settings = types.BatchSettings(max_latency=600)
    client = publisher.Client(batch_settings=batch_settings, credentials=creds)

    with mock.patch.object(
        client, "_start_commit_thread", autospec=True
    ) as _start_commit_thread:
        # First publish should create a commit thread.
        assert client.publish("topic", b"bytestring body", ordering_key="") is not None
        _start_commit_thread.assert_called_once()

        # Since _start_commit_thread is a mock, no actual thread has been
        # created, so let's put a sentinel there to mimic real behavior.
        client._commit_thread = mock.Mock()

        # Second publish should not create a commit thread since one (the mock)
        # already exists.
        assert client.publish("topic", b"bytestring body", ordering_key="") is not None
        # Call count should remain 1.
        _start_commit_thread.assert_called_once() 
开发者ID:googleapis,项目名称:python-pubsub,代码行数:24,代码来源:test_publisher_client.py


注:本文中的google.auth.credentials.Credentials方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。