Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a new ListBuckets command and its consumer API. #348

Merged
merged 23 commits into from
Oct 15, 2023

Conversation

aalekhpatel07
Copy link
Contributor

@aalekhpatel07 aalekhpatel07 commented Jun 4, 2023

Summary

  • Feature: Two new APIs to list existing buckets (i.e. Bucket::list_buckets), and to check if a given bucket instance exists (i.e. Bucket::exists).
  • Bug fix: CI was failing because of an unused tls_connector variable, so its been renamed to _tls_connector. Not too sure if this is the ideal long-term fix but its a band-aid for now.

- Feature: The serde_types now store chrono::DateTime<chrono::Utc> instead of String, wherever there was any datetime-like data to be stored. Turns out we get different formats across different datetime fields, so we can't specialize it into one type, unless we add a deserializer that guesses the format and tries to convert any datetime strings into a chrono::DateTime<chrono::Utc> by trying parsing different formats (and that probably merits another PR).

Bucket::list_buckets(region, credentials)

Given a region, and credentials, list all the buckets that are visible.

Usage

use s3::{Bucket, BucketConfiguration};
use s3::creds::Credentials;
use s3::region::Region;
use anyhow::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let region = Region::Custom {
      region: "eu-central-1".to_owned(),
      endpoint: "http://localhost:9000".to_owned()
    };
    let credentials = Credentials::default()?;
    
    // Async variant with `tokio` or `async-std` features
    let response = Bucket::list_buckets(region, credentials).await?;
    
    // `sync` feature will produce an identical method
    #[cfg(feature = "sync")]
    let response = Bucket::list_buckets(region, credentials)?;

    // Blocking variant, generated with `blocking` feature in combination
    // with `tokio` or `async-std` features.
    #[cfg(feature = "blocking")]
    let response = Bucket::list_buckets_blocking(region, credentials)?;

    let found_buckets = response.bucket_names().collect::<Vec<String>>();
    println!("found buckets: {:#?}", found_buckets);
    Ok(())
}

Bucket::exists

Determine whether the instantitated bucket exists.

Usage

use s3::{Bucket, BucketConfiguration};
use s3::creds::Credentials;
use s3::region::Region;
use anyhow::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let bucket_name = "some-bucket-that-is-known-to-exist";
    let region = Region::Custom {
      region: "eu-central-1".to_owned(),
      endpoint: "http://localhost:9000".to_owned()
    };
    let credentials = Credentials::default()?;
    
    let bucket = Bucket::new(bucket_name, region, credentials)?;
    
    // Async variant with `tokio` or `async-std` features
    let exists = bucket.exists().await?;
    
    // `sync` feature will produce an identical method
    #[cfg(feature = "sync")]
    let exists = bucket.exists()?;

    // Blocking variant, generated with `blocking` feature in combination
    // with `tokio` or `async-std` features.
    #[cfg(feature = "blocking")]
    let exists = bucket.exists_blocking()?;
    
    assert_eq!(exists, true);
    Ok(())
}

Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
…rialize it from responses. Add a test for when no buckets exist

Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
@aalekhpatel07
Copy link
Contributor Author

aalekhpatel07 commented Jun 4, 2023

haha. I didn't know when I issued this PR but this also closes #251. Initially I was working towards the sync API but I realized we need a few more building blocks to get there.

aalekhpatel07 and others added 10 commits June 4, 2023 18:20
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
…s to parse rfc3339 but aws timestamps are all rfc2822.
@durch durch merged commit e046de0 into durch:master Oct 15, 2023
@durch
Copy link
Owner

durch commented Oct 15, 2023

@aalekhpatel07 Nice work, thank you!

@aalekhpatel07
Copy link
Contributor Author

Thank you for merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants