-
Notifications
You must be signed in to change notification settings - Fork 20
Bootstrap socket location from env variable #73
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Clean code 👌 That will be useful.
I put two comments and was also wondering if we should add something about it in the README.md
?
src/core/ipc_handler/unix_socket.rs
Outdated
pub fn new(path: PathBuf, timeout: Option<Duration>) -> Self { | ||
Handler { path, timeout } | ||
pub fn new(path: PathBuf, timeout: Option<Duration>) -> Result<Self> { | ||
if path.exists() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you also need to check if path
points to a socket as we do in the service, it might be a folder or a regular file:
if path.exists() && fs::metadata(&path)?.file_type().is_socket() {
Ok(...)
} else {
Err(...)
}
src/core/request_client.rs
Outdated
} else { | ||
Ok(RequestClient { | ||
max_body_size: DEFAULT_MAX_BODY_SIZE, | ||
ipc_handler: Box::from(unix_socket::Handler::new( | ||
unix_socket::DEFAULT_SOCKET_PATH.into(), | ||
Some(ipc_handler::DEFAULT_TIMEOUT), | ||
)?), | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of this else
branch you could leverage the constructor from URL and do:
let url = env::var("PARSEC_SERVICE_ENDPOINT").or(DEFAULT_SERVICE_ENDPOINT);
and only keep the Ok
branch.
and have DEFAULT_SERVICE_ENDPOINT
as unix:///run/parsec/parsec.sock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I didn't create a DEFAULT_SERVICE_ENDPOINT
mostly because it's not that straight forward to combine two const &str
to obtain a new one, so I just stuck to formatting DEFAULT_SOCKET_PATH
in
Also, you don't need //
after the unix
scheme, so unix:/run/parsec/parsec.sock
is the corect value.
This commit adds functionality to create a IPC connector from a URL and to bootstrap the IPC handler creation from an environment variable using this new functionality. Signed-off-by: Ionut Mihalcea <[email protected]>
6b98f53
to
5d5ded7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
pub fn new(path: PathBuf, timeout: Option<Duration>) -> Result<Self> { | ||
if path.exists() | ||
&& std::fs::metadata(&path) | ||
.map_err(|_| Error::Client(ClientErrorKind::InvalidSocketAddress))? | ||
.file_type() | ||
.is_socket() | ||
{ | ||
Ok(Handler { path, timeout }) | ||
} else { | ||
Err(Error::Client(ClientErrorKind::InvalidSocketAddress)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
This commit adds functionality to create a IPC connector from a URL and
to bootstrap the IPC handler creation from an environment variable using
this new functionality.
Fixes #37