Exemple #1
0
def test_nested_credentials(monkeypatch):
    """Check that rasterio.open() doesn't wipe out surrounding credentials"""
    @ensure_env_with_credentials
    def fake_opener(path):
        return fiona.env.getenv()

    with fiona.env.Env(session=AWSSession(aws_access_key_id='foo',
                                          aws_secret_access_key='bar')):
        assert fiona.env.getenv()['AWS_ACCESS_KEY_ID'] == 'foo'
        assert fiona.env.getenv()['AWS_SECRET_ACCESS_KEY'] == 'bar'

        monkeypatch.setenv('AWS_ACCESS_KEY_ID', 'lol')
        monkeypatch.setenv('AWS_SECRET_ACCESS_KEY', 'wut')
        gdalenv = fake_opener('s3://foo/bar')
        assert gdalenv['AWS_ACCESS_KEY_ID'] == 'foo'
        assert gdalenv['AWS_SECRET_ACCESS_KEY'] == 'bar'
Exemple #2
0
    def aws_session(self):
        """Because the session object cannot be pickled this provides the session lazily (i.e. the first time it is
        needed)

        :return: A session for AWS services
        :rtype: AWSSession
        """
        if self._aws_session is None:
            boto_session = boto3.session.Session(
                aws_access_key_id=self.config.aws_access_key_id or None,
                aws_secret_access_key=self.config.aws_secret_access_key
                or None,
                aws_session_token=self.config.aws_session_token or None,
            )
            self._aws_session = AWSSession(boto_session)

        return self._aws_session
Exemple #3
0
    def aws_session(self):
        """ Because the session object cannot be pickled this provides the session lazily (i.e. the first time it is
        needed)

        :return: A session for AWS services
        :rtype: AWSSession
        """
        if self._aws_session is None:
            session_credentials = {}
            if self.config and self.config.aws_access_key_id and self.config.aws_secret_access_key:
                session_credentials[
                    'aws_access_key_id'] = self.config.aws_access_key_id
                session_credentials[
                    'aws_secret_access_key'] = self.config.aws_secret_access_key

            boto_session = boto3.session.Session(**session_credentials)
            self._aws_session = AWSSession(boto_session)

        return self._aws_session
Exemple #4
0
def main_group(
        ctx, verbose, quiet, aws_profile, aws_no_sign_requests,
        aws_requester_pays):
    """Fiona command line interface.
    """
    verbosity = verbose - quiet
    configure_logging(verbosity)
    ctx.obj = {}
    ctx.obj["verbosity"] = verbosity
    ctx.obj["aws_profile"] = aws_profile
    envopts = {"CPL_DEBUG": (verbosity > 2)}
    if aws_profile or aws_no_sign_requests:
        session = AWSSession(
            profile_name=aws_profile,
            aws_unsigned=aws_no_sign_requests,
            requester_pays=aws_requester_pays,
        )
    else:
        session = DummySession()
    ctx.obj["env"] = fiona.Env(session=session, **envopts)