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::{DEFAULT_METADATA_BASE_URL, DEFAULT_REALM_DOMAIN_COMPONENT};
12pub use instance_principal::{InstancePrincipalAuthProvider, InstancePrincipalConfig};
13
14#[derive(Debug, Clone)]
15pub struct SignRequest<'a> {
16    pub method: &'a str,
17    pub path: &'a str,
18    pub host: Option<&'a str>,
19    pub body: Option<&'a str>,
20    pub content_type: Option<&'a str>,
21}
22
23#[derive(Debug, Clone)]
24pub struct SignedHeaders {
25    pub date: String,
26    pub authorization: String,
27    pub content_type: Option<String>,
28    pub content_length: Option<String>,
29    pub x_content_sha256: Option<String>,
30    pub extra_headers: Vec<(String, String)>,
31}
32
33#[async_trait]
34pub trait OciAuthProvider: Send + Sync {
35    async fn sign(&self, request: &SignRequest<'_>) -> Result<SignedHeaders>;
36}
37
38pub type DynOciAuthProvider = Arc<dyn OciAuthProvider>;