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


Python firebase_admin.initialize_app方法代码示例

本文整理汇总了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() 
开发者ID:firebase,项目名称:firebase-admin-python,代码行数:21,代码来源:test_db.py

示例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) 
开发者ID:jbaltop,项目名称:57_Challenges,代码行数:19,代码来源:51.py

示例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 
开发者ID:firebase,项目名称:firebase-admin-python,代码行数:19,代码来源:test_db.py

示例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') 
开发者ID:firebase,项目名称:firebase-admin-python,代码行数:19,代码来源:test_instance_id.py

示例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) 
开发者ID:firebase,项目名称:firebase-admin-python,代码行数:24,代码来源:test_token_gen.py

示例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()) 
开发者ID:firebase,项目名称:firebase-admin-python,代码行数:21,代码来源:index.py

示例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()) 
开发者ID:firebase,项目名称:firebase-admin-python,代码行数:24,代码来源:index.py

示例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()) 
开发者ID:firebase,项目名称:firebase-admin-python,代码行数:22,代码来源:index.py

示例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)
    ) 
开发者ID:theacodes,项目名称:conducthotline.com,代码行数:10,代码来源:webhandlers.py

示例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 
开发者ID:tlkh,项目名称:SmartBin,代码行数:17,代码来源:iot.py

示例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() 
开发者ID:jbaltop,项目名称:57_Challenges,代码行数:12,代码来源:53.py

示例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() 
开发者ID:jbaltop,项目名称:57_Challenges,代码行数:12,代码来源:54.py

示例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() 
开发者ID:jbaltop,项目名称:57_Challenges,代码行数:12,代码来源:55.py

示例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') 
开发者ID:firebase,项目名称:firebase-admin-python,代码行数:8,代码来源:test_db.py

示例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) 
开发者ID:firebase,项目名称:firebase-admin-python,代码行数:12,代码来源:test_db.py


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