com.netflix.spinnaker.retrofit.Slf4jRetrofitLogger Java Examples

The following examples show how to use com.netflix.spinnaker.retrofit.Slf4jRetrofitLogger. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatadogSecretsDoNotLeakWhenApiCalledFunctionalTest.java    From kayenta with Apache License 2.0 6 votes vote down vote up
@Before
public void before() {
  listAppender = new ListAppender<>();
  Logger mockLogger =
      (Logger) LoggerFactory.getLogger("DatadogSecretsDoNotLeakWhenApiCalledFunctionalTest");
  mockLogger.addAppender(listAppender);
  listAppender.start();

  RetrofitClientFactory retrofitClientFactory = new RetrofitClientFactory();
  retrofitClientFactory.retrofitLogLevel = "BASIC";
  retrofitClientFactory.createRetrofitLogger =
      (type) -> {
        return new Slf4jRetrofitLogger(mockLogger);
      };

  objectMapper = new ObjectMapper();
  datadogRemoteService =
      DatadogConfiguration.createDatadogRemoteService(
          retrofitClientFactory,
          objectMapper,
          new RemoteService().setBaseUrl("http://localhost:" + mockServerRule.getPort()),
          new OkHttpClient());
}
 
Example #2
Source File: FiatAuthenticationConfig.java    From fiat with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean(FiatService.class) // Allows for override
public FiatService fiatService(
    FiatClientConfigurationProperties fiatConfigurationProperties,
    SpinnakerRequestInterceptor interceptor,
    OkHttpClientProvider okHttpClientProvider) {
  // New role providers break deserialization if this is not enabled.
  val objectMapper = new ObjectMapper();
  objectMapper.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL);
  objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

  OkHttpClient okHttpClient =
      okHttpClientProvider.getClient(
          new DefaultServiceEndpoint("fiat", fiatConfigurationProperties.getBaseUrl()));

  return new RestAdapter.Builder()
      .setEndpoint(Endpoints.newFixedEndpoint(fiatConfigurationProperties.getBaseUrl()))
      .setRequestInterceptor(interceptor)
      .setClient(new Ok3Client(okHttpClient))
      .setConverter(new JacksonConverter(objectMapper))
      .setLogLevel(retrofitLogLevel)
      .setLog(new Slf4jRetrofitLogger(FiatService.class))
      .build()
      .create(FiatService.class);
}
 
Example #3
Source File: IgorConfig.java    From echo with Apache License 2.0 6 votes vote down vote up
@Bean
public IgorService igorService(
    Endpoint igorEndpoint,
    OkHttpClientProvider clientProvider,
    LogLevel retrofitLogLevel,
    SpinnakerRequestInterceptor spinnakerRequestInterceptor) {
  log.info("igor service loaded");
  return new Builder()
      .setEndpoint(igorEndpoint)
      .setConverter(new JacksonConverter())
      .setClient(
          new Ok3Client(
              clientProvider.getClient(
                  new DefaultServiceEndpoint("igor", igorEndpoint.getUrl()))))
      .setRequestInterceptor(spinnakerRequestInterceptor)
      .setLogLevel(retrofitLogLevel)
      .setLog(new Slf4jRetrofitLogger(IgorService.class))
      .build()
      .create(IgorService.class);
}
 
Example #4
Source File: GithubConfig.java    From echo with Apache License 2.0 6 votes vote down vote up
@Bean
public GithubService githubService(
    Endpoint githubEndpoint, Client retrofitClient, RestAdapter.LogLevel retrofitLogLevel) {
  log.info("Github service loaded");

  GithubService githubClient =
      new RestAdapter.Builder()
          .setEndpoint(githubEndpoint)
          .setConverter(new JacksonConverter())
          .setClient(retrofitClient)
          .setLogLevel(RestAdapter.LogLevel.FULL)
          .setLog(new Slf4jRetrofitLogger(GithubService.class))
          .build()
          .create(GithubService.class);

  return githubClient;
}
 
Example #5
Source File: DryRunConfig.java    From echo with Apache License 2.0 6 votes vote down vote up
@Bean
DryRunNotificationAgent dryRunNotificationAgent(
    Front50Service front50,
    OkHttpClientProvider clientProvider,
    RestAdapter.LogLevel retrofitLogLevel,
    Endpoint dryRunEndpoint,
    DryRunProperties properties) {
  log.info("Pipeline dry runs will execute at {}", dryRunEndpoint.getUrl());
  OrcaService orca =
      new RestAdapter.Builder()
          .setEndpoint(dryRunEndpoint)
          .setConverter(new JacksonConverter())
          .setClient(
              new Ok3Client(
                  clientProvider.getClient(
                      new DefaultServiceEndpoint("orca", dryRunEndpoint.getUrl()))))
          .setLogLevel(retrofitLogLevel)
          .setLog(new Slf4jRetrofitLogger(OrcaService.class))
          .build()
          .create(OrcaService.class);
  return new DryRunNotificationAgent(front50, orca, properties);
}
 
Example #6
Source File: Front50Config.java    From echo with Apache License 2.0 6 votes vote down vote up
@Bean
public Front50Service front50Service(
    Endpoint front50Endpoint,
    OkHttpClientProvider clientProvider,
    LogLevel retrofitLogLevel,
    SpinnakerRequestInterceptor spinnakerRequestInterceptor) {
  log.info("front50 service loaded");

  return new Builder()
      .setEndpoint(front50Endpoint)
      .setConverter(new JacksonConverter())
      .setClient(
          new Ok3Client(
              clientProvider.getClient(
                  new DefaultServiceEndpoint("front50", front50Endpoint.getUrl()))))
      .setRequestInterceptor(spinnakerRequestInterceptor)
      .setLogLevel(retrofitLogLevel)
      .setLog(new Slf4jRetrofitLogger(Front50Service.class))
      .build()
      .create(Front50Service.class);
}
 
Example #7
Source File: RetrofitClientFactory.java    From kayenta with Apache License 2.0 5 votes vote down vote up
public <T> T createClient(
    Class<T> type,
    Converter converter,
    RemoteService remoteService,
    OkHttpClient okHttpClient,
    String username,
    String password,
    String usernamePasswordFile)
    throws IOException {
  String baseUrl = remoteService.getBaseUrl();

  baseUrl = baseUrl.endsWith("/") ? baseUrl.substring(0, baseUrl.length() - 1) : baseUrl;

  Endpoint endpoint = newFixedEndpoint(baseUrl);

  if (!(StringUtils.isEmpty(username)
      && StringUtils.isEmpty(password)
      && StringUtils.isEmpty(usernamePasswordFile))) {
    okHttpClient = createAuthenticatedClient(username, password, usernamePasswordFile);
  }

  Slf4jRetrofitLogger logger = createRetrofitLogger.apply(type);

  return new RestAdapter.Builder()
      .setEndpoint(endpoint)
      .setClient(new OkClient(okHttpClient))
      .setConverter(converter)
      .setLogLevel(RestAdapter.LogLevel.valueOf(retrofitLogLevel))
      .setLog(logger)
      .build()
      .create(type);
}
 
Example #8
Source File: ResourcesConfig.java    From fiat with Apache License 2.0 5 votes vote down vote up
@Bean
Front50Api front50Api() {
  return new RestAdapter.Builder()
      .setEndpoint(Endpoints.newFixedEndpoint(front50Endpoint))
      .setClient(
          new Ok3Client(
              clientProvider.getClient(new DefaultServiceEndpoint("front50", front50Endpoint))))
      .setConverter(new JacksonConverter(objectMapper))
      .setLogLevel(retrofitLogLevel)
      .setLog(new Slf4jRetrofitLogger(Front50Api.class))
      .build()
      .create(Front50Api.class);
}
 
Example #9
Source File: ResourcesConfig.java    From fiat with Apache License 2.0 5 votes vote down vote up
@Bean
ClouddriverApi clouddriverApi() {
  return new RestAdapter.Builder()
      .setEndpoint(Endpoints.newFixedEndpoint(clouddriverEndpoint))
      .setClient(
          new Ok3Client(
              clientProvider.getClient(
                  new DefaultServiceEndpoint("clouddriver", clouddriverEndpoint))))
      .setConverter(new JacksonConverter(objectMapper))
      .setLogLevel(retrofitLogLevel)
      .setLog(new Slf4jRetrofitLogger(ClouddriverApi.class))
      .build()
      .create(ClouddriverApi.class);
}
 
Example #10
Source File: ResourcesConfig.java    From fiat with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnProperty("services.igor.enabled")
IgorApi igorApi(@Value("${services.igor.base-url}") String igorEndpoint) {
  return new RestAdapter.Builder()
      .setEndpoint(Endpoints.newFixedEndpoint(igorEndpoint))
      .setClient(
          new Ok3Client(
              clientProvider.getClient(new DefaultServiceEndpoint("igor", igorEndpoint))))
      .setConverter(new JacksonConverter(objectMapper))
      .setLogLevel(retrofitLogLevel)
      .setLog(new Slf4jRetrofitLogger(IgorApi.class))
      .build()
      .create(IgorApi.class);
}
 
Example #11
Source File: KeelConfig.java    From echo with Apache License 2.0 5 votes vote down vote up
@Bean
public KeelService keelService(
    Endpoint keelEndpoint, OkHttpClientProvider clientProvider, LogLevel retrofitLogLevel) {
  return new RestAdapter.Builder()
      .setEndpoint(keelEndpoint)
      .setConverter(new JacksonConverter())
      .setClient(
          new Ok3Client(
              clientProvider.getClient(
                  new DefaultServiceEndpoint("keel", keelEndpoint.getUrl()))))
      .setLogLevel(retrofitLogLevel)
      .setLog(new Slf4jRetrofitLogger(KeelService.class))
      .build()
      .create(KeelService.class);
}
 
Example #12
Source File: PipelineTriggerConfiguration.java    From echo with Apache License 2.0 5 votes vote down vote up
private <T> T bindRetrofitService(final Class<T> type, final String endpoint) {
  log.info("Connecting {} to {}", type.getSimpleName(), endpoint);

  return new RestAdapter.Builder()
      .setClient(
          new Ok3Client(clientProvider.getClient(new DefaultServiceEndpoint("orca", endpoint))))
      .setRequestInterceptor(requestInterceptor)
      .setConverter(new JacksonConverter(EchoObjectMapper.getInstance()))
      .setEndpoint(endpoint)
      .setLogLevel(LogLevel.BASIC)
      .setLog(new Slf4jRetrofitLogger(type))
      .build()
      .create(type);
}
 
Example #13
Source File: JiraConfig.java    From echo with Apache License 2.0 5 votes vote down vote up
@Bean
JiraService jiraService(
    JiraProperties jiraProperties, Client retrofitClient, RestAdapter.LogLevel retrofitLogLevel) {
  if (x509ConfiguredClient != null) {
    LOGGER.info("Using X509 Cert for Jira Client");
    retrofitClient = x509ConfiguredClient;
  }

  RestAdapter.Builder builder =
      new RestAdapter.Builder()
          .setEndpoint(newFixedEndpoint(jiraProperties.getBaseUrl()))
          .setConverter(new JacksonConverter())
          .setClient(retrofitClient)
          .setLogLevel(retrofitLogLevel)
          .setLog(new Slf4jRetrofitLogger(JiraService.class));

  if (x509ConfiguredClient == null) {
    String credentials =
        String.format("%s:%s", jiraProperties.getUsername(), jiraProperties.getPassword());
    final String basic =
        String.format("Basic %s", Base64.encodeBase64String(credentials.getBytes()));
    builder.setRequestInterceptor(
        request -> {
          request.addHeader("Authorization", basic);
          request.addHeader("Accept", "application/json");
        });
  }

  return builder.build().create(JiraService.class);
}
 
Example #14
Source File: PagerDutyConfig.java    From echo with Apache License 2.0 5 votes vote down vote up
@Bean
PagerDutyService pagerDutyService(
    Endpoint pagerDutyEndpoint, Client retrofitClient, RestAdapter.LogLevel retrofitLogLevel) {
  log.info("Pager Duty service loaded");

  return new RestAdapter.Builder()
      .setEndpoint(pagerDutyEndpoint)
      .setConverter(new JacksonConverter())
      .setClient(retrofitClient)
      .setLogLevel(retrofitLogLevel)
      .setLog(new Slf4jRetrofitLogger(PagerDutyService.class))
      .build()
      .create(PagerDutyService.class);
}
 
Example #15
Source File: RestConfig.java    From echo with Apache License 2.0 4 votes vote down vote up
@Bean
RestUrls restServices(
    RestProperties restProperties,
    RestClientFactory clientFactory,
    RestAdapter.LogLevel retrofitLogLevel,
    RequestInterceptorAttacher requestInterceptorAttacher,
    HeadersFromFile headersFromFile) {

  RestUrls restUrls = new RestUrls();

  for (RestProperties.RestEndpointConfiguration endpoint : restProperties.getEndpoints()) {
    RestAdapter.Builder restAdapterBuilder =
        new RestAdapter.Builder()
            .setEndpoint(newFixedEndpoint(endpoint.getUrl()))
            .setClient(clientFactory.getClient(endpoint.insecure))
            .setLogLevel(retrofitLogLevel)
            .setLog(new Slf4jRetrofitLogger(RestService.class))
            .setConverter(new JacksonConverter());

    Map<String, String> headers = new HashMap<>();

    if (endpoint.getUsername() != null && endpoint.getPassword() != null) {
      String basicAuthCreds = endpoint.getUsername() + ":" + endpoint.getPassword();
      String auth = "Basic " + Base64.encodeBase64String(basicAuthCreds.getBytes());
      headers.put("Authorization", auth);
    }

    if (endpoint.getHeaders() != null) {
      headers.putAll(endpoint.headers);
    }

    if (endpoint.getHeadersFile() != null) {
      headers.putAll(headersFromFile.headers(endpoint.getHeadersFile()));
    }

    if (!headers.isEmpty()) {
      RequestInterceptor headerInterceptor = request -> headers.forEach(request::addHeader);
      requestInterceptorAttacher.attach(restAdapterBuilder, headerInterceptor);
    }

    RestUrls.Service service =
        RestUrls.Service.builder()
            .client(restAdapterBuilder.build().create(RestService.class))
            .config(endpoint)
            .build();

    restUrls.getServices().add(service);
  }

  return restUrls;
}