// Internal Functions - These functions are business logic for any handlers
//
Internal Functions - These functions are business logic for any handlers
Internal Functions - These functions are business logic for any handlers
fn do_validate_registry_credentials(body: Json<Body>, registry_type: &str) -> Result<()> {
    if body.username.is_none() || body.password.is_none() {
        debug!("Error: Missing username or password");
        return Err(Error::BadRequest);
    }
    let url = match body.url {
        Some(ref url) => url.to_string(),
        None => {
            match registry_type {
                "docker" => "https://hub.docker.com/v2".to_string(),
                _ => return Err(Error::BadRequest),
            }
        }
    };
    // TODO: This should absolutely not be our own custom http client type
    // if at all possible we should stop using raw hyper calls and use an
    // actix http client builder and stop doing this
    let actual_url: &str = url.as_ref();
    let client = match ApiClient::new(actual_url, PRODUCT, VERSION, None) {
        Ok(c) => c,
        Err(e) => {
            debug!("Error: Unable to create HTTP client: {}", e);
            return Err(Error::BadRequest);
        }
    };
    let sbody = serde_json::to_string(&body.into_inner()).unwrap();
    let result = client.post("users/login")
                       .header(Accept::json())
                       .header(ContentType::json())
                       .body(&sbody)
                       .send();
    match result {
        Ok(response) => {
            match response.status {
                hyper::status::StatusCode::Ok => Ok(()),
                _ => {
                    debug!("Non-OK Response: {}", &response.status);
                    Err(Error::BadRequest)
                }
            }
        }
        Err(e) => {
            debug!("Error sending request: {:?}", e);
            Err(Error::Authorization)
        }
    }
}
fn do_validate_registry_credentials ( body : Json < Body > , registry_type : & str ) -> Result < ( ) > { if body . username . is_none ( ) || body . password . is_none ( ) { debug ! ( " " ) ; return Err ( Error :: BadRequest ) ; } let url = match body . url { Some ( ref url ) => url . to_string ( ) , None => { match registry_type { " " => " " . to_string ( ) , _ => return Err ( Error :: BadRequest ) , } } } ; // TODO: This should absolutely not be our own custom http client type // if at all possible we should stop using raw hyper calls and use an // actix http client builder and stop doing this let actual_url : & str = url . as_ref ( ) ; let client = match ApiClient :: new ( actual_url , PRODUCT , VERSION , None ) { Ok ( c ) => c , Err ( e ) => { debug ! ( " " e ) ; return Err ( Error :: BadRequest ) ; } } ; let sbody = serde_json :: to_string ( & body . into_inner ( ) ) . unwrap ( ) ; let result = client . post ( " " ) . header ( Accept :: json ( ) ) . header ( ContentType :: json ( ) ) . body ( & sbody ) . send ( ) ; match result { Ok ( response ) => { match response . status { hyper :: status :: StatusCode :: Ok => Ok ( ( ) ) , _ => { debug ! ( " " response status ) ; Err ( Error :: BadRequest ) } } } Err ( e ) => { debug ! ( " " e ) ; Err ( Error :: Authorization ) } } }
Internal Functions - These functions are business logic for any handlers
Internal Functions - These functions are business logic for any handlers
body
Json<Body>
registry_type
&str