public RawConfigurationBuilder withContents(String content, String sha256) { rawConfig.setContents(content, sha256); return this; }
/** * Creates a deep copy of this object that includes all of the properties except for the parent configuration. If * the <code>keepId</code> flag is <code>false</code>, then the id property is not copied. * * @param keepId A flag indicating whether or not the id should be copied * @return A copy of this object */ public RawConfiguration deepCopy(boolean keepId) { RawConfiguration copy = new RawConfiguration(); if (keepId) { copy.id = this.id; } copy.path = this.path; if (this.contents != null) { copy.setContents(this.getContents(), this.getSha256()); } copy.errorMessage = this.errorMessage; return copy; }
private void mergedStructuredIntoRaws(Configuration configuration, ResourceConfigurationFacet facet) { Set<RawConfiguration> rawConfigs = facet.loadRawConfigurations(); if (rawConfigs == null) { return; } prepareConfigForMergeIntoRaws(configuration, rawConfigs); Queue<RawConfiguration> queue = new LinkedList<RawConfiguration>(rawConfigs); while (!queue.isEmpty()) { RawConfiguration originalRaw = queue.poll(); RawConfiguration mergedRaw = facet.mergeRawConfiguration(configuration, originalRaw); if (mergedRaw != null) { //TODO bypass validation of structured config for template values String contents = mergedRaw.getContents(); String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents); mergedRaw.setContents(contents, sha256); updateRawConfig(configuration, originalRaw, mergedRaw); } } }
public void mergeRawConfig(Configuration from, RawConfiguration existingConfig, RawConfiguration toUpdate) throws Exception { Augeas aug = null; try { String lens = configMap.get(existingConfig.getPath()); aug = createAugeas(lens, existingConfig.getContents()); String file = getFile(aug); for (String pathSuffix : nodePaths.get(existingConfig.getPath())) { String propName = ("/files" + existingConfig.getPath() + "/" + pathSuffix).substring(rootNodePath .length()); String propValue = translator.getPropertyValue(propName, from); aug.set("/files" + file + "/" + pathSuffix, propValue); } aug.save(); toUpdate.setPath(existingConfig.getPath()); String contents = FileUtils.readFileToString(new File(file)); String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents); toUpdate.setContents(contents, sha256); } finally { if (aug != null) { aug.close(); } } }
private void mergeRawsIntoStructured(Configuration configuration, ResourceConfigurationFacet facet) { Configuration structuredConfig = facet.loadStructuredConfiguration(); if (structuredConfig != null) { prepareConfigForMergeIntoStructured(configuration, structuredConfig); for (RawConfiguration rawConfig : configuration.getRawConfigurations()) { String contents = rawConfig.getContents(); String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents); rawConfig.setContents(contents, sha256); structuredConfig.addRawConfiguration(rawConfig); facet.mergeStructuredConfiguration(rawConfig, configuration); } } }