Skip to content

Commit

Permalink
https,http and without any scheme is working
Browse files Browse the repository at this point in the history
  • Loading branch information
adigeak committed May 5, 2021
1 parent f54e478 commit b3187ca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ fn main() -> Result<()> {

if matches.is_present(Other_commands::login) {
let (_, submatches) = matches.subcommand();
let input_url: &str = submatches.unwrap().value_of(Parameters::url).unwrap();
let https: &str = "https://";
let base = format!("{}{}",https,input_url);
let url = util::url_validation(&*base)?;

let url = util::url_validation(submatches.unwrap().value_of(Parameters::url).unwrap());
let refresh_token_val = submatches.unwrap().value_of(Other_commands::token);

let mut config = config_result.unwrap_or_else(|_| Config::empty());
Expand Down
27 changes: 22 additions & 5 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,25 @@ fn exit_with_code(r: reqwest::StatusCode) {

// todo : assume https as the default scheme
// Or get rid of this.
pub fn url_validation(url: &str) -> Result<Url> {
Url::parse(url).context(format!("URL args: \'{}\' is not valid", url))
pub fn url_validation(url: &str) -> Url {
let temp_url = Url::parse(url);
let temp_url = match temp_url {
Ok(pass) => {
https(pass)
},
Err(_error) => {
Url::parse(&format!("https://{}",url)).unwrap()
},
};
temp_url
}

fn https(url: Url) -> Url {
if url.as_str().starts_with("http://") {
Url::parse(&format!("https://{}",url.host_str().unwrap())).unwrap()
} else {
url
}
}

pub fn json_parse(data: Option<&str>) -> Result<Value> {
Expand Down Expand Up @@ -157,8 +174,8 @@ pub fn get_drogue_services_endpoint(url: Url) -> Result<(Url, Url)> {

// a trailing / is needed to append the rest of the path.
Ok((
url_validation(format!("{}/", sso).as_str())?,
url_validation(format!("{}/", registry).as_str())?,
url_validation(format!("{}/", sso).as_str()),
url_validation(format!("{}/", registry).as_str()),
))
}

Expand Down Expand Up @@ -186,7 +203,7 @@ pub fn get_auth_and_tokens_endpoints(issuer_url: Url) -> Result<(Url, Url)> {
.context("Missing `token_endpoint` in drogue openid-connect configuration")?;
let token_endpoint = url_validation(token);

Ok((auth_endpoint?, token_endpoint?))
Ok((auth_endpoint, token_endpoint))
}

pub fn log_level(matches: &ArgMatches) -> LevelFilter {
Expand Down

0 comments on commit b3187ca

Please sign in to comment.