本文整理汇总了Python中firebase_admin.initialize_app方法的典型用法代码示例。如果您正苦于以下问题:Python firebase_admin.initialize_app方法的具体用法?Python firebase_admin.initialize_app怎么用?Python firebase_admin.initialize_app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类firebase_admin
的用法示例。
在下文中一共展示了firebase_admin.initialize_app方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_listen_error
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def test_listen_error(self):
test_url = 'https://test.firebaseio.com'
firebase_admin.initialize_app(testutils.MockCredential(), {
'databaseURL' : test_url,
})
try:
ref = db.reference()
adapter = MockAdapter(json.dumps({'error' : 'json error message'}), 500, [])
session = ref._client.session
session.mount(test_url, adapter)
def callback(_):
pass
with pytest.raises(exceptions.InternalError) as excinfo:
ref._listen_with_session(callback, session)
assert str(excinfo.value) == 'json error message'
assert excinfo.value.cause is not None
assert excinfo.value.http_response is not None
finally:
testutils.cleanup_apps()
示例2: main
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def main():
config = configparser.ConfigParser()
config.read("../private/51.ini")
key = config["firebase"]["key_path"]
database_url = config["firebase"]["database_url"]
cred = credentials.Certificate(key)
myapp = firebase_admin.initialize_app(cred, {"databaseURL": database_url})
if len(sys.argv) <= 1:
sys.argv.append("")
command = sys.argv[1]
content_list = sys.argv[2:]
content = " ".join(content_list)
check_valid_command(command)
do_command(command, content)
示例3: test_multi_db_support
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def test_multi_db_support(self):
default_url = 'https://test.firebaseio.com'
firebase_admin.initialize_app(testutils.MockCredential(), {
'databaseURL' : default_url,
})
ref = db.reference()
assert ref._client.base_url == default_url
assert 'auth_variable_override' not in ref._client.params
assert ref._client is db.reference()._client
assert ref._client is db.reference(url=default_url)._client
other_url = 'https://other.firebaseio.com'
other_ref = db.reference(url=other_url)
assert other_ref._client.base_url == other_url
assert 'auth_variable_override' not in ref._client.params
assert other_ref._client is db.reference(url=other_url)._client
assert other_ref._client is db.reference(url=other_url + '/')._client
示例4: test_delete_instance_id_error
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def test_delete_instance_id_error(self, status):
cred = testutils.MockCredential()
app = firebase_admin.initialize_app(cred, {'projectId': 'explicit-project-id'})
_, recorder = self._instrument_iid_service(app, status, 'some error')
msg, exc = http_errors.get(status)
with pytest.raises(exc) as excinfo:
instance_id.delete_instance_id('test_iid')
assert str(excinfo.value) == msg
assert excinfo.value.cause is not None
assert excinfo.value.http_response is not None
if status != 401:
assert len(recorder) == 1
else:
# 401 responses are automatically retried by google-auth
assert len(recorder) == 3
assert recorder[0].method == 'DELETE'
assert recorder[0].url == self._get_url('explicit-project-id', 'test_iid')
示例5: test_sign_with_discovered_service_account
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def test_sign_with_discovered_service_account(self):
request = testutils.MockRequest(200, 'discovered-service-account')
options = {'projectId': 'mock-project-id'}
app = firebase_admin.initialize_app(testutils.MockCredential(), name='iam-signer-app',
options=options)
try:
_overwrite_iam_request(app, request)
# Force initialization of the signing provider. This will invoke the Metadata service.
client = auth._get_client(app)
assert client._token_generator.signing_provider is not None
# Now invoke the IAM signer.
signature = base64.b64encode(b'test').decode()
request.response = testutils.MockResponse(
200, '{{"signature": "{0}"}}'.format(signature))
custom_token = auth.create_custom_token(MOCK_UID, app=app).decode()
assert custom_token.endswith('.' + signature.rstrip('='))
self._verify_signer(custom_token, 'discovered-service-account')
assert len(request.log) == 2
assert request.log[0][1]['headers'] == {'Metadata-Flavor': 'Google'}
finally:
firebase_admin.delete_app(app)
示例6: authenticate_with_admin_privileges
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def authenticate_with_admin_privileges():
# [START authenticate_with_admin_privileges]
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
# Fetch the service account key JSON file contents
cred = credentials.Certificate('path/to/serviceAccountKey.json')
# Initialize the app with a service account, granting admin privileges
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://databaseName.firebaseio.com'
})
# As an admin, the app has access to read and write all data, regradless of Security Rules
ref = db.reference('restricted_access/secret_document')
print(ref.get())
# [END authenticate_with_admin_privileges]
firebase_admin.delete_app(firebase_admin.get_app())
示例7: authenticate_with_limited_privileges
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def authenticate_with_limited_privileges():
# [START authenticate_with_limited_privileges]
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
# Fetch the service account key JSON file contents
cred = credentials.Certificate('path/to/serviceAccountKey.json')
# Initialize the app with a custom auth variable, limiting the server's access
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://databaseName.firebaseio.com',
'databaseAuthVariableOverride': {
'uid': 'my-service-worker'
}
})
# The app only has access as defined in the Security Rules
ref = db.reference('/some_resource')
print(ref.get())
# [END authenticate_with_limited_privileges]
firebase_admin.delete_app(firebase_admin.get_app())
示例8: authenticate_with_guest_privileges
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def authenticate_with_guest_privileges():
# [START authenticate_with_guest_privileges]
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
# Fetch the service account key JSON file contents
cred = credentials.Certificate('path/to/serviceAccountKey.json')
# Initialize the app with a None auth variable, limiting the server's access
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://databaseName.firebaseio.com',
'databaseAuthVariableOverride': None
})
# The app only has access to public data as defined in the Security Rules
ref = db.reference('/public_resource')
print(ref.get())
# [END authenticate_with_guest_privileges]
firebase_admin.delete_app(firebase_admin.get_app())
示例9: firebase_admin_app
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def firebase_admin_app(service_account):
try:
return firebase_admin.get_app()
except ValueError:
pass
return firebase_admin.initialize_app(
firebase_admin.credentials.Certificate(service_account)
)
示例10: firebase_setup
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def firebase_setup():
"""
Required imports and authentication using json service key.
Instantiate firebase object for future manipulation.
"""
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
cred = credentials.Certificate(
'/home/pi/SmartBin/data/guiwithkivy-48023-firebase-adminsdk-i41qf-c08ecb8507.json')
firebase_admin.initialize_app(
cred, {'databaseURL': 'https://guiwithkivy-48023.firebaseio.com/', })
firebase = db.reference('/')
return firebase
示例11: main
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def main():
config = configparser.ConfigParser()
config.read("../private/53.ini")
key = config["firebase"]["key_path"]
database_url = config["firebase"]["database_url"]
cred = credentials.Certificate(key)
myapp = firebase_admin.initialize_app(cred, {"databaseURL": database_url})
run_server()
示例12: main
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def main():
config = configparser.ConfigParser()
config.read("../private/54.ini")
key = config["firebase"]["key_path"]
database_url = config["firebase"]["database_url"]
cred = credentials.Certificate(key)
myapp = firebase_admin.initialize_app(cred, {"databaseURL": database_url})
run_server()
示例13: main
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def main():
config = configparser.ConfigParser()
config.read("../private/55.ini")
key = config["firebase"]["key_path"]
database_url = config["firebase"]["database_url"]
cred = credentials.Certificate(key)
myapp = firebase_admin.initialize_app(cred, {"databaseURL": database_url})
run_server()
示例14: app
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def app(request):
cred, project_id = integration_conf(request)
ops = {
'databaseURL' : 'https://{0}.firebaseio.com'.format(project_id),
}
return firebase_admin.initialize_app(cred, ops, name='integration-db')
示例15: override_app
# 需要导入模块: import firebase_admin [as 别名]
# 或者: from firebase_admin import initialize_app [as 别名]
def override_app(request, update_rules):
del update_rules
cred, project_id = integration_conf(request)
ops = {
'databaseURL' : 'https://{0}.firebaseio.com'.format(project_id),
'databaseAuthVariableOverride' : {'uid' : 'user1'}
}
app = firebase_admin.initialize_app(cred, ops, 'db-override')
yield app
firebase_admin.delete_app(app)