Scala storage client Build Version

Finally-tagless implementation of client for misc. storages represented by backends. Supports backends fallbacks.

Currently supported backends:

  1. HCP (Hitachi Content Platform)
  2. GCS (Google Cloud Storage)

Dependency

Use dependency from README of selected backend:

compile "com.avast.clients.storage:storage-client-BACKEND_2.13:x.x.x"

Usage

The library has two levels:

  1. Storage client which contains so called backend
  2. Storage backend which is actual storage connector

The client has only single backend inside however backends are combinable to provide fallback support:

val backend1: StorageBackend[F] = ???
val backend2: StorageBackend[F] = ???

val merged: StorageBackend[F] = backend1 withFallbackTo backend2

Retries etc.

Retries and similar functionality is not supported out-of-the-box by the library but you can easily implement them by your own by using some F[_] which is capable of doing it and is familiar to you.

Example for monix.eval.Task:

import better.files.File
import com.avast.clients.storage.{GetResult, HeadResult, StorageBackend, StorageException}
import com.avast.scala.hashes.Sha256
import monix.eval.Task
val backend: StorageBackend[Task] = ???

val retried = new StorageBackend[Task] {
  override def head(sha256: Sha256): Task[Either[StorageException, HeadResult]] = backend.head(sha256).onErrorRestart(3)
  
  override def get(sha256: Sha256, dest: File): Task[Either[StorageException, GetResult]] = backend.get(sha256, dest).onErrorRestart(3)
  
  override def close(): Unit = backend.close()
}

Example

Example usage for monix.eval.Task:

import com.avast.clients.storage.{StorageBackend, StorageClient}
import monix.eval.Task
import monix.execution.Scheduler

implicit val scheduler: Scheduler = ???
val backend: StorageBackend[Task] = ???

val client = StorageClient(backend)