blob: 0ca1b3e5603aa61ef8c6701b0ace8ea3a1aabc4c (
plain) (
blame)
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
|
package ai.vespa.hosted.api;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.Environment;
import com.yahoo.config.provision.RegionName;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
/**
* Utilities and common definitions of system properties defining a Vespa application project.
*
* @author jonmv
*/
public class Properties {
public static ApplicationId application() {
return ApplicationId.from(requireNonBlankProperty("tenant"),
requireNonBlankProperty("application"),
getNonBlankProperty("instance").orElse("default"));
}
public static Optional<Environment> environment() {
return getNonBlankProperty("environment").map(Environment::from);
}
public static Optional<RegionName> region() {
return getNonBlankProperty("region").map(RegionName::from);
}
public static URI endpoint() {
return URI.create(requireNonBlankProperty("endpoint"));
}
public static Path privateKeyFile() {
return Paths.get(requireNonBlankProperty("privateKeyFile"));
}
public static Optional<Path> certificateFile() {
return getNonBlankProperty("certificateFile").map(Paths::get);
}
/** Returns the system property with the given name if it is set, or empty. */
public static Optional<String> getNonBlankProperty(String name) {
return Optional.ofNullable(System.getProperty(name)).filter(value -> ! value.isBlank());
}
/** Returns the system property with the given name if it is set, or throws. */
public static String requireNonBlankProperty(String name) {
return getNonBlankProperty(name).orElseThrow(() -> new IllegalStateException("Missing required property '" + name + "'"));
}
}
|