pub struct BucketClient<'a>(/* private fields */);
Expand description

Operations on Buckets.

Implementations§

source§

impl<'a> BucketClient<'a>

source

pub async fn create(&self, new_bucket: &NewBucket) -> Result<Bucket>

Creates a new Bucket. There are many options that you can provide for creating a new bucket, so the NewBucket resource contains all of them. Note that NewBucket implements Default, so you don’t have to specify the fields you’re not using. And error is returned if that bucket name is already taken.

Example
use cloud_storage::Client;
use cloud_storage::bucket::{Bucket, NewBucket};
use cloud_storage::bucket::{Location, MultiRegion};

let client = Client::default();
let new_bucket = NewBucket {
   name: "cloud-storage-rs-doc-1".to_string(), // this is the only mandatory field
   location: Location::Multi(MultiRegion::Eu),
   ..Default::default()
};
let bucket = client.bucket().create(&new_bucket).await?;
source

pub async fn list(&self) -> Result<Vec<Bucket>>

Returns all Buckets within this project.

Note

When using incorrect permissions, this function fails silently and returns an empty list.

Example
use cloud_storage::Client;
use cloud_storage::Bucket;

let client = Client::default();
let buckets = client.bucket().list().await?;
source

pub async fn read(&self, name: &str) -> Result<Bucket>

Returns a single Bucket by its name. If the Bucket does not exist, an error is returned.

Example
use cloud_storage::Client;
use cloud_storage::Bucket;

let client = Client::default();

let bucket = client.bucket().read("cloud-storage-rs-doc-2").await?;
source

pub async fn update(&self, bucket: &Bucket) -> Result<Bucket>

Update an existing Bucket. If you declare you bucket as mutable, you can edit its fields. You can then flush your changes to Google Cloud Storage using this method.

Example
use cloud_storage::Client;
use cloud_storage::bucket::{Bucket, RetentionPolicy};

let client = Client::default();

let mut bucket = client.bucket().read("cloud-storage-rs-doc-3").await?;
bucket.retention_policy = Some(RetentionPolicy {
    retention_period: 50,
    effective_time: chrono::Utc::now() + chrono::Duration::seconds(50),
    is_locked: Some(false),
});
client.bucket().update(&bucket).await?;
source

pub async fn delete(&self, bucket: Bucket) -> Result<()>

Delete an existing Bucket. This permanently removes a bucket from Google Cloud Storage. An error is returned when you don’t have sufficient permissions, or when the retention_policy prevents you from deleting your Bucket.

Example
use cloud_storage::Client;
use cloud_storage::Bucket;

let client = Client::default();

let bucket = client.bucket().read("unnecessary-bucket").await?;
client.bucket().delete(bucket).await?;
source

pub async fn get_iam_policy(&self, bucket: &Bucket) -> Result<IamPolicy>

Returns the IAM Policy for this bucket.

Example
use cloud_storage::Client;
use cloud_storage::Bucket;

let client = Client::default();

let bucket = client.bucket().read("cloud-storage-rs-doc-4").await?;
let policy = client.bucket().get_iam_policy(&bucket).await?;
source

pub async fn set_iam_policy( &self, bucket: &Bucket, iam: &IamPolicy ) -> Result<IamPolicy>

Updates the IAM Policy for this bucket.

Example
use cloud_storage::Client;
use cloud_storage::Bucket;
use cloud_storage::bucket::{IamPolicy, Binding, IamRole, StandardIamRole, Entity};

let client = Client::default();

let bucket = client.bucket().read("cloud-storage-rs-doc-5").await?;
let iam_policy = IamPolicy {
    version: 1,
    bindings: vec![
        Binding {
            role: IamRole::Standard(StandardIamRole::ObjectViewer),
            members: vec!["allUsers".to_string()],
            condition: None,
        }
    ],
    ..Default::default()
};
let policy = client.bucket().set_iam_policy(&bucket, &iam_policy).await?;
source

pub async fn test_iam_permission( &self, bucket: &Bucket, permission: &str ) -> Result<TestIamPermission>

Checks whether the user provided in the service account has this permission.

Example
use cloud_storage::Client;
use cloud_storage::Bucket;

let client = Client::default();
let bucket = client.bucket().read("my-bucket").await?;
client.bucket().test_iam_permission(&bucket, "storage.buckets.get").await?;

Trait Implementations§

source§

impl<'a> Debug for BucketClient<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for BucketClient<'a>

§

impl<'a> Send for BucketClient<'a>

§

impl<'a> Sync for BucketClient<'a>

§

impl<'a> Unpin for BucketClient<'a>

§

impl<'a> !UnwindSafe for BucketClient<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more