oracle_nosql_rust_sdk/auth_common/authentication_provider.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
//
// Copyright (c) 2024, 2025 Oracle and/or its affiliates. All rights reserved.
//
// Licensed under the Universal Permissive License v 1.0 as shown at
// https://oss.oracle.com/licenses/upl/
//
use openssl::pkey::Private;
use openssl::rsa::Rsa;
use std::error::Error;
use std::fmt::Debug;
/// Trait defining an Authentication Provider
pub trait AuthenticationProvider: Send + Sync + Debug + AuthenticationProviderClone {
/// Returns the Tenancy OCID associated with this AuthenticationProvider
fn tenancy_id(&self) -> &str;
/// Returns the User OCID associated with this AuthenticationProvider
fn user_id(&self) -> &str;
/// Returns the Fingerprint associated with the Private Key of this AuthenticationProvider
fn fingerprint(&self) -> &str;
/// Returns the Private Key associated with this AuthenticationProvider
fn private_key(&self) -> Result<Rsa<Private>, Box<dyn Error>>;
/// Returns the key id associated with this AuthenticationProvider to be used for signing requests
fn key_id(&self) -> String {
let key_id = format!(
"{}/{}/{}",
self.tenancy_id(),
self.user_id(),
self.fingerprint()
);
key_id
}
/// Returns the region-id associated with this AuthenticationProvider
fn region_id(&self) -> &str;
}
// This allows users of this library to clone a Box<dyn AuthenticationProvider>
pub trait AuthenticationProviderClone {
fn clone_box(&self) -> Box<dyn AuthenticationProvider>;
}
impl<T> AuthenticationProviderClone for T
where
T: 'static + AuthenticationProvider + Clone,
{
fn clone_box(&self) -> Box<dyn AuthenticationProvider> {
Box::new(self.clone())
}
}
impl Clone for Box<dyn AuthenticationProvider> {
fn clone(&self) -> Box<dyn AuthenticationProvider> {
self.clone_box()
}
}