Skip to content

Commit

Permalink
Merge pull request #8 from sebadob/improve-api
Browse files Browse the repository at this point in the history
improve internal API slightly for better DX
  • Loading branch information
sebadob authored Jul 20, 2024
2 parents ec91725 + 68fac6f commit 5b1d3f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct Bucket {
}

#[allow(dead_code)]
#[allow(clippy::assigning_clones)] // false-positive warnings
impl Bucket {
fn host_domain(&self) -> String {
match self.host.domain() {
Expand Down
14 changes: 12 additions & 2 deletions src/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::env;
use std::fmt::{Debug, Formatter};

#[derive(Debug, Clone)]
pub struct AccessKeyId(String);
pub struct AccessKeyId(pub String);

impl AsRef<str> for AccessKeyId {
fn as_ref(&self) -> &str {
Expand All @@ -20,7 +20,7 @@ impl AccessKeyId {
}

#[derive(Clone)]
pub struct AccessKeySecret(String);
pub struct AccessKeySecret(pub String);

impl Debug for AccessKeySecret {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Expand All @@ -47,6 +47,16 @@ pub struct Credentials {
}

impl Credentials {
pub fn new<S>(key: S, secret: S) -> Self
where
S: Into<String>,
{
Self {
access_key_id: AccessKeyId(key.into()),
access_key_secret: AccessKeySecret(secret.into()),
}
}

pub fn try_from_env() -> Result<Self, S3Error> {
let access_key_id = env::var("S3_ACCESS_KEY_ID")?;
let access_key_secret = env::var("S3_ACCESS_KEY_SECRET")?;
Expand Down
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@ mod types;

/// S3 Region Wrapper
#[derive(Debug, Clone)]
pub struct Region(String);
pub struct Region(pub String);

impl Region {
pub fn new<S>(region: S) -> Self
where
S: Into<String>,
{
Self(region.into())
}

pub fn try_from_env() -> Result<Self, S3Error> {
Ok(Self(env::var("S3_REGION")?))
}
Expand Down

0 comments on commit 5b1d3f4

Please sign in to comment.