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

UrlStyle #35

Merged
merged 8 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ Minio compatibility tested on every commit by GitHub Actions.
```rust
use std::env;
use std::time::Duration;
use rusty_s3::{Bucket, Credentials, S3Action};
use rusty_s3::{Bucket, Credentials, S3Action, UrlStyle};

// setting up a bucket
let endpoint = "https://s3.dualstack.eu-west-1.amazonaws.com".parse().expect("endpoint is a valid Url");
let path_style = true;
let path_style = UrlStyle::VirtualHost;
let name = String::from("rusty-s3");
let region = String::from("eu-west-1");
let bucket = Bucket::new(endpoint, path_style, name, region).expect("Url has a valid scheme and host");
Expand Down
4 changes: 2 additions & 2 deletions benches/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::Duration;

use criterion::{black_box, criterion_group, criterion_main, Criterion};

use rusty_s3::{Bucket, Credentials, S3Action};
use rusty_s3::{Bucket, Credentials, S3Action, UrlStyle};

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Authenticated GetObject", |b| {
Expand All @@ -13,7 +13,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let region = "us-east-1";

let credentials = Credentials::new(key, secret);
let bucket = Bucket::new(url, true, name, region).unwrap();
let bucket = Bucket::new(url, UrlStyle::Path, name, region).unwrap();

b.iter(|| {
let object = "text.txt";
Expand Down
4 changes: 2 additions & 2 deletions examples/create_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;

use reqwest::Client;
use rusty_s3::actions::{CreateBucket, S3Action};
use rusty_s3::{Bucket, Credentials};
use rusty_s3::{Bucket, Credentials, UrlStyle};

const ONE_HOUR: Duration = Duration::from_secs(3600);

Expand All @@ -16,7 +16,7 @@ async fn main() -> Result<(), Box<dyn StdError>> {
let secret = "minioadmin";
let region = "minio";

let bucket = Bucket::new(url, true, "test1234", region).unwrap();
let bucket = Bucket::new(url, UrlStyle::Path, "test1234", region).unwrap();
let credential = Credentials::new(key, secret);

let action = CreateBucket::new(&bucket, &credential);
Expand Down
4 changes: 2 additions & 2 deletions examples/list_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;

use reqwest::Client;
use rusty_s3::actions::{ListObjectsV2, S3Action};
use rusty_s3::{Bucket, Credentials};
use rusty_s3::{Bucket, Credentials, UrlStyle};

const ONE_HOUR: Duration = Duration::from_secs(3600);

Expand All @@ -16,7 +16,7 @@ async fn main() -> Result<(), Box<dyn StdError>> {
let secret = "minioadmin";
let region = "minio";

let bucket = Bucket::new(url, true, "test", region).unwrap();
let bucket = Bucket::new(url, UrlStyle::Path, "test", region).unwrap();
let credential = Credentials::new(key, secret);

let action = ListObjectsV2::new(&bucket, Some(&credential));
Expand Down
4 changes: 2 additions & 2 deletions examples/multipart_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Duration;
use reqwest::header::ETAG;
use reqwest::Client;
use rusty_s3::actions::{CompleteMultipartUpload, CreateMultipartUpload, S3Action, UploadPart};
use rusty_s3::{Bucket, Credentials};
use rusty_s3::{Bucket, Credentials, UrlStyle};

const ONE_HOUR: Duration = Duration::from_secs(3600);

Expand All @@ -18,7 +18,7 @@ async fn main() -> Result<(), Box<dyn StdError>> {
let secret = "minioadmin";
let region = "minio";

let bucket = Bucket::new(url, true, "test", region).unwrap();
let bucket = Bucket::new(url, UrlStyle::Path, "test", region).unwrap();
let credential = Credentials::new(key, secret);

let action = CreateMultipartUpload::new(&bucket, Some(&credential), "idk.txt");
Expand Down
4 changes: 2 additions & 2 deletions examples/sign_get.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use rusty_s3::actions::{GetObject, S3Action};
use rusty_s3::{Bucket, Credentials};
use rusty_s3::{Bucket, Credentials, UrlStyle};

const ONE_HOUR: Duration = Duration::from_secs(3600);

Expand All @@ -11,7 +11,7 @@ fn main() {
let secret = "minioadmin";
let region = "minio";

let bucket = Bucket::new(url, true, "test", region).unwrap();
let bucket = Bucket::new(url, UrlStyle::Path, "test", region).unwrap();
let credential = Credentials::new(key, secret);

let mut action = GetObject::new(&bucket, Some(&credential), "img.jpg");
Expand Down
4 changes: 2 additions & 2 deletions examples/sign_put.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use rusty_s3::actions::{PutObject, S3Action};
use rusty_s3::{Bucket, Credentials};
use rusty_s3::{Bucket, Credentials, UrlStyle};

const ONE_HOUR: Duration = Duration::from_secs(3600);

Expand All @@ -11,7 +11,7 @@ fn main() {
let secret = "minioadmin";
let region = "minio";

let bucket = Bucket::new(url, true, "test123", region).unwrap();
let bucket = Bucket::new(url, UrlStyle::Path, "test123", region).unwrap();
let credential = Credentials::new(key, secret);

let action = PutObject::new(&bucket, Some(&credential), "duck.jpg");
Expand Down
10 changes: 8 additions & 2 deletions src/actions/create_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod tests {
use pretty_assertions::assert_eq;

use super::*;
use crate::{Bucket, Credentials};
use crate::{Bucket, Credentials, UrlStyle};

#[test]
fn aws_example() {
Expand All @@ -79,7 +79,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();
let credentials = Credentials::new(
"AKIAIOSFODNN7EXAMPLE",
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
Expand Down
10 changes: 8 additions & 2 deletions src/actions/delete_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mod tests {
use pretty_assertions::assert_eq;

use super::*;
use crate::{Bucket, Credentials};
use crate::{Bucket, Credentials, UrlStyle};

#[test]
fn aws_example() {
Expand All @@ -81,7 +81,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();
let credentials = Credentials::new(
"AKIAIOSFODNN7EXAMPLE",
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
Expand Down
18 changes: 15 additions & 3 deletions src/actions/delete_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mod tests {
use pretty_assertions::assert_eq;

use super::*;
use crate::{Bucket, Credentials};
use crate::{Bucket, Credentials, UrlStyle};

#[test]
fn aws_example() {
Expand All @@ -85,7 +85,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();
let credentials = Credentials::new(
"AKIAIOSFODNN7EXAMPLE",
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
Expand All @@ -104,7 +110,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();

let action = DeleteObject::new(&bucket, None, "test.txt");
let url = action.sign(expires_in);
Expand Down
18 changes: 15 additions & 3 deletions src/actions/delete_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ mod tests {
use pretty_assertions::assert_eq;
use time::OffsetDateTime;

use crate::{Bucket, Credentials};
use crate::{Bucket, Credentials, UrlStyle};

use super::*;

Expand All @@ -165,7 +165,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();
let credentials = Credentials::new(
"AKIAIOSFODNN7EXAMPLE",
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
Expand Down Expand Up @@ -194,7 +200,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();

let objects = [
ObjectIdentifier {
Expand Down
26 changes: 22 additions & 4 deletions src/actions/get_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mod tests {
use pretty_assertions::assert_eq;

use super::*;
use crate::{Bucket, Credentials};
use crate::{Bucket, Credentials, UrlStyle};

#[test]
fn aws_example() {
Expand All @@ -85,7 +85,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();
let credentials = Credentials::new(
"AKIAIOSFODNN7EXAMPLE",
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
Expand All @@ -106,7 +112,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();
let credentials = Credentials::new(
"AKIAIOSFODNN7EXAMPLE",
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
Expand All @@ -128,7 +140,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();

let mut action = GetObject::new(&bucket, None, "test.txt");
action
Expand Down
26 changes: 22 additions & 4 deletions src/actions/head_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mod tests {
use pretty_assertions::assert_eq;

use super::*;
use crate::{Bucket, Credentials};
use crate::{Bucket, Credentials, UrlStyle};

#[test]
fn aws_example() {
Expand All @@ -85,7 +85,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();
let credentials = Credentials::new(
"AKIAIOSFODNN7EXAMPLE",
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
Expand All @@ -106,7 +112,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();
let credentials = Credentials::new(
"AKIAIOSFODNN7EXAMPLE",
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
Expand All @@ -128,7 +140,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();

let mut action = HeadObject::new(&bucket, None, "test.txt");
action
Expand Down
18 changes: 15 additions & 3 deletions src/actions/list_objects_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ mod tests {
use pretty_assertions::assert_eq;

use super::*;
use crate::{Bucket, Credentials};
use crate::{Bucket, Credentials, UrlStyle};

#[test]
fn aws_example() {
Expand All @@ -167,7 +167,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();
let credentials = Credentials::new(
"AKIAIOSFODNN7EXAMPLE",
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
Expand All @@ -186,7 +192,13 @@ mod tests {
let expires_in = Duration::from_secs(86400);

let endpoint = "https://s3.amazonaws.com".parse().unwrap();
let bucket = Bucket::new(endpoint, false, "examplebucket", "us-east-1").unwrap();
let bucket = Bucket::new(
endpoint,
UrlStyle::VirtualHost,
"examplebucket",
"us-east-1",
)
.unwrap();

let mut action = ListObjectsV2::new(&bucket, None);
action.query_mut().insert("continuation-token", "duck");
Expand Down