use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class VaultService method publishSecret.
public void publishSecret(DeploymentConfiguration deploymentConfiguration, String name, String contents) {
String vaultAddress = deploymentConfiguration.getDeploymentEnvironment().getVault().getAddress();
String encodedContents = Base64.getEncoder().encodeToString(contents.getBytes());
String secretName = vaultSecretPrefix + name;
List<String> command = new ArrayList<>();
command.add("vault");
command.add("write");
command.add("--address");
command.add(vaultAddress);
command.add(secretName);
command.add(encodedContents);
JobRequest request = new JobRequest().setTokenizedCommand(command).setTimeoutMillis(TimeUnit.SECONDS.toMillis(vaultTimeoutSeconds));
String id = jobExecutor.startJob(request);
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5));
JobStatus status = jobExecutor.updateJob(id);
if (!status.getResult().equals(JobStatus.Result.SUCCESS)) {
throw new HalException(Problem.Severity.FATAL, "Failed to publish secret " + name + ": " + status.getStdOut() + status.getStdErr());
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class GoogleWriteableProfileRegistry method writeTextObject.
private void writeTextObject(String name, String contents) {
try {
byte[] bytes = contents.getBytes();
StorageObject object = new StorageObject().setBucket(spinconfigBucket).setName(name);
ByteArrayContent content = new ByteArrayContent("application/text", bytes);
storage.objects().insert(spinconfigBucket, object, content).execute();
} catch (IOException e) {
log.error("Failed to write new object " + name, e);
throw new HalException(new ProblemBuilder(Severity.FATAL, "Failed to write to " + name + ": " + e.getMessage()).build());
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class SecureStorage method backupFile.
public void backupFile(String name, File file) {
String contents;
try {
contents = IOUtils.toString(new FileInputStream(file));
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Can't load file for secure storage: " + e.getMessage(), e);
}
storeContents(name, contents);
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class GoogleKms method ensureCryptoKeyExists.
private static CryptoKey ensureCryptoKeyExists(CloudKMS cloudKms, GoogleCredential credential, String keyRingId, String cryptoKeyId) {
CryptoKey cryptoKey;
try {
cryptoKey = cloudKms.projects().locations().keyRings().cryptoKeys().get(cryptoKeyId).execute();
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == 404) {
cryptoKey = null;
} else {
throw new HalException(Problem.Severity.FATAL, "Unexpected error retrieving crypto key: " + e.getMessage(), e);
}
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Unexpected error retrieving crypto key: " + e.getMessage(), e);
}
if (cryptoKey == null) {
String cryptoKeyName = cryptoKeyId.substring(cryptoKeyId.lastIndexOf('/') + 1);
log.info("Creating a new crypto key " + cryptoKeyName);
String user = "serviceAccount:" + credential.getServiceAccountId();
cryptoKey = createCryptoKey(cloudKms, keyRingId, cryptoKeyName, user);
}
return cryptoKey;
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class GoogleKms method ensureKeyRingExists.
private static KeyRing ensureKeyRingExists(CloudKMS cloudKms, String locationId, String keyRingId) {
KeyRing keyRing;
try {
keyRing = cloudKms.projects().locations().keyRings().get(keyRingId).execute();
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == 404) {
keyRing = null;
} else {
throw new HalException(Problem.Severity.FATAL, "Unexpected error retrieving key ring: " + e.getMessage(), e);
}
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Unexpected error retrieving key ring: " + e.getMessage(), e);
}
if (keyRing == null) {
String keyRingName = keyRingId.substring(keyRingId.lastIndexOf('/') + 1);
log.info("Creating a new key ring " + keyRingName);
keyRing = createKeyRing(cloudKms, locationId, keyRingName);
}
return keyRing;
}
Aggregations