use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMount in project halyard by spinnaker.
the class GoogleDistributedService method stageProfiles.
@Override
default List<ConfigSource> stageProfiles(AccountDeploymentDetails<GoogleAccount> details, ResolvedConfiguration resolvedConfiguration) {
String deploymentName = details.getDeploymentName();
SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings();
SpinnakerService thisService = getService();
ServiceSettings thisServiceSettings = resolvedConfiguration.getServiceSettings(thisService);
Map<String, String> env = new HashMap<>();
Integer version = getRunningServiceDetails(details, runtimeSettings).getLatestEnabledVersion();
if (version == null) {
version = 0;
} else {
version++;
}
List<ConfigSource> configSources = new ArrayList<>();
String stagingPath = getSpinnakerStagingPath(deploymentName);
GoogleVaultServerService vaultService = getVaultServerService();
VaultServerService.Vault vault = vaultService.connectToPrimaryService(details, runtimeSettings);
for (SidecarService sidecarService : getSidecars(runtimeSettings)) {
for (Profile profile : sidecarService.getSidecarProfiles(resolvedConfiguration, thisService)) {
if (profile == null) {
throw new HalException(Problem.Severity.FATAL, "Service " + sidecarService.getService().getCanonicalName() + " is required but was not supplied for deployment.");
}
String secretName = secretName(profile.getName(), version);
String mountPoint = Paths.get(profile.getOutputFile()).toString();
Path stagedFile = Paths.get(profile.getStagedFile(stagingPath));
VaultConfigMount vaultConfigMount = VaultConfigMount.fromLocalFile(stagedFile.toFile(), mountPoint);
secretName = vaultService.writeVaultConfig(deploymentName, vault, secretName, vaultConfigMount);
configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint));
}
}
Map<String, Profile> serviceProfiles = resolvedConfiguration.getProfilesForService(thisService.getType());
Set<String> requiredFiles = new HashSet<>();
for (Map.Entry<String, Profile> entry : serviceProfiles.entrySet()) {
Profile profile = entry.getValue();
requiredFiles.addAll(profile.getRequiredFiles());
env.putAll(profile.getEnv());
String mountPoint = profile.getOutputFile();
String secretName = secretName("profile-" + profile.getName(), version);
Path stagedFile = Paths.get(profile.getStagedFile(stagingPath));
VaultConfigMount vaultConfigMount = VaultConfigMount.fromLocalFile(stagedFile.toFile(), mountPoint);
secretName = vaultService.writeVaultConfig(deploymentName, vault, secretName, vaultConfigMount);
configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint));
}
for (String file : requiredFiles) {
String mountPoint = Paths.get(file).toString();
String secretName = secretName("dependencies-" + file, version);
VaultConfigMount vaultConfigMount = VaultConfigMount.fromLocalFile(Paths.get(file).toFile(), mountPoint);
secretName = vaultService.writeVaultConfig(deploymentName, vault, secretName, vaultConfigMount);
configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint));
}
env.putAll(thisServiceSettings.getEnv());
String envSourceFile = env.entrySet().stream().reduce("", (s, e) -> String.format("%s\n%s=%s", s, e.getKey(), e.getValue()), (s1, s2) -> String.join("\n", s1, s2));
String mountPoint = getEnvFile();
String secretName = secretName("env", version);
VaultConfigMount vaultConfigMount = VaultConfigMount.fromString(envSourceFile, mountPoint);
secretName = vaultService.writeVaultConfig(deploymentName, vault, secretName, vaultConfigMount);
configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint));
return configSources;
}
Aggregations