Permalink
Browse files

Make service companion accessible through config API

  • Loading branch information...
schrieveslaach committed Jan 30, 2019
1 parent a101f0f commit 747e4d50aba099834c97d7102e86d741163b13a8
Showing with 57 additions and 10 deletions.
  1. +55 −9 api/src/services/config_service.rs
  2. +1 −1 api/src/services/service_templating.rs
  3. +1 −0 frontend/src/store/index.js
@@ -110,24 +110,34 @@ impl Config {
}
}

pub fn get_service_companion_configs(&self) -> Result<Vec<ServiceConfig>, ConfigError> {
Ok(self.get_companion_configs(|companion| companion.companion_type == CompanionType::Service)?)
}

pub fn get_application_companion_configs(&self) -> Result<Vec<ServiceConfig>, ConfigError> {
Ok(self.get_companion_configs(|companion| companion.companion_type == CompanionType::Application)?)
}

fn get_companion_configs<P>(&self, predicate: P) -> Result<Vec<ServiceConfig>, ConfigError>
where P: FnMut(&&Companion) -> bool, {

let mut companions = Vec::new();

for companion in self
.companions
.iter()
.flat_map(|companions| companions.values())
.filter(|companion| companion.companion_type == CompanionType::Application)
{
let mut config = ServiceConfig::try_from(companion)?;
.filter(predicate)
{
let mut config = ServiceConfig::try_from(companion)?;

config.set_container_type(match &companion.companion_type {
CompanionType::Application => ContainerType::ApplicationCompanion,
CompanionType::Service => ContainerType::ServiceCompanion,
});
config.set_container_type(match &companion.companion_type {
CompanionType::Application => ContainerType::ApplicationCompanion,
CompanionType::Service => ContainerType::ServiceCompanion,
});

companions.push(config);
}
companions.push(config);
}

Ok(companions)
}
@@ -252,6 +262,42 @@ mod tests {
});
}

#[test]
fn should_return_service_companions_as_service_configs() {
let config_str = r#"
[[companions]]
[companions.openid]
serviceName = 'openid'
type = 'application'
image = 'private.example.com/library/opendid:latest'
env = [ 'KEY=VALUE' ]
[companions.nginx]
serviceName = '{{service-name}}-nginx'
type = 'service'
image = 'nginx:latest'
env = [ 'KEY=VALUE' ]
"#;

let config = from_str::<Config>(config_str).unwrap();
let companion_configs = config.get_service_companion_configs().unwrap();

assert_eq!(companion_configs.len(), 1);
companion_configs.iter().for_each(|config| {
assert_eq!(config.get_service_name(), "{{service-name}}-nginx");
assert_eq!(
&config.get_image().to_string(),
"docker.io/library/nginx:latest"
);
assert_eq!(
config.get_container_type(),
&ContainerType::ServiceCompanion
);
assert_eq!(config.get_labels(), None);
});
}


#[test]
fn should_return_application_companions_as_service_configs_with_volumes() {
let config_str = r#"
@@ -483,7 +483,7 @@ location /service-c {
proxy_pass http://service-c;
}
location /service-d {
proxy_pass http://service-d ;
proxy_pass http://service-d;
}"#
);
}
@@ -176,6 +176,7 @@ export default new Vuex.Store( {
const undefinedVersion = { 'build.time': 'N/A', 'git.revision': 'N/A' };
if ( container.versionUrl == null ) {
promises.push( Promise.resolve( ( { name, containerIndex, version: undefinedVersion } ) ) );
return;
}

promises.push( fetch( container.versionUrl )

0 comments on commit 747e4d5

Please sign in to comment.