List of usage examples for com.amazonaws.util IOUtils toString
public static String toString(InputStream is) throws IOException
From source file:AbstractAmazonKinesisFirehoseDelivery.java
License:Open Source License
/** * Method to read the resource for the given filename. * * @param name the file name/*from w w w. j a v a2s .c o m*/ * @return the input stream as string */ private static String readResource(String name) { try { return IOUtils.toString(AmazonKinesisFirehoseToRedshiftSample.class.getResourceAsStream(name)); } catch (IOException e) { throw new RuntimeException("Failed to read document resource: " + name, e); } }
From source file:com.forerunnergames.peril.client.application.ClientApplicationProperties.java
License:Open Source License
private static void fixUrisInPropertiesFile() { String propertiesFile;//from w w w. jav a 2s . com try (final FileInputStream in = new FileInputStream(PROPERTIES_FILE_PATH_AND_NAME)) { propertiesFile = IOUtils.toString(in); // Replace escaped colon characters in property value URI's, e.g., http\://example.com => http://example.com propertiesFile = propertiesFile.replace("\\://", "://"); } catch (final IOException e) { log.error("Failed to fix URI's in \"{}\".\n\nDetails:\n\n", PROPERTIES_FILE_PATH_AND_NAME, e); return; } // Re-write the properties file with the URI fix in place. try (final FileOutputStream out = new FileOutputStream(PROPERTIES_FILE_PATH_AND_NAME)) { out.write(propertiesFile.getBytes(Charsets.UTF_8)); } catch (final IOException e) { log.error("Failed to fix URI's in \"{}\".\n\nDetails:\n\n", PROPERTIES_FILE_PATH_AND_NAME, e); } }
From source file:com.netflix.spinnaker.echo.artifacts.MessageArtifactTranslator.java
License:Apache License
public MessageArtifactTranslator(InputStream templateStream) { if (templateStream == null) { this.jinjaTemplate = ""; } else {//from ww w. j a v a 2s.c o m try { this.jinjaTemplate = IOUtils.toString(templateStream); } catch (IOException ioe) { throw new RuntimeException(ioe); } } }
From source file:com.netflix.spinnaker.halyard.config.spinnaker.v1.component.SpinnakerComponent.java
License:Apache License
/** * @return the base config (typically found in a component's ./halconfig/ directory) for * the version of the component specified by the Spinnaker version in the loaded halconfig. *///from w w w. j a v a2 s . co m protected String getBaseConfig() { Halconfig currentConfig = parser.getConfig(true); NodeReference nodeReference = new NodeReference().setDeployment(currentConfig.getCurrentDeployment()); DeploymentConfiguration deploymentConfiguration = deploymentService .getDeploymentConfiguration(nodeReference); String version = deploymentConfiguration.getVersion(); if (version == null || version.isEmpty()) { throw new IllegalConfigException(new ProblemBuilder(Problem.Severity.FATAL, "In order to load a Spinnaker Component's profile, you must specify a version of Spinnaker in your halconfig") .build()); } String componentName = getComponentName(); String configFileName = getConfigFileName(); try { String bomName = "bom/" + version + ".yml"; BillOfMaterials bom = objectMapper.convertValue(yamlParser.load(getObjectContents(bomName)), BillOfMaterials.class); String componentVersion = bom.getServices().getComponentVersion(componentName); String componentObjectName = componentName + "/" + componentVersion + "/" + configFileName; return IOUtils.toString(getObjectContents(componentObjectName)); } catch (RetrofitError | IOException e) { throw new HalconfigException(new ProblemBuilder(Problem.Severity.FATAL, "Unable to retrieve a profile for \"" + componentName + "\": " + e.getMessage()).build()); } }
From source file:com.netflix.spinnaker.halyard.config.validate.v1.providers.dockerRegistry.DockerRegistryAccountValidator.java
License:Apache License
@Override public void validate(ProblemSetBuilder p, DockerRegistryAccount n) { String resolvedPassword = null; String password = n.getPassword(); String passwordFile = n.getPasswordFile(); String username = n.getUsername(); boolean passwordProvided = password != null && !password.isEmpty(); boolean passwordFileProvided = passwordFile != null && !passwordFile.isEmpty(); if (passwordProvided && passwordFileProvided) { p.addProblem(Severity.ERROR, "You have provided both a password and a password file for your docker registry. You can specify at most one."); return;//from w w w .j ava 2 s .c om } try { if (passwordProvided) { resolvedPassword = password; } else if (passwordFileProvided) { resolvedPassword = IOUtils.toString(new FileInputStream(passwordFile)); if (resolvedPassword.isEmpty()) { p.addProblem(Severity.WARNING, "The supplied password file is empty."); } } else { resolvedPassword = ""; } } catch (FileNotFoundException e) { p.addProblem(Severity.ERROR, "Cannot find provided password file: " + e.getMessage() + "."); } catch (IOException e) { p.addProblem(Severity.ERROR, "Error reading provided password file: " + e.getMessage() + "."); } if (resolvedPassword != null && !resolvedPassword.isEmpty()) { String message = "Your registry password has %s whitespace; if this is unintentional, authentication may fail."; if (Character.isWhitespace(resolvedPassword.charAt(0))) { p.addProblem(Severity.WARNING, String.format(message, "leading")); } if (Character.isWhitespace(resolvedPassword.charAt(resolvedPassword.length() - 1))) { p.addProblem(Severity.WARNING, String.format(message, "trailing")); } if (username == null || username.isEmpty()) { p.addProblem(Severity.WARNING, "You have supplied a password but no username."); } } else { if (username != null && !username.isEmpty()) { p.addProblem(Severity.WARNING, "You have a supplied a username but no password."); } } DockerRegistryNamedAccountCredentials credentials; try { credentials = (new DockerRegistryNamedAccountCredentials.Builder()).accountName(n.getName()) .address(n.getAddress()).email(n.getEmail()).password(n.getPassword()) .passwordFile(n.getPasswordFile()).dockerconfigFile(n.getDockerconfigFile()) .username(n.getUsername()).build(); } catch (Exception e) { p.addProblem(Severity.ERROR, "Failed to instantiate docker credentials for account \"" + n.getName() + "\"."); return; } try { credentials.getCredentials().getClient().checkV2Availability(); } catch (Exception e) { p.addProblem(Severity.ERROR, "Failed to assert docker registry v2 availability for registry \"" + n.getName() + "\" at address " + n.getAddress() + ": " + e.getMessage() + ".") .setRemediation("Make sure that the " + credentials.getV2Endpoint() + " is reachable, and that your credentials are correct."); } try { if (n.getRepositories() == null || n.getRepositories().size() == 0) { DockerRegistryCatalog catalog = credentials.getCredentials().getClient().getCatalog(); if (catalog.getRepositories() == null || catalog.getRepositories().size() == 0) { p.addProblem(Severity.ERROR, "Your docker registry has no repositories specified, and the registry's catalog is empty.") .setRemediation( "Manually specify some repositories for this docker registry to index."); } } } catch (Exception e) { p.addProblem(Severity.ERROR, "Unable to connect the registries catalog endpoint: " + e.getMessage() + ".") .setRemediation("Manually specify some repositories for this docker registry to index."); } }
From source file:com.netflix.spinnaker.halyard.config.validate.v1.providers.google.GoogleAccountValidator.java
License:Apache License
@Override public void validate(ProblemSetBuilder p, GoogleAccount n) { String jsonKey = null;/*from w w w .j av a 2 s . c o m*/ String jsonPath = n.getJsonPath(); String project = n.getProject(); GoogleNamedAccountCredentials credentials = null; try { if (jsonPath != null && !jsonPath.isEmpty()) { jsonKey = IOUtils.toString(new FileInputStream(n.getJsonPath())); if (jsonKey.isEmpty()) { p.addProblem(Severity.WARNING, "The supplied credentials file is empty."); } } } catch (FileNotFoundException e) { p.addProblem(Severity.ERROR, "Json path not found: " + e.getMessage() + "."); } catch (IOException e) { p.addProblem(Severity.ERROR, "Error opening specified json path: " + e.getMessage() + "."); } if (project == null || project.isEmpty()) { p.addProblem(Severity.ERROR, "No google project supplied."); return; } try { credentials = new GoogleNamedAccountCredentials.Builder().jsonKey(jsonKey).project(n.getProject()) .computeVersion(n.isAlphaListed() ? ComputeVersion.ALPHA : ComputeVersion.DEFAULT) .imageProjects(n.getImageProjects()).applicationName("halyard " + halyardVersion).build(); } catch (Exception e) { p.addProblem(Severity.ERROR, "Error instantiating Google credentials: " + e.getMessage() + "."); return; } try { credentials.getCompute().projects().get(project); for (String imageProject : n.getImageProjects()) { credentials.getCompute().projects().get(imageProject); } } catch (IOException e) { p.addProblem(Severity.ERROR, "Failed to load project \"" + n.getProject() + "\": " + e.getMessage() + "."); } }
From source file:com.netflix.spinnaker.halyard.config.validate.v1.util.ValidatingFileReader.java
License:Apache License
public static String contents(ConfigProblemSetBuilder ps, String path) { String noAccessRemediation = "Halyard is running as user " + System.getProperty("user.name") + ". Make sure that user can read the requested file."; try {/*from ww w .ja v a 2 s .com*/ return IOUtils.toString(new FileInputStream(path)); } catch (FileNotFoundException e) { ConfigProblemBuilder problemBuilder = ps.addProblem(Problem.Severity.FATAL, "Cannot find provided path: " + e.getMessage() + "."); if (e.getMessage().contains("denied")) { problemBuilder.setRemediation(noAccessRemediation); } return null; } catch (IOException e) { ConfigProblemBuilder problemBuilder = ps.addProblem(Problem.Severity.FATAL, "Failed to read path \"" + path + "\": " + e.getMessage() + "."); if (e.getMessage().contains("denied")) { problemBuilder.setRemediation(noAccessRemediation); } return null; } }
From source file:com.netflix.spinnaker.halyard.core.resource.v1.JarResource.java
License:Apache License
@Override protected String getContents() { InputStream contents = getClass().getResourceAsStream(path); if (contents == null) { throw new IllegalArgumentException("Path " + path + " could not be found in the JAR"); }/*from w ww . j a va2s .c o m*/ try { return IOUtils.toString(contents); } catch (IOException e) { throw new RuntimeException("Path " + path + " could not be opened", e); } }
From source file:com.netflix.spinnaker.halyard.deploy.provider.v1.kubernetes.KubernetesProviderInterface.java
License:Apache License
private void upsertSecret(AccountDeploymentDetails<KubernetesAccount> details, Set<String> files, String secretName, String namespace) { KubernetesClient client = getClient(details.getAccount()); createNamespace(client, namespace);/*from w ww.j ava 2s . co m*/ if (client.secrets().inNamespace(namespace).withName(secretName).get() != null) { client.secrets().inNamespace(namespace).withName(secretName).delete(); } Map<String, String> secretContents = new HashMap<>(); files.forEach(s -> { try { File f = new File(s); String name = f.getName(); String data = new String( Base64.getEncoder().encode(IOUtils.toString(new FileInputStream(f)).getBytes())); secretContents.putIfAbsent(name, data); } catch (IOException e) { throw new HalException( new ConfigProblemBuilder(Severity.ERROR, "Unable to read contents of \"" + s + "\": " + e) .build()); } }); SecretBuilder secretBuilder = new SecretBuilder(); secretBuilder = secretBuilder.withNewMetadata().withName(secretName).withNamespace(namespace).endMetadata() .withData(secretContents); log.info("Staging secret " + secretName + " in namespace " + namespace + " with contents " + files); client.secrets().inNamespace(namespace).create(secretBuilder.build()); }
From source file:com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService.java
License:Apache License
public void writeBom(String bomPath) { if (googleWriteableProfileRegistry == null) { throw new HalException(FATAL, NO_WRITER_ENABLED); }//from w ww . j av a 2 s .c om BillOfMaterials bom; String bomContents; String version; try { bomContents = IOUtils.toString(new FileInputStream(bomPath)); bom = relaxedObjectMapper.convertValue(yamlParser.load(bomContents), BillOfMaterials.class); version = bom.getVersion(); } catch (IOException e) { throw new HalException( new ConfigProblemBuilder(FATAL, "Unable to load Bill of Materials: " + e.getMessage()).build()); } if (version == null) { throw new HalException(new ConfigProblemBuilder(FATAL, "No version was supplied in this BOM.").build()); } googleWriteableProfileRegistry.writeBom(bom.getVersion(), bomContents); }