當前位置: 首頁>>代碼示例>>Python>>正文


Python credentials.AnonymousCredentials方法代碼示例

本文整理匯總了Python中google.auth.credentials.AnonymousCredentials方法的典型用法代碼示例。如果您正苦於以下問題:Python credentials.AnonymousCredentials方法的具體用法?Python credentials.AnonymousCredentials怎麽用?Python credentials.AnonymousCredentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.auth.credentials的用法示例。


在下文中一共展示了credentials.AnonymousCredentials方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: construct_client

# 需要導入模塊: from google.auth import credentials [as 別名]
# 或者: from google.auth.credentials import AnonymousCredentials [as 別名]
def construct_client(client_class,
                     use_mtls,
                     transport="grpc",
                     channel_creator=grpc.insecure_channel):
    if use_mtls:
        with mock.patch("grpc.ssl_channel_credentials", autospec=True) as mock_ssl_cred:
            mock_ssl_cred.return_value = ssl_credentials
            client = client_class(
                credentials=credentials.AnonymousCredentials(),
                client_options=client_options,
            )
            mock_ssl_cred.assert_called_once_with(
                certificate_chain=cert, private_key=key
            )
            return client
    else:
        transport = client_class.get_transport_class(transport)(
            channel=channel_creator("localhost:7469")
        )
        return client_class(transport=transport) 
開發者ID:googleapis,項目名稱:gapic-generator-python,代碼行數:22,代碼來源:conftest.py

示例2: setUp

# 需要導入模塊: from google.auth import credentials [as 別名]
# 或者: from google.auth.credentials import AnonymousCredentials [as 別名]
def setUp(self):
    super(ManagerTest, self).setUp()
    # Save the real modules for clean up.
    self.real_open = builtins.open
    # Create a fake file system and stub out builtin modules.
    self.fs = fake_filesystem.FakeFilesystem()
    self.os = fake_filesystem.FakeOsModule(self.fs)
    self.open = fake_filesystem.FakeFileOpen(self.fs)
    self.stdout = StringIO()
    self.stubs = mox3_stubout.StubOutForTesting()
    self.stubs.SmartSet(builtins, 'open', self.open)
    self.stubs.SmartSet(common, 'os', self.os)
    self.stubs.SmartSet(sys, 'stdout', self.stdout)

    # Setup Testdata.
    self._testdata_path = '/testdata'
    self._valid_config_path = self._testdata_path + '/valid_config.yaml'
    self._blank_config_path = self._testdata_path + '/blank_config.yaml'

    self.fs.CreateFile(self._valid_config_path, contents=_VALID_CONFIG)
    self.fs.CreateFile(self._blank_config_path, contents=_BLANK_CONFIG)

    # Load the default config.
    self._valid_default_config = common.ProjectConfig.from_yaml(
        common.DEFAULT, self._valid_config_path)

    # Create test constants.
    self._constants = {
        'test': app_constants.Constant(
            'test', 'message', '',
            parser=utils.StringParser(allow_empty_string=False),),
        'other': app_constants.Constant('other', 'other message', 'value'),
    }

    # Mock out the authentication credentials.
    self.auth_patcher = mock.patch.object(auth, 'CloudCredentials')
    self.mock_creds = self.auth_patcher.start()
    self.mock_creds.return_value.get_credentials.return_value = (
        credentials.AnonymousCredentials()) 
開發者ID:google,項目名稱:loaner,代碼行數:41,代碼來源:gng_impl_test.py

示例3: test_new__auth_error

# 需要導入模塊: from google.auth import credentials [as 別名]
# 或者: from google.auth.credentials import AnonymousCredentials [as 別名]
def test_new__auth_error(self):
    side_effect = [
        'default-project',
        'default.apps.googleusercontent.com',
        'default-secret',
    ]
    mock_creds = mock.Mock()
    mock_creds.get_credentials.return_value = credentials.AnonymousCredentials()
    with mock.patch.object(
        utils, 'prompt_string', side_effect=side_effect) as mock_prompt_string:
      with mock.patch.object(
          auth, 'CloudCredentials',
          side_effect=[auth.InvalidCredentials, mock_creds]):
        gng_impl._Manager.new(self._valid_config_path, False, common.DEFAULT)
      self.assertEqual(3, mock_prompt_string.call_count) 
開發者ID:google,項目名稱:loaner,代碼行數:17,代碼來源:gng_impl_test.py

示例4: get_default

# 需要導入模塊: from google.auth import credentials [as 別名]
# 或者: from google.auth.credentials import AnonymousCredentials [as 別名]
def get_default(scopes=None):
  """Get default Google Cloud credentials."""
  if _use_anonymous_credentials():
    return credentials.AnonymousCredentials(), ''

  return google.auth.default(scopes=scopes) 
開發者ID:google,項目名稱:clusterfuzz,代碼行數:8,代碼來源:credentials.py

示例5: __init__

# 需要導入模塊: from google.auth import credentials [as 別名]
# 或者: from google.auth.credentials import AnonymousCredentials [as 別名]
def __init__(self, *args, **kwargs):
        data_proxy_project = os.getenv("KAGGLE_DATA_PROXY_PROJECT")
        anon_credentials = credentials.AnonymousCredentials()
        anon_credentials.refresh = lambda *args: None
        super().__init__(
            project=data_proxy_project, credentials=anon_credentials, *args, **kwargs
        )
        # TODO: Remove this once https://github.com/googleapis/google-cloud-python/issues/7122 is implemented.
        self._connection = _DataProxyConnection(self) 
開發者ID:Kaggle,項目名稱:docker-python,代碼行數:11,代碼來源:kaggle_gcp.py

示例6: test_anonymous_credentials_ctor

# 需要導入模塊: from google.auth import credentials [as 別名]
# 或者: from google.auth.credentials import AnonymousCredentials [as 別名]
def test_anonymous_credentials_ctor():
    anon = credentials.AnonymousCredentials()
    assert anon.token is None
    assert anon.expiry is None
    assert not anon.expired
    assert anon.valid 
開發者ID:googleapis,項目名稱:google-auth-library-python,代碼行數:8,代碼來源:test_credentials.py

示例7: test_anonymous_credentials_refresh

# 需要導入模塊: from google.auth import credentials [as 別名]
# 或者: from google.auth.credentials import AnonymousCredentials [as 別名]
def test_anonymous_credentials_refresh():
    anon = credentials.AnonymousCredentials()
    request = object()
    with pytest.raises(ValueError):
        anon.refresh(request) 
開發者ID:googleapis,項目名稱:google-auth-library-python,代碼行數:7,代碼來源:test_credentials.py

示例8: test_anonymous_credentials_apply_default

# 需要導入模塊: from google.auth import credentials [as 別名]
# 或者: from google.auth.credentials import AnonymousCredentials [as 別名]
def test_anonymous_credentials_apply_default():
    anon = credentials.AnonymousCredentials()
    headers = {}
    anon.apply(headers)
    assert headers == {}
    with pytest.raises(ValueError):
        anon.apply(headers, token="TOKEN") 
開發者ID:googleapis,項目名稱:google-auth-library-python,代碼行數:9,代碼來源:test_credentials.py

示例9: test_anonymous_credentials_before_request

# 需要導入模塊: from google.auth import credentials [as 別名]
# 或者: from google.auth.credentials import AnonymousCredentials [as 別名]
def test_anonymous_credentials_before_request():
    anon = credentials.AnonymousCredentials()
    request = object()
    method = "GET"
    url = "https://example.com/api/endpoint"
    headers = {}
    anon.before_request(request, method, url, headers)
    assert headers == {} 
開發者ID:googleapis,項目名稱:google-auth-library-python,代碼行數:10,代碼來源:test_credentials.py

示例10: test_create_anonymous_client

# 需要導入模塊: from google.auth import credentials [as 別名]
# 或者: from google.auth.credentials import AnonymousCredentials [as 別名]
def test_create_anonymous_client(self):
        from google.auth.credentials import AnonymousCredentials
        from google.cloud.storage._http import Connection

        klass = self._get_target_class()
        client = klass.create_anonymous_client()

        self.assertIsNone(client.project)
        self.assertIsInstance(client._connection, Connection)
        self.assertIsInstance(client._connection.credentials, AnonymousCredentials) 
開發者ID:googleapis,項目名稱:python-storage,代碼行數:12,代碼來源:test_client.py

示例11: create_anonymous_client

# 需要導入模塊: from google.auth import credentials [as 別名]
# 或者: from google.auth.credentials import AnonymousCredentials [as 別名]
def create_anonymous_client(cls):
        """Factory: return client with anonymous credentials.

        .. note::

           Such a client has only limited access to "public" buckets:
           listing their contents and downloading their blobs.

        :rtype: :class:`google.cloud.storage.client.Client`
        :returns: Instance w/ anonymous credentials and no project.
        """
        client = cls(project="<none>", credentials=AnonymousCredentials())
        client.project = None
        return client 
開發者ID:googleapis,項目名稱:python-storage,代碼行數:16,代碼來源:client.py


注:本文中的google.auth.credentials.AnonymousCredentials方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。