Content Client

The content client provides a method to search for entities in Preservica.

Creating a client

The client takes mandatory arguments for the url of the Preservica service and the secret name of the secrets manager secret storing the API credentials.

There is a caching layer which caches the secret value and the API token on disk. The duration of the cache defaults to 15 minutes but can be configured here.

It is also possible to configure the secrets manager endpoint. This can be used for testing or if using private endpoints in a VPC.

These examples use both the FS2 client and the ZIO client

The content client doesn’t take a Stream type parameter as the search method doesn’t need to stream.

object ContentClients {
  import cats.effect.IO
  import uk.gov.nationalarchives.dp.client.ContentClient
  import uk.gov.nationalarchives.dp.client.fs2.Fs2Client

  import scala.concurrent.duration.*

  val preservicaUrl = "https://test.preservica.com"
  val secretName = "nameOfSecretsManagerSecretContainingAPICredentials"

  val fs2ContentClientWithDefaults: IO[ContentClient[IO]] = Fs2Client.contentClient(preservicaUrl, secretName)
  val fs2ContentClientWithCustomCacheDuration: IO[ContentClient[IO]] =
    Fs2Client.contentClient(preservicaUrl, secretName, 30.minutes)
  val fs2ContentClientWithCustomSecretsManagerEndpoint: IO[ContentClient[IO]] =
    Fs2Client.contentClient(preservicaUrl, secretName, ssmEndpointUri = "https://private.ssm.endpoint")
  val fs2ContentClientWithCustomProxy: IO[ContentClient[IO]] =
    Fs2Client.contentClient(preservicaUrl, secretName, potentialProxyUrl = Option(URI.create("http://proxy.url")))
}

Method descriptions

These are descriptions of the steps taken by each method. All methods get an authentication token first, either from the API or the cache.

searchEntities

  • Convert the SearchQuery argument into a url with query parameters
  • Queries the API to get the first 100 entities
  • Checks to see if the objectIds in the response are empty. If they are, we have retrieved all entities. If not:
  • Query the API to get the next 100 entities. Repeat until all entities are found.
  • Convert the responses to Entity case classes and return a List of them all.