Esempio n. 1
0
    def authenticate(self, options):
        """[authenticate function to authenticate the service (aws s3/gcp bucket)].

        Args:
            options ([dict]): [options dict contains all the configuration settings]

        Returns:
            [object]: [a client object when authentication is successful else exception is raised]
        """
        try:
            credentials = None
            if 'CREDENTIAL_JSON' in options and options['CREDENTIAL_JSON']:
                credentials = service_account.Credentials.from_service_account_info(
                    json.loads(options['CREDENTIAL_JSON']))
            else:
                credentials = service_account.Credentials.from_service_account_file(
                    options['CREDENTIAL_FILE'])
            if credentials:
                client = storage.Client(
                    credentials=credentials, project=options['PROJECT_NAME'])
            else:
                raise exceptions.Forbidden('Authentication Failed')
            if client:
                return client
            else:
                raise exceptions.GoogleCloudError('Authentication Failed')
        except Exception as E:
            logging.exception("Exception {err}".format())
            raise Exception('Authentication Failed')
Esempio n. 2
0
def test_no_permission_buckets(mock_connection, mock_minio):
    bad_s3_path = "s3://random/path"
    bad_gcs_path = "gs://random/path"
    # Access private buckets without credentials
    mock_minio.return_value = Minio("s3.us.cloud-object-storage.appdomain.cloud", secure=True)
    mock_connection.side_effect = error.AccessDenied()
    with pytest.raises(error.AccessDenied):
        kfserving.Storage.download(bad_s3_path)
    mock_connection.side_effect = exceptions.Forbidden(None)
    with pytest.raises(exceptions.Forbidden):
        kfserving.Storage.download(bad_gcs_path)
Esempio n. 3
0
def test_no_permission_buckets_gcs(mock_connection):
    bad_gcs_path = "gs://random/path"

    mock_connection.side_effect = exceptions.Forbidden(None)
    with pytest.raises(exceptions.Forbidden):
        seldon_core.Storage.download(bad_gcs_path)