Skip to content

feat(pedm): SQL support#1292

Merged
Benoît Cortier (CBenoit) merged 18 commits intomasterfrom
pedm-libsql
Apr 8, 2025
Merged

feat(pedm): SQL support#1292
Benoît Cortier (CBenoit) merged 18 commits intomasterfrom
pedm-libsql

Conversation

@allan2
Copy link
Copy Markdown
Contributor

This PR defines the structure for supporting multiple database backends, as well as accessing data from state/middleware, to the PEDM module.

  • adds support for libSQL and Postgres as database backends
    • libSQL is the default
  • new config file for specifying the database and defining configuration
  • introduces the Database trait
    • required queries are defined in the Database trait
    • per backend implementations are defined in the backend-specific file, i.e., libsql.rs or pg.rs
  • introduces LogLayer, tower middleware for logging request and response metadata
  • introduces AppState
    • the elevate_temporary handler is updated to illustrate accessing data from state (DB connection) and from middleware (request ID)
    • policies moved from global OnceLock to AppState
    • plays nice with Aide/OpenAPI generation

This PR defines the structure for supporting multiple database backends, as well as
accessing data from state/middleware, to the PEDM module.

- adds support for libSQL and Postgres as database backends
  - libSQL is the default
- new config file for specifying the database and defining configuration
- introduces the `Database` trait
  - required queries are defined in the `Database` trait
  - per backend implementations are defined in the backend-specific
    file, i.e., _libsql.rs_ or _pg.rs_
- introduces `LogLayer`, tower middleware for logging request and response
  metadata
- introduces `AppState`
  - the _elevate_temporary_ handler is updated to illustrate accessing data from state (DB connection) and from middleware (request
    ID)
  - policies moved from global `OnceLock` to `AppState`
  - plays nice with Aide/OpenAPI generation
@github-actions
Copy link
Copy Markdown

Let maintainers know that an action is required on their side

  • Add the label release-required Please cut a new release (Devolutions Gateway, Devolutions Agent, Jetsocat, PowerShell module) when you request a maintainer to cut a new release (Devolutions Gateway, Devolutions Agent, Jetsocat, PowerShell module)

  • Add the label release-blocker Follow-up is required before cutting a new release if a follow-up is required before cutting a new release

  • Add the label publish-required Please publish libraries (`Devolutions.Gateway.Utils`, OpenAPI clients, etc) when you request a maintainer to publish libraries (Devolutions.Gateway.Utils, OpenAPI clients, etc.)

  • Add the label publish-blocker Follow-up is required before publishing libraries if a follow-up is required before publishing libraries

It was previously not updated because I had test crates in the
workspace. But CI is failing.

Test crates removed. This updates Cargo.lock.
Comment thread Cargo.lock
Comment on lines +5280 to +5292
[[package]]
name = "rustls"
version = "0.22.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432"
dependencies = [
"log",
"ring 0.17.14",
"rustls-pki-types",
"rustls-webpki 0.102.8",
"subtle",
"zeroize",
]
Copy link
Copy Markdown
Member

@CBenoit Benoît Cortier (CBenoit) Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: This is duplicating the rustls dependency. 0.22 is the older one.

Comment thread Cargo.lock Outdated
Comment thread Cargo.lock
Comment thread Cargo.lock
Comment on lines 2342 to +2346
[[package]]
name = "hyper-rustls"
version = "0.27.3"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "399c78f9338483cb7e630c8474b07268983c6bd5acee012e4211f9f7bb21b070"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: hyper-rustls also got duplicated, with an older one.

Copy link
Copy Markdown
Member

@CBenoit Benoît Cortier (CBenoit) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suspicious changes in our dependency graph. I don’t expect everything to be fixable, but ideally we should avoid duplicating dependencies or downgrading dependencies. If there is no immediate solution, we will merge now and fix later.

Comment thread crates/devolutions-pedm/src/api/mod.rs Outdated
server = create_pipe(pipe_name)?;

let tower_service = make_service.call(&client).await?;
let tower_service = make_service.call(&client).await.unwrap(); // return type is Infallible
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: A better way of handling Infaillible is:

Suggested change
let tower_service = make_service.call(&client).await.unwrap(); // return type is Infallible
let Ok(tower_service) = make_service.call(&client).await;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in e99d392.

Comment thread crates/devolutions-pedm/src/api/mod.rs Outdated
Comment on lines +184 to +210
error!(%error, "Failed to serve connection");
error!(%e, "Failed to serve connection");
Copy link
Copy Markdown
Member

@CBenoit Benoît Cortier (CBenoit) Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in baf5f47.

Comment thread crates/devolutions-pedm/src/api/mod.rs Outdated

let mut server = create_pipe(pipe_name)?;

// log the server startup
Copy link
Copy Markdown
Member

@CBenoit Benoît Cortier (CBenoit) Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in cd67021.


use super::{Database, DbError};

pub(crate) struct PgPool(Pool<PostgresConnectionManager<NoTls>>);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is it really fine to use the "NoTls" variant?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add TLS support in the future.

Copy link
Copy Markdown
Member

@CBenoit Benoît Cortier (CBenoit) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving as discussed on Slack

@CBenoit Benoît Cortier (CBenoit) enabled auto-merge (squash) April 8, 2025 14:29
@CBenoit Benoît Cortier (CBenoit) merged commit abc57f9 into master Apr 8, 2025
38 checks passed
@CBenoit Benoît Cortier (CBenoit) deleted the pedm-libsql branch April 8, 2025 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants