/*
 * Copyright 2013-2015 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
 *
 *      http://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 org.springframework.cloud.netflix.sidecar;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Spencer Gibb
 */
@Configuration
@EnableConfigurationProperties
@ConditionalOnProperty(value = "sidecar.enabled", matchIfMissing = true)
public class SidecarConfiguration {

	@Value("${server.port:${SERVER_PORT:${PORT:8080}}}")
	private int serverPort = 8080;

	@Bean
	public SidecarProperties sidecarProperties() {
		return new SidecarProperties();
	}

	@Bean
	public EurekaInstanceConfigBean eurekaInstanceConfigBean() {
		EurekaInstanceConfigBean config = new EurekaInstanceConfigBean();
		int port = sidecarProperties().getPort();
		config.setNonSecurePort(port);
		String scheme = config.getSecurePortEnabled() ? "https" : "http";
		config.setStatusPageUrl(scheme + "://" + config.getHostname() + ":"
				+ this.serverPort + config.getStatusPageUrlPath());
		config.setHealthCheckUrl(scheme + "://" + config.getHostname() + ":"
				+ this.serverPort + config.getHealthCheckUrlPath());
		config.setHomePageUrl(scheme + "://" + config.getHostname() + ":" + port
				+ config.getHomePageUrlPath());
		return config;
	}

	@Bean
	public LocalApplicationHealthIndicator localApplicationHealthIndicator() {
		return new LocalApplicationHealthIndicator();
	}

	@Bean
	public SidecarController sidecarController() {
		return new SidecarController();
	}

}

@@ -719,21 +719,160 @@
 otation.
-Value
+Autowired;%0Aimport org.springframework.beans.factory.annotation.Value;%0Aimport org.springframework.boot.autoconfigure.condition.ConditionalOnClass
 ;%0Aimport
@@ -1214,16 +1214,66 @@
 ation;%0A%0A
+import com.netflix.discovery.EurekaClientConfig;%0A%0A
 /**%0A * @
@@ -1374,16 +1374,37 @@
 alue = %22
+spring.cloud.netflix.
 sidecar.
@@ -1479,95 +1479,8 @@
 %0A%0A%09@
-Value(%22$%7Bserver.port:$%7BSERVER_PORT:$%7BPORT:8080%7D%7D%7D%22)%0A%09private int serverPort = 8080;%0A%0A%09@
 Bean
@@ -1558,39 +1558,318 @@
 operties();%0A%09%7D%0A%0A
+%09@Configuration%0A%09@ConditionalOnClass(EurekaClientConfig.class)%0A%09protected static class EurekaInstanceConfigBeanConfiguration %7B%0A%09%09@Autowired%0A%09%09private SidecarProperties sidecarProperties;%0A%0A%09%09@Value(%22$%7Bserver.port:$%7BSERVER_PORT:$%7BPORT:8080%7D%7D%7D%22)%0A%09%09private int serverPort = 8080;%0A%0A%09
 %09@Bean%0A
+%09
 %09public EurekaIn
@@ -1914,16 +1914,17 @@
 ean() %7B%0A
+%09
 %09%09Eureka
@@ -1983,16 +1983,17 @@
 Bean();%0A
+%09
 %09%09int po
@@ -2014,18 +2014,16 @@
 operties
-()
 .getPort
@@ -2026,16 +2026,17 @@
 Port();%0A
+%09
 %09%09config
@@ -2062,16 +2062,17 @@
 ort);%0A%09%09
+%09
 String s
@@ -2129,16 +2129,17 @@
 %22http%22;%0A
+%09
 %09%09config
@@ -2192,32 +2192,33 @@
 ostname() + %22:%22%0A
+%09
 %09%09%09%09+ this.serve
@@ -2251,32 +2251,33 @@
 geUrlPath());%0A%09%09
+%09
 config.setHealth
@@ -2329,24 +2329,25 @@
 ) + %22:%22%0A%09%09%09%09
+%09
 + this.serve
@@ -2387,16 +2387,17 @@
 ath());%0A
+%09
 %09%09config
@@ -2467,16 +2467,17 @@
 ort%0A%09%09%09%09
+%09
 + config
@@ -2502,16 +2502,17 @@
 h());%0A%09%09
+%09
 return c
@@ -2518,16 +2518,20 @@
 config;%0A
+%09%09%7D%0A
 %09%7D%0A%0A%09@Be

update sidecare enabled property, make eureka portion of config conditional on eureka on classpath so other DiscoveryClient impls can use it.