Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Merge a76a999 into 0517c24
Browse files Browse the repository at this point in the history
  • Loading branch information
mmontgomery-square committed Oct 28, 2022
2 parents 0517c24 + a76a999 commit 7fe561f
Show file tree
Hide file tree
Showing 45 changed files with 611 additions and 66 deletions.
22 changes: 20 additions & 2 deletions api/src/main/java/keywhiz/api/ClientDetailResponse.java
Expand Up @@ -52,6 +52,9 @@ public class ClientDetailResponse {
@JsonProperty
public final ApiDate lastSeen;

@JsonProperty
public final String owner;

/**
* List of secrets the group has access to. The secrets do not contain content.
*/
Expand All @@ -70,6 +73,7 @@ public ClientDetailResponse(@JsonProperty("id") long id,
@JsonProperty("createdBy") String createdBy,
@JsonProperty("updatedBy") String updatedBy,
@JsonProperty("lastSeen") @Nullable ApiDate lastSeen,
@JsonProperty("owner") @Nullable String owner,
@JsonProperty("groups") ImmutableList<Group> groups,
@JsonProperty("secrets") ImmutableList<SanitizedSecret> secrets) {
this.id = id;
Expand All @@ -81,6 +85,7 @@ public ClientDetailResponse(@JsonProperty("id") long id,
this.createdBy = createdBy;
this.updatedBy = updatedBy;
this.lastSeen = lastSeen;
this.owner = owner;
this.groups = groups;
this.secrets = secrets;
}
Expand All @@ -96,13 +101,25 @@ public static ClientDetailResponse fromClient(Client client, ImmutableList<Group
client.getCreatedBy(),
client.getUpdatedBy(),
client.getLastSeen(),
client.getOwner(),
groups,
secrets);
}

public int hashCode() {
return Objects.hashCode(id, name, description, spiffeId, creationDate, updateDate, createdBy,
updatedBy, lastSeen, groups, secrets);
return Objects.hashCode(
id,
name,
description,
spiffeId,
creationDate,
updateDate,
createdBy,
updatedBy,
lastSeen,
owner,
groups,
secrets);
}

@Override
Expand All @@ -118,6 +135,7 @@ public boolean equals(Object o) {
Objects.equal(this.createdBy, that.createdBy) &&
Objects.equal(this.updatedBy, that.updatedBy) &&
Objects.equal(this.lastSeen, that.lastSeen) &&
Objects.equal(this.owner, that.owner) &&
Objects.equal(this.groups, that.groups) &&
Objects.equal(this.secrets, that.secrets);
}
Expand Down
35 changes: 30 additions & 5 deletions api/src/main/java/keywhiz/api/CreateClientRequest.java
Expand Up @@ -16,26 +16,51 @@

package keywhiz.api;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Objects;
import javax.annotation.Nullable;
import org.hibernate.validator.constraints.NotBlank;

public class CreateClientRequest {
private static final String NO_OWNER = null;

@NotBlank
@JsonProperty
public String name;

public CreateClientRequest(@JsonProperty("name") String name) {
@Nullable
@JsonProperty
public String owner;

@JsonCreator
public CreateClientRequest(
@JsonProperty("name") String name,
@JsonProperty("owner") String owner) {
this.name = name;
this.owner = owner;
}

public CreateClientRequest(String name) {
this(name, NO_OWNER);
}

@Override public int hashCode() {
return Objects.hashCode(name);
return Objects.hashCode(
name,
owner);
}

@Override public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CreateClientRequest)) return false;
return Objects.equal(this.name, ((CreateClientRequest) o).name);
if (this == o) {
return true;
}
if (o instanceof CreateClientRequest) {
CreateClientRequest that = (CreateClientRequest) o;
return
Objects.equal(this.name, that.name) &&
Objects.equal(this.owner, that.owner);
}
return false;
}
}
42 changes: 34 additions & 8 deletions api/src/main/java/keywhiz/api/CreateGroupRequest.java
Expand Up @@ -16,13 +16,16 @@

package keywhiz.api;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableMap;
import javax.annotation.Nullable;
import org.hibernate.validator.constraints.NotEmpty;

public class CreateGroupRequest {
private static final String NO_OWNER = null;

@NotEmpty
@JsonProperty
public final String name;
Expand All @@ -35,27 +38,50 @@ public class CreateGroupRequest {
@JsonProperty
public final ImmutableMap<String, String> metadata;

@Nullable
@JsonProperty
public final String owner;

@JsonCreator
public CreateGroupRequest(@JsonProperty("name") String name,
@Nullable @JsonProperty("description") String description,
@Nullable @JsonProperty("metadata") ImmutableMap<String, String> metadata) {
@Nullable @JsonProperty("metadata") ImmutableMap<String, String> metadata,
@Nullable @JsonProperty("owner") String owner) {
this.name = name;
this.description = description;
this.metadata = metadata == null ? ImmutableMap.of() : ImmutableMap.copyOf(metadata);
this.owner = owner;
}

@Override public int hashCode() {
return Objects.hashCode(name, description, metadata);
public CreateGroupRequest(String name,
String description,
ImmutableMap<String, String> metadata) {
this(
name,
description,
metadata,
NO_OWNER);
}

@Override public int hashCode() {
return Objects.hashCode(
name,
description,
metadata,
owner);
}

@Override public boolean equals(Object o) {
if (this == o) return true;
if (this == o) {
return true;
}
if (o instanceof CreateGroupRequest) {
CreateGroupRequest that = (CreateGroupRequest) o;
if (Objects.equal(this.name, that.name) &&
return
Objects.equal(this.name, that.name) &&
Objects.equal(this.description, that.description) &&
Objects.equal(this.metadata, that.metadata)) {
return true;
}
Objects.equal(this.metadata, that.metadata) &&
Objects.equal(this.owner, that.owner);
}
return false;
}
Expand Down
24 changes: 22 additions & 2 deletions api/src/main/java/keywhiz/api/GroupDetailResponse.java
Expand Up @@ -20,6 +20,7 @@
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import javax.annotation.Nullable;
import keywhiz.api.model.Client;
import keywhiz.api.model.Group;
import keywhiz.api.model.SanitizedSecret;
Expand Down Expand Up @@ -50,6 +51,9 @@ public class GroupDetailResponse {
@JsonProperty
private final ImmutableMap<String, String> metadata;

@JsonProperty
private final String owner;

@JsonProperty
private final ImmutableList<SanitizedSecret> secrets;

Expand All @@ -64,6 +68,7 @@ public GroupDetailResponse(@JsonProperty("id") long id,
@JsonProperty("createdBy") String createdBy,
@JsonProperty("updatedBy") String updatedBy,
@JsonProperty("metadata") ImmutableMap<String, String> metadata,
@JsonProperty("owner") @Nullable String owner,
@JsonProperty("secrets") ImmutableList<SanitizedSecret> secrets,
@JsonProperty("clients") ImmutableList<Client> clients) {
this.id = id;
Expand All @@ -74,6 +79,7 @@ public GroupDetailResponse(@JsonProperty("id") long id,
this.createdBy = createdBy;
this.updatedBy = updatedBy;
this.metadata = metadata;
this.owner = owner;
this.secrets = secrets;
this.clients = clients;
}
Expand All @@ -88,6 +94,7 @@ public static GroupDetailResponse fromGroup(Group group, ImmutableList<Sanitized
group.getCreatedBy(),
group.getUpdatedBy(),
group.getMetadata(),
group.getOwner(),
secrets,
clients);
}
Expand Down Expand Up @@ -124,6 +131,8 @@ public ImmutableMap<String, String> getMetadata() {
return metadata;
}

public String getOwner() { return owner; }

/**
* @return List of secrets the group has access to. The secrets do not contain content.
*/
Expand All @@ -137,8 +146,18 @@ public ImmutableList<Client> getClients() {

@Override
public int hashCode() {
return Objects.hashCode(id, name, description, creationDate, updateDate, createdBy, updatedBy,
metadata, secrets, clients);
return Objects.hashCode(
id,
name,
description,
creationDate,
updateDate,
createdBy,
updatedBy,
metadata,
owner,
secrets,
clients);
}

@Override
Expand All @@ -153,6 +172,7 @@ public boolean equals(Object o) {
Objects.equal(this.createdBy, that.createdBy) &&
Objects.equal(this.updatedBy, that.updatedBy) &&
Objects.equal(this.metadata, that.metadata) &&
Objects.equal(this.owner, that.owner) &&
Objects.equal(this.secrets, that.secrets) &&
Objects.equal(this.clients, that.clients);
}
Expand Down
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import java.util.Optional;
import javax.annotation.Nullable;
import keywhiz.api.ApiDate;
import keywhiz.api.model.Client;

Expand All @@ -24,8 +25,8 @@ public static ClientDetailResponseV2 fromClient(Client client) {
client.getUpdatedAt().toEpochSecond(),
client.getCreatedBy(),
client.getUpdatedBy(),
lastSeen.map(ApiDate::toEpochSecond)
);
lastSeen.map(ApiDate::toEpochSecond),
client.getOwner());
}

/**
Expand All @@ -40,9 +41,18 @@ public static ClientDetailResponseV2 fromClient(Client client) {
@JsonProperty("updatedAtSeconds") long updatedAtSeconds,
@JsonProperty("createdBy") String createdBy,
@JsonProperty("updatedBy") String updatedBy,
@JsonProperty("lastSeenSeconds") Optional<Long> lastSeenSeconds) {
return new AutoValue_ClientDetailResponseV2(name, description, spiffeId, createdAtSeconds,
updatedAtSeconds, createdBy, updatedBy, lastSeenSeconds);
@JsonProperty("lastSeenSeconds") Optional<Long> lastSeenSeconds,
@JsonProperty("owner") @Nullable String owner) {
return new AutoValue_ClientDetailResponseV2(
name,
description,
spiffeId,
createdAtSeconds,
updatedAtSeconds,
createdBy,
updatedBy,
lastSeenSeconds,
owner);
}

@JsonProperty("name") public abstract String name();
Expand All @@ -60,4 +70,6 @@ public static ClientDetailResponseV2 fromClient(Client client) {
@JsonProperty("updatedBy") public abstract String updatedBy();

@JsonProperty("lastSeenSeconds") public abstract Optional<Long> lastSeenSeconds();

@JsonProperty("owner") @Nullable public abstract String owner();
}
Expand Up @@ -30,6 +30,8 @@ public static Builder builder() {
public abstract Builder name(String name);
public abstract Builder description(String description);
public abstract Builder spiffeId(String spiffeId);
public abstract Builder owner(String owner);

abstract CreateClientRequestV2 autoBuild();

public Builder groups(String... groups) {
Expand All @@ -53,17 +55,20 @@ public CreateClientRequestV2 build() {
@JsonProperty("name") String name,
@JsonProperty("groups") @Nullable Iterable<String> groups,
@JsonProperty("description") @Nullable String description,
@JsonProperty("spiffeId") @Nullable String spiffeId) {
@JsonProperty("spiffeId") @Nullable String spiffeId,
@JsonProperty("owner") @Nullable String owner) {
return builder()
.name(name)
.groups(groups == null ? ImmutableSet.of() : ImmutableSet.copyOf(groups))
.description(nullToEmpty(description))
.spiffeId(nullToEmpty(spiffeId))
.owner(owner)
.build();
}

@JsonProperty("name") public abstract String name();
@JsonProperty("groups") public abstract ImmutableSet<String> groups();
@JsonProperty("description") public abstract String description();
@JsonProperty("spiffeId") public abstract String spiffeId();
@JsonProperty("owner") @Nullable public abstract String owner();
}
Expand Up @@ -21,6 +21,8 @@ public static Builder builder() {
public abstract Builder name(String name);
public abstract Builder description(String description);
public abstract Builder metadata(ImmutableMap<String, String> metadata);
public abstract Builder owner(String owner);

abstract CreateGroupRequestV2 autoBuild();

public CreateGroupRequestV2 build() {
Expand All @@ -39,15 +41,18 @@ public CreateGroupRequestV2 build() {
@JsonCreator public static CreateGroupRequestV2 fromParts(
@JsonProperty("name") String name,
@JsonProperty("description") @Nullable String description,
@JsonProperty("metadata") @Nullable ImmutableMap<String, String> metadata) {
@JsonProperty("metadata") @Nullable ImmutableMap<String, String> metadata,
@JsonProperty("owner") @Nullable String owner) {
return builder()
.name(name)
.description(nullToEmpty(description))
.metadata(metadata == null ? ImmutableMap.of() : ImmutableMap.copyOf(metadata))
.owner(owner)
.build();
}

@JsonProperty("name") public abstract String name();
@JsonProperty("description") public abstract String description();
@JsonProperty("metadata") public abstract ImmutableMap<String, String> metadata();
@JsonProperty("owner") @Nullable public abstract String owner();
}

0 comments on commit 7fe561f

Please sign in to comment.