Expand description
§MOVED TO cloud-storage
This crate aims to simplify interacting with the Google Cloud Storage JSON API. Use it until Google releases a Cloud Storage Client Library for Rust. Shoutout to MyEmma for funding this free and open source project.
Google Cloud Storage is a product by Google that allows for cheap file storage, with a
relatively sophisticated API. The idea is that storage happens in Bucket
s, which are
filesystems with a globally unique name. You can make as many of these Bucket
s as you like!
This project talks to Google using a Service Account
. A service account is an account that you
must create in the cloud storage console. When the account
is created, you can download the file service-account-********.json
. Store this file somewhere
on your machine, and place the path to this file in the environment parameter SERVICE_ACCOUNT
.
Environment parameters declared in the .env
file are also registered. The service account can
then be granted Roles
in the cloud storage console. The roles required for this project to
function are Service Account Token Creator
and Storage Object Admin
.
§Quickstart
Add the following line to your Cargo.toml
[dependencies]
cloud-storage = "0.4"
The two most important concepts are Buckets, which represent file systems, and Objects, which represent files.
§Examples:
Creating a new Bucket in Google Cloud Storage:
let bucket = Bucket::create(&NewBucket {
name: "doctest-bucket".to_string(),
..Default::default()
}).unwrap();
Connecting to an existing Bucket in Google Cloud Storage:
let bucket = Bucket::read("mybucket").unwrap();
Read a file from disk and store it on googles server:
let mut bytes: Vec<u8> = Vec::new();
for byte in File::open("myfile.txt").unwrap().bytes() {
bytes.push(byte.unwrap())
}
Object::create("mybucket", &bytes, "myfile.txt", "text/plain");
Renaming/moving a file
let mut object = Object::read("mybucket", "myfile").unwrap();
object.name = "mybetterfile".to_string();
object.update().unwrap();
Removing a file
Object::delete("mybucket", "myfile");
Modules§
- bucket
- This complex object represents a Bucket that can be used to store and read files in Google Cloud Storage.
- bucket_
access_ control - A Bucket Access Control object can be used to configure access on a bucket-wide level.
- default_
object_ access_ control - Default Object Access Control objects can be used the configure access that is used as a fallback in the abscence of more specific data.
- hmac_
key - An Hmac key is a secret key stored in Cloud Storage.
- object
- A file
- object_
access_ control - Contains data about to access specific files.
- service_
account - A deserialized version of the
service-account-********.json
file. Used to authenticate requests.
Structs§
- Bucket
- The Buckets resource represents a bucket in Google Cloud Storage. There is a single global namespace shared by all buckets. For more information, see Bucket Name Requirements.
- Google
Error Response - The structure of a error response returned by Google.
- NewBucket
- A model that can be used to insert new buckets into Google Cloud Storage.
- Object
- A resource representing a file in Google Cloud Storage.
- SERVICE_
ACCOUNT - The struct is the parsed service account json file. It is publicly exported to enable easier debugging of which service account is currently used. It is of the type ServiceAccount.