use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class KubernetesV1DistributedService method connectCommand.
default String connectCommand(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings, int localPort) {
ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
Map<Integer, List<Instance>> instances = runningServiceDetails.getInstances();
Integer latest = runningServiceDetails.getLatestEnabledVersion();
String namespace = getNamespace(settings);
List<Instance> latestInstances = instances.get(latest);
if (latestInstances.isEmpty()) {
throw new HalException(Problem.Severity.FATAL, "No instances running in latest server group for service " + getServiceName() + " in namespace " + namespace);
}
return Strings.join(KubernetesV1ProviderUtils.kubectlPortForwardCommand(details, namespace, latestInstances.get(0).getId(), settings.getPort(), localPort), " ");
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class KubernetesV1DistributedService method connectToInstance.
@Override
default <S> S connectToInstance(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings, SpinnakerService<S> sidecar, String instanceId) {
ServiceSettings settings = runtimeSettings.getServiceSettings(sidecar);
String namespace = getNamespace(settings);
int localPort = SocketUtils.findAvailableTcpPort();
int targetPort = settings.getPort();
List<String> command = KubernetesV1ProviderUtils.kubectlPortForwardCommand(details, namespace, instanceId, targetPort, localPort);
JobRequest request = new JobRequest().setTokenizedCommand(command);
String jobId = getJobExecutor().startJob(request);
// Wait for the proxy to spin up.
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5));
JobStatus status = getJobExecutor().updateJob(jobId);
// This should be a long-running job.
if (status.getState() == JobStatus.State.COMPLETED) {
throw new HalException(Problem.Severity.FATAL, "Unable to establish a proxy against " + getServiceName() + ":\n" + status.getStdOut() + "\n" + status.getStdErr());
}
return getServiceInterfaceFactory().createService(settings.getScheme() + "://localhost:" + localPort, sidecar);
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class GoogleKms method createCryptoKey.
private static CryptoKey createCryptoKey(CloudKMS cloudKms, String keyRingId, String cryptoKeyName, String user) {
CryptoKey cryptoKey;
try {
cryptoKey = cloudKms.projects().locations().keyRings().cryptoKeys().create(keyRingId, new CryptoKey().setPurpose(KEY_PURPOSE)).setCryptoKeyId(cryptoKeyName).execute();
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Failed to create a halyard crypto key: " + e.getMessage(), e);
}
Policy policy = getCryptoKeyPolicy(cloudKms, cryptoKey.getName());
policy.setBindings(Collections.singletonList(new Binding().setRole("roles/cloudkms.cryptoKeyEncrypterDecrypter").setMembers(Collections.singletonList(user))));
log.info("Updating iam policy for " + cryptoKey.getName());
setCryptoKeyPolicy(cloudKms, cryptoKey.getName(), policy);
return cryptoKey;
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class GoogleKms method setCryptoKeyPolicy.
private static void setCryptoKeyPolicy(CloudKMS cloudKms, String cryptoKeyId, Policy policy) {
try {
SetIamPolicyRequest iamPolicyRequest = new SetIamPolicyRequest().setPolicy(policy);
cloudKms.projects().locations().keyRings().cryptoKeys().setIamPolicy(cryptoKeyId, iamPolicyRequest).execute();
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Failed to set crypo key policy: " + e.getMessage(), e);
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class GoogleKms method encryptContents.
byte[] encryptContents(String plaintext) {
plaintext = Base64.getEncoder().encodeToString(plaintext.getBytes());
EncryptRequest encryptRequest = new EncryptRequest().encodePlaintext(plaintext.getBytes());
EncryptResponse response;
try {
response = cloudKms.projects().locations().keyRings().cryptoKeys().encrypt(cryptoKey.getName(), encryptRequest).execute();
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Failed to encrypt user data: " + e.getMessage(), e);
}
return response.decodeCiphertext();
}
Aggregations