blob: 4d31308d947f27f23ecc2a8f984fbdf7527eb9ee (
plain)
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
|
package moe.ymc.acron.config.json;
import com.google.gson.annotations.SerializedName;
import moe.ymc.acron.auth.Action;
import org.jetbrains.annotations.NotNull;
import java.util.List;
class Client implements ConfigJsonObject<moe.ymc.acron.auth.Client> {
@SerializedName("id")
private final String id;
@SerializedName("token")
private final String token;
@SerializedName("policy_mode")
private final Action policyMode;
@SerializedName("rules")
private final List<Rule> rules;
private Client(String id,
String token,
Action policyMode,
List<Rule> rules) {
this.id = id;
this.token = token;
this.policyMode = policyMode;
this.rules = rules;
}
@Override
public @NotNull moe.ymc.acron.auth.Client create(boolean startup) throws ConfigDeserializationException {
if (id == null || id.trim().equals("") ||
token == null || token.trim().equals("")) {
throw new ConfigDeserializationException(".clients[].id or .clients[].token is not supplied.");
}
return new moe.ymc.acron.auth.Client(id,
token,
policyMode == null ? Action.DENY : policyMode,
rules == null ? new moe.ymc.acron.auth.Rule[]{} :
rules.stream().map(rule -> rule.create(startup)).toList()
.toArray(new moe.ymc.acron.auth.Rule[rules.size()]));
}
}
|