pub struct Gcs { /* private fields */ }
services-gcs
only.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
GcsBackend
will 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
TokenLoader
viaGcsBuilder.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 scope(self, scope: &str) -> Self
pub fn scope(self, scope: &str) -> Self
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
pub fn service_account(self, service_account: &str) -> Self
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 credential(self, credential: &str) -> Self
pub fn credential(self, credential: &str) -> Self
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
pub fn credential_path(self, path: &str) -> Self
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
pub fn http_client(self, client: HttpClient) -> Self
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
pub fn customized_token_loader( self, token_load: Box<dyn GoogleTokenLoad>, ) -> Self
Specify the customized token loader used by this service.
sourcepub fn disable_vm_metadata(self) -> Self
pub fn disable_vm_metadata(self) -> Self
Disable attempting to load credentials from the GCE metadata server.
sourcepub fn disable_config_load(self) -> Self
pub fn disable_config_load(self) -> Self
Disable loading configuration from the environment.
sourcepub fn predefined_acl(self, acl: &str) -> Self
pub fn predefined_acl(self, acl: &str) -> Self
Set the predefined acl for GCS.
Available values are:
authenticatedRead
bucketOwnerFullControl
bucketOwnerRead
private
projectPrivate
publicRead
sourcepub fn default_storage_class(self, class: &str) -> Self
pub fn default_storage_class(self, class: &str) -> Self
Set the default storage class for GCS.
Available values are:
STANDARD
NEARLINE
COLDLINE
ARCHIVE
sourcepub fn allow_anonymous(self) -> Self
pub fn allow_anonymous(self) -> Self
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
impl Builder for GcsBuilder
source§impl Debug for GcsBuilder
impl Debug for GcsBuilder
source§impl Default for GcsBuilder
impl Default for GcsBuilder
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> CompatExt for T
impl<T> CompatExt for 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 moresource§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
source§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<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> 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.