davsclaus commented on code in PR #15063:
URL: https://github.com/apache/camel/pull/15063#discussion_r1711193275


##########
core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java:
##########
@@ -415,6 +421,15 @@ protected void configurePropertiesService(CamelContext 
camelContext) throws Exce
         if (op != null) {
             pc.setOverrideProperties(op);
         }
+
+        Optional<String> cloudLocations = 
pc.resolveProperty(MainConstants.CLOUD_PROPERTIES_LOCATION);
+        if (cloudLocations.isPresent()) {
+            LOG.info("Cloud properties location: {}", cloudLocations);
+            final Properties kp = tryLoadCloudProperties(op, 
cloudLocations.get());
+            if (kp != null) {
+                pc.setOverrideProperties(kp);

Review Comment:
   There is some code above that also set some OverrideProperties - so you 
would override what may have been added before. So I think you need to check if 
something exists, and then putAll in that case.



##########
core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java:
##########
@@ -2727,4 +2728,16 @@ public T withStartupRecorderDir(String 
startupRecorderDir) {
         return (T) this;
     }
 
+    public String getCloudPropertiesLocation() {
+        return cloudPropertiesLocation;
+    }
+
+    /**
+     * Sets the locations (comma separated values) where to find properties 
configuration as defined for cloud native
+     * environments such as Kubernetes.
+     */
+    public void setCloudPropertiesLocation(String cloudPropertiesLocation) {
+        this.cloudPropertiesLocation = cloudPropertiesLocation;
+    }
+

Review Comment:
   You should also add the `withXXX` method for this new option.



##########
core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java:
##########
@@ -433,6 +448,43 @@ private Properties tryLoadProperties(
         return ip;
     }
 
+    private static Properties tryLoadCloudProperties(
+            Properties overridProperties, String cloudPropertiesLocations)
+            throws IOException {
+
+        final Properties cp = new Properties();
+        try {
+            String[] locations = cloudPropertiesLocations.split(",");
+            for (String loc : locations) {
+                Path confPath = Paths.get(loc);
+                if (Files.exists(confPath) && Files.isDirectory(confPath)) {
+                    Files.walkFileTree(confPath, new SimpleFileVisitor<Path>() 
{
+                        @Override
+                        public FileVisitResult visitFile(Path file, 
BasicFileAttributes attrs) {
+                            if (!Files.isDirectory(file)) {
+                                try {
+                                    String val = new 
String(Files.readAllBytes(file));
+                                    cp.put(file.getFileName().toString(), val);
+                                } catch (IOException e) {
+                                    // Do nothing or should we throw a 
RuntimeException?
+                                }
+                            }
+                            return FileVisitResult.CONTINUE;
+                        }
+                    });
+                }
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        if (overridProperties == null) {
+            return cp;
+        }
+        Properties mergedProperties = new Properties(overridProperties);

Review Comment:
   Camel has a Location based properties so we know where they are from that we 
use for reporting to users. See `OrderedLocationProperties`



##########
core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java:
##########
@@ -433,6 +448,43 @@ private Properties tryLoadProperties(
         return ip;
     }
 
+    private static Properties tryLoadCloudProperties(
+            Properties overridProperties, String cloudPropertiesLocations)
+            throws IOException {
+
+        final Properties cp = new Properties();
+        try {
+            String[] locations = cloudPropertiesLocations.split(",");
+            for (String loc : locations) {
+                Path confPath = Paths.get(loc);
+                if (Files.exists(confPath) && Files.isDirectory(confPath)) {
+                    Files.walkFileTree(confPath, new SimpleFileVisitor<Path>() 
{
+                        @Override
+                        public FileVisitResult visitFile(Path file, 
BasicFileAttributes attrs) {
+                            if (!Files.isDirectory(file)) {
+                                try {
+                                    String val = new 
String(Files.readAllBytes(file));
+                                    cp.put(file.getFileName().toString(), val);
+                                } catch (IOException e) {
+                                    // Do nothing or should we throw a 
RuntimeException?

Review Comment:
   Yeah I am not sure if its possible to know if its binary vs text (I guess 
there is no good naming convention).
   
   Also I wonder if they file name should have extension stripped as they key 
should be without the extension should it not? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to