-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEnvUtils.java
More file actions
67 lines (62 loc) · 2.45 KB
/
Copy pathEnvUtils.java
File metadata and controls
67 lines (62 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright © 2026 DataSQRL (contact@datasqrl.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.datasqrl.flinkrunner.utils;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/** Utility class for environment variable operations. */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class EnvUtils {
/**
* Returns a map of environment variables with deployment-specific defaults.
*
* <p>This method creates a copy of the current system environment variables and adds default
* values for the following variables if they are not already set:
*
* <ul>
* <li>{@code DEPLOYMENT_ID} - A unique identifier for the deployment (random UUID)
* <li>{@code DEPLOYMENT_TIMESTAMP} - The deployment timestamp in milliseconds since epoch
* </ul>
*
* @return an immutable map containing all environment variables with defaults applied
*/
public static Map<String, String> getEnvWithDeploymentDefaults() {
return addDeploymentDefaults(System.getenv());
}
/**
* Returns a copy of the supplied environment variables with deployment-specific defaults added.
*
* <p>Deployment defaults are only added when the supplied map does not already contain those
* keys. Existing values are preserved.
*
* @param envVars environment variables to augment with deployment defaults
* @return an immutable map containing the supplied variables plus any missing deployment defaults
*/
public static Map<String, String> addDeploymentDefaults(Map<String, String> envVars) {
var env = new HashMap<>(envVars);
getDeploymentDefaults().forEach(env::putIfAbsent);
return Map.copyOf(env);
}
public static Map<String, String> getDeploymentDefaults() {
return Map.of(
"DEPLOYMENT_ID",
UUID.randomUUID().toString(),
"DEPLOYMENT_TIMESTAMP",
String.valueOf(System.currentTimeMillis()));
}
}