This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new update endpoint in Keywhiz client
- Loading branch information
Jesse Peirce
committed
Dec 5, 2016
1 parent
c8a8ab5
commit 7eb68a2
Showing
15 changed files
with
348 additions
and
196 deletions.
There are no files selected for viewing
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
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,83 @@ | |||
/* | |||
* 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.cli.commands; | |||
|
|||
import com.fasterxml.jackson.databind.ObjectMapper; | |||
import com.google.common.base.Throwables; | |||
import com.google.common.io.ByteStreams; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import keywhiz.cli.configs.AddOrUpdateActionConfig; | |||
import keywhiz.cli.configs.UpdateActionConfig; | |||
import keywhiz.client.KeywhizClient; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
|
|||
import static java.lang.String.format; | |||
import static keywhiz.cli.Utilities.VALID_NAME_PATTERN; | |||
import static keywhiz.cli.Utilities.validName; | |||
|
|||
public class UpdateAction implements Runnable { | |||
private static final Logger logger = LoggerFactory.getLogger(UpdateAction.class); | |||
|
|||
private final UpdateActionConfig config; | |||
private final KeywhizClient keywhizClient; | |||
private final ObjectMapper mapper; | |||
|
|||
InputStream stream = System.in; | |||
|
|||
public UpdateAction(UpdateActionConfig config, KeywhizClient client, | |||
ObjectMapper mapper) { | |||
this.config = config; | |||
this.keywhizClient = client; | |||
this.mapper = mapper; | |||
} | |||
|
|||
@Override public void run() { | |||
String secretName = config.name; | |||
|
|||
if (secretName == null || !validName(secretName)) { | |||
throw new IllegalArgumentException(format("Invalid name, must match %s", VALID_NAME_PATTERN)); | |||
} | |||
|
|||
byte[] content = {}; | |||
if (config.contentProvided) { | |||
content = readSecretContent(); | |||
} | |||
partialUpdateSecret(secretName, content, config); | |||
} | |||
|
|||
private void partialUpdateSecret(String secretName, byte[] content, | |||
AddOrUpdateActionConfig config) { | |||
try { | |||
keywhizClient.updateSecret(secretName, config.description != null, | |||
config.getDescription(), content.length > 0, content, config.json != null, | |||
config.getMetadata(mapper), config.expiry != null, config.getExpiry()); | |||
logger.info("partialUpdate secret '{}'.", secretName); | |||
} catch (IOException e) { | |||
throw Throwables.propagate(e); | |||
} | |||
} | |||
|
|||
private byte[] readSecretContent() { | |||
try { | |||
return ByteStreams.toByteArray(stream); | |||
} catch (IOException e) { | |||
throw Throwables.propagate(e); | |||
} | |||
} | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,39 +1,11 @@ | |||
/* | |||
* 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.cli.configs; | package keywhiz.cli.configs; | ||
|
|
||
import com.beust.jcommander.Parameter; | import com.beust.jcommander.Parameter; | ||
import com.beust.jcommander.Parameters; | import com.beust.jcommander.Parameters; | ||
import java.util.List; | import java.util.List; | ||
|
|
||
@Parameters(commandDescription = "Add clients, groups, or secrets to KeyWhiz") | @Parameters(commandDescription = "Add clients, groups, or secrets to KeyWhiz") | ||
public class AddActionConfig { | public class AddActionConfig extends AddOrUpdateActionConfig { | ||
@Parameter(description = "<client|group|secret>") | @Parameter(description = "<client|group|secret>") | ||
public List<String> addType; | public List<String> addType; | ||
|
|||
@Parameter(names = "--name", description = "Name of the item to add", required = true) | |||
public String name; | |||
|
|||
@Parameter(names = "--json", description = "Metadata JSON blob") | |||
public String json; | |||
|
|||
@Parameter(names = { "-g", "--group" }, description = "Also assign the secret to this group (secrets only)") | |||
public String group; | |||
|
|||
@Parameter(names = { "-e", "--expiry" }, description = "Secret expiry. For keystores, it is recommended to use the expiry of the earliest key. Format should be 2006-01-02T15:04:05Z or seconds since epoch.") | |||
public String expiry; | |||
} | } |
Oops, something went wrong.