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

Add ReadOnly in TargetSessionAttrs #1110

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions tokio-postgres/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum TargetSessionAttrs {
Any,
/// The session must allow writes.
ReadWrite,
/// The session allow only reads.
ReadOnly,
Copy link
Owner

Choose a reason for hiding this comment

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

This presumably needs to be used somewhere in the connection code.

Copy link
Contributor Author

@chandr-andr chandr-andr Mar 3, 2024

Choose a reason for hiding this comment

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

@sfackler Sry, haven't committed my latest changes. Please have a look.

}

/// TLS configuration.
Expand Down Expand Up @@ -622,6 +624,7 @@ impl Config {
let target_session_attrs = match value {
"any" => TargetSessionAttrs::Any,
"read-write" => TargetSessionAttrs::ReadWrite,
"read-only" => TargetSessionAttrs::ReadOnly,
_ => {
return Err(Error::config_parse(Box::new(InvalidValue(
"target_session_attrs",
Expand Down
8 changes: 8 additions & 0 deletions tokio-postgres/tests/test/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ fn settings() {
.keepalives_idle(Duration::from_secs(30))
.target_session_attrs(TargetSessionAttrs::ReadWrite),
);
check(
"connect_timeout=3 keepalives=0 keepalives_idle=30 target_session_attrs=read-only",
Config::new()
.connect_timeout(Duration::from_secs(3))
.keepalives(false)
.keepalives_idle(Duration::from_secs(30))
.target_session_attrs(TargetSessionAttrs::ReadOnly),
);
}

#[test]
Expand Down
Loading