use of org.yaml.snakeyaml.Yaml in project fabric-sdk-java by hyperledger.
the class NetworkConfig method fromYamlStream.
/**
* Creates a new NetworkConfig instance configured with details supplied in YAML format
*
* @param configStream A stream opened on a YAML document containing network configuration details
* @return A new NetworkConfig instance
* @throws InvalidArgumentException
*/
public static NetworkConfig fromYamlStream(InputStream configStream) throws InvalidArgumentException, NetworkConfigurationException {
logger.trace("NetworkConfig.fromYamlStream...");
// Sanity check
if (configStream == null) {
throw new InvalidArgumentException("configStream must be specified");
}
Yaml yaml = new Yaml();
@SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) yaml.load(configStream);
JsonObjectBuilder builder = Json.createObjectBuilder(map);
JsonObject jsonConfig = builder.build();
return fromJsonObject(jsonConfig);
}
use of org.yaml.snakeyaml.Yaml in project fabric-sdk-java by hyperledger.
the class ChaincodeEndorsementPolicy method fromYamlFile.
/**
* From a yaml file
*
* @param yamlPolicyFile File location for the chaincode endorsement policy specification.
* @throws IOException
* @throws ChaincodeEndorsementPolicyParseException
*/
public void fromYamlFile(File yamlPolicyFile) throws IOException, ChaincodeEndorsementPolicyParseException {
final Yaml yaml = new Yaml();
final Map<?, ?> load = (Map<?, ?>) yaml.load(new FileInputStream(yamlPolicyFile));
Map<?, ?> mp = (Map<?, ?>) load.get("policy");
if (null == mp) {
throw new ChaincodeEndorsementPolicyParseException("The policy file has no policy section");
}
IndexedHashMap<String, MSPPrincipal> identities = parseIdentities((Map<?, ?>) load.get("identities"));
SignaturePolicy sp = parsePolicy(identities, mp);
policyBytes = Policies.SignaturePolicyEnvelope.newBuilder().setVersion(0).addAllIdentities(identities.values()).setRule(sp).build().toByteArray();
}
use of org.yaml.snakeyaml.Yaml in project jmx_exporter by prometheus.
the class JmxCollector method reloadConfig.
private void reloadConfig() {
try {
FileReader fr = new FileReader(configFile);
try {
Map<String, Object> newYamlConfig = (Map<String, Object>) new Yaml().load(fr);
config = loadConfig(newYamlConfig);
config.lastUpdate = configFile.lastModified();
configReloadSuccess.inc();
} catch (Exception e) {
LOGGER.severe("Configuration reload failed: " + e.toString());
configReloadFailure.inc();
} finally {
fr.close();
}
} catch (IOException e) {
LOGGER.severe("Configuration reload failed: " + e.toString());
configReloadFailure.inc();
}
}
use of org.yaml.snakeyaml.Yaml in project LogHub by fbacchella.
the class Parser method initialize.
private void initialize(InputStream regexYaml) {
Yaml yaml = new Yaml(new SafeConstructor());
@SuppressWarnings("unchecked") Map<String, List<Map<String, String>>> regexConfig = (Map<String, List<Map<String, String>>>) yaml.load(regexYaml);
List<Map<String, String>> uaParserConfigs = regexConfig.get("user_agent_parsers");
if (uaParserConfigs == null) {
throw new IllegalArgumentException("user_agent_parsers is missing from yaml");
}
uaParser = UserAgentParser.fromList(uaParserConfigs);
List<Map<String, String>> osParserConfigs = regexConfig.get("os_parsers");
if (osParserConfigs == null) {
throw new IllegalArgumentException("os_parsers is missing from yaml");
}
osParser = OSParser.fromList(osParserConfigs);
List<Map<String, String>> deviceParserConfigs = regexConfig.get("device_parsers");
if (deviceParserConfigs == null) {
throw new IllegalArgumentException("device_parsers is missing from yaml");
}
deviceParser = DeviceParser.fromList(deviceParserConfigs);
}
use of org.yaml.snakeyaml.Yaml in project fabric8 by fabric8io.
the class Controller method convertYamlToJson.
private String convertYamlToJson(String yamlString) throws FileNotFoundException {
Yaml yaml = new Yaml();
Map<String, Object> map = (Map<String, Object>) yaml.load(yamlString);
JSONObject jsonObject = new JSONObject(map);
return jsonObject.toString();
}
Aggregations