Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate few things, lock and lints #1111

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions docs/src/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

You can also configure Martin using environment variables, but only if the configuration file is not used. See [configuration section](config-file.md) on how to use environment variables with config files. See also [SSL configuration](pg-connections.md#postgresql-ssl-connections) section below.

| Environment var <br/> Config File key | Example | Description |
|------------------------------------------|--------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `DATABASE_URL` <br/> `connection_string` | `postgresql://postgres@localhost/db` | Postgres database connection |
| `DEFAULT_SRID` <br/> `default_srid` | `4326` | If a PostgreSQL table has a geometry column with SRID=0, use this value instead |
| `PGSSLCERT` <br/> `ssl_cert` | `./postgresql.crt` | A file with a client SSL certificate. [docs](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLCERT) |
| `PGSSLKEY` <br/> `ssl_key` | `./postgresql.key` | A file with the key for the client SSL certificate. [docs](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLKEY) |
| `PGSSLROOTCERT` <br/> `ssl_root_cert` | `./root.crt` | A file with trusted root certificate(s). The file should contain a sequence of PEM-formatted CA certificates. [docs](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLROOTCERT)<br/>This env var used to be called `CA_ROOT_FILE`, but support for it will be removed soon. |
| Environment var <br/> Config File key | Example | Description |
|------------------------------------------|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `DATABASE_URL` <br/> `connection_string` | `postgresql://postgres@localhost/db` | Postgres database connection |
| `DEFAULT_SRID` <br/> `default_srid` | `4326` | If a PostgreSQL table has a geometry column with SRID=0, use this value instead |
| `PGSSLCERT` <br/> `ssl_cert` | `./postgresql.crt` | A file with a client SSL certificate. [docs](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLCERT) |
| `PGSSLKEY` <br/> `ssl_key` | `./postgresql.key` | A file with the key for the client SSL certificate. [docs](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLKEY) |
| `PGSSLROOTCERT` <br/> `ssl_root_cert` | `./root.crt` | A file with trusted root certificate(s). The file should contain a sequence of PEM-formatted CA certificates. [docs](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLROOTCERT) |
10 changes: 1 addition & 9 deletions martin/src/args/pg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ impl PgArgs {
}

for v in &[
"CA_ROOT_FILE",
"DANGER_ACCEPT_INVALID_CERTS",
"DATABASE_URL",
"DEFAULT_SRID",
Expand Down Expand Up @@ -167,13 +166,6 @@ impl PgArgs {
if result.ssl_root_cert.is_none() {
result.ssl_root_cert = Self::parse_env_var(env, "PGSSLROOTCERT", "root certificate(s)");
}
if result.ssl_root_cert.is_none() {
result.ssl_root_cert = Self::parse_env_var(
env,
"CA_ROOT_FILE",
"root certificate(s). This setting is obsolete, please use PGSSLROOTCERT instead",
);
}

result
}
Expand Down Expand Up @@ -255,7 +247,7 @@ mod tests {
("DATABASE_URL", os("postgres://localhost:5432")),
("DEFAULT_SRID", os("10")),
("DANGER_ACCEPT_INVALID_CERTS", os("1")),
("CA_ROOT_FILE", os("file")),
("PGSSLROOTCERT", os("file")),
]
.into_iter()
.collect(),
Expand Down
27 changes: 11 additions & 16 deletions martin/src/args/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,11 @@ impl Args {
pub fn merge_into_config<'a>(
self,
config: &mut Config,
env: &impl Env<'a>,
#[allow(unused_variables)] env: &impl Env<'a>,
) -> MartinResult<()> {
if self.meta.watch {
warn!("The --watch flag is no longer supported, and will be ignored");
}
if env.has_unused_var("WATCH_MODE") {
warn!("The WATCH_MODE env variable is no longer supported, and will be ignored");
}
if self.meta.config.is_some() && !self.meta.connection.is_empty() {
return Err(ConfigAndConnectionsError(self.meta.connection));
}
Expand Down Expand Up @@ -138,19 +135,17 @@ pub fn parse_file_args<T: crate::file_config::ConfigExtras>(
) -> FileConfigEnum<T> {
use crate::args::State::{Ignore, Share, Take};

let paths = cli_strings.process(|s| match PathBuf::try_from(s) {
Ok(v) => {
if allow_url && is_url(s, extension) {
Take(v)
} else if v.is_dir() {
Share(v)
} else if v.is_file() && v.extension().map_or(false, |e| e == extension) {
Take(v)
} else {
Ignore
}
let paths = cli_strings.process(|s| {
let path = PathBuf::from(s);
if allow_url && is_url(s, extension) {
Take(path)
} else if path.is_dir() {
Share(path)
} else if path.is_file() && path.extension().map_or(false, |e| e == extension) {
Take(path)
} else {
Ignore
}
Err(_) => Ignore,
});

FileConfigEnum::new(paths)
Expand Down
70 changes: 35 additions & 35 deletions mbtiles/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,41 @@ LIMIT 1;"
}
}

/// Compute the hash of the combined tiles in the mbtiles file tiles table/view.
/// This should work on all mbtiles files perf `MBTiles` specification.
pub async fn calc_agg_tiles_hash<T>(conn: &mut T) -> MbtResult<String>
where
for<'e> &'e mut T: SqliteExecutor<'e>,
{
debug!("Calculating agg_tiles_hash");
let query = query(
// The md5_concat func will return NULL if there are no rows in the tiles table.
// For our use case, we will treat it as an empty string, and hash that.
// `tile_data` values must be stored as a blob per MBTiles spec
// `md5` functions will fail if the value is not text/blob/null
//
// Note that ORDER BY controls the output ordering, which is important for the hash value,
// and having it at the top level would not order values properly.
// See https://sqlite.org/forum/forumpost/228bb96e12a746ce
"
SELECT coalesce(
(SELECT md5_concat_hex(
cast(zoom_level AS text),
cast(tile_column AS text),
cast(tile_row AS text),
tile_data
)
OVER (ORDER BY zoom_level, tile_column, tile_row ROWS
BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
FROM tiles
LIMIT 1),
md5_hex('')
);
",
);
Ok(query.fetch_one(conn).await?.get::<String, _>(0))
}

#[cfg(test)]
pub(crate) mod tests {
use super::*;
Expand Down Expand Up @@ -499,38 +534,3 @@ pub(crate) mod tests {
Ok(())
}
}

/// Compute the hash of the combined tiles in the mbtiles file tiles table/view.
/// This should work on all mbtiles files perf `MBTiles` specification.
pub async fn calc_agg_tiles_hash<T>(conn: &mut T) -> MbtResult<String>
where
for<'e> &'e mut T: SqliteExecutor<'e>,
{
debug!("Calculating agg_tiles_hash");
let query = query(
// The md5_concat func will return NULL if there are no rows in the tiles table.
// For our use case, we will treat it as an empty string, and hash that.
// `tile_data` values must be stored as a blob per MBTiles spec
// `md5` functions will fail if the value is not text/blob/null
//
// Note that ORDER BY controls the output ordering, which is important for the hash value,
// and having it at the top level would not order values properly.
// See https://sqlite.org/forum/forumpost/228bb96e12a746ce
"
SELECT coalesce(
(SELECT md5_concat_hex(
cast(zoom_level AS text),
cast(tile_column AS text),
cast(tile_row AS text),
tile_data
)
OVER (ORDER BY zoom_level, tile_column, tile_row ROWS
BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
FROM tiles
LIMIT 1),
md5_hex('')
);
",
);
Ok(query.fetch_one(conn).await?.get::<String, _>(0))
}
Loading