cloud_storage

Struct Bucket

Source
pub struct Bucket {
Show 26 fields pub kind: String, pub id: String, pub self_link: String, pub project_number: u64, pub name: String, pub time_created: DateTime<Utc>, pub updated: DateTime<Utc>, pub default_event_based_hold: Option<bool>, pub retention_policy: Option<RetentionPolicy>, pub metageneration: i64, pub acl: Option<Vec<BucketAccessControl>>, pub default_object_acl: Option<Vec<DefaultObjectAccessControl>>, pub iam_configuration: Option<IamConfiguration>, pub encryption: Option<Encryption>, pub owner: Option<Owner>, pub location: Location, pub location_type: String, pub website: Option<Website>, pub logging: Option<Logging>, pub versioning: Option<Versioning>, pub cors: Option<Vec<Cors>>, pub lifecycle: Option<Lifecycle>, pub labels: Option<HashMap<String, String>>, pub storage_class: StorageClass, pub billing: Option<Billing>, pub etag: String,
}
Expand description

The Buckets resource represents a bucket in Google Cloud Storage. There is a single global namespace shared by all buckets. For more information, see Bucket Name Requirements.

Buckets contain objects which can be accessed by their own methods. In addition to the ACL property, buckets contain BucketAccessControls, for use in fine-grained manipulation of an existing bucket’s access controls.

A bucket is always owned by the project team owners group.

Fields§

§kind: String

The kind of item this is. For buckets, this is always storage#bucket.

§id: String

The ID of the bucket. For buckets, the id and name properties are the same.

§self_link: String

The URI of this bucket.

§project_number: u64

The project number of the project the bucket belongs to.

§name: String

The name of the bucket.

§time_created: DateTime<Utc>

The creation time of the bucket in RFC 3339 format.

§updated: DateTime<Utc>

The modification time of the bucket in RFC 3339 format.

§default_event_based_hold: Option<bool>

Whether or not to automatically apply an eventBasedHold to new objects added to the bucket.

§retention_policy: Option<RetentionPolicy>

The bucket’s retention policy, which defines the minimum age an object in the bucket must reach before it can be deleted or overwritten.

§metageneration: i64

The metadata generation of this bucket.

§acl: Option<Vec<BucketAccessControl>>

Access controls on the bucket, containing one or more bucketAccessControls Resources. If iamConfiguration.uniformBucketLevelAccess.enabled is set to true, this field is omitted in responses, and requests that specify this field fail with a 400 Bad Request response.

§default_object_acl: Option<Vec<DefaultObjectAccessControl>>

Default access controls to apply to new objects when no ACL is provided. This list contains one or more defaultObjectAccessControls Resources. If iamConfiguration.uniformBucketLevelAccess.enabled is set to true, this field is omitted in responses, and requests that specify this field fail.

§iam_configuration: Option<IamConfiguration>

The bucket’s IAM configuration.

§encryption: Option<Encryption>

Encryption configuration for a bucket.

§owner: Option<Owner>

The owner of the bucket. This is always the project team’s owner group.

§location: Location

The location of the bucket. Object data for objects in the bucket resides in physical storage within this region. Defaults to US. See Cloud Storage bucket locations for the authoritative list.

§location_type: String

The type of location that the bucket resides in, as determined by the location property.

§website: Option<Website>

The bucket’s website configuration, controlling how the service behaves when accessing bucket contents as a web site. See the Static Website Examples for more information.

§logging: Option<Logging>

The bucket’s logging configuration, which defines the destination bucket and optional name prefix for the current bucket’s logs.

§versioning: Option<Versioning>

The bucket’s versioning configuration.

§cors: Option<Vec<Cors>>

The bucket’s Cross-Origin Resource Sharing (CORS) configuration.

§lifecycle: Option<Lifecycle>

The bucket’s lifecycle configuration. See lifecycle management for more information.

§labels: Option<HashMap<String, String>>

User-provided bucket labels, in key/value pairs.

§storage_class: StorageClass

The bucket’s default storage class, used whenever no storageClass is specified for a newly-created object. If storageClass is not specified when the bucket is created, it defaults to STANDARD. For more information, see storage classes.

§billing: Option<Billing>

The bucket’s billing configuration.

§etag: String

HTTP 1.1 Entity tag for the bucket.

Implementations§

Source§

impl Bucket

Source

pub async fn create(new_bucket: &NewBucket) -> Result<Self>

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::bucket::{Bucket, NewBucket};
use cloud_storage::bucket::{Location, MultiRegion};

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 = Bucket::create(&new_bucket).await?;
Source

pub fn create_sync(new_bucket: &NewBucket) -> Result<Self>

The synchronous equivalent of Bucket::create.

§Features

This function requires that the feature flag sync is enabled in Cargo.toml.

Source

pub async fn list() -> Result<Vec<Self>>

Returns all Buckets within this project.

§Note

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

§Example
use cloud_storage::Bucket;

let buckets = Bucket::list().await?;
Source

pub fn list_sync() -> Result<Vec<Self>>

The synchronous equivalent of Bucket::list.

§Features

This function requires that the feature flag sync is enabled in Cargo.toml.

Source

pub async fn read(name: &str) -> Result<Self>

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

§Example
use cloud_storage::Bucket;

let bucket = Bucket::read("cloud-storage-rs-doc-2").await?;
Source

pub fn read_sync(name: &str) -> Result<Self>

The synchronous equivalent of Bucket::read.

§Features

This function requires that the feature flag sync is enabled in Cargo.toml.

Source

pub async fn update(&self) -> Result<Self>

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::bucket::{Bucket, RetentionPolicy};

let mut bucket = 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),
});
bucket.update().await?;
Source

pub fn update_sync(&self) -> Result<Self>

The synchronous equivalent of Bucket::update.

§Features

This function requires that the feature flag sync is enabled in Cargo.toml.

Source

pub async fn delete(self) -> 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::Bucket;

let bucket = Bucket::read("unnecessary-bucket").await?;
bucket.delete().await?;
Source

pub fn delete_sync(self) -> Result<()>

The synchronous equivalent of Bucket::delete.

§Features

This function requires that the feature flag sync is enabled in Cargo.toml.

Source

pub async fn get_iam_policy(&self) -> Result<IamPolicy>

Returns the IAM Policy for this bucket.

§Example
use cloud_storage::Bucket;

let bucket = Bucket::read("cloud-storage-rs-doc-4").await?;
let policy = bucket.get_iam_policy().await?;
Source

pub fn get_iam_policy_sync(&self) -> Result<IamPolicy>

The synchronous equivalent of Bucket::get_iam_policy.

§Features

This function requires that the feature flag sync is enabled in Cargo.toml.

Source

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

Updates the IAM Policy for this bucket.

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

let bucket = 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 = bucket.set_iam_policy(&iam_policy).await?;
Source

pub fn set_iam_policy_sync(&self, iam: &IamPolicy) -> Result<IamPolicy>

The synchronous equivalent of Bucket::set_iam_policy.

§Features

This function requires that the feature flag sync is enabled in Cargo.toml.

Source

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

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

§Example
use cloud_storage::Bucket;

let bucket = Bucket::read("my-bucket").await?;
bucket.test_iam_permission("storage.buckets.get").await?;
Source

pub fn test_iam_permission_sync( &self, permission: &str, ) -> Result<TestIamPermission>

The synchronous equivalent of Bucket::test_iam_policy.

§Features

This function requires that the feature flag sync is enabled in Cargo.toml.

Trait Implementations§

Source§

impl Debug for Bucket

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Bucket

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Bucket

Source§

fn eq(&self, other: &Bucket) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Bucket

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Bucket

Auto Trait Implementations§

§

impl Freeze for Bucket

§

impl RefUnwindSafe for Bucket

§

impl Send for Bucket

§

impl Sync for Bucket

§

impl Unpin for Bucket

§

impl UnwindSafe for Bucket

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>,

Source§

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>,

Source§

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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T