pub struct Gcs { /* private fields */ }Expand description
Google Cloud Storage services support.
§Capabilities
This service can be used to:
- create_dir
- stat
- read
- write
- delete
- list
- copy
- rename
- presign
§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 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
👎Deprecated since 0.53.0: Use Operator::update_http_client instead
pub fn http_client(self, client: HttpClient) -> Self
Use Operator::update_http_client instead
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:
authenticatedReadbucketOwnerFullControlbucketOwnerReadprivateprojectPrivatepublicRead
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:
STANDARDNEARLINECOLDLINEARCHIVE
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.