Commit e74e4078 authored by Kostis Trantzas's avatar Kostis Trantzas
Browse files

Reinforce error handling of secrets client

parent 32841130
Loading
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -7,10 +7,16 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


@Service
@ConditionalOnExpression("${SECRETS_CONTROLLER_ENABLE:false}")
public class SecretsClient {

	private static final transient Log logger = LogFactory.getLog( SecretsClient.class.getName() );

	private final ProducerTemplate producerTemplate;

	private final String unsealSecretQueue;
@@ -31,14 +37,24 @@ public class SecretsClient {
			final var cmd = new UnsealCharacteristicCommand(uri, characteristic);
			final var payload = this.mapper.writeValueAsString(cmd);
			final var responseRaw = this.producerTemplate.requestBody(this.unsealSecretQueue, payload, String.class);
			
			if (responseRaw == null || responseRaw.isEmpty()) {
				return uri;
			}
			
			final var response = this.mapper.readValue(responseRaw, String.class);

			if (response == null)
				return "";
			if (response == null || response.isEmpty()) {
				return uri;
			}

			return response;
		} catch (JsonProcessingException e) {
			throw new RuntimeException(e);
		} catch (Exception e) {
			// controller is enabled by the request failed (no route, timeout, broker down)
			logger.warn("Secrets controller did not respond for " + uri, e);
			return uri;
		}
	}