Skip to content

Commit

Permalink
Make s2s api without feign decoder (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmendrak authored Dec 15, 2017
1 parent c56012c commit 045f901
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group 'uk.gov.hmcts.reform'
version '0.0.7'
version '0.0.8'

checkstyle {
maxWarnings = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
package uk.gov.hmcts.reform.authorisation;

import feign.codec.Decoder;
import feign.jackson.JacksonDecoder;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import uk.gov.hmcts.reform.authorisation.healthcheck.InternalHealth;

import static org.springframework.http.HttpHeaders.AUTHORIZATION;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;

@FeignClient(name = "idam-s2s-auth", url = "${idam.s2s-auth.url}",
configuration = ServiceAuthorisationApi.ServiceAuthConfiguration.class)
@FeignClient(name = "idam-s2s-auth", url = "${idam.s2s-auth.url}")
public interface ServiceAuthorisationApi {
@PostMapping(value = "/lease")
String serviceToken(@RequestParam("microservice") final String microservice,
Expand All @@ -28,21 +17,4 @@ String serviceToken(@RequestParam("microservice") final String microservice,
@GetMapping(value = "/authorisation-check")
void authorise(@RequestHeader(AUTHORIZATION) final String authHeader,
@RequestParam("role") final String[] roles);

@RequestMapping(
method = RequestMethod.GET,
value = "/health",
headers = CONTENT_TYPE + "=" + APPLICATION_JSON_UTF8_VALUE
)
InternalHealth health();


class ServiceAuthConfiguration {
@Bean
@Primary
@Scope("prototype")
Decoder feignDecoder() {
return new JacksonDecoder();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package uk.gov.hmcts.reform.authorisation;

import feign.codec.Decoder;
import feign.jackson.JacksonDecoder;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import uk.gov.hmcts.reform.authorisation.healthcheck.InternalHealth;

import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;

@FeignClient(name = "idam-s2s-auth-health", url = "${idam.s2s-auth.url}",
configuration = ServiceAuthorisationHealthApi.ServiceAuthConfiguration.class)
public interface ServiceAuthorisationHealthApi {

@RequestMapping(
method = RequestMethod.GET,
value = "/health",
headers = CONTENT_TYPE + "=" + APPLICATION_JSON_UTF8_VALUE
)
InternalHealth health();

class ServiceAuthConfiguration {
@Bean
@Primary
@Scope("prototype")
Decoder feignDecoder() {
return new JacksonDecoder();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.authorisation.ServiceAuthorisationApi;
import uk.gov.hmcts.reform.authorisation.ServiceAuthorisationHealthApi;

@Component
public class ServiceAuthHealthIndicator implements HealthIndicator {

private static final Logger LOGGER = LoggerFactory.getLogger(ServiceAuthHealthIndicator.class);

private final ServiceAuthorisationApi serviceAuthorisationApi;
private final ServiceAuthorisationHealthApi serviceAuthorisationHealthApi;

@Autowired
public ServiceAuthHealthIndicator(final ServiceAuthorisationApi serviceAuthorisationApi) {
this.serviceAuthorisationApi = serviceAuthorisationApi;
public ServiceAuthHealthIndicator(final ServiceAuthorisationHealthApi serviceAuthorisationHealthApi) {
this.serviceAuthorisationHealthApi = serviceAuthorisationHealthApi;
}

@Override
public Health health() {
try {
InternalHealth internalHealth = this.serviceAuthorisationApi.health();
InternalHealth internalHealth = this.serviceAuthorisationHealthApi.health();
return new Health.Builder(internalHealth.getStatus()).build();
} catch (Exception ex) {
LOGGER.error("Error on service auth healthcheck", ex);
Expand Down

0 comments on commit 045f901

Please sign in to comment.