public BenderSchema(File schemaFile) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerSubtypes(BenderConfig.subtypes); try { this.schema = objectMapper.readTree(schemaFile); } catch (IOException e) { throw new ConfigurationException("unable to load schema file", e); } }
} catch (ConfigurationException e) { System.out.println("Invalid"); e.printStackTrace(); hasFailures = true;
public BenderSchema(File schemaFile) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerSubtypes(BenderConfig.subtypes); try { this.schema = objectMapper.readTree(schemaFile); } catch (IOException e) { throw new ConfigurationException("unable to load schema file", e); } }
public Subtypes() { long start = System.nanoTime(); try { subtypes.addAll(ClassScanner.getSubtypes(abstractConfigClasses)); } catch (InterruptedException | ExecutionException e) { throw new ConfigurationException("unable to find config classes", e); } logger.debug( "Generating config subtype list took " + ((System.nanoTime() - start) / 1000000) + "ms"); /* * Sort the subtypes so that the order is deterministic. Without this locally generated * schemas differ in order from those generated by CircleCI. */ subtypes.sort(new Comparator<Class>() { @Override public int compare(Class o1, Class o2) { return o1.getName().compareToIgnoreCase(o2.getName()); } }); }
public Subtypes() { long start = System.nanoTime(); try { subtypes.addAll(ClassScanner.getSubtypes(abstractConfigClasses)); } catch (InterruptedException | ExecutionException e) { throw new ConfigurationException("unable to find config classes", e); } logger.debug( "Generating config subtype list took " + ((System.nanoTime() - start) / 1000000) + "ms"); /* * Sort the subtypes so that the order is deterministic. Without this locally generated * schemas differ in order from those generated by CircleCI. */ subtypes.sort(new Comparator<Class>() { @Override public int compare(Class o1, Class o2) { return o1.getName().compareToIgnoreCase(o2.getName()); } }); }
public static BenderConfig load(String filename, String data, ObjectMapper mapper, boolean validate) { String swappedData = swapEnvironmentVariables(data); if (validate) { BenderConfig.validate(swappedData, mapper); } BenderConfig config = null; try { config = mapper.readValue(swappedData, BenderConfig.class); } catch (IOException e) { throw new ConfigurationException("invalid config file", e); } return config; }
public static BenderConfig load(String filename, String data, ObjectMapper mapper, boolean validate) { String swappedData = swapEnvironmentVariables(data); if (validate) { BenderConfig.validate(swappedData, mapper); } BenderConfig config = null; try { config = mapper.readValue(swappedData, BenderConfig.class); } catch (IOException e) { throw new ConfigurationException("invalid config file", e); } return config; }
throw new ConfigurationException("unable to find " + resource); data = IOUtils.toString(new InputStreamReader(url.openStream(), "UTF-8")); } catch (NullPointerException | IOException e) { throw new ConfigurationException("unable to read " + resource, e);
throw new ConfigurationException("unable to find " + resource); data = IOUtils.toString(new InputStreamReader(url.openStream(), "UTF-8")); } catch (NullPointerException | IOException e) { throw new ConfigurationException("unable to read " + resource, e);
public String getValue() { if (this.value == null) { return value; } /* * Ensure that the value is only decrypted once regardless of usage. This prevents KMS from * being called over and over from within the function to decrypt the same field. */ if (!this.decrypted) { try { this.value = Passwords.decrypt(this.value, Region.getRegion(this.region)); } catch (UnsupportedEncodingException e) { throw new ConfigurationException("Unable to decrypt", e); } this.decrypted = true; } return this.value; }
return this.schema; } catch (Exception e) { throw new ConfigurationException("unable generate schema");
return this.schema; } catch (Exception e) { throw new ConfigurationException("unable generate schema");
public String getValue() { if (this.value == null) { return value; } /* * Ensure that the value is only decrypted once regardless of usage. This prevents KMS from * being called over and over from within the function to decrypt the same field. */ if (!this.decrypted) { try { this.value = Passwords.decrypt(this.value, Region.getRegion(this.region)); } catch (UnsupportedEncodingException e) { throw new ConfigurationException("Unable to decrypt", e); } this.decrypted = true; } return this.value; }
public static BenderConfig load(AmazonS3ClientFactory s3ClientFactory, AmazonS3URI s3Uri) { AmazonS3Client s3 = s3ClientFactory.newInstance(); S3Object s3object = s3.getObject(s3Uri.getBucket(), s3Uri.getKey()); StringWriter writer = new StringWriter(); try { IOUtils.copy(s3object.getObjectContent(), writer, "UTF-8"); } catch (IOException e) { throw new ConfigurationException("Unable to read file from s3", e); } BenderConfig config = load(s3Uri.getKey().toString(), writer.toString()); config.setConfigFile(s3Uri.getURI().toString()); return config; }
public static BenderConfig load(AmazonS3ClientFactory s3ClientFactory, AmazonS3URI s3Uri) { AmazonS3Client s3 = s3ClientFactory.newInstance(); S3Object s3object = s3.getObject(s3Uri.getBucket(), s3Uri.getKey()); StringWriter writer = new StringWriter(); try { IOUtils.copy(s3object.getObjectContent(), writer, "UTF-8"); } catch (IOException e) { throw new ConfigurationException("Unable to read file from s3", e); } BenderConfig config = load(s3Uri.getKey().toString(), writer.toString()); config.setConfigFile(s3Uri.getURI().toString()); return config; }
/** * Parses an input String and replaces instances of {@literal <XXX>}" with the value of the XXX OS * Environment Variable. This is used as a pre-parser for the Config files, allowing environment * variables to be swapped at run-time. * * @param raw A raw string (not necessarily valid configuration data) * @return A parsed string with OS variables swapped in * @throws ConfigurationException If any discovered {@literal <WRAPPED_VALUES>} are not found in * System.getenv(). */ public static String swapEnvironmentVariables(String raw) throws ConfigurationException { ErrorBuffer errors = new ErrorBuffer(); ST template = new ST(raw); STGroup g = template.groupThatCreatedThisInstance; g.setListener(errors); Map<String, String> env = System.getenv(); for (String envName : env.keySet()) { if (envName.contains(".")) { logger.warn("skipping " + envName + " because it contains '.' which is not allowed"); continue; } template.add(envName, env.get(envName)); } String parsed = template.render(); if (errors.errors.size() > 0) { throw new ConfigurationException(errors.toString()); } return parsed; }
/** * Parses an input String and replaces instances of {@literal <XXX>}" with the value of the XXX OS * Environment Variable. This is used as a pre-parser for the Config files, allowing environment * variables to be swapped at run-time. * * @param raw A raw string (not necessarily valid configuration data) * @return A parsed string with OS variables swapped in * @throws ConfigurationException If any discovered {@literal <WRAPPED_VALUES>} are not found in * System.getenv(). */ public static String swapEnvironmentVariables(String raw) throws ConfigurationException { ErrorBuffer errors = new ErrorBuffer(); ST template = new ST(raw); STGroup g = template.groupThatCreatedThisInstance; g.setListener(errors); Map<String, String> env = System.getenv(); for (String envName : env.keySet()) { if (envName.contains(".")) { logger.warn("skipping " + envName + " because it contains '.' which is not allowed"); continue; } template.add(envName, env.get(envName)); } String parsed = template.render(); if (errors.errors.size() > 0) { throw new ConfigurationException(errors.toString()); } return parsed; }
public static boolean validate(String data, ObjectMapper objectMapper, BenderSchema benderSchema) throws ConfigurationException { ProcessingReport report; try { /* * Create object */ JsonNode node = objectMapper.readTree(data); /* * Create JSON schema */ JsonNode jsonSchema = benderSchema.getSchema(); /* * Validate */ final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); final JsonSchema schema = factory.getJsonSchema(jsonSchema); report = schema.validate(node); } catch (IOException | ProcessingException ioe) { throw new ConfigurationException("unable to validate config", ioe); } if (report.isSuccess()) { return true; } else { throw new ConfigurationException("invalid config file", report.iterator().next().asException()); } }
public static boolean validate(String data, ObjectMapper objectMapper, BenderSchema benderSchema) throws ConfigurationException { ProcessingReport report; try { /* * Create object */ JsonNode node = objectMapper.readTree(data); /* * Create JSON schema */ JsonNode jsonSchema = benderSchema.getSchema(); /* * Validate */ final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); final JsonSchema schema = factory.getJsonSchema(jsonSchema); report = schema.validate(node); } catch (IOException | ProcessingException ioe) { throw new ConfigurationException("unable to validate config", ioe); } if (report.isSuccess()) { return true; } else { throw new ConfigurationException("invalid config file", report.iterator().next().asException()); } }
@Override public void setConf(AbstractConfig config) { this.config = (GeoIpOperationConfig) config; AmazonS3Client client = this.s3Factory.newInstance(); AmazonS3URI uri = new AmazonS3URI(this.config.getGeoLiteDb()); GetObjectRequest req = new GetObjectRequest(uri.getBucket(), uri.getKey()); S3Object obj = client.getObject(req); try { this.databaseReader = new DatabaseReader.Builder(obj.getObjectContent()).withCache(new CHMCache()).build(); } catch (IOException e) { throw new ConfigurationException("Unable to read " + this.config.getGeoLiteDb(), e); } } }