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

feat(pedm): SQL support #1292

Merged
merged 18 commits into from
Apr 8, 2025
Merged

feat(pedm): SQL support #1292

merged 18 commits into from
Apr 8, 2025

Conversation

allan2
Copy link
Contributor

@allan2 allan2 commented Mar 31, 2025

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
Copy link

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

allan2 added 5 commits March 31, 2025 23:33
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 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
Member

@CBenoit 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.

Cargo.lock Outdated
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
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
Member

@CBenoit 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.

loop {
server.connect().await?;
let client = server;

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
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
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 on lines 184 to 210
error!(%error, "Failed to serve connection");
error!(%e, "Failed to serve connection");
Copy link
Member

@CBenoit 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
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.


let mut make_service = app.into_make_service_with_connect_info::<RawNamedPipeConnectInfo>();

let mut server = create_pipe(pipe_name)?;

// log the server startup
Copy link
Member

@CBenoit 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
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
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
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
Member

@CBenoit 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 CBenoit enabled auto-merge (squash) April 8, 2025 14:29
@CBenoit CBenoit merged commit abc57f9 into master Apr 8, 2025
38 checks passed
@CBenoit 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