This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
Add endpoint for automation clients to read secret contents #327
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
api/src/main/java/keywhiz/api/automation/v2/SecretContentsRequestV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package keywhiz.api.automation.v2; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.auto.value.AutoValue; | ||
import com.google.common.collect.ImmutableSet; | ||
|
||
@AutoValue public abstract class SecretContentsRequestV2 { | ||
SecretContentsRequestV2() {} // prevent sub-classing | ||
|
||
|
||
public static Builder builder() { | ||
return new AutoValue_SecretContentsRequestV2.Builder() | ||
.secrets(); | ||
} | ||
|
||
@AutoValue.Builder public abstract static class Builder { | ||
// intended to be package-private | ||
abstract SecretContentsRequestV2.Builder secrets(ImmutableSet<String> secrets); | ||
|
||
public SecretContentsRequestV2.Builder secrets(String... secrets) { | ||
return secrets(ImmutableSet.copyOf(secrets)); | ||
} | ||
|
||
public abstract SecretContentsRequestV2 build(); | ||
} | ||
|
||
/** | ||
* Static factory method used by Jackson for deserialization | ||
*/ | ||
@SuppressWarnings("unused") | ||
@JsonCreator public static SecretContentsRequestV2 fromParts( | ||
@JsonProperty("secrets") ImmutableSet<String> secrets) { | ||
return builder().secrets(secrets).build(); | ||
} | ||
|
||
@JsonProperty("secrets") public abstract ImmutableSet<String> secrets(); | ||
} |
49 changes: 49 additions & 0 deletions
49
api/src/main/java/keywhiz/api/automation/v2/SecretContentsResponseV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package keywhiz.api.automation.v2; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.auto.value.AutoValue; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@AutoValue public abstract class SecretContentsResponseV2 { | ||
SecretContentsResponseV2() {} // prevent sub-classing | ||
|
||
|
||
public static Builder builder() { | ||
return new AutoValue_SecretContentsResponseV2.Builder() | ||
.successSecrets(ImmutableMap.of()) | ||
.missingSecrets(ImmutableList.of()); | ||
} | ||
|
||
@AutoValue.Builder public abstract static class Builder { | ||
// intended to be package-private | ||
abstract SecretContentsResponseV2.Builder successSecrets(ImmutableMap<String, String> successSecrets); | ||
abstract SecretContentsResponseV2.Builder missingSecrets(ImmutableList<String> missingSecrets); | ||
|
||
|
||
public SecretContentsResponseV2.Builder successSecrets(Map<String, String> successSecrets) { | ||
return successSecrets(ImmutableMap.copyOf(successSecrets)); | ||
} | ||
public SecretContentsResponseV2.Builder missingSecrets(List<String> missingSecrets) { | ||
return missingSecrets(ImmutableList.copyOf(missingSecrets)); | ||
} | ||
|
||
public abstract SecretContentsResponseV2 build(); | ||
} | ||
|
||
/** | ||
* Static factory method used by Jackson for deserialization | ||
*/ | ||
@SuppressWarnings("unused") | ||
@JsonCreator public static SecretContentsResponseV2 fromParts( | ||
@JsonProperty("successSecrets") ImmutableMap<String, String> successSecrets, | ||
@JsonProperty("missingSecrets") ImmutableList<String> missingSecrets) { | ||
return builder().successSecrets(successSecrets).missingSecrets(missingSecrets).build(); | ||
} | ||
|
||
@JsonProperty("successSecrets") public abstract ImmutableMap<String, String> successSecrets(); | ||
@JsonProperty("missingSecrets") public abstract ImmutableList<String> missingSecrets(); | ||
} |
35 changes: 35 additions & 0 deletions
35
api/src/test/java/keywhiz/api/automation/v2/SecretContentsRequestV2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2015 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package keywhiz.api.automation.v2; | ||
|
||
import org.junit.Test; | ||
|
||
import static keywhiz.testing.JsonHelpers.fromJson; | ||
import static keywhiz.testing.JsonHelpers.jsonFixture; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class SecretContentsRequestV2Test { | ||
@Test public void deserializesCorrectly() throws Exception { | ||
SecretContentsRequestV2 secretContentsRequest = SecretContentsRequestV2.builder() | ||
.secrets("secret1", "secret2", "secret3") | ||
.build(); | ||
|
||
assertThat(fromJson( | ||
jsonFixture("fixtures/v2/secretContentsRequest.json"), SecretContentsRequestV2.class)) | ||
.isEqualTo(secretContentsRequest); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
api/src/test/java/keywhiz/api/automation/v2/SecretContentsResponseV2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2015 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package keywhiz.api.automation.v2; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.junit.Test; | ||
|
||
import static keywhiz.testing.JsonHelpers.fromJson; | ||
import static keywhiz.testing.JsonHelpers.jsonFixture; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class SecretContentsResponseV2Test { | ||
@Test public void deserializesCorrectly() throws Exception { | ||
SecretContentsResponseV2 secretContentsResponse = SecretContentsResponseV2.builder() | ||
.successSecrets(ImmutableMap.of("secret1", "supersecretcontent1", "secret2", "supersecretcontent2")) | ||
.missingSecrets(ImmutableList.of("secret3")) | ||
.build(); | ||
|
||
assertThat(fromJson( | ||
jsonFixture("fixtures/v2/secretContentsResponse.json"), SecretContentsResponseV2.class)) | ||
.isEqualTo(secretContentsResponse); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
api/src/test/resources/fixtures/v2/secretContentsRequest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"secrets": ["secret1", "secret2", "secret3"] | ||
} |
7 changes: 7 additions & 0 deletions
7
api/src/test/resources/fixtures/v2/secretContentsResponse.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"successSecrets": { | ||
"secret1" : "supersecretcontent1", | ||
"secret2": "supersecretcontent2" | ||
}, | ||
"missingSecrets": ["secret3"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seemed to me that having separate fields for secrets which were successfully read (and their contents) and secrets which were not successfully read (and any error messages thrown in the reading) would be easier than returning a single map of secrets to "the results of the operation" and making the client distinguish success and failure. However, we can update the API to make it more flexible or easier to use.
At the moment, the only error case is that a secret was not found, so
errorSecrets
could be a list rather than a map; however, having it as a map leaves flexibility to introduce other error cases later on without changing the API.