Skip to content

Commit a884e67

Browse files
committed
Leftovers I forgot to commit
1 parent cabe070 commit a884e67

6 files changed

Lines changed: 94 additions & 86 deletions

File tree

crates/stackable-operator/src/database_connections/databases/postgresql.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct PostgresqlConnection {
4141

4242
/// Name of a Secret containing the `username` and `password` keys used to authenticate
4343
/// against the PostgreSQL server.
44-
pub credentials_secret: String,
44+
pub credentials_secret_name: String,
4545

4646
/// Additional map of JDBC connection parameters to append to the connection URL. The given
4747
/// `HashMap<String, String>` will be converted to query parameters in the form of
@@ -66,22 +66,22 @@ impl JdbcDatabaseConnection for PostgresqlConnection {
6666
host,
6767
port,
6868
database,
69-
credentials_secret,
69+
credentials_secret_name,
7070
parameters,
7171
} = self;
7272
let (username_env, password_env) =
73-
username_and_password_envs(unique_database_name, credentials_secret);
73+
username_and_password_envs(unique_database_name, credentials_secret_name);
7474

75-
let connection_uri = format!(
75+
let connection_url = format!(
7676
"jdbc:postgresql://{host}:{port}/{database}{parameters}",
7777
parameters =
7878
connection_parameters_as_url_query_parameters(parameters).unwrap_or_default()
7979
);
80-
let connection_uri = connection_uri.parse().context(ParseConnectionUrlSnafu)?;
80+
let connection_url = connection_url.parse().context(ParseConnectionUrlSnafu)?;
8181

8282
Ok(JdbcDatabaseConnectionDetails {
8383
driver: POSTGRES_JDBC_DRIVER_CLASS.to_owned(),
84-
connection_uri,
84+
connection_url,
8585
username_env: Some(username_env),
8686
password_env: Some(password_env),
8787
})
@@ -98,17 +98,17 @@ impl SqlAlchemyDatabaseConnection for PostgresqlConnection {
9898
host,
9999
port,
100100
database,
101-
credentials_secret,
101+
credentials_secret_name,
102102
parameters,
103103
} = self;
104104
let (username_env, password_env) =
105-
username_and_password_envs(unique_database_name, credentials_secret);
105+
username_and_password_envs(unique_database_name, credentials_secret_name);
106106
let username_env_name = &username_env.name;
107107
let password_env_name = &password_env.name;
108108
let parameters =
109109
connection_parameters_as_url_query_parameters(parameters).unwrap_or_default();
110110

111-
let uri_template = match templating_mechanism {
111+
let url_template = match templating_mechanism {
112112
TemplatingMechanism::ConfigUtils => format!(
113113
"postgresql+psycopg2://${{env:{username_env_name}}}:${{env:{password_env_name}}}@{host}:{port}/{database}{parameters}",
114114
),
@@ -117,10 +117,10 @@ impl SqlAlchemyDatabaseConnection for PostgresqlConnection {
117117
),
118118
};
119119
SqlAlchemyDatabaseConnectionDetails {
120-
uri_template,
120+
url_template,
121121
username_env: Some(username_env),
122122
password_env: Some(password_env),
123-
generic_uri_var: None,
123+
generic_url_var: None,
124124
}
125125
}
126126
}
@@ -135,17 +135,17 @@ impl CeleryDatabaseConnection for PostgresqlConnection {
135135
host,
136136
port,
137137
database,
138-
credentials_secret,
138+
credentials_secret_name,
139139
parameters,
140140
} = self;
141141
let (username_env, password_env) =
142-
username_and_password_envs(unique_database_name, credentials_secret);
142+
username_and_password_envs(unique_database_name, credentials_secret_name);
143143
let username_env_name = &username_env.name;
144144
let password_env_name = &password_env.name;
145145
let parameters =
146146
connection_parameters_as_url_query_parameters(parameters).unwrap_or_default();
147147

148-
let uri_template = match templating_mechanism {
148+
let url_template = match templating_mechanism {
149149
TemplatingMechanism::ConfigUtils => format!(
150150
"db+postgresql://${{env:{username_env_name}}}:${{env:{password_env_name}}}@{host}:{port}/{database}{parameters}",
151151
),
@@ -154,10 +154,10 @@ impl CeleryDatabaseConnection for PostgresqlConnection {
154154
),
155155
};
156156
CeleryDatabaseConnectionDetails {
157-
uri_template,
157+
url_template,
158158
username_env: Some(username_env),
159159
password_env: Some(password_env),
160-
generic_uri_var: None,
160+
generic_url_var: None,
161161
}
162162
}
163163
}
@@ -174,26 +174,26 @@ mod tests {
174174
"
175175
host: airflow-postgresql
176176
database: airflow
177-
credentialsSecret: airflow-postgresql-credentials
177+
credentialsSecretName: airflow-postgresql-credentials
178178
",
179179
)
180180
.expect("invalid test input");
181181
let sqlalchemy_connection_details =
182182
postgres_connection.sqlalchemy_connection_details(UNIQUE_DATABASE_NAME);
183183
assert_eq!(
184-
sqlalchemy_connection_details.uri_template,
184+
sqlalchemy_connection_details.url_template,
185185
"postgresql+psycopg2://${env:METADATA_DATABASE_USERNAME}:${env:METADATA_DATABASE_PASSWORD}@airflow-postgresql:5432/airflow"
186186
);
187187
assert!(sqlalchemy_connection_details.username_env.is_some());
188188
assert!(sqlalchemy_connection_details.password_env.is_some());
189-
assert!(sqlalchemy_connection_details.generic_uri_var.is_none());
189+
assert!(sqlalchemy_connection_details.generic_url_var.is_none());
190190

191191
let jdbc_connection_details = postgres_connection
192192
.jdbc_connection_details(UNIQUE_DATABASE_NAME)
193193
.expect("failed to get JDBC connection details");
194194
assert_eq!(jdbc_connection_details.driver, POSTGRES_JDBC_DRIVER_CLASS);
195195
assert_eq!(
196-
jdbc_connection_details.connection_uri.to_string(),
196+
jdbc_connection_details.connection_url.to_string(),
197197
"jdbc:postgresql://airflow-postgresql:5432/airflow"
198198
);
199199
assert_eq!(
@@ -208,12 +208,12 @@ mod tests {
208208
let celery_connection_details =
209209
postgres_connection.celery_connection_details(UNIQUE_DATABASE_NAME);
210210
assert_eq!(
211-
celery_connection_details.uri_template,
211+
celery_connection_details.url_template,
212212
"db+postgresql://${env:METADATA_DATABASE_USERNAME}:${env:METADATA_DATABASE_PASSWORD}@airflow-postgresql:5432/airflow"
213213
);
214214
assert!(celery_connection_details.username_env.is_some());
215215
assert!(celery_connection_details.password_env.is_some());
216-
assert!(celery_connection_details.generic_uri_var.is_none());
216+
assert!(celery_connection_details.generic_url_var.is_none());
217217
}
218218

219219
#[test]
@@ -223,7 +223,7 @@ mod tests {
223223
host: my-airflow.default.svc.cluster.local
224224
database: my_database
225225
port: 1234
226-
credentialsSecret: airflow-postgresql-credentials
226+
credentialsSecretName: airflow-postgresql-credentials
227227
parameters:
228228
createDatabaseIfNotExist: true
229229
foo: bar
@@ -233,15 +233,15 @@ mod tests {
233233
let sqlalchemy_connection_details =
234234
postgres_connection.sqlalchemy_connection_details(UNIQUE_DATABASE_NAME);
235235
assert_eq!(
236-
sqlalchemy_connection_details.uri_template,
236+
sqlalchemy_connection_details.url_template,
237237
"postgresql+psycopg2://${env:METADATA_DATABASE_USERNAME}:${env:METADATA_DATABASE_PASSWORD}@my-airflow.default.svc.cluster.local:1234/my_database?createDatabaseIfNotExist=true&foo=bar"
238238
);
239239

240240
let jdbc_connection_details = postgres_connection
241241
.jdbc_connection_details(UNIQUE_DATABASE_NAME)
242242
.expect("failed to get JDBC connection details");
243243
assert_eq!(
244-
jdbc_connection_details.connection_uri.to_string(),
244+
jdbc_connection_details.connection_url.to_string(),
245245
"jdbc:postgresql://my-airflow.default.svc.cluster.local:1234/my_database?createDatabaseIfNotExist=true&foo=bar"
246246
);
247247
}

crates/stackable-operator/src/database_connections/databases/redis.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct RedisConnection {
3232

3333
/// Name of a Secret containing the `username` and `password` keys used to authenticate
3434
/// against the Redis server.
35-
pub credentials_secret: String,
35+
pub credentials_secret_name: String,
3636
}
3737

3838
impl RedisConnection {
@@ -55,14 +55,14 @@ impl CeleryDatabaseConnection for RedisConnection {
5555
host,
5656
port,
5757
database_id,
58-
credentials_secret,
58+
credentials_secret_name,
5959
} = self;
6060
let (username_env, password_env) =
61-
username_and_password_envs(unique_database_name, credentials_secret);
61+
username_and_password_envs(unique_database_name, credentials_secret_name);
6262
let username_env_name = &username_env.name;
6363
let password_env_name = &password_env.name;
6464

65-
let uri_template = match templating_mechanism {
65+
let url_template = match templating_mechanism {
6666
TemplatingMechanism::ConfigUtils => format!(
6767
"redis://${{env:{username_env_name}}}:${{env:{password_env_name}}}@{host}:{port}/{database_id}",
6868
),
@@ -71,10 +71,10 @@ impl CeleryDatabaseConnection for RedisConnection {
7171
),
7272
};
7373
CeleryDatabaseConnectionDetails {
74-
uri_template,
74+
url_template,
7575
username_env: Some(username_env),
7676
password_env: Some(password_env),
77-
generic_uri_var: None,
77+
generic_url_var: None,
7878
}
7979
}
8080
}
@@ -92,18 +92,18 @@ mod tests {
9292
host: my-redis
9393
port: 42
9494
databaseId: 13
95-
credentialsSecret: redis-credentials
95+
credentialsSecretName: redis-credentials
9696
",
9797
)
9898
.expect("invalid test input");
9999
let celery_connection_details =
100100
redis_connection.celery_connection_details(UNIQUE_DATABASE_NAME);
101101
assert_eq!(
102-
celery_connection_details.uri_template,
102+
celery_connection_details.url_template,
103103
"redis://${env:WORKER_QUEUE_DATABASE_USERNAME}:${env:WORKER_QUEUE_DATABASE_PASSWORD}@my-redis:42/13"
104104
);
105105
assert!(celery_connection_details.username_env.is_some());
106106
assert!(celery_connection_details.password_env.is_some());
107-
assert!(celery_connection_details.generic_uri_var.is_none());
107+
assert!(celery_connection_details.generic_url_var.is_none());
108108
}
109109
}

crates/stackable-operator/src/database_connections/drivers/celery.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
/// Implemented by database connection types that can serve as a
1111
/// [Celery](https://docs.celeryq.dev/) broker or result backend.
1212
///
13-
/// Provides a standardized way to obtain a Celery connection URI template together with the
13+
/// Provides a standardized way to obtain a Celery connection URL template together with the
1414
/// necessary credential env vars, regardless of the concrete database or message broker type.
1515
pub trait CeleryDatabaseConnection {
1616
/// Returns the Celery connection details for the given `unique_database_name` using the
@@ -40,28 +40,28 @@ pub trait CeleryDatabaseConnection {
4040
}
4141

4242
pub struct CeleryDatabaseConnectionDetails {
43-
/// The connection URI, which can contain env variable templates, e.g.
43+
/// The connection URL, which can contain env variable templates, e.g.
4444
/// `redis://:${env:METADATA_DATABASE_PASSWORD}@airflow-redis-master:6379/0`
4545
/// or
46-
/// `<generic URI from the user>`.
47-
pub uri_template: String,
46+
/// `<generic URL from the user>`.
47+
pub url_template: String,
4848

4949
/// The [`EnvVar`] that mounts the credentials Secret and provides the username.
5050
pub username_env: Option<EnvVar>,
5151

5252
/// The [`EnvVar`] that mounts the credentials Secret and provides the password.
5353
pub password_env: Option<EnvVar>,
5454

55-
/// The [`EnvVar`] that mounts the user-specified Secret and provides the generic URI.
56-
pub generic_uri_var: Option<EnvVar>,
55+
/// The [`EnvVar`] that mounts the user-specified Secret and provides the generic URL.
56+
pub generic_url_var: Option<EnvVar>,
5757
}
5858

5959
impl CeleryDatabaseConnectionDetails {
6060
pub fn env_vars(&self) -> impl Iterator<Item = &EnvVar> {
6161
[
6262
&self.username_env,
6363
&self.password_env,
64-
&self.generic_uri_var,
64+
&self.generic_url_var,
6565
]
6666
.into_iter()
6767
.flatten()
@@ -81,13 +81,13 @@ impl CeleryDatabaseConnectionDetails {
8181
/// dedicated variant.
8282
///
8383
/// Use this when you need a Celery-compatible connection that does not have a first-class
84-
/// connection type. The complete connection URI is read from a Secret, giving the user full
84+
/// connection type. The complete connection URL is read from a Secret, giving the user full
8585
/// control over the connection string.
8686
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
8787
#[serde(rename_all = "camelCase")]
8888
pub struct GenericCeleryDatabaseConnection {
89-
/// The name of the Secret that contains an `uri` key with the complete SQLAlchemy URI.
90-
pub uri_secret: String,
89+
/// The name of the Secret that contains an `connectionUrl` key with the complete Celery URL.
90+
pub connection_url_secret_name: String,
9191
}
9292

9393
impl CeleryDatabaseConnection for GenericCeleryDatabaseConnection {
@@ -96,21 +96,25 @@ impl CeleryDatabaseConnection for GenericCeleryDatabaseConnection {
9696
unique_database_name: &str,
9797
templating_mechanism: &TemplatingMechanism,
9898
) -> CeleryDatabaseConnectionDetails {
99-
let uri_env_name = format!(
100-
"{upper}_DATABASE_URI",
99+
let url_env_name = format!(
100+
"{upper}_DATABASE_URL",
101101
upper = unique_database_name.to_uppercase()
102102
);
103-
let uri_env_var = env_var_from_secret(&uri_env_name, &self.uri_secret, "uri");
104-
let uri_template = match templating_mechanism {
105-
TemplatingMechanism::ConfigUtils => format!("${{env:{uri_env_name}}}"),
106-
TemplatingMechanism::BashEnvSubstitution => format!("${{{uri_env_name}}}"),
103+
let url_env_var = env_var_from_secret(
104+
&url_env_name,
105+
&self.connection_url_secret_name,
106+
"connectionUrl",
107+
);
108+
let url_template = match templating_mechanism {
109+
TemplatingMechanism::ConfigUtils => format!("${{env:{url_env_name}}}"),
110+
TemplatingMechanism::BashEnvSubstitution => format!("${{{url_env_name}}}"),
107111
};
108112

109113
CeleryDatabaseConnectionDetails {
110-
uri_template,
114+
url_template,
111115
username_env: None,
112116
password_env: None,
113-
generic_uri_var: Some(uri_env_var),
117+
generic_url_var: Some(url_env_var),
114118
}
115119
}
116120
}

crates/stackable-operator/src/database_connections/drivers/jdbc.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010

1111
/// Implemented by database connection types that support JDBC.
1212
///
13-
/// Provides a standardized way to obtain JDBC connection details (driver class, URI, and
13+
/// Provides a standardized way to obtain JDBC connection details (driver class, URL, and
1414
/// credential env vars) regardless of the concrete database type.
1515
pub trait JdbcDatabaseConnection {
1616
/// Returns the JDBC connection details for the given `unique_database_name` using the
@@ -43,9 +43,9 @@ pub struct JdbcDatabaseConnectionDetails {
4343
/// The Java class name of the driver, e.g. `org.postgresql.Driver`
4444
pub driver: String,
4545

46-
/// The connection URI (without user and password), e.g.
46+
/// The connection URL (without user and password), e.g.
4747
/// `jdbc:postgresql://airflow-postgresql:5432/airflow`
48-
pub connection_uri: Url,
48+
pub connection_url: Url,
4949

5050
/// The [`EnvVar`] that mounts the credentials Secret and provides the username.
5151
pub username_env: Option<EnvVar>,
@@ -70,22 +70,22 @@ impl JdbcDatabaseConnectionDetails {
7070
///
7171
/// Use this when you need to connect to a JDBC-compatible database that does not have a
7272
/// first-class connection type. You are responsible for providing the correct driver class name
73-
/// and a fully-formed JDBC URI as well as providing the needed classes on the Java classpath.
73+
/// and a fully-formed JDBC URL as well as providing the needed classes on the Java classpath.
7474
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
7575
#[serde(rename_all = "camelCase")]
7676
pub struct GenericJdbcDatabaseConnection {
7777
/// Fully-qualified Java class name of the JDBC driver, e.g. `org.postgresql.Driver` or
7878
/// `com.mysql.jdbc.Driver`. The driver JAR must be provided by you on the classpath.
7979
pub driver: String,
8080

81-
/// The JDBC connection URI, e.g. `jdbc:postgresql://my-host:5432/mydb`. Credentials must
82-
/// not be embedded in this URI; they are instead injected via environment variables sourced
81+
/// The JDBC connection URL, e.g. `jdbc:postgresql://my-host:5432/mydb`. Credentials must
82+
/// not be embedded in this URL; they are instead injected via environment variables sourced
8383
/// from `credentials_secret`.
84-
pub uri: Url,
84+
pub url: Url,
8585

8686
/// Name of a Secret containing the `username` and `password` keys used to authenticate
8787
/// against the database.
88-
pub credentials_secret: String,
88+
pub credentials_secret_name: String,
8989
}
9090

9191
impl JdbcDatabaseConnection for GenericJdbcDatabaseConnection {
@@ -95,11 +95,11 @@ impl JdbcDatabaseConnection for GenericJdbcDatabaseConnection {
9595
_templating_mechanism: &TemplatingMechanism,
9696
) -> Result<JdbcDatabaseConnectionDetails, crate::database_connections::Error> {
9797
let (username_env, password_env) =
98-
username_and_password_envs(unique_database_name, &self.credentials_secret);
98+
username_and_password_envs(unique_database_name, &self.credentials_secret_name);
9999

100100
Ok(JdbcDatabaseConnectionDetails {
101101
driver: self.driver.clone(),
102-
connection_uri: self.uri.clone(),
102+
connection_url: self.url.clone(),
103103
username_env: Some(username_env),
104104
password_env: Some(password_env),
105105
})

0 commit comments

Comments
 (0)