Use non-root user to access DES database and
[dcaegen2/services.git] / components / datalake-handler / des / src / main / java / org / onap / datalake / des / DesApplication.java
index 7689b27..4ed5d99 100644 (file)
@@ -3,6 +3,7 @@
 * ONAP : Data Extraction Service
 * ================================================================================
 * Copyright 2020 China Mobile
+* Copyright (C) 2021 Wipro Limited
 *=================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 
 package org.onap.datalake.des;
 
+import javax.sql.DataSource;
+
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.jdbc.DataSourceBuilder;
+import org.springframework.context.annotation.Bean;
 
 import springfox.documentation.swagger2.annotations.EnableSwagger2;
 
@@ -40,4 +45,12 @@ public class DesApplication {
         SpringApplication.run(DesApplication.class, args);
     }
 
+    @Bean
+    public DataSource dataSource() {
+
+        String url = "jdbc:postgresql://" + System.getenv("PG_HOST").trim() + ":" + System.getenv("PG_PORT").trim() + "/datalake";
+        return DataSourceBuilder.create().url(url).username(System.getenv("PG_USER").trim())
+                .password(System.getenv("PG_PASSWORD").trim()).build();
+    }
+
 }