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
11pub struct OciClient {
12    /// HTTP client
13    client: Client,
14
15    /// OCI configuration
16    config: OciConfig,
17
18    /// Request signer
19    signer: OciSigner,
20}
21
22impl OciClient {
23    /// Create new OCI client
24    pub fn new(config: &OciConfig) -> Result<Self> {
25        let client = Client::builder().build()?;
26        let signer = OciSigner::new(config)?;
27
28        Ok(Self {
29            client,
30            config: config.clone(),
31            signer,
32        })
33    }
34
35    /// Get OCI configuration
36    pub fn config(&self) -> &OciConfig {
37        &self.config
38    }
39
40    /// Get request signer
41    pub fn signer(&self) -> &OciSigner {
42        &self.signer
43    }
44
45    /// Return HTTP client reference
46    pub fn client(&self) -> &Client {
47        &self.client
48    }
49
50    /// Return region
51    pub fn region(&self) -> &str {
52        &self.config.region
53    }
54
55    /// Return compartment ID (defaults to tenancy_id if not set)
56    pub fn compartment_id(&self) -> &str {
57        self.config
58            .compartment_id
59            .as_ref()
60            .unwrap_or(&self.config.tenancy_id)
61    }
62}