aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/client/zms/bindings/RoleEntity.java
blob: bbdbcbd47d8f95134ce6e9299c318b9f3f020890 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

package com.yahoo.vespa.athenz.client.zms.bindings;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @author mortent
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class RoleEntity {
    private final String roleName;
    private final List<Member> roleMembers;
    private final Boolean selfServe;
    private final Boolean reviewEnabled;
    private final List<AuditLogEntry> auditLog;

    @JsonCreator
    public RoleEntity(@JsonProperty("name") String roleName,
                      @JsonProperty("roleMembers") List<Member> roleMembers,
                      @JsonProperty("selfServe") Boolean selfServe,
                      @JsonProperty("reviewEnabled") Boolean reviewEnabled,
                      @JsonProperty("auditLog") List<AuditLogEntry> auditLog) {
        this.roleName = roleName;
        this.roleMembers = Optional.ofNullable(roleMembers).orElse(new ArrayList<>());
        this.selfServe = Optional.ofNullable(selfServe).orElse(false);
        this.reviewEnabled = Optional.ofNullable(reviewEnabled).orElse(false);
        this.auditLog = Optional.ofNullable(auditLog).orElse(new ArrayList<>());;
    }

    public String roleName() {
        return roleName;
    }

    public List<Member> roleMembers() {
        return roleMembers;
    }

    public Boolean selfServe() {
        return selfServe;
    }

    public Boolean reviewEnabled() {
        return reviewEnabled;
    }

    public List<AuditLogEntry> auditLog() {
        return auditLog;
    }

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static final class Member {
        private final String memberName;
        private final boolean active;
        private final boolean approved;
        private final String auditRef;
        private final String requestTime;

        @JsonCreator
        public Member(@JsonProperty("memberName") String memberName,
                      @JsonProperty("active") boolean active,
                      @JsonProperty("approved") boolean approved,
                      @JsonProperty("auditRef") String auditRef,
                      @JsonProperty("requestTime") String requestTime) {
            this.memberName = memberName;
            this.active = active;
            this.approved = approved;
            this.auditRef = auditRef;
            this.requestTime = requestTime;
        }

        public String memberName() {
            return memberName;
        }

        public boolean pendingApproval() {
            return !approved;
        }

        public String auditRef() {
            return auditRef;
        }

        public String requestTime() {
            return requestTime;
        }

        public boolean active() {
            return active;
        }
    }

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static final class AuditLogEntry {
        private final String member;
        private final String admin;
        private final String action;
        private final String auditRef;
        private final String created;

        @JsonCreator
        public AuditLogEntry(@JsonProperty("member") String member,
                             @JsonProperty("admin") String admin,
                             @JsonProperty("created") String created,
                             @JsonProperty("action") String action,
                             @JsonProperty("auditRef") String auditRef) {
            this.member = member;
            this.admin = admin;
            this.created = created;
            this.action = action;
            this.auditRef = auditRef;
        }

        public String getMember() {
            return member;
        }

        public String getAdmin() {
            return admin;
        }

        public String getAction() {
            return action;
        }

        public String getAuditRef() {
            return auditRef;
        }

        public String getCreated() {
            return created;
        }
    }
}