-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathauthorization.rs
More file actions
49 lines (44 loc) · 1.59 KB
/
Copy pathauthorization.rs
File metadata and controls
49 lines (44 loc) · 1.59 KB
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
use stackable_operator::{client::Client, commons::opa::OpaApiVersion, shared::time::Duration};
use crate::crd::{AirflowAuthorization, AirflowOpaConfig, v1alpha1};
pub struct AirflowAuthorizationResolved {
pub opa: Option<OpaConfigResolved>,
}
impl AirflowAuthorizationResolved {
pub async fn from_authorization_config(
client: &Client,
airflow: &v1alpha1::AirflowCluster,
authorization: &Option<AirflowAuthorization>,
) -> Result<Self, stackable_operator::commons::opa::Error> {
let opa = if let Some(AirflowAuthorization {
opa: Some(opa_config),
}) = authorization
{
Some(OpaConfigResolved::from_opa_config(client, airflow, opa_config).await?)
} else {
None
};
Ok(AirflowAuthorizationResolved { opa })
}
}
pub struct OpaConfigResolved {
pub connection_string: String,
pub cache_entry_time_to_live: Duration,
pub cache_max_entries: u32,
}
impl OpaConfigResolved {
pub async fn from_opa_config(
client: &Client,
airflow: &v1alpha1::AirflowCluster,
airflow_opa_config: &AirflowOpaConfig,
) -> Result<Self, stackable_operator::commons::opa::Error> {
let connection_string = airflow_opa_config
.opa
.full_document_url_from_config_map(client, airflow, None, OpaApiVersion::V1)
.await?;
Ok(OpaConfigResolved {
connection_string,
cache_entry_time_to_live: airflow_opa_config.cache.entry_time_to_live,
cache_max_entries: airflow_opa_config.cache.max_entries,
})
}
}