Struct google_cloud_storage::client::Client
source · pub struct Client { /* private fields */ }Implementations§
source§impl Client
impl Client
sourcepub fn new(config: ClientConfig) -> Self
pub fn new(config: ClientConfig) -> Self
New client
sourcepub async fn signed_url(
&self,
bucket: &str,
object: &str,
google_access_id: Option<String>,
sign_by: Option<SignBy>,
opts: SignedURLOptions,
) -> Result<String, SignedURLError>
pub async fn signed_url( &self, bucket: &str, object: &str, google_access_id: Option<String>, sign_by: Option<SignBy>, opts: SignedURLOptions, ) -> Result<String, SignedURLError>
Get signed url. SignedURL returns a URL for the specified object. Signed URLs allow anyone access to a restricted resource for a limited time without needing a Google account or signing in. For more information about signed URLs, see https://cloud.google.com/storage/docs/accesscontrol#signed_urls_query_string_authentication
Using the client defaults:
use google_cloud_storage::client::Client;
use google_cloud_storage::sign::{SignedURLOptions, SignedURLMethod};
async fn run(client: Client) {
let url_for_download = client.signed_url("bucket", "file.txt", None, None, SignedURLOptions::default()).await;
let url_for_upload = client.signed_url("bucket", "file.txt", None, None, SignedURLOptions {
method: SignedURLMethod::PUT,
..Default::default()
}).await;
}Overwriting the client defaults:
use google_cloud_storage::client::Client;
use google_cloud_storage::sign::{SignBy, SignedURLOptions, SignedURLMethod};
async fn run(client: Client) {
let url_for_download = client.signed_url("bucket", "file.txt", Some("google_access_id".to_string()), Some(private_key.clone()), SignedURLOptions::default()).await;
let url_for_upload = client.signed_url("bucket", "file.txt", Some("google_access_id".to_string()), Some(private_key.clone()), SignedURLOptions {
method: SignedURLMethod::PUT,
..Default::default()
}).await;
}Methods from Deref<Target = StorageClient>§
sourcepub async fn delete_bucket(
&self,
req: &DeleteBucketRequest,
) -> Result<(), Error>
pub async fn delete_bucket( &self, req: &DeleteBucketRequest, ) -> Result<(), Error>
Deletes the bucket. https://cloud.google.com/storage/docs/json_api/v1/buckets/delete
use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::delete::DeleteBucketRequest;
async fn run(client:Client) {
let result = client.delete_bucket(&DeleteBucketRequest {
bucket: "bucket".to_string(),
..Default::default()
}).await;
}sourcepub async fn insert_bucket(
&self,
req: &InsertBucketRequest,
) -> Result<Bucket, Error>
pub async fn insert_bucket( &self, req: &InsertBucketRequest, ) -> Result<Bucket, Error>
Inserts the bucket. https://cloud.google.com/storage/docs/json_api/v1/buckets/insert
use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::insert::{BucketCreationConfig, InsertBucketParam, InsertBucketRequest};
async fn run(client:Client) {
let result = client.insert_bucket(&InsertBucketRequest {
name: "bucket".to_string(),
param: InsertBucketParam {
project: "project_id".to_string(),
..Default::default()
},
..Default::default()
}).await;
}sourcepub async fn get_bucket(&self, req: &GetBucketRequest) -> Result<Bucket, Error>
pub async fn get_bucket(&self, req: &GetBucketRequest) -> Result<Bucket, Error>
Gets the bucket. https://cloud.google.com/storage/docs/json_api/v1/buckets/get
use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::get::GetBucketRequest;
async fn run(client:Client) {
let result = client.get_bucket(&GetBucketRequest {
bucket: "bucket".to_string(),
..Default::default()
}).await;
}sourcepub async fn patch_bucket(
&self,
req: &PatchBucketRequest,
) -> Result<Bucket, Error>
pub async fn patch_bucket( &self, req: &PatchBucketRequest, ) -> Result<Bucket, Error>
Patches the bucket. https://cloud.google.com/storage/docs/json_api/v1/buckets/patch
use google_cloud_storage::client::Client;
use google_cloud_storage::client::ClientConfig;
use google_cloud_storage::http::buckets::patch::{BucketPatchConfig, PatchBucketRequest};
async fn run(config: ClientConfig) {
let mut client = Client::new(config);
let result = client.patch_bucket(&PatchBucketRequest {
bucket: "bucket".to_string(),
metadata: Some(BucketPatchConfig {
..Default::default()
}),
..Default::default()
}).await;
}sourcepub async fn list_buckets(
&self,
req: &ListBucketsRequest,
) -> Result<ListBucketsResponse, Error>
pub async fn list_buckets( &self, req: &ListBucketsRequest, ) -> Result<ListBucketsResponse, Error>
Lists the bucket. https://cloud.google.com/storage/docs/json_api/v1/buckets/list
use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::list::ListBucketsRequest;
async fn run(client:Client) {
let result = client.list_buckets(&ListBucketsRequest{
project: "project_id".to_string(),
..Default::default()
}).await;
}sourcepub async fn set_iam_policy(
&self,
req: &SetIamPolicyRequest,
) -> Result<Policy, Error>
pub async fn set_iam_policy( &self, req: &SetIamPolicyRequest, ) -> Result<Policy, Error>
Sets the iam policy. https://cloud.google.com/storage/docs/json_api/v1/buckets/setIamPolicy
use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::{Binding, Policy};
use google_cloud_storage::http::buckets::set_iam_policy::SetIamPolicyRequest;
async fn run(client:Client) {
let result = client.set_iam_policy(&SetIamPolicyRequest{
resource: "bucket".to_string(),
policy: Policy {
bindings: vec![Binding {
role: "roles/storage.objectViewer".to_string(),
members: vec!["allAuthenticatedUsers".to_string()],
condition: None,
}],
..Default::default()
},
..Default::default()
}).await;
}sourcepub async fn get_iam_policy(
&self,
req: &GetIamPolicyRequest,
) -> Result<Policy, Error>
pub async fn get_iam_policy( &self, req: &GetIamPolicyRequest, ) -> Result<Policy, Error>
Gets the iam policy. https://cloud.google.com/storage/docs/json_api/v1/buckets/getIamPolicy
use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::get_iam_policy::GetIamPolicyRequest;
use google_cloud_storage::http::buckets::list::ListBucketsRequest;
async fn run(client:Client) {
let result = client.get_iam_policy(&GetIamPolicyRequest{
resource: "bucket".to_string(),
..Default::default()
}).await;
}sourcepub async fn test_iam_permissions(
&self,
req: &TestIamPermissionsRequest,
) -> Result<TestIamPermissionsResponse, Error>
pub async fn test_iam_permissions( &self, req: &TestIamPermissionsRequest, ) -> Result<TestIamPermissionsResponse, Error>
Tests the iam permissions. https://cloud.google.com/storage/docs/json_api/v1/buckets/testIamPermissions
use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::test_iam_permissions::TestIamPermissionsRequest;
async fn run(client:Client) {
let result = client.test_iam_permissions(&TestIamPermissionsRequest{
resource: "bucket".to_string(),
permissions: vec!["storage.buckets.get".to_string()],
}).await;
}sourcepub async fn list_default_object_access_controls(
&self,
req: &ListDefaultObjectAccessControlsRequest,
) -> Result<ListDefaultObjectAccessControlsResponse, Error>
pub async fn list_default_object_access_controls( &self, req: &ListDefaultObjectAccessControlsRequest, ) -> Result<ListDefaultObjectAccessControlsResponse, Error>
Lists the default object ACL. https://cloud.google.com/storage/docs/json_api/v1/defaultObjectAccessControls/list
use google_cloud_storage::client::Client;
use google_cloud_storage::http::buckets::test_iam_permissions::TestIamPermissionsRequest;
use google_cloud_storage::http::default_object_access_controls::list::ListDefaultObjectAccessControlsRequest;
async fn run(client:Client) {
let result = client.list_default_object_access_controls(&ListDefaultObjectAccessControlsRequest{
bucket: "bucket".to_string(),
..Default::default()
}).await;
}sourcepub async fn get_default_object_access_control(
&self,
req: &GetDefaultObjectAccessControlRequest,
) -> Result<ObjectAccessControl, Error>
pub async fn get_default_object_access_control( &self, req: &GetDefaultObjectAccessControlRequest, ) -> Result<ObjectAccessControl, Error>
Gets the default object ACL. https://cloud.google.com/storage/docs/json_api/v1/defaultObjectAccessControls/get
use google_cloud_storage::client::Client;
use google_cloud_storage::http::default_object_access_controls::get::GetDefaultObjectAccessControlRequest;
async fn run(client:Client) {
let result = client.get_default_object_access_control(&GetDefaultObjectAccessControlRequest{
bucket: "bucket".to_string(),
entity: "allAuthenticatedUsers".to_string(),
}).await;
}sourcepub async fn insert_default_object_access_control(
&self,
req: &InsertDefaultObjectAccessControlRequest,
) -> Result<ObjectAccessControl, Error>
pub async fn insert_default_object_access_control( &self, req: &InsertDefaultObjectAccessControlRequest, ) -> Result<ObjectAccessControl, Error>
Inserts the default object ACL. https://cloud.google.com/storage/docs/json_api/v1/defaultObjectAccessControls/insert
use google_cloud_storage::client::Client;
use google_cloud_storage::http::default_object_access_controls::insert::InsertDefaultObjectAccessControlRequest;
use google_cloud_storage::http::object_access_controls::insert::ObjectAccessControlCreationConfig;
use google_cloud_storage::http::object_access_controls::ObjectACLRole;
async fn run(client:Client) {
let result = client.insert_default_object_access_control(&InsertDefaultObjectAccessControlRequest{
bucket: "bucket".to_string(),
object_access_control: ObjectAccessControlCreationConfig {
entity: "allAuthenticatedUsers".to_string(),
role: ObjectACLRole::READER
} ,
}).await;
}sourcepub async fn patch_default_object_access_control(
&self,
req: &PatchDefaultObjectAccessControlRequest,
) -> Result<ObjectAccessControl, Error>
pub async fn patch_default_object_access_control( &self, req: &PatchDefaultObjectAccessControlRequest, ) -> Result<ObjectAccessControl, Error>
Patches the default object ACL. https://cloud.google.com/storage/docs/json_api/v1/defaultObjectAccessControls/patch
use google_cloud_storage::client::Client;
use google_cloud_storage::http::default_object_access_controls::patch::PatchDefaultObjectAccessControlRequest;
use google_cloud_storage::http::object_access_controls::insert::ObjectAccessControlCreationConfig;
use google_cloud_storage::http::object_access_controls::{ObjectAccessControl, ObjectACLRole};
use google_cloud_storage::http::object_access_controls::patch::PatchObjectAccessControlRequest;
async fn run(client:Client) {
let result = client.patch_default_object_access_control(&PatchDefaultObjectAccessControlRequest{
bucket: "bucket".to_string(),
entity: "allAuthenticatedUsers".to_string(),
object_access_control: ObjectAccessControl {
role: ObjectACLRole::READER,
..Default::default()
},
}).await;
}sourcepub async fn delete_default_object_access_control(
&self,
req: &DeleteDefaultObjectAccessControlRequest,
) -> Result<(), Error>
pub async fn delete_default_object_access_control( &self, req: &DeleteDefaultObjectAccessControlRequest, ) -> Result<(), Error>
Deletes the default object ACL. https://cloud.google.com/storage/docs/json_api/v1/defaultObjectAccessControls/delete
use google_cloud_storage::client::Client;
use google_cloud_storage::http::default_object_access_controls::delete::DeleteDefaultObjectAccessControlRequest;
async fn run(client:Client) {
let result = client.delete_default_object_access_control(&DeleteDefaultObjectAccessControlRequest{
bucket: "bucket".to_string(),
entity: "allAuthenticatedUsers".to_string(),
}).await;
}sourcepub async fn list_bucket_access_controls(
&self,
req: &ListBucketAccessControlsRequest,
) -> Result<ListBucketAccessControlsResponse, Error>
pub async fn list_bucket_access_controls( &self, req: &ListBucketAccessControlsRequest, ) -> Result<ListBucketAccessControlsResponse, Error>
Lists the bucket ACL. https://cloud.google.com/storage/docs/json_api/v1/bucketAccessControls/list
use google_cloud_storage::client::Client;
use google_cloud_storage::http::bucket_access_controls::list::ListBucketAccessControlsRequest;
async fn run(client:Client) {
let result = client.list_bucket_access_controls(&ListBucketAccessControlsRequest{
bucket: "bucket".to_string(),
}).await;
}sourcepub async fn get_bucket_access_control(
&self,
req: &GetBucketAccessControlRequest,
) -> Result<BucketAccessControl, Error>
pub async fn get_bucket_access_control( &self, req: &GetBucketAccessControlRequest, ) -> Result<BucketAccessControl, Error>
Gets the bucket ACL. https://cloud.google.com/storage/docs/json_api/v1/bucketAccessControls/get
use google_cloud_storage::client::Client;
use google_cloud_storage::http::bucket_access_controls::get::GetBucketAccessControlRequest;
async fn run(client:Client) {
let result = client.get_bucket_access_control(&GetBucketAccessControlRequest{
bucket: "bucket".to_string(),
entity: "allAuthenticatedUsers".to_string(),
}).await;
}sourcepub async fn insert_bucket_access_control(
&self,
req: &InsertBucketAccessControlRequest,
) -> Result<BucketAccessControl, Error>
pub async fn insert_bucket_access_control( &self, req: &InsertBucketAccessControlRequest, ) -> Result<BucketAccessControl, Error>
Inserts the bucket ACL. https://cloud.google.com/storage/docs/json_api/v1/bucketAccessControls/insert
use google_cloud_storage::client::Client;
use google_cloud_storage::http::bucket_access_controls::BucketACLRole;
use google_cloud_storage::http::bucket_access_controls::insert::{BucketAccessControlCreationConfig, InsertBucketAccessControlRequest};
async fn run(client:Client) {
let result = client.insert_bucket_access_control(&InsertBucketAccessControlRequest{
bucket: "bucket".to_string(),
acl: BucketAccessControlCreationConfig {
entity: "allAuthenticatedUsers".to_string(),
role: BucketACLRole::READER
}
}).await;
}sourcepub async fn patch_bucket_access_control(
&self,
req: &PatchBucketAccessControlRequest,
) -> Result<BucketAccessControl, Error>
pub async fn patch_bucket_access_control( &self, req: &PatchBucketAccessControlRequest, ) -> Result<BucketAccessControl, Error>
Patches the bucket ACL. https://cloud.google.com/storage/docs/json_api/v1/bucketAccessControls/patch
use google_cloud_storage::client::Client;
use google_cloud_storage::http::bucket_access_controls::BucketAccessControl;
use google_cloud_storage::http::bucket_access_controls::BucketACLRole;
use google_cloud_storage::http::bucket_access_controls::patch::PatchBucketAccessControlRequest;
async fn run(client:Client) {
let result = client.patch_bucket_access_control(&PatchBucketAccessControlRequest{
bucket: "bucket".to_string(),
entity: "allAuthenticatedUsers".to_string(),
acl: BucketAccessControl {
role: BucketACLRole::READER,
..Default::default()
}
}).await;
}sourcepub async fn delete_bucket_access_control(
&self,
req: &DeleteBucketAccessControlRequest,
) -> Result<(), Error>
pub async fn delete_bucket_access_control( &self, req: &DeleteBucketAccessControlRequest, ) -> Result<(), Error>
Deletes the bucket ACL.
use google_cloud_storage::client::Client;
use google_cloud_storage::http::bucket_access_controls::BucketAccessControl;
use google_cloud_storage::http::bucket_access_controls::delete::DeleteBucketAccessControlRequest;
async fn run(client:Client) {
let result = client.delete_bucket_access_control(&DeleteBucketAccessControlRequest{
bucket: "bucket".to_string(),
entity: "allAuthenticatedUsers".to_string(),
}).await;
}sourcepub async fn list_object_access_controls(
&self,
req: &ListObjectAccessControlsRequest,
) -> Result<ListBucketAccessControlsResponse, Error>
pub async fn list_object_access_controls( &self, req: &ListObjectAccessControlsRequest, ) -> Result<ListBucketAccessControlsResponse, Error>
Lists the object ACL. https://cloud.google.com/storage/docs/json_api/v1/objectAccessControls/list
use google_cloud_storage::client::Client;
use google_cloud_storage::http::object_access_controls::list::ListObjectAccessControlsRequest;
async fn run(client:Client) {
let result = client.list_object_access_controls(&ListObjectAccessControlsRequest{
bucket: "bucket".to_string(),
object: "filename".to_string(),
..Default::default()
}).await;
}sourcepub async fn get_object_access_control(
&self,
req: &GetObjectAccessControlRequest,
) -> Result<ObjectAccessControl, Error>
pub async fn get_object_access_control( &self, req: &GetObjectAccessControlRequest, ) -> Result<ObjectAccessControl, Error>
Gets the object ACL. https://cloud.google.com/storage/docs/json_api/v1/objectAccessControls/get
use google_cloud_storage::client::Client;
use google_cloud_storage::http::object_access_controls::get::GetObjectAccessControlRequest;
async fn run(client:Client) {
let result = client.get_object_access_control(&GetObjectAccessControlRequest{
bucket: "bucket".to_string(),
object: "filename".to_string(),
entity: "allAuthenticatedUsers".to_string(),
..Default::default()
}).await;
}sourcepub async fn insert_object_access_control(
&self,
req: &InsertObjectAccessControlRequest,
) -> Result<ObjectAccessControl, Error>
pub async fn insert_object_access_control( &self, req: &InsertObjectAccessControlRequest, ) -> Result<ObjectAccessControl, Error>
Inserts the object ACL. https://cloud.google.com/storage/docs/json_api/v1/objectAccessControls/insert
use google_cloud_storage::client::Client;
use google_cloud_storage::http::object_access_controls::insert::{InsertObjectAccessControlRequest, ObjectAccessControlCreationConfig};
use google_cloud_storage::http::object_access_controls::ObjectACLRole;
async fn run(client:Client) {
let result = client.insert_object_access_control(&InsertObjectAccessControlRequest{
bucket: "bucket".to_string(),
object: "filename".to_string(),
acl: ObjectAccessControlCreationConfig {
entity: "allAuthenticatedUsers".to_string(),
role: ObjectACLRole::READER
},
..Default::default()
}).await;
}sourcepub async fn patch_object_access_control(
&self,
req: &PatchObjectAccessControlRequest,
) -> Result<ObjectAccessControl, Error>
pub async fn patch_object_access_control( &self, req: &PatchObjectAccessControlRequest, ) -> Result<ObjectAccessControl, Error>
Patches the bucket ACL. https://cloud.google.com/storage/docs/json_api/v1/objectAccessControls/patch
use google_cloud_storage::client::Client;
use google_cloud_storage::http::object_access_controls::{ObjectAccessControl, ObjectACLRole};
use google_cloud_storage::http::object_access_controls::patch::PatchObjectAccessControlRequest;
async fn run(client:Client) {
let result = client.patch_object_access_control(&PatchObjectAccessControlRequest{
bucket: "bucket".to_string(),
object: "filename".to_string(),
entity: "allAuthenticatedUsers".to_string(),
acl: ObjectAccessControl {
role: ObjectACLRole::READER,
..Default::default()
},
..Default::default()
}).await;
}sourcepub async fn delete_object_access_control(
&self,
req: &DeleteObjectAccessControlRequest,
) -> Result<(), Error>
pub async fn delete_object_access_control( &self, req: &DeleteObjectAccessControlRequest, ) -> Result<(), Error>
Deletes the bucket ACL. https://cloud.google.com/storage/docs/json_api/v1/objectAccessControls/delete
use google_cloud_storage::client::Client;
use google_cloud_storage::http::object_access_controls::{ObjectAccessControl, ObjectACLRole};
use google_cloud_storage::http::object_access_controls::delete::DeleteObjectAccessControlRequest;
async fn run(client:Client) {
let result = client.delete_object_access_control(&DeleteObjectAccessControlRequest{
bucket: "bucket".to_string(),
object: "filename".to_string(),
entity: "allAuthenticatedUsers".to_string(),
..Default::default()
}).await;
}sourcepub async fn list_notifications(
&self,
req: &ListNotificationsRequest,
) -> Result<ListNotificationsResponse, Error>
pub async fn list_notifications( &self, req: &ListNotificationsRequest, ) -> Result<ListNotificationsResponse, Error>
Lists the notification. https://cloud.google.com/storage/docs/json_api/v1/notifications/list
use google_cloud_storage::client::Client;
use google_cloud_storage::http::notifications::list::ListNotificationsRequest;
async fn run(client:Client) {
let result = client.list_notifications(&ListNotificationsRequest{
bucket: "bucket".to_string(),
..Default::default()
}).await;
}sourcepub async fn get_notification(
&self,
req: &GetNotificationRequest,
) -> Result<Notification, Error>
pub async fn get_notification( &self, req: &GetNotificationRequest, ) -> Result<Notification, Error>
Gets the notification. https://cloud.google.com/storage/docs/json_api/v1/notifications/get
use google_cloud_storage::client::Client;
use google_cloud_storage::http::notifications::get::GetNotificationRequest;
async fn run(client:Client) {
let result = client.get_notification(&GetNotificationRequest{
bucket: "bucket".to_string(),
notification: "notification".to_string()
}).await;
}sourcepub async fn insert_notification(
&self,
req: &InsertNotificationRequest,
) -> Result<Notification, Error>
pub async fn insert_notification( &self, req: &InsertNotificationRequest, ) -> Result<Notification, Error>
Inserts the notification. https://cloud.google.com/storage/docs/json_api/v1/notifications/insert
use google_cloud_storage::client::Client;
use google_cloud_storage::http::notifications::EventType;
use google_cloud_storage::http::notifications::insert::{InsertNotificationRequest, NotificationCreationConfig};
async fn run(client:Client) {
let result = client.insert_notification(&InsertNotificationRequest {
bucket: "bucket".to_string(),
notification: NotificationCreationConfig {
topic: format!("projects/{}/topics/{}", "project","bucket"),
event_types: Some(vec![EventType::ObjectMetadataUpdate, EventType::ObjectDelete]),
..Default::default()
}
}).await;
}sourcepub async fn delete_notification(
&self,
req: &DeleteNotificationRequest,
) -> Result<(), Error>
pub async fn delete_notification( &self, req: &DeleteNotificationRequest, ) -> Result<(), Error>
Deletes the notification. https://cloud.google.com/storage/docs/json_api/v1/notifications/delete
use google_cloud_storage::client::Client;
use google_cloud_storage::http::notifications::delete::DeleteNotificationRequest;
async fn run(client:Client) {
let result = client.delete_notification(&DeleteNotificationRequest {
bucket: "bucket".to_string(),
notification: "notification".to_string()
}).await;
}sourcepub async fn list_hmac_keys(
&self,
req: &ListHmacKeysRequest,
) -> Result<ListHmacKeysResponse, Error>
pub async fn list_hmac_keys( &self, req: &ListHmacKeysRequest, ) -> Result<ListHmacKeysResponse, Error>
Lists the hmac keys. https://cloud.google.com/storage/docs/json_api/v1/projects/hmacKeys/list
use google_cloud_storage::client::Client;
use google_cloud_storage::http::hmac_keys::list::ListHmacKeysRequest;
async fn run(client:Client) {
let result = client.list_hmac_keys(&ListHmacKeysRequest {
project_id: "project_id".to_string(),
..Default::default()
}).await;
}sourcepub async fn get_hmac_key(
&self,
req: &GetHmacKeyRequest,
) -> Result<HmacKeyMetadata, Error>
pub async fn get_hmac_key( &self, req: &GetHmacKeyRequest, ) -> Result<HmacKeyMetadata, Error>
Gets the hmac keys. https://cloud.google.com/storage/docs/json_api/v1/projects/hmacKeys/get
use google_cloud_storage::client::Client;
use google_cloud_storage::http::hmac_keys::get::GetHmacKeyRequest;
async fn run(client:Client) {
let result = client.get_hmac_key(&GetHmacKeyRequest {
access_id: "access_id".to_string(),
project_id: "project_id".to_string(),
}).await;
}sourcepub async fn create_hmac_key(
&self,
req: &CreateHmacKeyRequest,
) -> Result<CreateHmacKeyResponse, Error>
pub async fn create_hmac_key( &self, req: &CreateHmacKeyRequest, ) -> Result<CreateHmacKeyResponse, Error>
Creates the hmac key. https://cloud.google.com/storage/docs/json_api/v1/projects/hmacKeys/create
use google_cloud_storage::client::Client;
use google_cloud_storage::http::hmac_keys::create::CreateHmacKeyRequest;
async fn run(client:Client) {
let result = client.create_hmac_key(&CreateHmacKeyRequest {
service_account_email: "service_account_email".to_string(),
project_id: "project".to_string(),
}).await;
}sourcepub async fn update_hmac_key(
&self,
req: &UpdateHmacKeyRequest,
) -> Result<HmacKeyMetadata, Error>
pub async fn update_hmac_key( &self, req: &UpdateHmacKeyRequest, ) -> Result<HmacKeyMetadata, Error>
Updates the hmac key. https://cloud.google.com/storage/docs/json_api/v1/projects/hmacKeys/update
use google_cloud_storage::client::Client;
use google_cloud_storage::http::hmac_keys::HmacKeyMetadata;
use google_cloud_storage::http::hmac_keys::update::UpdateHmacKeyRequest;
async fn run(client:Client) {
let result = client.update_hmac_key(&UpdateHmacKeyRequest{
access_id: "access_id".to_string(),
project_id: "project_id".to_string(),
metadata: HmacKeyMetadata {
state: "INACTIVE".to_string(),
..Default::default()
},
}).await;
}sourcepub async fn delete_hmac_key(
&self,
req: &DeleteHmacKeyRequest,
) -> Result<(), Error>
pub async fn delete_hmac_key( &self, req: &DeleteHmacKeyRequest, ) -> Result<(), Error>
Deletes the hmac key. https://cloud.google.com/storage/docs/json_api/v1/projects/hmacKeys/delete
use google_cloud_storage::client::Client;
use google_cloud_storage::http::hmac_keys::delete::DeleteHmacKeyRequest;
async fn run(client:Client) {
let result = client.delete_hmac_key(&DeleteHmacKeyRequest{
access_id: "access_id".to_string(),
project_id:"project_id".to_string(),
}).await;
}sourcepub async fn list_objects(
&self,
req: &ListObjectsRequest,
) -> Result<ListObjectsResponse, Error>
pub async fn list_objects( &self, req: &ListObjectsRequest, ) -> Result<ListObjectsResponse, Error>
Lists the objects. https://cloud.google.com/storage/docs/json_api/v1/objects/list
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::list::ListObjectsRequest;
async fn run(client:Client) {
let result = client.list_objects(&ListObjectsRequest{
bucket: "bucket".to_string(),
..Default::default()
}).await;
}sourcepub async fn get_object(&self, req: &GetObjectRequest) -> Result<Object, Error>
pub async fn get_object(&self, req: &GetObjectRequest) -> Result<Object, Error>
Gets the object. https://cloud.google.com/storage/docs/json_api/v1/objects/get
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::get::GetObjectRequest;
async fn run(client:Client) {
let result = client.get_object(&GetObjectRequest{
bucket: "bucket".to_string(),
object: "object".to_string(),
..Default::default()
}).await;
}sourcepub async fn copy_object(
&self,
req: &CopyObjectRequest,
) -> Result<Object, Error>
pub async fn copy_object( &self, req: &CopyObjectRequest, ) -> Result<Object, Error>
Copy the object. https://cloud.google.com/storage/docs/json_api/v1/objects/copy
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::copy::CopyObjectRequest;
async fn run(client:Client) {
let result = client.copy_object(&CopyObjectRequest{
source_bucket: "bucket".to_string(),
destination_bucket: "bucket".to_string(),
destination_object: "object".to_string(),
source_object: "object".to_string(),
..Default::default()
}).await;
}sourcepub async fn move_object(
&self,
req: &MoveObjectRequest,
) -> Result<Object, Error>
pub async fn move_object( &self, req: &MoveObjectRequest, ) -> Result<Object, Error>
Move the object. https://cloud.google.com/storage/docs/copying-renaming-moving-objects#rest-move-object This function will first make a copy of the object, and then delete the original object.
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::r#move::MoveObjectRequest;
async fn run(client:Client) {
let result = client.move_object(&MoveObjectRequest{
source_bucket: "source_bucket".to_string(),
source_object: "source_object".to_string(),
destination_bucket: "destination_source".to_string(),
destination_object: "destination_object".to_string(),
..Default::default()
}).await;
}sourcepub async fn download_object(
&self,
req: &GetObjectRequest,
range: &Range,
) -> Result<Vec<u8>, Error>
pub async fn download_object( &self, req: &GetObjectRequest, range: &Range, ) -> Result<Vec<u8>, Error>
Download the object. https://cloud.google.com/storage/docs/json_api/v1/objects/get alt is always media
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::get::GetObjectRequest;
use google_cloud_storage::http::objects::download::Range;
async fn run(client:Client) {
let result = client.download_object(&GetObjectRequest{
bucket: "bucket".to_string(),
object: "object".to_string(),
..Default::default()
}, &Range::default()).await;
}sourcepub async fn download_streamed_object(
&self,
req: &GetObjectRequest,
range: &Range,
) -> Result<impl Stream<Item = Result<Bytes, Error>>, Error>
pub async fn download_streamed_object( &self, req: &GetObjectRequest, range: &Range, ) -> Result<impl Stream<Item = Result<Bytes, Error>>, Error>
Download the object. https://cloud.google.com/storage/docs/json_api/v1/objects/get alt is always media
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::get::GetObjectRequest;
use google_cloud_storage::http::objects::download::Range;
async fn run(client:Client) {
let result = client.download_streamed_object(&GetObjectRequest{
bucket: "bucket".to_string(),
object: "object".to_string(),
..Default::default()
}, &Range::default()).await;
// while let Some(v) = downloaded.next().await? {
// let d: bytes::Bytes = v.unwrap();
// }
}sourcepub async fn upload_object<T: Into<Body>>(
&self,
req: &UploadObjectRequest,
data: T,
upload_type: &UploadType,
) -> Result<Object, Error>
pub async fn upload_object<T: Into<Body>>( &self, req: &UploadObjectRequest, data: T, upload_type: &UploadType, ) -> Result<Object, Error>
Uploads the object. https://cloud.google.com/storage/docs/json_api/v1/objects/insert
use std::collections::HashMap;
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::Object;
use google_cloud_storage::http::objects::upload::{Media, UploadObjectRequest, UploadType};
async fn run_simple(client:Client) {
let upload_type = UploadType::Simple(Media::new("filename"));
let result = client.upload_object(&UploadObjectRequest{
bucket: "bucket".to_string(),
..Default::default()
}, "hello world".as_bytes(), &upload_type).await;
}
async fn run_multipart(client:Client) {
let mut metadata = HashMap::<String, String>::new();
metadata.insert("key1".to_string(), "value1".to_string());
let upload_type = UploadType::Multipart(Box::new(Object {
name: "test1_meta".to_string(),
content_type: Some("text/plain".to_string()),
metadata: Some(metadata),
..Default::default()
}));
let result = client.upload_object(&UploadObjectRequest{
bucket: "bucket".to_string(),
..Default::default()
}, "hello world".as_bytes(), &upload_type).await;
}sourcepub fn get_resumable_upload(&self, url: String) -> ResumableUploadClient
pub fn get_resumable_upload(&self, url: String) -> ResumableUploadClient
Creates resumable upload from known URL.
Assumes URL is correct, if not, ResumableUploadClient is not guaranteed to perform correctly.
sourcepub async fn prepare_resumable_upload(
&self,
req: &UploadObjectRequest,
upload_type: &UploadType,
) -> Result<ResumableUploadClient, Error>
pub async fn prepare_resumable_upload( &self, req: &UploadObjectRequest, upload_type: &UploadType, ) -> Result<ResumableUploadClient, Error>
Perform resumable uploads https://cloud.google.com/storage/docs/performing-resumable-uploads
use std::collections::HashMap;
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::Object;
use google_cloud_storage::http::objects::upload::{Media, UploadObjectRequest, UploadType};
use google_cloud_storage::http::resumable_upload_client::{ChunkSize, UploadedRange, UploadStatus};
async fn run_simple(client:Client) {
let upload_type = UploadType::Simple(Media::new("filename"));
let uploader = client.prepare_resumable_upload(&UploadObjectRequest{
bucket: "bucket".to_string(),
..Default::default()
}, &upload_type).await.unwrap();
// We can also use upload_multiple_chunk.
let data = [1,2,3,4,5];
let result = uploader.upload_single_chunk(Vec::from(data), data.len()).await;
}
async fn run_with_metadata(client:Client) {
let mut metadata = HashMap::<String, String>::new();
metadata.insert("key1".to_string(), "value1".to_string());
let upload_type = UploadType::Multipart(Box::new(Object {
name: "test1_meta".to_string(),
content_type: Some("text/plain".to_string()),
metadata: Some(metadata),
..Default::default()
}));
let uploader = client.prepare_resumable_upload(&UploadObjectRequest{
bucket: "bucket".to_string(),
..Default::default()
}, &upload_type).await.unwrap();
let chunk1_data : Vec<u8>= (0..256 * 1024).map(|i| (i % 256) as u8).collect();
let chunk2_data : Vec<u8>= (1..256 * 1024 + 50).map(|i| (i % 256) as u8).collect();
let chunk1_size = chunk1_data.len() as u64;
let chunk2_size = chunk2_data.len() as u64;
let total_size = Some(chunk1_size + chunk2_size);
// The chunk size should be multiple of 256KiB, unless it's the last chunk that completes the upload.
let chunk1 = ChunkSize::new(0, chunk1_size - 1, total_size.clone());
let status1 = uploader.upload_multiple_chunk(chunk1_data.clone(), &chunk1).await.unwrap();
assert_eq!(
status1,
UploadStatus::ResumeIncomplete(UploadedRange {
first_byte: 0,
last_byte: chunk1_data.len() as u64 - 1
})
);
let chunk2 = ChunkSize::new(chunk1_size, chunk1_size + chunk2_size - 1, total_size.clone());
let status2 = uploader.upload_multiple_chunk(chunk2_data.clone(), &chunk2).await.unwrap();
assert!(matches!(status2, UploadStatus::Ok(_)));
}sourcepub async fn upload_streamed_object<S>(
&self,
req: &UploadObjectRequest,
data: S,
upload_type: &UploadType,
) -> Result<Object, Error>
pub async fn upload_streamed_object<S>( &self, req: &UploadObjectRequest, data: S, upload_type: &UploadType, ) -> Result<Object, Error>
Uploads the streamed object. https://cloud.google.com/storage/docs/json_api/v1/objects/insert
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::upload::{Media, UploadObjectRequest, UploadType};
async fn run(client:Client) {
let source = vec!["hello", " ", "world"];
let size = source.iter().map(|x| x.len() as u64).sum();
let chunks: Vec<Result<_, ::std::io::Error>> = source.clone().into_iter().map(|x| Ok(x)).collect();
let stream = futures_util::stream::iter(chunks);
let mut media = Media::new("filename");
media.content_length = Some(size);
let mut upload_type = UploadType::Simple(media);
let result = client.upload_streamed_object(&UploadObjectRequest{
bucket: "bucket".to_string(),
..Default::default()
}, stream, &upload_type).await;
}sourcepub async fn patch_object(
&self,
req: &PatchObjectRequest,
) -> Result<Object, Error>
pub async fn patch_object( &self, req: &PatchObjectRequest, ) -> Result<Object, Error>
Patches the object. https://cloud.google.com/storage/docs/json_api/v1/objects/patch
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::patch::PatchObjectRequest;
async fn run(client:Client) {
let result = client.patch_object(&PatchObjectRequest{
bucket: "bucket".to_string(),
object: "object".to_string(),
..Default::default()
}).await;
}sourcepub async fn delete_object(
&self,
req: &DeleteObjectRequest,
) -> Result<(), Error>
pub async fn delete_object( &self, req: &DeleteObjectRequest, ) -> Result<(), Error>
Deletes the object. https://cloud.google.com/storage/docs/json_api/v1/objects/delete
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::delete::DeleteObjectRequest;
async fn run(client:Client) {
let result = client.delete_object(&DeleteObjectRequest{
bucket: "bucket".to_string(),
object: "object".to_string(),
..Default::default()
}).await;
}sourcepub async fn rewrite_object(
&self,
req: &RewriteObjectRequest,
) -> Result<RewriteObjectResponse, Error>
pub async fn rewrite_object( &self, req: &RewriteObjectRequest, ) -> Result<RewriteObjectResponse, Error>
Rewrites the object. https://cloud.google.com/storage/docs/json_api/v1/objects/rewrite
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::rewrite::RewriteObjectRequest;
async fn run(client:Client) {
let mut done = false;
let mut rewrite_token = None;
while !done {
let result = client.rewrite_object(&RewriteObjectRequest{
source_bucket: "bucket1".to_string(),
source_object: "object".to_string(),
destination_bucket: "bucket2".to_string(),
destination_object: "object1".to_string(),
rewrite_token: rewrite_token.clone(),
..Default::default()
}).await.unwrap();
done = result.done;
rewrite_token = result.rewrite_token;
}
}sourcepub async fn compose_object(
&self,
req: &ComposeObjectRequest,
) -> Result<Object, Error>
pub async fn compose_object( &self, req: &ComposeObjectRequest, ) -> Result<Object, Error>
Composes the object. https://cloud.google.com/storage/docs/json_api/v1/objects/compose
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::compose::{ComposeObjectRequest, ComposingTargets};
use google_cloud_storage::http::objects::rewrite::RewriteObjectRequest;
use google_cloud_storage::http::objects::SourceObjects;
async fn run(client:Client) {
let result = client.compose_object(&ComposeObjectRequest{
bucket: "bucket1".to_string(),
destination_object: "object1".to_string(),
composing_targets: ComposingTargets {
source_objects: vec![SourceObjects {
name: "src".to_string(),
..Default::default()
}],
..Default::default()
},
..Default::default()
}).await;
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)