Search in sources :

Example 1 with GoogleNamedAccountCredentials

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();
}
Also used : ConfigProblemSetBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) GoogleNamedAccountCredentials(com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials)

Example 2 with GoogleNamedAccountCredentials

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));
}
Also used : GoogleBaseImage(com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleBaseImage) GoogleNamedAccountCredentials(com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials)

Example 3 with GoogleNamedAccountCredentials

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.");
        }
    }
}
Also used : Compute(com.google.api.services.compute.Compute) IOException(java.io.IOException) GoogleNamedAccountCredentials(com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials)

Example 4 with GoogleNamedAccountCredentials

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() + ".");
    }
}
Also used : GoogleNamedAccountCredentials(com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials) HttpHeaders(com.google.api.client.http.HttpHeaders) GoogleJsonError(com.google.api.client.googleapis.json.GoogleJsonError) GoogleBaseImage(com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleBaseImage) IOException(java.io.IOException) HttpRequest(com.google.api.client.http.HttpRequest) ImageList(com.google.api.services.compute.model.ImageList) EqualsAndHashCode(lombok.EqualsAndHashCode) ConfigProblemSetBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder) List(java.util.List) Lists(com.google.common.collect.Lists) Validator(com.netflix.spinnaker.halyard.config.model.v1.node.Validator) Data(lombok.Data) Problem(com.netflix.spinnaker.halyard.core.problem.v1.Problem) JsonBatchCallback(com.google.api.client.googleapis.batch.json.JsonBatchCallback) BatchRequest(com.google.api.client.googleapis.batch.BatchRequest) Compute(com.google.api.services.compute.Compute) StringUtils(org.springframework.util.StringUtils) BatchRequest(com.google.api.client.googleapis.batch.BatchRequest) HttpHeaders(com.google.api.client.http.HttpHeaders) JsonBatchCallback(com.google.api.client.googleapis.batch.json.JsonBatchCallback) IOException(java.io.IOException) GoogleNamedAccountCredentials(com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials) ImageList(com.google.api.services.compute.model.ImageList) Compute(com.google.api.services.compute.Compute) GoogleJsonError(com.google.api.client.googleapis.json.GoogleJsonError)

Example 5 with GoogleNamedAccountCredentials

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() + ".");
    }
}
Also used : Compute(com.google.api.services.compute.Compute) IOException(java.io.IOException) GoogleCanaryAccount(com.netflix.spinnaker.halyard.config.model.v1.canary.google.GoogleCanaryAccount) GoogleNamedAccountCredentials(com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials)

Aggregations

GoogleNamedAccountCredentials (com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials)5 Compute (com.google.api.services.compute.Compute)3 IOException (java.io.IOException)3 GoogleBaseImage (com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleBaseImage)2 ConfigProblemSetBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder)2 BatchRequest (com.google.api.client.googleapis.batch.BatchRequest)1 JsonBatchCallback (com.google.api.client.googleapis.batch.json.JsonBatchCallback)1 GoogleJsonError (com.google.api.client.googleapis.json.GoogleJsonError)1 HttpHeaders (com.google.api.client.http.HttpHeaders)1 HttpRequest (com.google.api.client.http.HttpRequest)1 ImageList (com.google.api.services.compute.model.ImageList)1 Lists (com.google.common.collect.Lists)1 GoogleCanaryAccount (com.netflix.spinnaker.halyard.config.model.v1.canary.google.GoogleCanaryAccount)1 Validator (com.netflix.spinnaker.halyard.config.model.v1.node.Validator)1 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)1 Problem (com.netflix.spinnaker.halyard.core.problem.v1.Problem)1 List (java.util.List)1 Data (lombok.Data)1 EqualsAndHashCode (lombok.EqualsAndHashCode)1 StringUtils (org.springframework.util.StringUtils)1