package com.emc.ecs.serviceBroker.config;

import java.net.URL;

import org.cloudfoundry.community.servicebroker.model.BrokerApiVersion;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.emc.ecs.managementClient.Connection;
import com.emc.ecs.serviceBroker.repository.EcsRepositoryCredentials;

@Configuration
@ComponentScan(basePackages = "com.emc.ecs.serviceBroker")
public class BrokerConfig {
	
	@Value("${endpoint}")
	private String endpoint;
	
	@Value("${namespace}")
	private String namespace;
	
	@Value("${replicationGroup}")
	private String replicationGroup;
	
	@Value("${repositoryUser:user}")
	private String repositoryUser;
	
	@Value("${managementPort:4443}")
	private String managementPort;
	
	@Value("${username:root}")
	private String username;
	
	@Value("${password:ChangeMe}")
	private String password;
	
	@Value("${repositoryBucket:repository}")
	private String repositoryBucket;
	
	@Value("${prefix:ecs-cf-broker-}")
	private String prefix;

	@Bean
	public Connection ecsConnection() {
		URL certificate = getClass().getClassLoader().getResource("localhost.pem");
		return new Connection("https://" + endpoint + ":" + managementPort, username, password, certificate);
	}
	
	@Bean
	public BrokerApiVersion brokerApiVersion() {
		return new BrokerApiVersion("2.7");
	}
	
	@Bean
	public EcsRepositoryCredentials getRepositoryCredentials() {
		return new EcsRepositoryCredentials(repositoryBucket, repositoryUser, namespace, replicationGroup, prefix);
	}
}
@@ -1147,16 +1147,87 @@
  prefix;
+%0A%09%0A%09@Value(%22$%7BbrokerApiVersion:2.8%7D%22)%0A%09private String brokerApiVersion;
 %0A%0A%09@Bean
@@ -1538,13 +1538,24 @@
 ion(
-%222.7%22
+brokerApiVersion
 );%0A%09

Make CF Service Broker Version configurable