Skip to content

Commit

Permalink
docs: Add an example of signing an upload URL
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed Sep 29, 2023
1 parent 68c2ff7 commit 74972e3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions object_store/src/aws/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,36 @@ impl<'a> AwsAuthorizer<'a> {
/// by attaching the relevant [AWS SigV4] query parameters.
///
/// [AWS SigV4]: https://docs.aws.amazon.com/IAM/latest/UserGuide/create-signed-request.html
///
/// # Example
///
/// This example modifies `url` to add the signing parameters needed to enable a user to upload
/// a file to "some-folder/some-file.txt" in the next hour.
///
/// ```
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// use object_store::{aws::{AmazonS3Builder, AwsAuthorizer}, path::Path};
/// use reqwest::Method;
/// use std::time::Duration;
/// use url::Url;
///
/// let region = "us-east-1";
/// let s3 = AmazonS3Builder::new()
/// .with_region(region)
/// .with_bucket_name("my-bucket")
/// .with_access_key_id("my-access-key-id")
/// .with_secret_access_key("my-secret-access-key")
/// .build()?;
/// let credential = s3
/// .credentials()
/// .get_credential()
/// .await?;
/// let authorizer = AwsAuthorizer::new(&credential, "s3", region);
/// let mut url = Url::parse(&s3.path_url(&Path::from("some-folder/some-file.txt")))?;
/// authorizer.sign(Method::PUT, &mut url, Duration::from_secs(60 * 60));
/// # Ok(())
/// # }
/// ```
pub fn sign(&self, method: Method, url: &mut Url, expires_in: Duration) {
let date = self.date.unwrap_or_else(Utc::now);
let scope = self.scope(date);
Expand Down

0 comments on commit 74972e3

Please sign in to comment.