package org.zalando.stups.tokens.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.zalando.stups.tokens.AccessTokensBean;
import org.zalando.stups.tokens.Secrets;

/**
 * 
 * @author jbellmann
 *
 */
@Configuration
@ConditionalOnProperty(prefix = "k8s", name = "enabled", havingValue = "true")
public class SecretsAutoConfiguration {

    @Bean
    public Secrets secrets(AccessTokensBean accessTokensBean) {
        return (Secrets) accessTokensBean.getDelegate();
    }

}

@@ -35,16 +35,65 @@
 onfig;%0A%0A
+import static java.util.Objects.requireNonNull;%0A%0A
 import o
@@ -163,16 +163,16 @@
 operty;%0A
-
 import o
@@ -322,24 +322,115 @@
 TokensBean;%0A
+import org.zalando.stups.tokens.ClientCredentials;%0Aimport org.zalando.stups.tokens.Secret;%0A
 import org.z
@@ -719,16 +719,35 @@
  return 
+new SecretsAdapter(
 (Secrets
@@ -778,17 +778,542 @@
 legate()
-;
+);%0A    %7D%0A%0A    static class SecretsAdapter implements Secrets %7B%0A%0A        private Secrets delegate;%0A%0A        SecretsAdapter(Secrets delegate) %7B%0A            this.delegate = requireNonNull(delegate, %22'secrets'-delegate should never be null%22);%0A        %7D%0A%0A        @Override%0A        public Secret getSecret(String identifier) %7B%0A            return delegate.getSecret(identifier);%0A        %7D%0A%0A        @Override%0A        public ClientCredentials getClient(String identifier) %7B%0A            return delegate.getClient(identifier);%0A        %7D%0A
 %0A    %7D%0A%0A

fix multiple 'AccessTokens'-instances