use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails in project halyard by spinnaker.
the class GoogleDistributedService method buildConnectionDetails.
default VaultConnectionDetails buildConnectionDetails(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, String secretName) {
GoogleVaultServerService vaultService = getVaultServerService();
VaultServerService.Vault vault = vaultService.connectToPrimaryService(details, runtimeSettings);
ServiceSettings vaultSettings = runtimeSettings.getServiceSettings(vaultService);
RunningServiceDetails vaultDetails = vaultService.getRunningServiceDetails(details, runtimeSettings);
Integer latestVaultVersion = vaultDetails.getLatestEnabledVersion();
if (latestVaultVersion == null) {
throw new IllegalStateException("No vault services have been started yet. This is a bug.");
}
List<RunningServiceDetails.Instance> instances = vaultDetails.getInstances().get(latestVaultVersion);
if (instances.isEmpty()) {
throw new IllegalStateException("Current vault service has no running instances. This is a bug.");
}
String instanceId = instances.get(0).getId();
String address = new URIBuilder().setScheme("http").setHost(instanceId).setPort(vaultSettings.getPort()).toString();
String token = vaultService.getToken(details.getDeploymentName(), vault);
return new VaultConnectionDetails().setAddress(address).setSecret(secretName).setToken(token);
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails in project halyard by spinnaker.
the class GoogleDistributedService method getMetadata.
default List<Metadata.Items> getMetadata(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, List<ConfigSource> configSources, Integer version) {
List<Metadata.Items> metadataItems = new ArrayList<>();
String deploymentName = details.getDeploymentName();
Metadata.Items items = new Metadata.Items().setKey("startup-script").setValue(getStartupScript());
metadataItems.add(items);
items = new Metadata.Items().setKey("ssh-keys").setValue(GoogleProviderUtils.getSshPublicKey());
metadataItems.add(items);
if (!configSources.isEmpty()) {
DaemonTaskHandler.message("Mounting config in vault server");
GoogleVaultServerService vaultService = getVaultServerService();
VaultServerService.Vault vault = vaultService.connectToPrimaryService(details, runtimeSettings);
String secretName = secretName("config-mounts", version);
VaultConfigMountSet mountSet = VaultConfigMountSet.fromConfigSources(configSources);
secretName = vaultService.writeVaultConfigMountSet(deploymentName, vault, secretName, mountSet);
VaultConnectionDetails connectionDetails = buildConnectionDetails(details, runtimeSettings, secretName);
DaemonTaskHandler.message("Placing vault connection details into instance metadata");
items = new Metadata.Items().setKey("vault_address").setValue(connectionDetails.getAddress());
metadataItems.add(items);
items = new Metadata.Items().setKey("vault_token").setValue(connectionDetails.getToken());
metadataItems.add(items);
items = new Metadata.Items().setKey("vault_secret").setValue(connectionDetails.getSecret());
metadataItems.add(items);
}
GoogleConsulServerService consulServerService = getConsulServerService();
RunningServiceDetails consulServerDetails = consulServerService.getRunningServiceDetails(details, runtimeSettings);
Integer latestConsulVersion = consulServerDetails.getLatestEnabledVersion();
if (latestConsulVersion != null) {
List<RunningServiceDetails.Instance> instances = consulServerDetails.getInstances().get(latestConsulVersion);
String instancesValue = String.join(" ", instances.stream().map(RunningServiceDetails.Instance::getId).collect(Collectors.toList()));
items = new Metadata.Items().setKey(// TODO(lwander) change to consul_members for consistency w/ vault
"consul-members").setValue(instancesValue);
DaemonTaskHandler.message("Placing consul connection details into instance metadata");
metadataItems.add(items);
}
return metadataItems;
}
Aggregations