All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scala.googleapis.storage.BucketsClient.scala Maven / Gradle / Ivy

The newest version!
package googleapis.storage

import cats.effect.Concurrent
import org.http4s._
import org.http4s.implicits._
import org.http4s.client.Client

class BucketsClient[F[_]: Concurrent](client: Client[F]) extends AbstractClient[F](client) {
  val baseUri = uri"https://storage.googleapis.com/storage/v1"
  def testIamPermissions(
      /** Name of a bucket.
        */
      bucket: String,
      query: BucketsClient.TestIamPermissionsParams = BucketsClient.TestIamPermissionsParams(),
  ): F[TestIamPermissionsResponse] = expectJson[TestIamPermissionsResponse](
    request(
      method = Method.GET,
      uri = (baseUri / "b" / s"${bucket}" / "iam" / "testPermissions")
        .copy(query = Query("permissions" -> query.permissions, "userProject" -> query.userProject)),
    )
  )
  def insert(
      query: BucketsClient.InsertParams = BucketsClient.InsertParams()
  )(input: Bucket): F[Bucket] = expectJson[Bucket](
    requestWithBody(
      method = Method.POST,
      uri = (baseUri / "b").copy(query =
        Query(
          "enableObjectRetention" -> query.enableObjectRetention.map(s =>
            QueryParamEncoder[Boolean].encode(s).value
          ),
          "predefinedAcl" -> query.predefinedAcl,
          "predefinedDefaultObjectAcl" -> query.predefinedDefaultObjectAcl,
          "project" -> query.project,
          "projection" -> query.projection,
          "userProject" -> query.userProject,
        )
      ),
    )(input)
  )
  def restore(
      /** Name of a bucket.
        */
      bucket: String,
      query: BucketsClient.RestoreParams = BucketsClient.RestoreParams(),
  ): F[Status] = client.status(
    request(
      method = Method.POST,
      uri = (baseUri / "b" / s"${bucket}" / "restore")
        .copy(query = Query("generation" -> query.generation, "userProject" -> query.userProject)),
    )
  )
  def setIamPolicy(
      /** Name of a bucket.
        */
      bucket: String,
      query: BucketsClient.SetIamPolicyParams = BucketsClient.SetIamPolicyParams(),
  )(input: Policy): F[Policy] = expectJson[Policy](
    requestWithBody(
      method = Method.PUT,
      uri = (baseUri / "b" / s"${bucket}" / "iam")
        .copy(query = Query("userProject" -> query.userProject)),
    )(input)
  )
  def getIamPolicy(
      /** Name of a bucket.
        */
      bucket: String,
      query: BucketsClient.GetIamPolicyParams = BucketsClient.GetIamPolicyParams(),
  ): F[Policy] = expectJson[Policy](
    request(
      method = Method.GET,
      uri = (baseUri / "b" / s"${bucket}" / "iam").copy(query =
        Query(
          "optionsRequestedPolicyVersion" -> query.optionsRequestedPolicyVersion.map(s =>
            QueryParamEncoder[Int].encode(s).value
          ),
          "userProject" -> query.userProject,
        )
      ),
    )
  )
  def delete(
      /** Name of a bucket.
        */
      bucket: String,
      query: BucketsClient.DeleteParams = BucketsClient.DeleteParams(),
  ): F[Status] = client.status(
    request(
      method = Method.DELETE,
      uri = (baseUri / "b" / s"${bucket}").copy(query =
        Query(
          "ifMetagenerationMatch" -> query.ifMetagenerationMatch,
          "ifMetagenerationNotMatch" -> query.ifMetagenerationNotMatch,
          "userProject" -> query.userProject,
        )
      ),
    )
  )
  def getStorageLayout(
      /** Name of a bucket.
        */
      bucket: String,
      query: BucketsClient.GetStorageLayoutParams = BucketsClient.GetStorageLayoutParams(),
  ): F[BucketStorageLayout] = expectJson[BucketStorageLayout](
    request(
      method = Method.GET,
      uri = (baseUri / "b" / s"${bucket}" / "storageLayout")
        .copy(query = Query("prefix" -> query.prefix)),
    )
  )
  def get(
      /** Name of a bucket.
        */
      bucket: String,
      query: BucketsClient.GetParams = BucketsClient.GetParams(),
  ): F[Bucket] = expectJson[Bucket](
    request(
      method = Method.GET,
      uri = (baseUri / "b" / s"${bucket}").copy(query =
        Query(
          "generation" -> query.generation,
          "ifMetagenerationMatch" -> query.ifMetagenerationMatch,
          "ifMetagenerationNotMatch" -> query.ifMetagenerationNotMatch,
          "projection" -> query.projection,
          "softDeleted" -> query.softDeleted.map(s => QueryParamEncoder[Boolean].encode(s).value),
          "userProject" -> query.userProject,
        )
      ),
    )
  )
  def update(
      /** Name of a bucket.
        */
      bucket: String,
      query: BucketsClient.UpdateParams = BucketsClient.UpdateParams(),
  )(input: Bucket): F[Bucket] = expectJson[Bucket](
    requestWithBody(
      method = Method.PUT,
      uri = (baseUri / "b" / s"${bucket}").copy(query =
        Query(
          "ifMetagenerationMatch" -> query.ifMetagenerationMatch,
          "ifMetagenerationNotMatch" -> query.ifMetagenerationNotMatch,
          "predefinedAcl" -> query.predefinedAcl,
          "predefinedDefaultObjectAcl" -> query.predefinedDefaultObjectAcl,
          "projection" -> query.projection,
          "userProject" -> query.userProject,
        )
      ),
    )(input)
  )
  def patch(
      /** Name of a bucket.
        */
      bucket: String,
      query: BucketsClient.PatchParams = BucketsClient.PatchParams(),
  )(input: Bucket): F[Bucket] = expectJson[Bucket](
    requestWithBody(
      method = Method.PATCH,
      uri = (baseUri / "b" / s"${bucket}").copy(query =
        Query(
          "ifMetagenerationMatch" -> query.ifMetagenerationMatch,
          "ifMetagenerationNotMatch" -> query.ifMetagenerationNotMatch,
          "predefinedAcl" -> query.predefinedAcl,
          "predefinedDefaultObjectAcl" -> query.predefinedDefaultObjectAcl,
          "projection" -> query.projection,
          "userProject" -> query.userProject,
        )
      ),
    )(input)
  )
  def lockRetentionPolicy(
      /** Name of a bucket.
        */
      bucket: String,
      query: BucketsClient.LockRetentionPolicyParams = BucketsClient.LockRetentionPolicyParams(),
  ): F[Bucket] = expectJson[Bucket](
    request(
      method = Method.POST,
      uri = (baseUri / "b" / s"${bucket}" / "lockRetentionPolicy").copy(query =
        Query(
          "ifMetagenerationMatch" -> query.ifMetagenerationMatch,
          "userProject" -> query.userProject,
        )
      ),
    )
  )
  def list(
      query: BucketsClient.ListParams = BucketsClient.ListParams()
  ): F[Buckets] = expectJson[Buckets](
    request(
      method = Method.GET,
      uri = (baseUri / "b").copy(query =
        Query(
          "maxResults" -> query.maxResults.map(s => QueryParamEncoder[Int].encode(s).value),
          "pageToken" -> query.pageToken,
          "prefix" -> query.prefix,
          "project" -> query.project,
          "projection" -> query.projection,
          "softDeleted" -> query.softDeleted.map(s => QueryParamEncoder[Boolean].encode(s).value),
          "userProject" -> query.userProject,
        )
      ),
    )
  )
}
object BucketsClient {
  final case class TestIamPermissionsParams(
      /** Permissions to test.
        */
      permissions: Option[String] = None,
      /** The project to be billed for this request. Required for Requester Pays buckets.
        */
      userProject: Option[String] = None,
  )
  final case class InsertParams(
      /** When set to true, object retention is enabled for this bucket.
        */
      enableObjectRetention: Option[Boolean] = None,
      /** Apply a predefined set of access controls to this bucket.
        */
      predefinedAcl: Option[String] = None,
      /** Apply a predefined set of default object access controls to this bucket.
        */
      predefinedDefaultObjectAcl: Option[String] = None,
      /** A valid API project identifier.
        */
      project: Option[String] = None,
      /** Set of properties to return. Defaults to noAcl, unless the bucket resource specifies acl or defaultObjectAcl properties, when it defaults to full.
        */
      projection: Option[String] = None,
      /** The project to be billed for this request.
        */
      userProject: Option[String] = None,
  )
  final case class RestoreParams(
      /** Generation of a bucket.
        */
      generation: Option[String] = None,
      /** The project to be billed for this request. Required for Requester Pays buckets.
        */
      userProject: Option[String] = None,
  )
  final case class SetIamPolicyParams(
      /** The project to be billed for this request. Required for Requester Pays buckets.
        */
      userProject: Option[String] = None
  )
  final case class GetIamPolicyParams(
      /** The IAM policy format version to be returned. If the optionsRequestedPolicyVersion is for an older version that doesn't support part of the requested IAM policy, the request fails.
        */
      optionsRequestedPolicyVersion: Option[Int] = None,
      /** The project to be billed for this request. Required for Requester Pays buckets.
        */
      userProject: Option[String] = None,
  )
  final case class DeleteParams(
      /** If set, only deletes the bucket if its metageneration matches this value.
        */
      ifMetagenerationMatch: Option[String] = None,
      /** If set, only deletes the bucket if its metageneration does not match this value.
        */
      ifMetagenerationNotMatch: Option[String] = None,
      /** The project to be billed for this request. Required for Requester Pays buckets.
        */
      userProject: Option[String] = None,
  )
  final case class GetStorageLayoutParams(
      /** An optional prefix used for permission check. It is useful when the caller only has storage.objects.list permission under a specific prefix.
        */
      prefix: Option[String] = None
  )
  final case class GetParams(
      /** If present, specifies the generation of the bucket. This is required if softDeleted is true.
        */
      generation: Option[String] = None,
      /** Makes the return of the bucket metadata conditional on whether the bucket's current metageneration matches the given value.
        */
      ifMetagenerationMatch: Option[String] = None,
      /** Makes the return of the bucket metadata conditional on whether the bucket's current metageneration does not match the given value.
        */
      ifMetagenerationNotMatch: Option[String] = None,
      /** Set of properties to return. Defaults to noAcl.
        */
      projection: Option[String] = None,
      /** If true, return the soft-deleted version of this bucket. The default is false. For more information, see [Soft Delete](https://cloud.google.com/storage/docs/soft-delete).
        */
      softDeleted: Option[Boolean] = None,
      /** The project to be billed for this request. Required for Requester Pays buckets.
        */
      userProject: Option[String] = None,
  )
  final case class UpdateParams(
      /** Makes the return of the bucket metadata conditional on whether the bucket's current metageneration matches the given value.
        */
      ifMetagenerationMatch: Option[String] = None,
      /** Makes the return of the bucket metadata conditional on whether the bucket's current metageneration does not match the given value.
        */
      ifMetagenerationNotMatch: Option[String] = None,
      /** Apply a predefined set of access controls to this bucket.
        */
      predefinedAcl: Option[String] = None,
      /** Apply a predefined set of default object access controls to this bucket.
        */
      predefinedDefaultObjectAcl: Option[String] = None,
      /** Set of properties to return. Defaults to full.
        */
      projection: Option[String] = None,
      /** The project to be billed for this request. Required for Requester Pays buckets.
        */
      userProject: Option[String] = None,
  )
  final case class PatchParams(
      /** Makes the return of the bucket metadata conditional on whether the bucket's current metageneration matches the given value.
        */
      ifMetagenerationMatch: Option[String] = None,
      /** Makes the return of the bucket metadata conditional on whether the bucket's current metageneration does not match the given value.
        */
      ifMetagenerationNotMatch: Option[String] = None,
      /** Apply a predefined set of access controls to this bucket.
        */
      predefinedAcl: Option[String] = None,
      /** Apply a predefined set of default object access controls to this bucket.
        */
      predefinedDefaultObjectAcl: Option[String] = None,
      /** Set of properties to return. Defaults to full.
        */
      projection: Option[String] = None,
      /** The project to be billed for this request. Required for Requester Pays buckets.
        */
      userProject: Option[String] = None,
  )
  final case class LockRetentionPolicyParams(
      /** Makes the operation conditional on whether bucket's current metageneration matches the given value.
        */
      ifMetagenerationMatch: Option[String] = None,
      /** The project to be billed for this request. Required for Requester Pays buckets.
        */
      userProject: Option[String] = None,
  )
  final case class ListParams(
      /** Maximum number of buckets to return in a single response. The service will use this parameter or 1,000 items, whichever is smaller.
        */
      maxResults: Option[Int] = None,
      /** A previously-returned page token representing part of the larger set of results to view.
        */
      pageToken: Option[String] = None,
      /** Filter results to buckets whose names begin with this prefix.
        */
      prefix: Option[String] = None,
      /** A valid API project identifier.
        */
      project: Option[String] = None,
      /** Set of properties to return. Defaults to noAcl.
        */
      projection: Option[String] = None,
      /** If true, only soft-deleted bucket versions will be returned. The default is false. For more information, see [Soft Delete](https://cloud.google.com/storage/docs/soft-delete).
        */
      softDeleted: Option[Boolean] = None,
      /** The project to be billed for this request.
        */
      userProject: Option[String] = None,
  )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy