/** * Returns a new NetworkConfig instance and populates it from the specified JSON object * * @param jsonConfig The JSON object containing the config details * @return A populated NetworkConfig instance * @throws InvalidArgumentException */ private static NetworkConfig load(JsonObject jsonConfig) throws InvalidArgumentException, NetworkConfigurationException { // Sanity check if (jsonConfig == null) { throw new InvalidArgumentException("config must be specified"); } return new NetworkConfig(jsonConfig); }
private NetworkConfig(JsonObject jsonConfig) throws InvalidArgumentException, NetworkConfigurationException { this.jsonConfig = jsonConfig; // Extract the main details String configName = getJsonValueAsString(jsonConfig.get("name")); if (configName == null || configName.isEmpty()) { throw new InvalidArgumentException("Network config must have a name"); } String configVersion = getJsonValueAsString(jsonConfig.get("version")); if (configVersion == null || configVersion.isEmpty()) { throw new InvalidArgumentException("Network config must have a version"); // TODO: Validate the version } // Preload and create all peers, orderers, etc createAllPeers(); createAllOrderers(); Map<String, JsonObject> foundCertificateAuthorities = findCertificateAuthorities(); //createAllCertificateAuthorities(); createAllOrganizations(foundCertificateAuthorities); // Validate the organization for this client JsonObject jsonClient = getJsonObject(jsonConfig, "client"); String orgName = jsonClient == null ? null : getJsonValueAsString(jsonClient.get("organization")); if (orgName == null || orgName.isEmpty()) { throw new InvalidArgumentException("A client organization must be specified"); } clientOrganization = getOrganizationInfo(orgName); if (clientOrganization == null) { throw new InvalidArgumentException("Client organization " + orgName + " is not defined"); } }
String mspId = getJsonValueAsString(jsonOrg.get("mspid")); JsonArray jsonPeers = getJsonValueAsArray(jsonOrg.get("peers")); if (jsonPeers != null) { for (JsonValue peer : jsonPeers) { String peerName = getJsonValueAsString(peer); if (peerName != null) { org.addPeerName(peerName); JsonArray jsonCertificateAuthorities = getJsonValueAsArray(jsonOrg.get("certificateAuthorities")); if (jsonCertificateAuthorities != null) { for (JsonValue jsonCA : jsonCertificateAuthorities) { String caName = getJsonValueAsString(jsonCA); org.addCertificateAuthority(createCA(caName, jsonObject, org)); } else { throw new NetworkConfigurationException(format("%s: Certificate Authority %s is not defined", msgPrefix, caName)); String adminPrivateKeyString = extractPemString(jsonOrg, "adminPrivateKey", msgPrefix); String signedCert = extractPemString(jsonOrg, "signedCert", msgPrefix); privateKey = getPrivateKeyFromString(adminPrivateKeyString); } catch (IOException ioe) { throw new NetworkConfigurationException(format("%s: Invalid private key", msgPrefix), ioe);
private void createAllOrganizations(Map<String, JsonObject> foundCertificateAuthorities) throws NetworkConfigurationException { // Sanity check if (organizations != null) { throw new NetworkConfigurationException("INTERNAL ERROR: organizations has already been initialized!"); } organizations = new HashMap<>(); // organizations is a JSON object containing a nested object for each Org JsonObject jsonOrganizations = getJsonObject(jsonConfig, "organizations"); if (jsonOrganizations != null) { for (Entry<String, JsonValue> entry : jsonOrganizations.entrySet()) { String orgName = entry.getKey(); JsonObject jsonOrg = getJsonValueAsObject(entry.getValue()); if (jsonOrg == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid Organization entry: %s", orgName)); } OrgInfo org = createOrg(orgName, jsonOrg, foundCertificateAuthorities); organizations.put(orgName, org); } } }
Properties props = extractProperties(jsonNode, "grpcOptions"); getTLSCerts(nodeName, jsonNode, props);
private void createAllOrderers() throws NetworkConfigurationException { // Sanity check if (orderers != null) { throw new NetworkConfigurationException("INTERNAL ERROR: orderers has already been initialized!"); } orderers = new HashMap<>(); // orderers is a JSON object containing a nested object for each orderers JsonObject jsonOrderers = getJsonObject(jsonConfig, "orderers"); if (jsonOrderers != null) { for (Entry<String, JsonValue> entry : jsonOrderers.entrySet()) { String ordererName = entry.getKey(); JsonObject jsonOrderer = getJsonValueAsObject(entry.getValue()); if (jsonOrderer == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid orderer entry: %s", ordererName)); } Node orderer = createNode(ordererName, jsonOrderer, "url"); if (orderer == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid orderer entry: %s", ordererName)); } orderers.put(ordererName, orderer); } } }
private CAInfo createCA(String name, JsonObject jsonCA, OrgInfo org) throws NetworkConfigurationException { String url = getJsonValueAsString(jsonCA.get("url")); Properties httpOptions = extractProperties(jsonCA, "httpOptions"); List<JsonObject> registrars = getJsonValueAsList(jsonCA.get("registrar")); List<UserInfo> regUsers = new LinkedList<>(); if (registrars != null) { enrollId = getJsonValueAsString(reg.get("enrollId")); enrollSecret = getJsonValueAsString(reg.get("enrollSecret")); try { regUsers.add(new UserInfo(CryptoSuite.Factory.getCryptoSuite(), org.mspId, enrollId, enrollSecret)); String caName = getJsonValueAsString(jsonCA.get("caName")); if (caName != null) { caInfo.setCaName(caName); properties.setProperty("allowAllHostNames", "true"); getTLSCerts(name, jsonCA, properties); caInfo.setProperties(properties);
JsonObject jsonPeers = getJsonObject(jsonConfig, "peers"); String peerName = entry.getKey(); JsonObject jsonPeer = getJsonValueAsObject(entry.getValue()); if (jsonPeer == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid peer entry: %s", peerName)); Node peer = createNode(peerName, jsonPeer, "url"); if (peer == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid peer entry: %s", peerName)); Node eventHub = createNode(peerName, jsonPeer, "eventUrl"); // may not be present if (null != eventHub) { eventHubs.put(peerName, eventHub);
private CAInfo createCA(String name, JsonObject jsonCA, OrgInfo org) throws NetworkConfigurationException { String url = getJsonValueAsString(jsonCA.get("url")); Properties httpOptions = extractProperties(jsonCA, "httpOptions"); String enrollId = null; String enrollSecret = null; List<JsonObject> registrars = getJsonValueAsList(jsonCA.get("registrar")); List<UserInfo> regUsers = new LinkedList<>(); if (registrars != null) { for (JsonObject reg : registrars) { enrollId = getJsonValueAsString(reg.get("enrollId")); enrollSecret = getJsonValueAsString(reg.get("enrollSecret")); regUsers.add(new UserInfo(org.mspId, enrollId, enrollSecret)); } } CAInfo caInfo = new CAInfo(name, org.mspId, url, regUsers, httpOptions); String caName = getJsonValueAsString(jsonCA.get("caName")); if (caName != null) { caInfo.setCaName(caName); } Properties properties = new Properties(); if (null != httpOptions && "false".equals(httpOptions.getProperty("verify"))) { properties.setProperty("allowAllHostNames", "true"); } getTLSCerts(name, jsonCA, properties); caInfo.setProperties(properties); return caInfo; }
private void createAllOrganizations(Map<String, JsonObject> foundCertificateAuthorities) throws NetworkConfigurationException { // Sanity check if (organizations != null) { throw new NetworkConfigurationException("INTERNAL ERROR: organizations has already been initialized!"); } organizations = new HashMap<>(); // organizations is a JSON object containing a nested object for each Org JsonObject jsonOrganizations = getJsonObject(jsonConfig, "organizations"); if (jsonOrganizations != null) { for (Entry<String, JsonValue> entry : jsonOrganizations.entrySet()) { String orgName = entry.getKey(); JsonObject jsonOrg = getJsonValueAsObject(entry.getValue()); if (jsonOrg == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid Organization entry: %s", orgName)); } OrgInfo org = createOrg(orgName, jsonOrg, foundCertificateAuthorities); organizations.put(orgName, org); } } }
Properties props = extractProperties(jsonNode, "grpcOptions"); getTLSCerts(nodeName, jsonNode, props);
private NetworkConfig(JsonObject jsonConfig) throws InvalidArgumentException, NetworkConfigurationException { this.jsonConfig = jsonConfig; // Extract the main details String configName = getJsonValueAsString(jsonConfig.get("name")); if (configName == null || configName.isEmpty()) { throw new InvalidArgumentException("Network config must have a name"); } String configVersion = getJsonValueAsString(jsonConfig.get("version")); if (configVersion == null || configVersion.isEmpty()) { throw new InvalidArgumentException("Network config must have a version"); // TODO: Validate the version } // Preload and create all peers, orderers, etc createAllPeers(); createAllOrderers(); Map<String, JsonObject> foundCertificateAuthorities = findCertificateAuthorities(); //createAllCertificateAuthorities(); createAllOrganizations(foundCertificateAuthorities); // Validate the organization for this client JsonObject jsonClient = getJsonObject(jsonConfig, "client"); String orgName = jsonClient == null ? null : getJsonValueAsString(jsonClient.get("organization")); if (orgName == null || orgName.isEmpty()) { throw new InvalidArgumentException("A client organization must be specified"); } clientOrganization = getOrganizationInfo(orgName); if (clientOrganization == null) { throw new InvalidArgumentException("Client organization " + orgName + " is not defined"); } }
String mspId = getJsonValueAsString(jsonOrg.get("mspid")); JsonArray jsonPeers = getJsonValueAsArray(jsonOrg.get("peers")); if (jsonPeers != null) { for (JsonValue peer : jsonPeers) { String peerName = getJsonValueAsString(peer); if (peerName != null) { org.addPeerName(peerName); JsonArray jsonCertificateAuthorities = getJsonValueAsArray(jsonOrg.get("certificateAuthorities")); if (jsonCertificateAuthorities != null) { for (JsonValue jsonCA : jsonCertificateAuthorities) { String caName = getJsonValueAsString(jsonCA); org.addCertificateAuthority(createCA(caName, jsonObject, org)); } else { throw new NetworkConfigurationException(format("%s: Certificate Authority %s is not defined", msgPrefix, caName)); String adminPrivateKeyString = extractPemString(jsonOrg, "adminPrivateKey", msgPrefix); String signedCert = extractPemString(jsonOrg, "signedCert", msgPrefix); privateKey = getPrivateKeyFromString(adminPrivateKeyString); } catch (IOException ioe) { throw new NetworkConfigurationException(format("%s: Invalid private key", msgPrefix), ioe);
private void createAllOrderers() throws NetworkConfigurationException { // Sanity check if (orderers != null) { throw new NetworkConfigurationException("INTERNAL ERROR: orderers has already been initialized!"); } orderers = new HashMap<>(); // orderers is a JSON object containing a nested object for each orderers JsonObject jsonOrderers = getJsonObject(jsonConfig, "orderers"); if (jsonOrderers != null) { for (Entry<String, JsonValue> entry : jsonOrderers.entrySet()) { String ordererName = entry.getKey(); JsonObject jsonOrderer = getJsonValueAsObject(entry.getValue()); if (jsonOrderer == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid orderer entry: %s", ordererName)); } Node orderer = createNode(ordererName, jsonOrderer, "url"); if (orderer == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid orderer entry: %s", ordererName)); } orderers.put(ordererName, orderer); } } }
private CAInfo createCA(String name, JsonObject jsonCA, OrgInfo org) throws NetworkConfigurationException { String url = getJsonValueAsString(jsonCA.get("url")); Properties httpOptions = extractProperties(jsonCA, "httpOptions"); List<JsonObject> registrars = getJsonValueAsList(jsonCA.get("registrar")); List<UserInfo> regUsers = new LinkedList<>(); if (registrars != null) { enrollId = getJsonValueAsString(reg.get("enrollId")); enrollSecret = getJsonValueAsString(reg.get("enrollSecret")); try { regUsers.add(new UserInfo(CryptoSuite.Factory.getCryptoSuite(), org.mspId, enrollId, enrollSecret)); String caName = getJsonValueAsString(jsonCA.get("caName")); if (caName != null) { caInfo.setCaName(caName); properties.setProperty("allowAllHostNames", "true"); getTLSCerts(name, jsonCA, properties); caInfo.setProperties(properties);
private void createAllOrganizations(Map<String, JsonObject> foundCertificateAuthorities) throws NetworkConfigurationException { // Sanity check if (organizations != null) { throw new NetworkConfigurationException("INTERNAL ERROR: organizations has already been initialized!"); } organizations = new HashMap<>(); // organizations is a JSON object containing a nested object for each Org JsonObject jsonOrganizations = getJsonObject(jsonConfig, "organizations"); if (jsonOrganizations != null) { for (Entry<String, JsonValue> entry : jsonOrganizations.entrySet()) { String orgName = entry.getKey(); JsonObject jsonOrg = getJsonValueAsObject(entry.getValue()); if (jsonOrg == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid Organization entry: %s", orgName)); } OrgInfo org = createOrg(orgName, jsonOrg, foundCertificateAuthorities); organizations.put(orgName, org); } } }
Properties props = extractProperties(jsonNode, "grpcOptions"); getTLSCerts(nodeName, jsonNode, props);
/** * Returns a new NetworkConfig instance and populates it from the specified JSON object * * @param jsonConfig The JSON object containing the config details * @return A populated NetworkConfig instance * @throws InvalidArgumentException */ private static NetworkConfig load(JsonObject jsonConfig) throws InvalidArgumentException, NetworkConfigurationException { // Sanity check if (jsonConfig == null) { throw new InvalidArgumentException("config must be specified"); } return new NetworkConfig(jsonConfig); }
private NetworkConfig(JsonObject jsonConfig) throws InvalidArgumentException, NetworkConfigurationException { this.jsonConfig = jsonConfig; // Extract the main details String configName = getJsonValueAsString(jsonConfig.get("name")); if (configName == null || configName.isEmpty()) { throw new InvalidArgumentException("Network config must have a name"); } String configVersion = getJsonValueAsString(jsonConfig.get("version")); if (configVersion == null || configVersion.isEmpty()) { throw new InvalidArgumentException("Network config must have a version"); // TODO: Validate the version } // Preload and create all peers, orderers, etc createAllPeers(); createAllOrderers(); Map<String, JsonObject> foundCertificateAuthorities = findCertificateAuthorities(); //createAllCertificateAuthorities(); createAllOrganizations(foundCertificateAuthorities); // Validate the organization for this client JsonObject jsonClient = getJsonObject(jsonConfig, "client"); String orgName = jsonClient == null ? null : getJsonValueAsString(jsonClient.get("organization")); if (orgName == null || orgName.isEmpty()) { throw new InvalidArgumentException("A client organization must be specified"); } clientOrganization = getOrganizationInfo(orgName); if (clientOrganization == null) { throw new InvalidArgumentException("Client organization " + orgName + " is not defined"); } }
String mspId = getJsonValueAsString(jsonOrg.get("mspid")); JsonArray jsonPeers = getJsonValueAsArray(jsonOrg.get("peers")); if (jsonPeers != null) { for (JsonValue peer : jsonPeers) { String peerName = getJsonValueAsString(peer); if (peerName != null) { org.addPeerName(peerName); JsonArray jsonCertificateAuthorities = getJsonValueAsArray(jsonOrg.get("certificateAuthorities")); if (jsonCertificateAuthorities != null) { for (JsonValue jsonCA : jsonCertificateAuthorities) { String caName = getJsonValueAsString(jsonCA); org.addCertificateAuthority(createCA(caName, jsonObject, org)); } else { throw new NetworkConfigurationException(format("%s: Certificate Authority %s is not defined", msgPrefix, caName)); String adminPrivateKeyString = extractPemString(jsonOrg, "adminPrivateKey", msgPrefix); String signedCert = extractPemString(jsonOrg, "signedCert", msgPrefix); privateKey = getPrivateKeyFromString(adminPrivateKeyString); } catch (IOException ioe) { throw new NetworkConfigurationException(format("%s: Invalid private key", msgPrefix), ioe);