blob: 0ab8ad47e0fedd8786589a416a35775a18d1f00a (
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
56
57
58
59
60
61
62
63
64
65
66
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.athenz.api;
import com.yahoo.vespa.athenz.utils.AthenzIdentities;
import java.util.Objects;
/**
* @author bjorncs
*/
public class AthenzService implements AthenzIdentity {
private final AthenzDomain domain;
private final String serviceName;
public AthenzService(AthenzDomain domain, String serviceName) {
this.domain = domain;
this.serviceName = serviceName;
}
public AthenzService(String domain, String serviceName) {
this(new AthenzDomain(domain), serviceName);
}
public AthenzService(String fullName) {
AthenzIdentity identity = AthenzIdentities.from(fullName);
if ( ! (identity instanceof AthenzService service)) {
throw new IllegalArgumentException(String.format("'%s' is not an Athenz service", fullName));
}
this.domain = service.domain;
this.serviceName = service.serviceName;
}
public AthenzResourceName toResourceName() {
return new AthenzResourceName(domain, "service." + serviceName);
}
@Override
public AthenzDomain getDomain() {
return domain;
}
@Override
public String getName() {
return serviceName;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AthenzService that = (AthenzService) o;
return Objects.equals(domain, that.domain) &&
Objects.equals(serviceName, that.serviceName);
}
@Override
public int hashCode() {
return Objects.hash(domain, serviceName);
}
@Override
public String toString() {
return String.format("AthenzService(%s)", getFullName());
}
}
|