Skip to content

Commit

Permalink
Add optional basic auth support to outgoing rest webhooks. (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Duftler authored Jan 12, 2017
1 parent 4747e75 commit 65158b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.netflix.spinnaker.echo.config

import static retrofit.Endpoints.newFixedEndpoint

import org.apache.commons.codec.binary.Base64
import com.netflix.spinnaker.echo.rest.RestService
import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Value
Expand All @@ -26,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Scope
import retrofit.RequestInterceptor
import retrofit.RestAdapter
import retrofit.RestAdapter.LogLevel
import retrofit.client.Client
Expand Down Expand Up @@ -59,16 +61,28 @@ class RestConfig {

restProperties

restProperties.endpoints.each { endpoint ->
restProperties.endpoints.each { RestProperties.RestEndpointConfiguration endpoint ->
RestAdapter.Builder restAdapterBuilder = new RestAdapter.Builder()
.setEndpoint(newFixedEndpoint(endpoint.url as String))
.setClient(retrofitClient)
.setLogLevel(retrofitLogLevel)
.setConverter(new JacksonConverter())

if (endpoint.username && endpoint.password) {
RequestInterceptor authInterceptor = new RequestInterceptor() {
@Override
public void intercept(RequestInterceptor.RequestFacade request) {
String auth = "Basic " + Base64.encodeBase64String("${endpoint.username}:${endpoint.password}".getBytes())
request.addHeader("Authorization", auth)
}
}

restAdapterBuilder.setRequestInterceptor(authInterceptor)
}

restUrls.services.add(
[
client: new RestAdapter.Builder()
.setEndpoint(newFixedEndpoint(endpoint.url as String))
.setClient(retrofitClient)
.setLogLevel(retrofitLogLevel)
.setConverter(new JacksonConverter())
.build()
.create(RestService),
client: restAdapterBuilder.build().create(RestService),
config: endpoint
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class RestProperties {
Boolean wrap = false
@NotEmpty
String url
String username
String password
Boolean flatten = false

}
Expand Down

0 comments on commit 65158b2

Please sign in to comment.