Skip to main content

bitwarden_api_api/apis/
pam_access_connector_rotation_jobs_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21    apis::{AuthRequired, ContentType, ResponseContent},
22    models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait PamAccessConnectorRotationJobsApi: Send + Sync {
29    /// POST /access-connectors/rotation/jobs/{id}/claim
30    /// Atomically claims a job -- first-claim-wins -- and returns the work snapshot needed to
31    /// execute the rotation. 409 means another access connector won the race (claim a different
32    /// job); 404 means this access connector was never eligible to claim it (no assignment, wrong
33    /// organization, or a disabled target/config).
34    async fn claim<'a>(&self, id: uuid::Uuid) -> Result<models::RotationClaimResponseModel, Error>;
35
36    /// GET /access-connectors/rotation/jobs
37    /// The calling access connector's currently claimable jobs on its assigned targets -- the poll.
38    /// Doubles as a heartbeat when idle. Heartbeat contract: an access connector MUST call some
39    /// connector-facing rotation endpoint at an interval shorter than ConnectorOfflineAfter for as
40    /// long as it holds a claim, or the release sweep may reclaim the job once the claim's lease
41    /// also expires; an access connector SHOULD poll no more often than HeartbeatMinInterval, since
42    /// the heartbeat write is conditional on that interval and polling faster gains nothing.
43    async fn get_all(
44        &self,
45    ) -> Result<models::ClaimableRotationJobResponseModelListResponseModel, Error>;
46}
47
48pub struct PamAccessConnectorRotationJobsApiClient {
49    configuration: Arc<configuration::Configuration>,
50}
51
52impl PamAccessConnectorRotationJobsApiClient {
53    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
54        Self { configuration }
55    }
56}
57
58#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
59#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
60impl PamAccessConnectorRotationJobsApi for PamAccessConnectorRotationJobsApiClient {
61    /// Atomically claims a job -- first-claim-wins -- and returns the work snapshot needed to
62    /// execute the rotation. 409 means another access connector won the race (claim a different
63    /// job); 404 means this access connector was never eligible to claim it (no assignment, wrong
64    /// organization, or a disabled target/config).
65    async fn claim<'a>(&self, id: uuid::Uuid) -> Result<models::RotationClaimResponseModel, Error> {
66        let local_var_configuration = &self.configuration;
67
68        let local_var_client = &local_var_configuration.client;
69
70        let local_var_uri_str = format!(
71            "{}/access-connectors/rotation/jobs/{id}/claim",
72            local_var_configuration.base_path,
73            id = id
74        );
75        let mut local_var_req_builder =
76            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
77
78        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
79
80        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
81    }
82
83    /// The calling access connector's currently claimable jobs on its assigned targets -- the poll.
84    /// Doubles as a heartbeat when idle. Heartbeat contract: an access connector MUST call some
85    /// connector-facing rotation endpoint at an interval shorter than ConnectorOfflineAfter for as
86    /// long as it holds a claim, or the release sweep may reclaim the job once the claim's lease
87    /// also expires; an access connector SHOULD poll no more often than HeartbeatMinInterval, since
88    /// the heartbeat write is conditional on that interval and polling faster gains nothing.
89    async fn get_all(
90        &self,
91    ) -> Result<models::ClaimableRotationJobResponseModelListResponseModel, Error> {
92        let local_var_configuration = &self.configuration;
93
94        let local_var_client = &local_var_configuration.client;
95
96        let local_var_uri_str = format!(
97            "{}/access-connectors/rotation/jobs",
98            local_var_configuration.base_path
99        );
100        let mut local_var_req_builder =
101            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
102
103        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
104
105        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
106    }
107}