use of com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials in project halyard by spinnaker.
the class GoogleProviderUtils method getCompute.
static Compute getCompute(AccountDeploymentDetails<GoogleAccount> details) {
ConfigProblemSetBuilder problemSetBuilder = new ConfigProblemSetBuilder(null);
GoogleNamedAccountCredentials credentials = details.getAccount().getNamedAccountCredentials("", problemSetBuilder);
if (credentials == null) {
throw new HalException(problemSetBuilder.build().getProblems());
}
return credentials.getCompute();
}
use of com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials in project halyard by spinnaker.
the class GoogleBakeryDefaultsValidator method validate.
@Override
public void validate(ConfigProblemSetBuilder p, GoogleBakeryDefaults n) {
DaemonTaskHandler.message("Validating " + n.getNodeName() + " with " + GoogleBakeryDefaultsValidator.class.getSimpleName());
String zone = n.getZone();
String network = n.getNetwork();
String networkProjectId = n.getNetworkProjectId();
List<GoogleBaseImage> baseImages = n.getBaseImages();
if (StringUtils.isEmpty(zone) && StringUtils.isEmpty(network) && CollectionUtils.isEmpty(baseImages)) {
return;
} else if (CollectionUtils.isEmpty(credentialsList)) {
return;
}
if (StringUtils.isEmpty(zone)) {
p.addProblem(Problem.Severity.ERROR, "No zone supplied for google bakery defaults.");
} else {
int i = 0;
boolean foundZone = false;
while (!foundZone && i < credentialsList.size()) {
GoogleNamedAccountCredentials credentials = credentialsList.get(i);
try {
credentials.getCompute().zones().get(credentials.getProject(), zone).execute();
foundZone = true;
} catch (Exception e) {
}
i++;
}
if (!foundZone) {
p.addProblem(Problem.Severity.ERROR, "Zone " + zone + " not found via any configured google account.");
}
}
if (StringUtils.isEmpty(network)) {
p.addProblem(Problem.Severity.ERROR, "No network supplied for google bakery defaults.");
} else {
int j = 0;
boolean foundNetwork = false;
while (!foundNetwork && j < credentialsList.size()) {
GoogleNamedAccountCredentials credentials = credentialsList.get(j);
try {
String project = !StringUtils.isEmpty(networkProjectId) ? networkProjectId : credentials.getProject();
credentials.getCompute().networks().get(project, network).execute();
foundNetwork = true;
} catch (Exception e) {
}
j++;
}
if (!foundNetwork) {
p.addProblem(Problem.Severity.ERROR, "Network " + network + " not found via any configured google account.");
}
}
GoogleBaseImageValidator googleBaseImageValidator = new GoogleBaseImageValidator(credentialsList, halyardVersion);
baseImages.forEach(googleBaseImage -> googleBaseImageValidator.validate(p, googleBaseImage));
}
use of com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials in project halyard by spinnaker.
the class GoogleAccountValidator method validate.
@Override
public void validate(ConfigProblemSetBuilder p, GoogleAccount n) {
DaemonTaskHandler.message("Validating " + n.getNodeName() + " with " + GoogleAccountValidator.class.getSimpleName());
GoogleNamedAccountCredentials credentials = n.getNamedAccountCredentials(halyardVersion, p);
if (credentials == null) {
return;
} else {
credentialsList.add(credentials);
}
try {
Compute compute = credentials.getCompute();
compute.projects().get(n.getProject()).execute();
for (String imageProject : n.getImageProjects()) {
compute.projects().get(imageProject).execute();
}
} catch (IOException e) {
p.addProblem(Severity.ERROR, "Failed to load project \"" + n.getProject() + "\": " + e.getMessage() + ".");
}
String userDataFile = null;
if (!StringUtils.isEmpty(n.getUserDataFile())) {
userDataFile = ValidatingFileReader.contents(p, n.getUserDataFile());
if (userDataFile == null) {
return;
} else if (userDataFile.isEmpty()) {
p.addProblem(Severity.WARNING, "The supplied user data file is empty.");
}
}
}
use of com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials in project halyard by spinnaker.
the class GoogleBaseImageValidator method validate.
@Override
public void validate(ConfigProblemSetBuilder p, GoogleBaseImage n) {
String sourceImage = n.getVirtualizationSettings().getSourceImage();
String sourceImageFamily = n.getVirtualizationSettings().getSourceImageFamily();
if (StringUtils.isEmpty(sourceImage) && StringUtils.isEmpty(sourceImageFamily)) {
p.addProblem(Problem.Severity.ERROR, "Either source image or source image family must be specified for " + n.getBaseImage().getId() + ".");
}
if (!StringUtils.isEmpty(sourceImage)) {
int i = 0;
boolean[] foundSourceImageHolder = new boolean[1];
while (!foundSourceImageHolder[0] && i < credentialsList.size()) {
GoogleNamedAccountCredentials credentials = credentialsList.get(i);
List<String> imageProjects = Lists.newArrayList(credentials.getProject());
imageProjects.addAll(credentials.getImageProjects());
imageProjects.addAll(baseImageProjects);
Compute compute = credentials.getCompute();
BatchRequest imageListBatch = buildBatchRequest(compute);
JsonBatchCallback<ImageList> imageListCallback = new JsonBatchCallback<ImageList>() {
@Override
public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) throws IOException {
p.addProblem(Problem.Severity.ERROR, "Error locating " + sourceImage + " in these projects: " + imageProjects + ": " + e.getMessage() + ".");
}
@Override
public void onSuccess(ImageList imageList, HttpHeaders responseHeaders) throws IOException {
// No need to look through these images if the requested image was already found.
if (!foundSourceImageHolder[0]) {
if (imageList.getItems() != null) {
foundSourceImageHolder[0] = imageList.getItems().stream().filter(image -> image.getName().equals(sourceImage)).findFirst().isPresent();
}
}
}
};
try {
for (String imageProject : imageProjects) {
compute.images().list(imageProject).queue(imageListBatch, imageListCallback);
}
imageListBatch.execute();
} catch (IOException e) {
p.addProblem(Problem.Severity.ERROR, "Error locating " + sourceImage + " in these projects: " + imageProjects + ": " + e.getMessage() + ".");
}
i++;
}
if (!foundSourceImageHolder[0]) {
p.addProblem(Problem.Severity.ERROR, "Image " + sourceImage + " not found via any configured google account.");
}
}
if (!StringUtils.isEmpty(sourceImageFamily)) {
int i = 0;
boolean[] foundSourceImageFamilyHolder = new boolean[1];
while (!foundSourceImageFamilyHolder[0] && i < credentialsList.size()) {
GoogleNamedAccountCredentials credentials = credentialsList.get(i);
List<String> imageProjects = Lists.newArrayList(credentials.getProject());
imageProjects.addAll(credentials.getImageProjects());
imageProjects.addAll(baseImageProjects);
Compute compute = credentials.getCompute();
BatchRequest imageListBatch = buildBatchRequest(compute);
JsonBatchCallback<ImageList> imageListCallback = new JsonBatchCallback<ImageList>() {
@Override
public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) throws IOException {
p.addProblem(Problem.Severity.ERROR, "Error locating " + sourceImageFamily + " in these projects: " + imageProjects + ": " + e.getMessage() + ".");
}
@Override
public void onSuccess(ImageList imageList, HttpHeaders responseHeaders) throws IOException {
// No need to look through these images if the requested image family was already found.
if (!foundSourceImageFamilyHolder[0]) {
if (imageList.getItems() != null) {
foundSourceImageFamilyHolder[0] = imageList.getItems().stream().filter(image -> sourceImageFamily.equals(image.getFamily())).findFirst().isPresent();
}
}
}
};
try {
for (String imageProject : imageProjects) {
compute.images().list(imageProject).queue(imageListBatch, imageListCallback);
}
imageListBatch.execute();
} catch (IOException e) {
p.addProblem(Problem.Severity.ERROR, "Error locating " + sourceImageFamily + " in these projects: " + imageProjects + ": " + e.getMessage() + ".");
}
i++;
}
if (!foundSourceImageFamilyHolder[0]) {
p.addProblem(Problem.Severity.ERROR, "Image family " + sourceImageFamily + " not found via any configured google account.");
}
}
if (StringUtils.isEmpty(n.getBaseImage().getPackageType())) {
p.addProblem(Problem.Severity.ERROR, "Package type must be specified for " + n.getBaseImage().getId() + ".");
}
}
use of com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials in project halyard by spinnaker.
the class GoogleCanaryAccountValidator method validate.
@Override
public void validate(ConfigProblemSetBuilder p, AbstractCanaryAccount n) {
super.validate(p, n);
GoogleCanaryAccount canaryAccount = (GoogleCanaryAccount) n;
DaemonTaskHandler.message("Validating " + n.getNodeName() + " with " + GoogleCanaryAccountValidator.class.getSimpleName());
GoogleNamedAccountCredentials credentials = canaryAccount.getNamedAccountCredentials(halyardVersion, p);
if (credentials == null) {
return;
}
try {
Compute compute = credentials.getCompute();
compute.projects().get(canaryAccount.getProject()).execute();
} catch (IOException e) {
p.addProblem(Severity.ERROR, "Failed to load project \"" + canaryAccount.getProject() + "\": " + e.getMessage() + ".");
}
}
Aggregations