pub struct Gcs { /* private fields */ }Expand description
Google Cloud Storage services support.
§Capabilities
This service can be used to:
- stat
- read
- write
- create_dir
- delete
- copy
- rename
- list
- presign
- blocking
§Configuration
root: Set the work directory for backendbucket: Set the container name for backendendpoint: Customizable endpoint settingcredential: Service Account or External Account JSON, in base64credential_path: local path to Service Account or External Account JSON fileservice_account: name of Service Accountpredefined_acl: Predefined ACL for GCSdefault_storage_class: Default storage class for GCS
Refer to public API docs for more information. For authentication related options, read on.
§Options to authenticate to GCS
OpenDAL supports the following authentication options:
- Provide a base64-ed JSON key string with
credential - Provide a JSON key file at explicit path with
credential_path - Provide a JSON key file at implicit path
GcsBackendwill attempt to load Service Account key from ADC well-known places.
- Fetch access token from VM metadata
- Only works when running inside Google Cloud.
- If a non-default Service Account name is required, set with
service_account. Otherwise, nothing need to be set.
- A custom
TokenLoaderviaGcsBuilder.customized_token_loader()
Notes:
- When a Service Account key is provided, it will be used to create access tokens (VM metadata will not be used).
- Explicit Service Account key, in json or path, always take precedence over ADC-defined key paths.
- Due to limitation in GCS, a private key is required to create Pre-signed URL. Currently, OpenDAL only supports Service Account key.
§Example
§Via Builder
use anyhow::Result;
use opendal::services::Gcs;
use opendal::Operator;
#[tokio::main]
async fn main() -> Result<()> {
// create backend builder
let mut builder = Gcs::default()
// set the storage bucket for OpenDAL
.bucket("test")
// set the working directory root for GCS
// all operations will happen within it
.root("/path/to/dir")
// set the credentials with service account
.credential("service account JSON in base64")
// set the predefined ACL for GCS
.predefined_acl("publicRead")
// set the default storage class for GCS
.default_storage_class("STANDARD");
let op: Operator = Operator::new(builder)?.finish();
Ok(())
}Implementations§
Source§impl GcsBuilder
impl GcsBuilder
Sourcepub fn root(self, root: &str) -> Self
Available on crate feature services-gcs only.
pub fn root(self, root: &str) -> Self
services-gcs only.set the working directory root of backend
Sourcepub fn bucket(self, bucket: &str) -> Self
Available on crate feature services-gcs only.
pub fn bucket(self, bucket: &str) -> Self
services-gcs only.set the container’s name
Sourcepub fn scope(self, scope: &str) -> Self
Available on crate feature services-gcs only.
pub fn scope(self, scope: &str) -> Self
services-gcs only.set the GCS service scope
If not set, we will use https://www.googleapis.com/auth/devstorage.read_write.
§Valid scope examples
- read-only:
https://www.googleapis.com/auth/devstorage.read_only - read-write:
https://www.googleapis.com/auth/devstorage.read_write - full-control:
https://www.googleapis.com/auth/devstorage.full_control
Reference: Cloud Storage authentication
Sourcepub fn service_account(self, service_account: &str) -> Self
Available on crate feature services-gcs only.
pub fn service_account(self, service_account: &str) -> Self
services-gcs only.Set the GCS service account.
service account will be used for fetch token from vm metadata.
If not set, we will try to fetch with default service account.
Sourcepub fn endpoint(self, endpoint: &str) -> Self
Available on crate feature services-gcs only.
pub fn endpoint(self, endpoint: &str) -> Self
services-gcs only.set the endpoint GCS service uses
Sourcepub fn credential(self, credential: &str) -> Self
Available on crate feature services-gcs only.
pub fn credential(self, credential: &str) -> Self
services-gcs only.set the base64 hashed credentials string used for OAuth2 authentication.
this method allows to specify the credentials directly as a base64 hashed string.
alternatively, you can use credential_path() to provide the local path to a credentials file.
we will use one of credential and credential_path to complete the OAuth2 authentication.
Reference: Google Cloud Storage Authentication.
Sourcepub fn credential_path(self, path: &str) -> Self
Available on crate feature services-gcs only.
pub fn credential_path(self, path: &str) -> Self
services-gcs only.set the local path to credentials file which is used for OAuth2 authentication.
credentials file contains the original credentials that have not been base64 hashed.
we will use one of credential and credential_path to complete the OAuth2 authentication.
Reference: Google Cloud Storage Authentication.
Sourcepub fn http_client(self, client: HttpClient) -> Self
👎Deprecated since 0.53.0: Use Operator::update_http_client insteadAvailable on crate feature services-gcs only.
pub fn http_client(self, client: HttpClient) -> Self
Operator::update_http_client insteadservices-gcs only.Specify the http client that used by this service.
§Notes
This API is part of OpenDAL’s Raw API. HttpClient could be changed
during minor updates.
Sourcepub fn customized_token_loader(
self,
token_load: Box<dyn GoogleTokenLoad>,
) -> Self
Available on crate feature services-gcs only.
pub fn customized_token_loader( self, token_load: Box<dyn GoogleTokenLoad>, ) -> Self
services-gcs only.Specify the customized token loader used by this service.
Sourcepub fn token(self, token: String) -> Self
Available on crate feature services-gcs only.
pub fn token(self, token: String) -> Self
services-gcs only.Provide the OAuth2 token to use.
Sourcepub fn disable_vm_metadata(self) -> Self
Available on crate feature services-gcs only.
pub fn disable_vm_metadata(self) -> Self
services-gcs only.Disable attempting to load credentials from the GCE metadata server.
Sourcepub fn disable_config_load(self) -> Self
Available on crate feature services-gcs only.
pub fn disable_config_load(self) -> Self
services-gcs only.Disable loading configuration from the environment.
Sourcepub fn predefined_acl(self, acl: &str) -> Self
Available on crate feature services-gcs only.
pub fn predefined_acl(self, acl: &str) -> Self
services-gcs only.Set the predefined acl for GCS.
Available values are:
authenticatedReadbucketOwnerFullControlbucketOwnerReadprivateprojectPrivatepublicRead
Sourcepub fn default_storage_class(self, class: &str) -> Self
Available on crate feature services-gcs only.
pub fn default_storage_class(self, class: &str) -> Self
services-gcs only.Set the default storage class for GCS.
Available values are:
STANDARDNEARLINECOLDLINEARCHIVE
Sourcepub fn allow_anonymous(self) -> Self
Available on crate feature services-gcs only.
pub fn allow_anonymous(self) -> Self
services-gcs only.Allow anonymous requests.
This is typically used for buckets which are open to the public or GCS storage emulators.
Trait Implementations§
Source§impl Builder for GcsBuilder
Available on crate feature services-gcs only.
impl Builder for GcsBuilder
services-gcs only.Source§impl Debug for GcsBuilder
Available on crate feature services-gcs only.
impl Debug for GcsBuilder
services-gcs only.Source§impl Default for GcsBuilder
Available on crate feature services-gcs only.
impl Default for GcsBuilder
services-gcs only.Source§fn default() -> GcsBuilder
fn default() -> GcsBuilder
Auto Trait Implementations§
impl Freeze for GcsBuilder
impl !RefUnwindSafe for GcsBuilder
impl Send for GcsBuilder
impl Sync for GcsBuilder
impl Unpin for GcsBuilder
impl !UnwindSafe for GcsBuilder
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
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.