pub fn validate_integrations(workspace: &Workspace) -> Result<()> {
    // Validate project integration
    {
        let prj_integrations = workspace.job.get_project_integrations();
        if prj_integrations.is_empty() {
            // No project integrations, that's cool, we're done!
            return Ok(());
        }

        let prj_integration = prj_integrations.first().unwrap();

        // TODO fn: use a struct and serde to do heavy lifting
        let opts: JsonValue = match serde_json::from_str(prj_integration.get_body()) {
            Ok(json) => json,
            Err(err) => {
                return Err(Error::InvalidIntegrations(format!(
                    "project integration body does not deserialize as JSON: {:?}",
                    err
                )))
            }
        };
        // Required keys with string values
        for str_key in vec!["docker_hub_repo_name"].iter() {
            match opts.get(str_key) {
                Some(val) => {
                    if val.is_string() {
                        if val.as_str().unwrap().is_empty() {
                            return Err(Error::InvalidIntegrations(format!(
                                "project integration {} value must be a nonempty string",
                                str_key
                            )));
                        }
                    } else {
                        return Err(Error::InvalidIntegrations(format!(
                            "project integration {} value must be a string",
                            str_key
                        )));
                    }
                }
                None => {
                    return Err(Error::InvalidIntegrations(format!(
                        "project integration {} missing",
                        str_key
                    )));
                }
            }
        }
        // Required keys with boolean values
        for bool_key in vec!["latest_tag", "version_tag", "version_release_tag"].iter() {
            match opts.get(bool_key) {
                Some(val) => {
                    if !val.is_boolean() {
                        return Err(Error::InvalidIntegrations(format!(
                            "project integration {} value must be a bool",
                            bool_key
                        )));
                    }
                }
                None => {
                    return Err(Error::InvalidIntegrations(format!(
                        "project integration {} missing",
                        bool_key
                    )));
                }
            }
        }
        // Optional keys with string values
        if let Some(val) = opts.get("custom_tag") {
            if !val.is_string() {
                return Err(Error::InvalidIntegrations(
                    "project integration custom_tag value must be a string".to_string(),
                ));
            }
        }
    }
    // Validate origin integration
    {
        let org_integrations = workspace.job.get_integrations();
        if org_integrations.is_empty() {
            return Err(Error::InvalidIntegrations(
                "missing Docker credentials from origin integrations".to_string(),
            ));
        }
        let org_integration = org_integrations.first().unwrap();

        // TODO fn: use a struct and serde to do heavy lifting
        let creds: JsonValue = match serde_json::from_str(org_integration.get_body()) {
            Ok(json) => json,
            Err(err) => {
                return Err(Error::InvalidIntegrations(format!(
                    "origin integration body does not deserialize as JSON: {:?}",
                    err
                )))
            }
        };
        // Required keys with string values
        for str_key in vec!["username", "password"].iter() {
            match creds.get(str_key) {
                Some(s) => {
                    if s.is_string() {
                        if s.as_str().unwrap().is_empty() {
                            return Err(Error::InvalidIntegrations(format!(
                                "origin integration {} value must be a nonempty string",
                                str_key
                            )));
                        }
                    } else {
                        return Err(Error::InvalidIntegrations(format!(
                            "origin integration {} value must be a string",
                            str_key
                        )));
                    }
                }
                None => {
                    return Err(Error::InvalidIntegrations(format!(
                        "origin integration {} missing",
                        str_key
                    )));
                }
            }
        }
    }
    debug!("validated integrations");
    Ok(())
}
/// Validate integration data in job.
Validate integration data in job.
Validate integration data in job .
pub fn validate_integrations(workspace: &Workspace) -> Result<()> {
    // Validate project integration
    {
        let prj_integrations = workspace.job.get_project_integrations();
        if prj_integrations.is_empty() {
            // No project integrations, that's cool, we're done!
            return Ok(());
        }
        let prj_integration = prj_integrations.first().unwrap();
        // TODO fn: use a struct and serde to do heavy lifting
        let opts: JsonValue = match serde_json::from_str(prj_integration.get_body()) {
            Ok(json) => json,
            Err(err) => {
                return Err(Error::InvalidIntegrations(format!(
                    "project integration body does not deserialize as JSON: {:?}",
                    err
                )))
            }
        };
        // Required keys with string values
        for str_key in vec!["docker_hub_repo_name"].iter() {
            match opts.get(str_key) {
                Some(val) => {
                    if val.is_string() {
                        if val.as_str().unwrap().is_empty() {
                            return Err(Error::InvalidIntegrations(format!(
                                "project integration {} value must be a nonempty string",
                                str_key
                            )));
                        }
                    } else {
                        return Err(Error::InvalidIntegrations(format!(
                            "project integration {} value must be a string",
                            str_key
                        )));
                    }
                }
                None => {
                    return Err(Error::InvalidIntegrations(format!(
                        "project integration {} missing",
                        str_key
                    )));
                }
            }
        }
        // Required keys with boolean values
        for bool_key in vec!["latest_tag", "version_tag", "version_release_tag"].iter() {
            match opts.get(bool_key) {
                Some(val) => {
                    if !val.is_boolean() {
                        return Err(Error::InvalidIntegrations(format!(
                            "project integration {} value must be a bool",
                            bool_key
                        )));
                    }
                }
                None => {
                    return Err(Error::InvalidIntegrations(format!(
                        "project integration {} missing",
                        bool_key
                    )));
                }
            }
        }
        // Optional keys with string values
        if let Some(val) = opts.get("custom_tag") {
            if !val.is_string() {
                return Err(Error::InvalidIntegrations(
                    "project integration custom_tag value must be a string".to_string(),
                ));
            }
        }
    }
    // Validate origin integration
    {
        let org_integrations = workspace.job.get_integrations();
        if org_integrations.is_empty() {
            return Err(Error::InvalidIntegrations(
                "missing Docker credentials from origin integrations".to_string(),
            ));
        }
        let org_integration = org_integrations.first().unwrap();
        // TODO fn: use a struct and serde to do heavy lifting
        let creds: JsonValue = match serde_json::from_str(org_integration.get_body()) {
            Ok(json) => json,
            Err(err) => {
                return Err(Error::InvalidIntegrations(format!(
                    "origin integration body does not deserialize as JSON: {:?}",
                    err
                )))
            }
        };
        // Required keys with string values
        for str_key in vec!["username", "password"].iter() {
            match creds.get(str_key) {
                Some(s) => {
                    if s.is_string() {
                        if s.as_str().unwrap().is_empty() {
                            return Err(Error::InvalidIntegrations(format!(
                                "origin integration {} value must be a nonempty string",
                                str_key
                            )));
                        }
                    } else {
                        return Err(Error::InvalidIntegrations(format!(
                            "origin integration {} value must be a string",
                            str_key
                        )));
                    }
                }
                None => {
                    return Err(Error::InvalidIntegrations(format!(
                        "origin integration {} missing",
                        str_key
                    )));
                }
            }
        }
    }
    debug!("validated integrations");
    Ok(())
}
pub fn validate_integrations ( workspace : & Workspace ) -> Result < ( ) > { // Validate project integration { let prj_integrations = workspace . job . get_project_integrations ( ) ; if prj_integrations . is_empty ( ) { // No project integrations, that's cool, we're done! return Ok ( ( ) ) ; } let prj_integration = prj_integrations . first ( ) . unwrap ( ) ; // TODO fn: use a struct and serde to do heavy lifting let opts : JsonValue = match serde_json :: from_str ( prj_integration . get_body ( ) ) { Ok ( json ) => json , Err ( err ) => { return Err ( Error :: InvalidIntegrations ( format ! ( " " err ) ) ) } } ; // Required keys with string values for str_key in vec ! [ " " ] . iter ( ) { match opts . get ( str_key ) { Some ( val ) => { if val . is_string ( ) { if val . as_str ( ) . unwrap ( ) . is_empty ( ) { return Err ( Error :: InvalidIntegrations ( format ! ( " " str_key ) ) ) ; } } else { return Err ( Error :: InvalidIntegrations ( format ! ( " " str_key ) ) ) ; } } None => { return Err ( Error :: InvalidIntegrations ( format ! ( " " str_key ) ) ) ; } } } // Required keys with boolean values for bool_key in vec ! [ " " " " " " ] . iter ( ) { match opts . get ( bool_key ) { Some ( val ) => { if ! val . is_boolean ( ) { return Err ( Error :: InvalidIntegrations ( format ! ( " " bool_key ) ) ) ; } } None => { return Err ( Error :: InvalidIntegrations ( format ! ( " " bool_key ) ) ) ; } } } // Optional keys with string values if let Some ( val ) = opts . get ( " " ) { if ! val . is_string ( ) { return Err ( Error :: InvalidIntegrations ( " " . to_string ( ) , ) ) ; } } } // Validate origin integration { let org_integrations = workspace . job . get_integrations ( ) ; if org_integrations . is_empty ( ) { return Err ( Error :: InvalidIntegrations ( " " . to_string ( ) , ) ) ; } let org_integration = org_integrations . first ( ) . unwrap ( ) ; // TODO fn: use a struct and serde to do heavy lifting let creds : JsonValue = match serde_json :: from_str ( org_integration . get_body ( ) ) { Ok ( json ) => json , Err ( err ) => { return Err ( Error :: InvalidIntegrations ( format ! ( " " err ) ) ) } } ; // Required keys with string values for str_key in vec ! [ " " " " ] . iter ( ) { match creds . get ( str_key ) { Some ( s ) => { if s . is_string ( ) { if s . as_str ( ) . unwrap ( ) . is_empty ( ) { return Err ( Error :: InvalidIntegrations ( format ! ( " " str_key ) ) ) ; } } else { return Err ( Error :: InvalidIntegrations ( format ! ( " " str_key ) ) ) ; } } None => { return Err ( Error :: InvalidIntegrations ( format ! ( " " str_key ) ) ) ; } } } } debug ! ( " " ) ; Ok ( ( ) ) }
Validate integration data in job.
Validate integration data in job .
workspace
&Workspace