Skip to main content

oci_api/auth/providers/
mod.rs

1use std::sync::Arc;
2
3use async_trait::async_trait;
4
5use crate::error::Result;
6
7mod api_key;
8mod instance_principal;
9
10pub use api_key::ApiKeyAuthProvider;
11pub(crate) use instance_principal::{
12    DEFAULT_METADATA_BASE_URL, DEFAULT_REALM_DOMAIN_COMPONENT, MetadataRegionInfo,
13};
14pub use instance_principal::{InstancePrincipalAuthProvider, InstancePrincipalConfig};
15
16#[derive(Debug, Clone)]
17pub struct SignRequest<'a> {
18    pub method: &'a str,
19    pub path: &'a str,
20    pub host: Option<&'a str>,
21    pub body: Option<&'a str>,
22    pub content_type: Option<&'a str>,
23}
24
25#[derive(Debug, Clone)]
26pub struct SignedHeaders {
27    pub date: String,
28    pub authorization: String,
29    pub content_type: Option<String>,
30    pub content_length: Option<String>,
31    pub x_content_sha256: Option<String>,
32    pub extra_headers: Vec<(String, String)>,
33}
34
35#[async_trait]
36pub trait OciAuthProvider: Send + Sync {
37    async fn sign(&self, request: &SignRequest<'_>) -> Result<SignedHeaders>;
38}
39
40pub type DynOciAuthProvider = Arc<dyn OciAuthProvider>;