本文整理汇总了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)
示例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())
示例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)
示例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)
示例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)
示例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
示例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)
示例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")
示例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 == {}
示例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)
示例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