<commit_before>/*
 * Copyright 2016 Google, Inc.
 *
 * 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 com.netflix.spinnaker.config

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.MapperFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spectator.api.Registry
import com.netflix.spinnaker.clouddriver.eureka.api.EurekaApiFactory
import com.netflix.spinnaker.clouddriver.eureka.deploy.ops.EurekaSupportConfigurationProperties
import com.netflix.spinnaker.clouddriver.eureka.provider.EurekaCachingProvider
import com.netflix.spinnaker.clouddriver.eureka.provider.agent.EurekaAwareProvider
import com.netflix.spinnaker.clouddriver.eureka.provider.agent.EurekaCachingAgent
import com.netflix.spinnaker.clouddriver.eureka.provider.config.EurekaAccountConfigurationProperties
import com.netflix.spinnaker.okhttp.OkHttpClientConfigurationProperties
import com.netflix.spinnaker.okhttp.OkHttpMetricsInterceptor
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.context.properties.bind.Bindable
import org.springframework.boot.context.properties.bind.Binder
import org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver
import org.springframework.boot.context.properties.source.ConfigurationPropertyName
import org.springframework.boot.context.properties.source.ConfigurationPropertySources
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.core.convert.ConversionService
import org.springframework.core.env.ConfigurableEnvironment
import retrofit.converter.Converter
import retrofit.converter.JacksonConverter

import java.util.regex.Pattern

@Configuration
@EnableConfigurationProperties(EurekaSupportConfigurationProperties)
@ConditionalOnProperty('eureka.provider.enabled')
@ComponentScan(["com.netflix.spinnaker.clouddriver.eureka"])
class EurekaProviderConfiguration {

  @Autowired
  Registry registry

  @Autowired
  ConversionService conversionService

  @Autowired
  ConfigurableEnvironment environment

  @Bean
  @ConfigurationProperties("eureka.provider")
  EurekaAccountConfigurationProperties eurekaConfigurationProperties() {
    new EurekaAccountConfigurationProperties()
  }

  private OkHttpClientConfigurationProperties eurekaClientConfig() {
    Binder binder = new Binder(
      ConfigurationPropertySources.from(environment.propertySources),
      new PropertySourcesPlaceholdersResolver(environment),
      conversionService)

    OkHttpClientConfigurationProperties properties =
      new OkHttpClientConfigurationProperties(
        propagateSpinnakerHeaders: false,
        connectTimoutMs: 10000,
        keyStore: null,
        trustStore: null)
    binder.bind(
      ConfigurationPropertyName.of("eureka.readonly.ok-http-client"),
      Bindable.ofInstance(properties))
    return properties
  }

  private OkHttpClientConfiguration eurekaOkHttpClientConfig() {
    new OkHttpClientConfiguration(eurekaClientConfig(), new OkHttpMetricsInterceptor(registry, true))
  }

  private static Converter eurekaConverter() {
    new JacksonConverter(new ObjectMapper()
      .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
      .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
      .enable(DeserializationFeature.UNWRAP_ROOT_VALUE)<commit_msg>fix(config): Fix OkHttpClientConfiguration instantiation (#4395)<commit_after>/*
 * Copyright 2016 Google, Inc.
 *
 * 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 com.netflix.spinnaker.config

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.MapperFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spectator.api.Registry
import com.netflix.spinnaker.clouddriver.eureka.api.EurekaApiFactory
import com.netflix.spinnaker.clouddriver.eureka.deploy.ops.EurekaSupportConfigurationProperties
import com.netflix.spinnaker.clouddriver.eureka.provider.EurekaCachingProvider
import com.netflix.spinnaker.clouddriver.eureka.provider.agent.EurekaAwareProvider
import com.netflix.spinnaker.clouddriver.eureka.provider.agent.EurekaCachingAgent
import com.netflix.spinnaker.clouddriver.eureka.provider.config.EurekaAccountConfigurationProperties
import com.netflix.spinnaker.okhttp.OkHttpClientConfigurationProperties
import com.netflix.spinnaker.okhttp.OkHttpMetricsInterceptor
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.context.properties.bind.Bindable
import org.springframework.boot.context.properties.bind.Binder
import org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver
import org.springframework.boot.context.properties.source.ConfigurationPropertyName
import org.springframework.boot.context.properties.source.ConfigurationPropertySources
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.core.convert.ConversionService
import org.springframework.core.env.ConfigurableEnvironment
import retrofit.converter.Converter
import retrofit.converter.JacksonConverter

import java.util.regex.Pattern

@Configuration
@EnableConfigurationProperties(EurekaSupportConfigurationProperties)
@ConditionalOnProperty('eureka.provider.enabled')
@ComponentScan(["com.netflix.spinnaker.clouddriver.eureka"])
class EurekaProviderConfiguration {

  @Autowired
  Registry registry

  @Autowired
  ConversionService conversionService

  @Autowired
  ConfigurableEnvironment environment

  @Bean
  @ConfigurationProperties("eureka.provider")
  EurekaAccountConfigurationProperties eurekaConfigurationProperties() {
    new EurekaAccountConfigurationProperties()
  }

  private OkHttpClientConfigurationProperties eurekaClientConfig() {
    Binder binder = new Binder(
      ConfigurationPropertySources.from(environment.propertySources),
      new PropertySourcesPlaceholdersResolver(environment),
      conversionService)

    OkHttpClientConfigurationProperties properties =
      new OkHttpClientConfigurationProperties(
        propagateSpinnakerHeaders: false,
        connectTimoutMs: 10000,
        keyStore: null,
        trustStore: null)
    binder.bind(
      ConfigurationPropertyName.of("eureka.readonly.ok-http-client"),
      Bindable.ofInstance(properties))
    return properties
  }

  private OkHttpClientConfiguration eurekaOkHttpClientConfig() {
    new OkHttpClientConfiguration(eurekaClientConfig(), new OkHttpMetricsInterceptor({ registry }, true))
  }

  private static Converter eurekaConverter() {
    new JacksonConverter(new ObjectMapper()
      .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
      .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
      .enable(DeserializationFeature.UNWRAP_ROOT_VALUE)
{'fraction_non_alphanumeric': 0.07137064071370641, 'fraction_numerical': 0.003475842891901286, 'mean_word_length': 6.235540653813914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '2021229', 'n_tokens_mistral': 2270, 'n_tokens_neox': 2206, 'n_words': 428}