google_cloud_storage/lib.rs
1//! # google-cloud-storage
2//!
3//! Google Cloud Platform Storage Client library.
4//!
5//! * [About Cloud Storage](https://cloud.google.com/storage/)
6//! * [JSON API Documentation](https://cloud.google.com/storage/docs/json_api/v1)
7//!
8//! ## Quick Start
9//!
10//! ### Authentication
11//! There are two ways to create a client that is authenticated against the google cloud.
12//!
13//! #### Automatically
14//!
15//! The function `with_auth()` will try and read the credentials from a file specified in the environment variable `GOOGLE_APPLICATION_CREDENTIALS`, `GOOGLE_APPLICATION_CREDENTIALS_JSON` or
16//! from a metadata server.
17//!
18//! This is also described in [google-cloud-auth](https://github.com/yoshidan/google-cloud-rust/blob/main/foundation/auth/README.md)
19//!
20//! ```
21//! use google_cloud_storage::client::{ClientConfig, Client};
22//!
23//! async fn run() {
24//! let config = ClientConfig::default().with_auth().await.unwrap();
25//! let client = Client::new(config);
26//! }
27//! ```
28//!
29//! #### Manually
30//!
31//! When you cant use the `gcloud` authentication but you have a different way to get your credentials (e.g a different environment variable)
32//! you can parse your own version of the 'credentials-file' and use it like that:
33//!
34//! ```
35//! use google_cloud_auth::credentials::CredentialsFile;
36//! // or google_cloud_storage::client::google_cloud_auth::credentials::CredentialsFile
37//! use google_cloud_storage::client::{ClientConfig, Client};
38//!
39//! async fn run(cred: CredentialsFile) {
40//! let config = ClientConfig::default().with_credentials(cred).await.unwrap();
41//! let client = Client::new(config);
42//! }
43//! ```
44//!
45//! ### Anonymous Access
46//!
47//! To provide [anonymous access without authentication](https://cloud.google.com/storage/docs/authentication), do the following.
48//!
49//! ```rust
50//! use google_cloud_storage::client::{ClientConfig, Client};
51//!
52//! async fn run() {
53//! let config = ClientConfig::default().anonymous();
54//! let client = Client::new(config);
55//! }
56//! ```
57//!
58//! ### Usage
59//!
60//! ```
61//! use google_cloud_storage::client::Client;
62//! use google_cloud_storage::client::ClientConfig;
63//! use google_cloud_storage::sign::SignedURLOptions;
64//! use google_cloud_storage::sign::SignedURLMethod;
65//! use google_cloud_storage::http::Error;
66//! use google_cloud_storage::http::objects::download::Range;
67//! use google_cloud_storage::http::objects::get::GetObjectRequest;
68//! use google_cloud_storage::http::objects::upload::{Media, UploadObjectRequest, UploadType};
69//! use tokio::task::JoinHandle;
70//! use std::fs::File;
71//! use std::io::BufReader;
72//! use std::io::Read;
73//!
74//! async fn run(config: ClientConfig) -> Result<(), Error> {
75//!
76//! // Create client.
77//! let mut client = Client::new(config);
78//!
79//! // Upload the file
80//! let upload_type = UploadType::Simple(Media::new("file.png"));
81//! let uploaded = client.upload_object(&UploadObjectRequest {
82//! bucket: "bucket".to_string(),
83//! ..Default::default()
84//! }, "hello world".as_bytes(), &upload_type).await;
85//!
86//! // Download the file
87//! let data = client.download_object(&GetObjectRequest {
88//! bucket: "bucket".to_string(),
89//! object: "file.png".to_string(),
90//! ..Default::default()
91//! }, &Range::default()).await;
92//!
93//! // Create signed url with the default key and google-access-id of the client
94//! let url_for_download = client.signed_url("bucket", "foo.txt", None, None, SignedURLOptions::default());
95//! let url_for_upload = client.signed_url("bucket", "foo.txt", None, None, SignedURLOptions {
96//! method: SignedURLMethod::PUT,
97//! ..Default::default()
98//! });
99//!
100//! Ok(())
101//! }
102//! ```
103
104extern crate core;
105
106pub mod client;
107pub mod http;
108pub mod sign;