-
Notifications
You must be signed in to change notification settings - Fork 14
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
Refactor #12
Refactor #12
Conversation
Signed-off-by: Berend Sliedrecht <[email protected]>
Signed-off-by: Berend Sliedrecht <[email protected]>
Signed-off-by: Berend Sliedrecht <[email protected]>
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.
Hey @blu3beri, left a few comments, but really nice work man! (Comments mostly me being confused tbf)
cli.yaml
Outdated
long: invite | ||
help: create a proper mediation invitation | ||
- auto-accept: | ||
help: Wether the invitation should be auto-accepted |
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.
Whether 😅
.expect(&format!("Could not join on {}", id).to_string()) | ||
} | ||
fn create_invitation(agent: &HttpAgent) -> Url { | ||
reqwest::Url::parse(&agent.url) |
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.
NOt sure as I'm a total noob here but
reqwest::Url::parse(&agent.url)
.expect(&format!("Could not join on {}", agent.url).to_string())
.join("connections/")
.expect(&format!("Could not join on connections/").to_string())
seems to be the same base route 3 times? Maybe this can be refactored into a base connections route and used in all 3 methods just that get_connection_by_id
and create_invitation
append sth else as well?
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.
Yeah definitely agree! The whole endpoint generation needs a refactor as this is an extremely boated way to create urls :)
use async_trait::async_trait; | ||
|
||
#[async_trait] | ||
pub trait Agent { |
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.
nice!
src/agent/http_agent.rs
Outdated
async fn check_endpoint(&self) -> typing::Result<bool> { | ||
match reqwest::get(Endpoint::connections(&self)).await { | ||
Ok(res) => { | ||
if res.status() == 404 { |
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.
Maybe it'd make sense to check for status != 200 instead of == 400?
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.
How about:
if res.status() >= 200 && res.status() < 300
:D
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.
hmm but then you won't catch the 400 ones, will you?!
b.insert("group", "admin"); | ||
a.insert("metadata", b); | ||
|
||
body = Some(a); |
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.
Interesting! This is how you create
{"metadata": {"group": "admin"}}
?! Just wondering whether tehre is another way of doing this wo having to create two hast maps
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.
Just been reading into json in Rust a little bit. and serde seems to be recommended by people to handle json like stuff - and it's in the dependencies. Maybe it makes sense to use that here? Not sure, again, just a noob atm...
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.
Yeah Serde-json can be used. Serde is a lib that just does SERialization and DEserialization. serde-json is def the way to go. The reqwest json
just expected this type so I am not sure wether it'll work.
Will try!
src/agent/http_agent.rs
Outdated
match http::post(Endpoint::create_invitation(&self), query, body).await { | ||
Ok(res) => match res.json().await { | ||
Ok(parsed) => parsed, | ||
//Err(_) => error::throw(error::Error::ServerResponseParseError), |
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.
can be removed?
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.
Oui!
let mut body = None; | ||
|
||
if config.toolbox { | ||
query.push(("multi_use", false.to_string())); |
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.
Not sure I udnerstand this 100%. does false.to_string()
mean you're always setting this to false or default value?
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.
When we want to create a toolbox invite we don't want multi use. This way we don't pollute the invitations.
false.to_string() just gives back "false". However this is less error-prone as typos cannot occur :)
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.
ah ok get it - nice!
@@ -3,8 +3,15 @@ use serde::{Deserialize, Serialize}; | |||
|
|||
pub type Result<T> = std::result::Result<T, Error>; | |||
|
|||
pub struct InviteConfiguration<'a> { |
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.
what does the '
do in <'a>
?
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 is about lifetimes or variables. I truly do not understand it one bit and this was recommend to me by fellow ferris-lovers. :)
https://doc.rust-lang.org/rust-by-example/scope/lifetime.html
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.
ah hanks for the pointer (pun intended)
src/utils/qr.rs
Outdated
|
||
if let Err(_) = qr2term::print_qr(&url.as_ref()) { | ||
pub fn print_qr_code(text: &String) { | ||
if let Err(_) = qr2term::print_qr(text) { |
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 is some weird syntax😅🤓 does this actually print the qr code? Is this some Rust magic short hand thing? Looks like this only throws and error to me 🤦♂️
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 is an odd way to ignore the out come and only handle the error case. This should probably be done with an expect when the proper panic handler is implemented!
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.
ah ok. interesting! Adn how does the QR get printed then?
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.
print_qr prints a qrcode in the terminal by painting the background of a cell black or white. Quite fancy :)
Signed-off-by: Berend Sliedrecht <[email protected]>
cli.yaml
Outdated
short: a | ||
long: auto-accept | ||
- multi-use: | ||
help: Wether the invitation should be multi-use |
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.
all the wether should be whether ;P whether you like it or not
Signed-off-by: morrieinmaas <[email protected]>
MERGE #9 FIRST :D