waihona

mythra

Crates.io Build Status Publish Status

Usage

Add the following line to your Cargo.toml

rust [dependencies] waihona = "0.0.1"

Rust library for cloud storage across major cloud providers It aims to provide simple to use functions to perform CRUD operations on buckets and blobs. Waihona simply means storage in Hawaiian

## Feature Flags

The following feature flags exist for this crate - [x] aws: Enable aws provider and dependencies - [x] gcp: Enable gcp provider and dependencies - [] azure: Enable azure provider and dependencies

Examples

These quick examples will show you how to make use of the library for basic actions

List buckets from project waihona on GCP

```rust // ensure to export service credential using GOOGLEAPPLICATIONCREDENTIALS

[cfg(feature = "gcp")]

use waihona::providers::gcp::GcpBucket;

[tokio::test]

[cfg(feature = "gcp")]

async fn testlistbuckets() -> Vec { // Import Buckets trait from crate use waihona::types::bucket::{Buckets}; use waihona::providers::gcp; let mut gcpbuckets = providers::gcp::GcpBuckets::new( "waihona" ); // Returns (Vec) // where Option is the cursor for the token for next page listing let resp = gcpbuckets.list().await; resp[0] } ```

Check bucket waihona exists on AWS

```rust

[tokio::test]

[cfg(feature = "aws")]

async fn testbucketexists() -> bool { use waihona::types::bucket::{Buckets}; use waihona::providers; let mut awsbuckets = providers::aws::AwsBuckets::new( "us-east-2" ); let resp = awsbuckets.exists( "waihona" ).await; // OR you can do let resp = providers::aws::AwsBucket::exists( "us-east-2", "waihona" ).await; resp } ```

Write content to a blob "example.txt" in waihona bucket on Azure

```rust

[cfg(feature = "azure")]

use waihona::providers::azure::AzureBlob;

[tokio::test]

[cfg(feature = "azure")]

async fn testcreateblob() -> AzureBlob { // !! UNIMPLEMENTED use waihona::types::bucket::{Buckets, Bucket}; use waihona::types::blob::{Blob}; use waihona::providers; use bytes::Bytes; let mut azurebuckets = providers::azure::AzureBuckets::new(); let waihona = azurebuckets.open( "waihona", ).await.unwrap(); let mut blob = waihona.write_blob( "example.txt", Some(Bytes::from("Hello world")) ).await .unwrap(); blob } ```

Copy file content from "example.txt" blob on AWS to blob on GCP and delete AWS blob afterwards assuming waihona buckets exist on both platforms

```rust

[cfg(feature = "gcp")]

use waihona::providers::gcp::GcpBlob;

[tokio::test]

[cfg(all(feature = "gcp", feature = "aws" ))]

async fn testtransferblob() -> GcpBlob { use waihona::types::bucket::{Buckets, Bucket}; use waihona::types::blob::{Blob}; use waihona::providers; use bytes::Bytes; let mut awsblob = providers::aws::AwsBlob::get( "us-east-2", // Region "waihona", // Bucket name "example.txt", // Blob name None // Content range ).await .unwrap(); let mut gcpblob = providers::gcp::GcpBlob::get( "gcp-project-name", // Project name "waihona", // Bucket name "example.txt", // Blob name None // Content range ).await .unwrap(); let content: Bytes = awsblob.read().unwrap(); gcpblob.write(Some(content)).await.unwrap(); awsblob.delete().unwrap(); gcpblob } ```

License

This project is opened under the MIT License which allows very broad use for both academic and commercial purposes