From 22d8380bce4a18d40b31a10e6a5c3f1a4846cd9a Mon Sep 17 00:00:00 2001 From: Maxime Dor Date: Sun, 17 Sep 2017 02:03:45 +0200 Subject: [PATCH] Configuration management - Default values - Compute values --- .../mxisd/config/rest/RestBackendConfig.java | 32 +++++++++++++------ src/main/resources/application.yaml | 7 ++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/main/groovy/io/kamax/mxisd/config/rest/RestBackendConfig.java b/src/main/groovy/io/kamax/mxisd/config/rest/RestBackendConfig.java index fd56209..d5b7dd9 100644 --- a/src/main/groovy/io/kamax/mxisd/config/rest/RestBackendConfig.java +++ b/src/main/groovy/io/kamax/mxisd/config/rest/RestBackendConfig.java @@ -20,7 +20,6 @@ package io.kamax.mxisd.config.rest; -import com.google.gson.Gson; import io.kamax.mxisd.exception.ConfigurationException; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; @@ -112,14 +111,9 @@ public class RestBackendConfig { this.endpoints = endpoints; } - @PostConstruct - private void postConstruct() { - Gson gson = new Gson(); - log.info("--- REST backend config ---"); - log.info("Enabled: {}", isEnabled()); - - if (isEnabled()) { - if (StringUtils.isBlank(host)) { + private String buildEndpointUrl(String endpoint) { + if (StringUtils.startsWith(endpoint, "/")) { + if (StringUtils.isBlank(getHost())) { throw new ConfigurationException("rest.host"); } @@ -129,8 +123,26 @@ public class RestBackendConfig { throw new ConfigurationException("rest.host", e.getMessage()); } + return getHost() + endpoint; + } else { + return endpoint; + } + } + + @PostConstruct + private void postConstruct() { + log.info("--- REST backend config ---"); + log.info("Enabled: {}", isEnabled()); + + if (isEnabled()) { + endpoints.setAuth(buildEndpointUrl(endpoints.getAuth())); + endpoints.identity.setSingle(buildEndpointUrl(endpoints.identity.getSingle())); + endpoints.identity.setBulk(buildEndpointUrl(endpoints.identity.getBulk())); + log.info("Host: {}", getHost()); - log.info("Endpoints: {}", gson.toJson(endpoints)); + log.info("Auth endpoint: {}", endpoints.getAuth()); + log.info("Identity Single endpoint: {}", endpoints.identity.getSingle()); + log.info("Identity Bulk endpoint: {}", endpoints.identity.getBulk()); } } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 77998c0..f8e5ec0 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -23,6 +23,13 @@ lookup: enabled: false recursiveOnly: true +rest: + endpoints: + auth: "/_mxisd/identity/api/v1/auth" + identity: + single: "/_mxisd/identity/api/v1/lookup/single" + bulk: "/_mxisd/identity/api/v1/lookup/bulk" + ldap: enabled: false connection: