Skip to content

Commit 54a7e8a

Browse files
committed
chore: version any other structures defined outside of the main crd
This is helpful for later crd version sharing substructures that might not change. For example: v1alpha2::OpaCluster might still use user_info_fetcher::v1alpha1::Config, or perhaps it uses user_info_fetcher::v1beta1::Config. Similarly, shared structures from stackable-operators can then be versioned in the same way.
1 parent b1ef2f7 commit 54a7e8a

File tree

2 files changed

+90
-86
lines changed

2 files changed

+90
-86
lines changed

rust/operator-binary/src/crd/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub mod versioned {
108108
/// Configures how to fetch additional metadata about users (such as group memberships)
109109
/// from an external directory service.
110110
#[serde(default)]
111-
pub user_info: Option<user_info_fetcher::Config>,
111+
pub user_info: Option<user_info_fetcher::v1alpha1::Config>,
112112
}
113113

114114
// TODO: Temporary solution until listener-operator is finished

rust/operator-binary/src/crd/user_info_fetcher.rs

Lines changed: 89 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -7,111 +7,115 @@ use stackable_operator::{
77
schemars::{self, JsonSchema},
88
time::Duration,
99
};
10+
use stackable_versioned::versioned;
11+
12+
#[versioned(version(name = "v1alpha1"))]
13+
pub mod versioned {
14+
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
15+
#[serde(rename_all = "camelCase")]
16+
pub struct Config {
17+
/// The backend directory service to use.
18+
#[serde(default)]
19+
pub backend: v1alpha1::Backend,
20+
21+
/// Caching configuration.
22+
#[serde(default)]
23+
pub cache: v1alpha1::Cache,
24+
}
1025

11-
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
12-
#[serde(rename_all = "camelCase")]
13-
pub struct Config {
14-
/// The backend directory service to use.
15-
#[serde(default)]
16-
pub backend: Backend,
17-
18-
/// Caching configuration.
19-
#[serde(default)]
20-
pub cache: Cache,
21-
}
22-
23-
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
24-
#[serde(rename_all = "camelCase")]
25-
pub enum Backend {
26-
/// Dummy backend that adds no extra user information.
27-
None {},
26+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
27+
#[serde(rename_all = "camelCase")]
28+
pub enum Backend {
29+
/// Dummy backend that adds no extra user information.
30+
None {},
2831

29-
/// Backend that fetches user information from Keycloak.
30-
Keycloak(KeycloakBackend),
32+
/// Backend that fetches user information from Keycloak.
33+
Keycloak(v1alpha1::KeycloakBackend),
3134

32-
/// Backend that fetches user information from the Gaia-X
33-
/// Cross Federation Services Components (XFSC) Authentication & Authorization Service.
34-
ExperimentalXfscAas(AasBackend),
35+
/// Backend that fetches user information from the Gaia-X
36+
/// Cross Federation Services Components (XFSC) Authentication & Authorization Service.
37+
ExperimentalXfscAas(v1alpha1::AasBackend),
3538

36-
/// Backend that fetches user information from Active Directory
37-
#[serde(rename = "experimentalActiveDirectory")]
38-
ActiveDirectory(ActiveDirectoryBackend),
39-
}
39+
/// Backend that fetches user information from Active Directory
40+
#[serde(rename = "experimentalActiveDirectory")]
41+
ActiveDirectory(v1alpha1::ActiveDirectoryBackend),
42+
}
4043

41-
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
42-
#[serde(rename_all = "camelCase")]
43-
pub struct KeycloakBackend {
44-
/// Hostname of the identity provider, e.g. `my.keycloak.corp`.
45-
pub hostname: HostName,
44+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
45+
#[serde(rename_all = "camelCase")]
46+
pub struct KeycloakBackend {
47+
/// Hostname of the identity provider, e.g. `my.keycloak.corp`.
48+
pub hostname: HostName,
4649

47-
/// Port of the identity provider. If TLS is used defaults to `443`, otherwise to `80`.
48-
pub port: Option<u16>,
50+
/// Port of the identity provider. If TLS is used defaults to `443`, otherwise to `80`.
51+
pub port: Option<u16>,
4952

50-
/// Root HTTP path of the identity provider. Defaults to `/`.
51-
#[serde(default = "default_root_path")]
52-
pub root_path: String,
53+
/// Root HTTP path of the identity provider. Defaults to `/`.
54+
#[serde(default = "default_root_path")]
55+
pub root_path: String,
5356

54-
/// Use a TLS connection. If not specified no TLS will be used.
55-
#[serde(flatten)]
56-
pub tls: TlsClientDetails,
57+
/// Use a TLS connection. If not specified no TLS will be used.
58+
#[serde(flatten)]
59+
pub tls: TlsClientDetails,
5760

58-
/// Name of a Secret that contains client credentials of a Keycloak account with permission to read user metadata.
59-
///
60-
/// Must contain the fields `clientId` and `clientSecret`.
61-
pub client_credentials_secret: String,
61+
/// Name of a Secret that contains client credentials of a Keycloak account with permission to read user metadata.
62+
///
63+
/// Must contain the fields `clientId` and `clientSecret`.
64+
pub client_credentials_secret: String,
6265

63-
/// The Keycloak realm that OPA's Keycloak account (as specified by `credentialsSecretName` exists in).
64-
///
65-
/// Typically `master`.
66-
pub admin_realm: String,
66+
/// The Keycloak realm that OPA's Keycloak account (as specified by `credentialsSecretName` exists in).
67+
///
68+
/// Typically `master`.
69+
pub admin_realm: String,
6770

68-
/// The Keycloak realm that user metadata should be resolved from.
69-
pub user_realm: String,
70-
}
71+
/// The Keycloak realm that user metadata should be resolved from.
72+
pub user_realm: String,
73+
}
7174

72-
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
73-
#[serde(rename_all = "camelCase")]
74-
pub struct AasBackend {
75-
/// Hostname of the identity provider, e.g. `my.aas.corp`.
76-
pub hostname: String,
75+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
76+
#[serde(rename_all = "camelCase")]
77+
pub struct AasBackend {
78+
/// Hostname of the identity provider, e.g. `my.aas.corp`.
79+
pub hostname: String,
7780

78-
/// Port of the identity provider. Defaults to port 5000.
79-
#[serde(default = "aas_default_port")]
80-
pub port: u16,
81-
}
81+
/// Port of the identity provider. Defaults to port 5000.
82+
#[serde(default = "aas_default_port")]
83+
pub port: u16,
84+
}
8285

83-
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
84-
#[serde(rename_all = "camelCase")]
85-
pub struct ActiveDirectoryBackend {
86-
/// Hostname of the domain controller, e.g. `ad-ds-1.contoso.com`.
87-
pub ldap_server: String,
86+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
87+
#[serde(rename_all = "camelCase")]
88+
pub struct ActiveDirectoryBackend {
89+
/// Hostname of the domain controller, e.g. `ad-ds-1.contoso.com`.
90+
pub ldap_server: String,
8891

89-
/// The root Distinguished Name (DN) where users and groups are located.
90-
pub base_distinguished_name: String,
92+
/// The root Distinguished Name (DN) where users and groups are located.
93+
pub base_distinguished_name: String,
9194

92-
/// The name of the Kerberos SecretClass.
93-
pub kerberos_secret_class_name: String,
95+
/// The name of the Kerberos SecretClass.
96+
pub kerberos_secret_class_name: String,
9497

95-
/// Use a TLS connection. If not specified then no TLS will be used.
96-
#[serde(flatten)]
97-
pub tls: TlsClientDetails,
98+
/// Use a TLS connection. If not specified then no TLS will be used.
99+
#[serde(flatten)]
100+
pub tls: TlsClientDetails,
98101

99-
/// Custom attributes, and their LDAP attribute names.
100-
#[serde(default)]
101-
pub custom_attribute_mappings: BTreeMap<String, String>,
102-
}
102+
/// Custom attributes, and their LDAP attribute names.
103+
#[serde(default)]
104+
pub custom_attribute_mappings: BTreeMap<String, String>,
105+
}
103106

104-
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize, Derivative)]
105-
#[derivative(Default)]
106-
#[serde(rename_all = "camelCase")]
107-
pub struct Cache {
108-
/// How long metadata about each user should be cached for.
109-
#[derivative(Default(value = "Cache::default_entry_time_to_live()"))]
110-
#[serde(default = "Cache::default_entry_time_to_live")]
111-
pub entry_time_to_live: Duration,
107+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize, Derivative)]
108+
#[derivative(Default)]
109+
#[serde(rename_all = "camelCase")]
110+
pub struct Cache {
111+
/// How long metadata about each user should be cached for.
112+
#[derivative(Default(value = "v1alpha1::Cache::default_entry_time_to_live()"))]
113+
#[serde(default = "v1alpha1::Cache::default_entry_time_to_live")]
114+
pub entry_time_to_live: Duration,
115+
}
112116
}
113117

114-
impl Default for Backend {
118+
impl Default for v1alpha1::Backend {
115119
fn default() -> Self {
116120
Self::None {}
117121
}
@@ -125,7 +129,7 @@ fn aas_default_port() -> u16 {
125129
5000
126130
}
127131

128-
impl Cache {
132+
impl v1alpha1::Cache {
129133
const fn default_entry_time_to_live() -> Duration {
130134
Duration::from_minutes_unchecked(1)
131135
}

0 commit comments

Comments
 (0)