@JsonIgnore public GoogleNamedAccountCredentials getNamedAccountCredentials(String version, ConfigProblemSetBuilder p) { String jsonKey = null; if (!StringUtils.isEmpty(getJsonPath())) { jsonKey = ValidatingFileReader.contents(p, getJsonPath()); if (jsonKey == null) { return null; } else if (jsonKey.isEmpty()) { p.addProblem(Problem.Severity.WARNING, "The supplied credentials file is empty."); } } if (StringUtils.isEmpty(getProject())) { p.addProblem(Problem.Severity.ERROR, "No google project supplied."); return null; } try { return new GoogleNamedAccountCredentials.Builder() .jsonKey(jsonKey) .project(getProject()) .computeVersion(isAlphaListed() ? ComputeVersion.ALPHA : ComputeVersion.DEFAULT) .imageProjects(getImageProjects()) .applicationName("halyard " + version) .liveLookupsEnabled(false) .build(); } catch (Exception e) { p.addProblem(Problem.Severity.ERROR, "Error instantiating Google credentials: " + e.getMessage() + ".") .setRemediation("Do the provided credentials have access to project " + getProject() + "?"); return null; } }
@JsonIgnore public GoogleNamedAccountCredentials getNamedAccountCredentials(String version, ConfigProblemSetBuilder p) { String jsonKey = null; if (!StringUtils.isEmpty(getJsonPath())) { jsonKey = ValidatingFileReader.contents(p, getJsonPath()); if (jsonKey == null) { return null; } else if (jsonKey.isEmpty()) { p.addProblem(Problem.Severity.WARNING, "The supplied credentials file is empty."); } } if (StringUtils.isEmpty(getProject())) { p.addProblem(Problem.Severity.ERROR, "No google project supplied."); return null; } try { return new GoogleNamedAccountCredentials.Builder() .jsonKey(jsonKey) .project(getProject()) .computeVersion(isAlphaListed() ? ComputeVersion.ALPHA : ComputeVersion.DEFAULT) .imageProjects(getImageProjects()) .applicationName("halyard " + version) .liveLookupsEnabled(false) .build(); } catch (Exception e) { p.addProblem(Problem.Severity.ERROR, "Error instantiating Google credentials: " + e.getMessage() + ".") .setRemediation("Do the provided credentials have access to project " + getProject() + "?"); return null; } }
@Override protected Account editAccount(GoogleAccount account) { account.setJsonPath(isSet(jsonPath) ? jsonPath : account.getJsonPath()); account.setProject(isSet(project) ? project : account.getProject()); account.setAlphaListed(alphaListed != null ? alphaListed : account.isAlphaListed()); try { account.setImageProjects( updateStringList(account.getImageProjects(), imageProjects, addImageProject, removeImageProject)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Set either --image-projects or --[add/remove]-image-project"); } try { account.setRegions( updateStringList(account.getRegions(), regions, addRegion, removeRegion)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Set either --regions or --[add/remove]-region"); } return account; } }
@Override protected Account editAccount(GoogleAccount account) { account.setJsonPath(isSet(jsonPath) ? jsonPath : account.getJsonPath()); account.setProject(isSet(project) ? project : account.getProject()); account.setAlphaListed(alphaListed != null ? alphaListed : account.isAlphaListed()); account.setUserDataFile(userDataFile != null ? userDataFile : account.getUserDataFile()); try { account.setImageProjects( updateStringList(account.getImageProjects(), imageProjects, addImageProject, removeImageProject)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Set either --image-projects or --[add/remove]-image-project"); } try { account.setRegions( updateStringList(account.getRegions(), regions, addRegion, removeRegion)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Set either --regions or --[add/remove]-region"); } return account; } }