-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCredentials.java
More file actions
73 lines (61 loc) · 2.37 KB
/
Credentials.java
File metadata and controls
73 lines (61 loc) · 2.37 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
68
69
70
71
72
73
package com.contentstack.sdk;
import java.rmi.AccessException;
import java.util.Arrays;
import io.github.cdimascio.dotenv.Dotenv;
public class Credentials {
static Dotenv env = getEnv();
private static String envChecker() {
String githubActions = System.getenv("GITHUB_ACTIONS");
if (githubActions != null && githubActions.equals("true")) {
return "GitHub";
} else {
return "local";
}
}
public static Dotenv getEnv() {
env = Dotenv.configure()
.directory("src/test/resources")
.filename("env") // instead of '.env', use 'env'
.load();
return Dotenv.load();
}
public static final String HOST = env.get("HOST", "cdn.contentstack.io");
public static final String API_KEY = env.get("API_KEY", "");
public static final String DELIVERY_TOKEN = env.get("DELIVERY_TOKEN", "");
public static final String ENVIRONMENT = env.get("ENVIRONMENT", "env1");
public static final String CONTENT_TYPE = env.get("contentType", "product");
public static final String ENTRY_UID = env.get("assetUid", "");
public static final String VARIANT_UID = env.get("variantUid", "");
public final static String[] VARIANTS_UID;
static {
String variantsUidString = env.get("variantsUid");
if (variantsUidString != null && !variantsUidString.trim().isEmpty()) {
VARIANTS_UID = Arrays.stream(variantsUidString.split(","))
.map(String::trim)
.toArray(String[]::new);
} else {
VARIANTS_UID = new String[] {};
}
}
private static volatile Stack stack;
private Credentials() throws AccessException {
throw new AccessException("Can not access");
}
public static Stack getStack() {
if (stack == null) {
envChecker();
synchronized (Credentials.class) {
if (stack == null) {
try {
Config config = new Config();
config.setHost(HOST);
stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENVIRONMENT, config);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
}
return stack;
}
}