io.pivotal.cfenv.core.CfService Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.pivotal.cfenv.core;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Contains the Map of values and type-safe accessors for properties of a single service
* defined in VCAP_SERVICES.
*
* @author Mark Pollack
*/
public class CfService {
private static final String TAGS = "tags";
private static final String CREDENTIALS = "credentials";
private static final String VOLUME_MOUNTS = "volume_mounts";
private final Map serviceData;
private final CfCredentials cfCredentials;
private final List cfVolumes;
public CfService(Map serviceData) {
this.serviceData = serviceData;
this.cfCredentials = createCredentials();
this.cfVolumes = createVolumes();
}
public CfCredentials createCredentials() {
Map credentials = new HashMap<>();
if (this.serviceData.containsKey(CREDENTIALS)) {
credentials = (Map) this.serviceData.get(CREDENTIALS);
}
if (credentials == null) {
credentials = new HashMap<>();
}
return new CfCredentials(credentials);
}
public List createVolumes() {
List volumes = new ArrayList<>();
if (this.serviceData.containsKey(VOLUME_MOUNTS)) {
List