oci_api/client/
http.rs

1//! OCI HTTP client
2//!
3//! OCI API HTTP client with custom request signing
4
5use crate::auth::OciConfig;
6use crate::client::signer::OciSigner;
7use crate::error::Result;
8use reqwest::Client;
9
10/// OCI HTTP client
11#[derive(Clone)]
12pub struct OciClient {
13    /// HTTP client
14    client: Client,
15
16    /// OCI configuration
17    config: OciConfig,
18
19    /// Request signer
20    signer: OciSigner,
21}
22
23impl OciClient {
24    /// Create new OCI client
25    pub fn new(config: &OciConfig) -> Result<Self> {
26        let client = Client::builder().build()?;
27        let signer = OciSigner::new(config)?;
28
29        Ok(Self {
30            client,
31            config: config.clone(),
32            signer,
33        })
34    }
35
36    /// Get OCI configuration
37    pub fn config(&self) -> &OciConfig {
38        &self.config
39    }
40
41    /// Get request signer
42    pub fn signer(&self) -> &OciSigner {
43        &self.signer
44    }
45
46    /// Return HTTP client reference
47    pub fn client(&self) -> &Client {
48        &self.client
49    }
50
51    /// Return region
52    pub fn region(&self) -> &str {
53        &self.config.region
54    }
55
56    /// Return tenancy ID
57    pub fn tenancy_id(&self) -> &str {
58        &self.config.tenancy_id
59    }
60
61    /// Return compartment ID (defaults to tenancy_id if not set)
62    pub fn compartment_id(&self) -> &str {
63        self.config
64            .compartment_id
65            .as_ref()
66            .unwrap_or(&self.config.tenancy_id)
67    }
68}