object_store/signer.rs
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18//! Abstraction of signed URL generation for those object store implementations that support it
19
20use crate::{path::Path, Result};
21use async_trait::async_trait;
22use reqwest::Method;
23use std::{fmt, time::Duration};
24use url::Url;
25
26/// Universal API to generate presigned URLs from multiple object store services.
27#[async_trait]
28pub trait Signer: Send + Sync + fmt::Debug + 'static {
29 /// Given the intended [`Method`] and [`Path`] to use and the desired length of time for which
30 /// the URL should be valid, return a signed [`Url`] created with the object store
31 /// implementation's credentials such that the URL can be handed to something that doesn't have
32 /// access to the object store's credentials, to allow limited access to the object store.
33 async fn signed_url(&self, method: Method, path: &Path, expires_in: Duration) -> Result<Url>;
34
35 /// Generate signed urls for multiple paths.
36 ///
37 /// See [`Signer::signed_url`] for more details.
38 async fn signed_urls(
39 &self,
40 method: Method,
41 paths: &[Path],
42 expires_in: Duration,
43 ) -> Result<Vec<Url>> {
44 let mut urls = Vec::with_capacity(paths.len());
45 for path in paths {
46 urls.push(self.signed_url(method.clone(), path, expires_in).await?);
47 }
48 Ok(urls)
49 }
50}