• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

square / keywhiz / 3626523165

pending completion
3626523165

push

github

GitHub
Adding owner support to ClientDAO (#1167)

55 of 55 new or added lines in 3 files covered. (100.0%)

5023 of 6502 relevant lines covered (77.25%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.22
/api/src/main/java/keywhiz/api/model/Client.java
1
/*
2
 * Copyright (C) 2015 Square, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package keywhiz.api.model;
18

19
import com.fasterxml.jackson.annotation.JsonCreator;
20
import com.fasterxml.jackson.annotation.JsonProperty;
21
import com.google.common.base.MoreObjects;
22
import com.google.common.base.Objects;
23
import javax.annotation.Nullable;
24
import keywhiz.api.ApiDate;
25

26
import static com.google.common.base.Preconditions.checkNotNull;
27
import static com.google.common.base.Strings.nullToEmpty;
28

29
/**
30
 * Clients table entry for a client-cert authenticated client.
31
 */
32
public class Client {
33
  private static final String NO_OWNER = null;
1✔
34

35
  @JsonProperty
36
  private final long id;
37

38
  @JsonProperty
39
  private final String name;
40

41
  @JsonProperty
42
  private final String description;
43

44
  /**
45
   * Optional: SPIFFE ID associated with this client.
46
   */
47
  @JsonProperty
48
  private final String spiffeId;
49

50
  @JsonProperty
51
  private final ApiDate createdAt;
52

53
  @JsonProperty
54
  private final String createdBy;
55

56
  @JsonProperty
57
  private final ApiDate updatedAt;
58

59
  @JsonProperty
60
  private final String updatedBy;
61

62
  @JsonProperty
63
  private final ApiDate lastSeen;
64

65
  @JsonProperty
66
  private final ApiDate expiration;
67

68
  /**
69
   * True if client is enabled to retrieve secrets.
70
   */
71
  @JsonProperty
72
  private final boolean enabled;
73

74
  @JsonProperty
75
  private String owner;
76

77
  /**
78
   * True if client is enabled to do automationAllowed tasks.
79
   */
80
  @JsonProperty
81
  private final boolean automationAllowed;
82

83
  @JsonCreator
84
  public Client(@JsonProperty("id") long id,
85
      @JsonProperty("name") String name,
86
      @JsonProperty("description") @Nullable String description,
87
      @JsonProperty("spiffeId") @Nullable String spiffeId,
88
      @JsonProperty("createdAt") ApiDate createdAt,
89
      @JsonProperty("createdBy") @Nullable String createdBy,
90
      @JsonProperty("updatedAt") ApiDate updatedAt,
91
      @JsonProperty("updatedBy") @Nullable String updatedBy,
92
      @JsonProperty("lastSeen") @Nullable ApiDate lastSeen,
93
      @JsonProperty("expiration") @Nullable ApiDate expiration,
94
      @JsonProperty("enabled") boolean enabled,
95
      @JsonProperty("owner") @Nullable String owner,
96
      @JsonProperty("automationAllowed") boolean automationAllowed) {
1✔
97
    this.id = id;
1✔
98
    this.name = checkNotNull(name, "Client name must not be null");
1✔
99
    this.description = nullToEmpty(description);
1✔
100
    this.spiffeId = spiffeId;
1✔
101
    this.createdAt = createdAt;
1✔
102
    this.createdBy = nullToEmpty(createdBy);
1✔
103
    this.updatedAt = updatedAt;
1✔
104
    this.updatedBy = nullToEmpty(updatedBy);
1✔
105
    this.lastSeen = cleanTimestamp(lastSeen);
1✔
106
    this.expiration = cleanTimestamp(expiration);
1✔
107
    this.enabled = enabled;
1✔
108
    this.owner = owner;
1✔
109
    this.automationAllowed = automationAllowed;
1✔
110
  }
1✔
111

112
  public Client(
113
      long id,
114
      String name,
115
      String description,
116
      String spiffeId,
117
      ApiDate createdAt,
118
      String createdBy,
119
      ApiDate updatedAt,
120
      String updatedBy,
121
      ApiDate lastSeen,
122
      ApiDate expiration,
123
      boolean enabled,
124
      boolean automationAllowed) {
125
    this(
×
126
        id,
127
        name,
128
        description,
129
        spiffeId,
130
        createdAt,
131
        createdBy,
132
        updatedAt,
133
        updatedBy,
134
        lastSeen,
135
        expiration,
136
        enabled,
137
        NO_OWNER,
138
        automationAllowed);
139
  }
×
140

141
  private static ApiDate cleanTimestamp(ApiDate instant) {
142
    if (instant != null && instant.toEpochSecond() == 0L) {
1✔
143
      return null;
×
144
    }
145
    return instant;
1✔
146
  }
147

148
  public long getId() {
149
    return id;
1✔
150
  }
151

152
  public String getName() {
153
    return name;
1✔
154
  }
155

156
  public String getDescription() {
157
    return description;
1✔
158
  }
159

160
  public String getSpiffeId() {
161
    return spiffeId;
1✔
162
  }
163

164
  public ApiDate getCreatedAt() {
165
    return createdAt;
1✔
166
  }
167

168
  public String getCreatedBy() {
169
    return createdBy;
1✔
170
  }
171

172
  public ApiDate getUpdatedAt() {
173
    return updatedAt;
1✔
174
  }
175

176
  public String getUpdatedBy() {
177
    return updatedBy;
1✔
178
  }
179

180
  public ApiDate getLastSeen() {
181
    return lastSeen;
1✔
182
  }
183

184
  public ApiDate getExpiration() {
185
    return expiration;
1✔
186
  }
187

188
  public boolean isEnabled() {
189
    return enabled;
1✔
190
  }
191

192
  public String getOwner() { return owner; }
1✔
193

194
  public void setOwner(String owner) { this.owner = owner; }
×
195

196
  public boolean isAutomationAllowed() {
197
    return automationAllowed;
1✔
198
  }
199

200
  @Override
201
  public boolean equals(Object o) {
202
    if (o instanceof Client) {
1✔
203
      Client that = (Client) o;
1✔
204
      if (this.id == that.id &&
1✔
205
          Objects.equal(this.name, that.name) &&
1✔
206
          Objects.equal(this.description, that.description) &&
1✔
207
          Objects.equal(this.spiffeId, that.spiffeId) &&
1✔
208
          Objects.equal(this.createdAt, that.createdAt) &&
1✔
209
          Objects.equal(this.createdBy, that.createdBy) &&
1✔
210
          Objects.equal(this.updatedAt, that.updatedAt) &&
1✔
211
          Objects.equal(this.updatedBy, that.updatedBy) &&
1✔
212
          Objects.equal(this.lastSeen, that.lastSeen) &&
1✔
213
          Objects.equal(this.expiration, that.expiration) &&
1✔
214
          this.enabled == that.enabled &&
215
          Objects.equal(this.owner, that.owner) &&
1✔
216
          this.automationAllowed == that.automationAllowed
217
      ) {
218
        return true;
1✔
219
      }
220
    }
221

222
    return false;
×
223
  }
224

225
  @Override
226
  public int hashCode() {
227
    return Objects.hashCode(
×
228
        id,
×
229
        name,
230
        description,
231
        spiffeId,
232
        createdAt,
233
        createdBy,
234
        updatedAt,
235
        updatedBy,
236
        lastSeen,
237
        expiration,
238
        enabled,
×
239
        owner,
240
        automationAllowed);
×
241
  }
242

243
  @Override
244
  public String toString() {
245
    return MoreObjects.toStringHelper(this)
×
246
        .add("id", id)
×
247
        .add("name", name)
×
248
        .add("description", description)
×
249
        .add("spiffeId", spiffeId)
×
250
        .add("createdAt", createdAt)
×
251
        .add("createdBy", createdBy)
×
252
        .add("updatedAt", updatedAt)
×
253
        .add("updatedBy", updatedBy)
×
254
        .add("lastSeen", lastSeen)
×
255
        .add("expiration", expiration)
×
256
        .add("enabled", enabled)
×
257
        .add("owner", owner)
×
258
        .add("automationAllowed", automationAllowed)
×
259
        .toString();
×
260
  }
261
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc