<commit_before>/*
 * 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 <NAME>
 */
@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;<commit_msg>update sidecare enabled property, make eureka portion of config conditional on eureka on classpath so other DiscoveryClient impls can use it.<commit_after>/*
 * 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.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
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;

import com.netflix.discovery.EurekaClientConfig;

/**
 * @author <NAME>
 */
@Configuration
@EnableConfigurationProperties
@ConditionalOnProperty(value = "spring.cloud.netflix.sidecar.enabled", matchIfMissing = true)
public class SidecarConfiguration {

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

	@Configuration
	@ConditionalOnClass(EurekaClientConfig.class)
	protected static class EurekaInstanceConfigBeanConfiguration {
		@Autowired
		private SidecarProperties sidecarProperties;

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

		@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;
		}
{'fraction_non_alphanumeric': 0.10392849719393057, 'fraction_numerical': 0.008314279775514447, 'mean_word_length': 5.323258869908016, 'pattern_counts': {'":': 12, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5533624', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1290, 'n_words': 343}