constructor()

in src/registry.ts [46:68]


  constructor(config: Registry.TransportConfig, restApiClient?: RestApiClient) {
    if (!config) {
      /*Codes_SRS_NODE_IOTHUB_REGISTRY_16_023: [The `Registry` constructor shall throw a `ReferenceError` if the config object is falsy.]*/
      throw new ReferenceError('The \'config\' parameter cannot be \'' + config + '\'');
    } else if (!config.host) {
      /*SRS_NODE_IOTHUB_REGISTRY_05_001: [** The `Registry` constructor shall throw an `ArgumentException` if the config object is missing one or more of the following properties:
      - `host`: the IoT Hub hostname
      - `sharedAccessSignature`: shared access signature with the permissions for the desired operations.]*/
      throw new errors.ArgumentError('The \'config\' argument is missing either the host property');
    } else if ((!config.sharedAccessSignature) && (!config.tokenCredential)) {
      throw new errors.ArgumentError('The \'config\' argument is missing either the sharedAccessSignature or the tokenCredential property');
    } else if ((config.sharedAccessSignature) && (config.tokenCredential)) {
      throw new errors.ArgumentError('The \'config\' argument has both the sharedAccessSignature and the tokenCredential property defined');
    }

    /*SRS_NODE_IOTHUB_REGISTRY_16_024: [The `Registry` constructor shall use the `restApiClient` provided as a second argument if it is provided.]*/
    /*SRS_NODE_IOTHUB_REGISTRY_16_025: [The `Registry` constructor shall use `azure-iothub.RestApiClient` if no `restApiClient` argument is provided.]*/
    // This httpRequestBuilder parameter is used only for unit-testing purposes and should not be used in other situations.
    this._restApiClient = restApiClient || new RestApiClient(config, packageJson.name + '/' + packageJson.version);
    if (this._restApiClient.setOptions) {
      this._restApiClient.setOptions({ http: { agent: new Agent({ keepAlive: true }) } });
    }
  }