Skip to content
Snippets Groups Projects
Commit 8bba0e0e authored by Martin Vogel's avatar Martin Vogel
Browse files

#414 Use HOCON notation for app config

parent 6031df20
No related branches found
No related tags found
2 merge requests!2#414 Remaining changes from MR,!1planning#414 Methoden Signaturen (Zwischenstand)
package de.fitko.fitconnect.dependency;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.List;
import java.util.Properties;
@Getter
@Setter
@ToString
public class ApplicationConfig {
private String httpProxyHost;
private String httpProxyPort;
private String authTokenUrl;
private List<String> apiUrls;
private String clientId;
private String clientSecret;
public Properties getAsProperties() {
var props = new Properties();
props.put("httpProxyHost", getHttpProxyHost());
props.put("httpProxyPort", getHttpProxyPort());
props.put("authTokenUrl", getAuthTokenUrl());
props.put("apiUrls", String.join(",",getApiUrls()));
props.put("clientId", clientId);
props.put("clientSecret", clientSecret);
return props;
}
}
...@@ -5,6 +5,9 @@ import com.google.inject.Provides; ...@@ -5,6 +5,9 @@ import com.google.inject.Provides;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.google.inject.name.Named; import com.google.inject.name.Named;
import com.google.inject.name.Names; import com.google.inject.name.Names;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigBeanFactory;
import com.typesafe.config.ConfigFactory;
import de.fitko.fitconnect.api.services.Sender; import de.fitko.fitconnect.api.services.Sender;
import de.fitko.fitconnect.api.services.Subscriber; import de.fitko.fitconnect.api.services.Subscriber;
import de.fitko.fitconnect.api.services.auth.OAuthService; import de.fitko.fitconnect.api.services.auth.OAuthService;
...@@ -24,15 +27,12 @@ import org.slf4j.Logger; ...@@ -24,15 +27,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.io.FileInputStream; import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class SdkModule extends AbstractModule { public class SdkModule extends AbstractModule {
private static final Logger logger = LoggerFactory.getLogger(SdkModule.class); private static final Logger logger = LoggerFactory.getLogger(SdkModule.class);
public static final String CONFIG_PATH = "sdk-config/sdk.properties"; public static final String CONFIG_NAME = "sdk.conf";
@Override @Override
protected void configure() { protected void configure() {
...@@ -43,16 +43,12 @@ public class SdkModule extends AbstractModule { ...@@ -43,16 +43,12 @@ public class SdkModule extends AbstractModule {
bind(CertificateValidator.class).to(KeyValidator.class); bind(CertificateValidator.class).to(KeyValidator.class);
bind(MetadataValidator.class).to(MetadataSubmissionValidator.class); bind(MetadataValidator.class).to(MetadataSubmissionValidator.class);
bind(MetadataService.class).to(MetadataUploadService.class); bind(MetadataService.class).to(MetadataUploadService.class);
bind(OAuthService.class).to(DefaultOAuthService.class);
bind(Sender.class).to(SubmissionSender.class); bind(Sender.class).to(SubmissionSender.class);
bind(Subscriber.class).to(SubmissionSubscriber.class); bind(Subscriber.class).to(SubmissionSubscriber.class);
} }
@Provides
OAuthService provideOAuthService(@Named("authTokenUrl") String tokenUrl, RestTemplate restTemplate) {
return new DefaultOAuthService(restTemplate, tokenUrl);
}
@Provides @Provides
@Singleton @Singleton
RestTemplate provideRestTemplate(@Named("httpProxyHost") String proxyHost, @Named("httpProxyPort") int proxyPort) { RestTemplate provideRestTemplate(@Named("httpProxyHost") String proxyHost, @Named("httpProxyPort") int proxyPort) {
...@@ -60,13 +56,9 @@ public class SdkModule extends AbstractModule { ...@@ -60,13 +56,9 @@ public class SdkModule extends AbstractModule {
} }
private void bindConfigProperties() { private void bindConfigProperties() {
try (InputStream in = new FileInputStream(CONFIG_PATH)) { final Config conf = ConfigFactory.load( ConfigFactory.parseFile(new File(CONFIG_NAME))).getConfig("sdk");
final Properties properties = new Properties(); final ApplicationConfig appConfig = ConfigBeanFactory.create(conf, ApplicationConfig.class);
properties.load(in); Names.bindProperties(binder(), appConfig.getAsProperties());
Names.bindProperties(binder(), properties); logger.info("using sdk config: {}", appConfig);
logger.info("using sdk config: {}", properties);
} catch (IOException e) {
logger.error("could not read sdk properties", e);
}
} }
} }
authTokenUrl=https://auth-testing.fit-connect.fitko.dev/token
httpProxyHost=
httpProxyPort=0
\ No newline at end of file
sdk.conf 0 → 100644
# SKD application properties and global configurations
sdk {
clientId: "781f6213-0f0f-4a79-9372-e7187ffda98b"
clientSecret: "PnzR8Vbmhpv_VwTkT34wponqXWK8WBm-LADlryYdV4o"
httpProxyHost: ""
httpProxyPort: "0"
apiUrls: ["http://test.url1", "http://test.url2", "http://test.url3"]
authTokenUrl: "https://auth-testing.fit-connect.fitko.dev/token"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment