Esempio n. 1
0
def test_gs_session_class():
    """GSSession works"""
    gs_session = GSSession(google_application_credentials='foo')
    assert gs_session._creds
    assert gs_session.get_credential_options(
    )['GOOGLE_APPLICATION_CREDENTIALS'] == 'foo'
    assert gs_session.hascreds({'GOOGLE_APPLICATION_CREDENTIALS': 'foo'})
Esempio n. 2
0
def test_gs_session_class():
    """GSSession works"""
    gs_session = GSSession(
        google_application_credentials='foo')
    assert gs_session._creds
    assert gs_session.get_credential_options()['GOOGLE_APPLICATION_CREDENTIALS'] == 'foo'
    assert gs_session.hascreds({'GOOGLE_APPLICATION_CREDENTIALS': 'foo'})
Esempio n. 3
0
def get_raster_profile(request):
    """
    Cloud function that get a raster from Google Cloud Storage and returns its `rasterio` profile.

    :param request:
    :return:
    """
    try:
        filename = request.args["filename"]
    except KeyError:
        logging.error("'filename' parameter is missing", exc_info=True)
        flask.abort(400)

    try:
        bucket = request.args["bucket"]
    except KeyError:
        logging.error("'bucket' parameter is missing", exc_info=True)
        flask.abort(400)

    # Get the credentials and project ID from the environment
    credentials, project = google.auth.default()
    print(credentials)
    print(credentials.to_json())
    print(project)
    google.auth.C
    # Create a requests Session object with the credentials
    session = requests.AuthorizedSession(credentials)
    print(session)

    with rasterio.Env(session_class=GSSession(credentials.to_json())):
        with rasterio.open(f"gs://{bucket}/{filename}") as src:
            profile = src.profile

    return flask.jsonify(profile)
Esempio n. 4
0
def test_google_session_ctor_no_arg():
    session = GSSession()
    assert not session._creds