How to use the azure-iot-http-base.RestApiClient function in azure-iot-http-base

To help you get started, we’ve selected a few azure-iot-http-base examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-iot-sdk-node / device / core / src / iotedge_authentication_provider.ts View on Github external
if (!this._authConfig.generationId) {
      throw new ReferenceError('_authConfig.generationId cannot be \'' + this._authConfig.generationId + '\'');
    }

    // Codes_SRS_NODE_IOTEDGED_AUTHENTICATION_PROVIDER_13_005: [ The constructor shall throw a TypeError if the _authConfig.workloadUri field is not a valid URI. ]
    // Codes_SRS_NODE_IOTEDGED_AUTHENTICATION_PROVIDER_13_006: [ The constructor shall build a unix domain socket path host if the workload URI protocol is unix. ]
    // Codes_SRS_NODE_IOTEDGED_AUTHENTICATION_PROVIDER_13_007: [ The constructor shall build a string host if the workload URI protocol is not unix. ]
    this._workloadUri = url.parse(this._authConfig.workloadUri);
    const config: RestApiClient.TransportConfig = {
      host: this._workloadUri.protocol === 'unix:' ? { socketPath: this._workloadUri.pathname } : this._workloadUri.hostname
    };

    // TODO: The user agent string below needs to be constructed using the utils.getUserAgentString function.
    // But that is an async function and since we can't do async things while initializing fields, one way to
    // handle this might be to make this._restApiClient a lazily initialized object.
    this._restApiClient = new RestApiClient(config, `${packageJson.name}/${packageJson.version}`);
  }
github lcarli / NodeRedIoTHub / node_modules / azure-iothub / lib / registry.js View on Github external
function Registry(config, 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 || !config.sharedAccessSignature) {
            /*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 ArgumentError('The \'config\' argument is missing either the host or the sharedAccessSignature property');
        }
        this._config = config;
        /*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 azure_iot_http_base_1.RestApiClient(config, packageJson.name + '/' + packageJson.version);
    }
    /**
github Azure / azure-iot-sdk-node / provisioning / service / src / provisioningserviceclient.ts View on Github external
constructor(config: RestApiClient.TransportConfig, restApiClient?: RestApiClient) {
    if (!config) {
      /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_001: [The `ProvisioningServiceClient` construction shall throw a `ReferenceError` if the `config` object is falsy.] */
      throw new ReferenceError('The \'config\' parameter cannot be \'' + config + '\'');
    } else if (!config.host || !config.sharedAccessSignature) {
      /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_002: [The `ProvisioningServiceClient` constructor shall throw an `ArgumentError` 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 ArgumentError('The \'config\' argument is missing either the host or the sharedAccessSignature property');
    }
    this._config = config;

    /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_003: [The `ProvisioningServiceClient` constructor shall use the `restApiClient` provided as a second argument if it is provided.] */
    /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_004: [The `ProvisioningServiceClient` constructor shall use `azure-iot-http-base.RestApiClient` if no `restApiClient` argument is provided.] */
    this._restApiClient = restApiClient || new RestApiClient(config, packageJson.name + '/' + packageJson.version);
  }
github Azure / azure-iot-sdk-node / service / src / job_client.ts View on Github external
static fromSharedAccessSignature(sharedAccessSignature: string): JobClient {
    /*Codes_SRS_NODE_JOB_CLIENT_16_004: [The `fromSharedAccessSignature` method shall throw a `ReferenceError` if `sharedAccessSignature` is falsy.]*/
    if (!sharedAccessSignature) throw new ReferenceError('sharedAccessSignature cannot be \'' + sharedAccessSignature + '\'');

    const sas = SharedAccessSignature.parse(sharedAccessSignature);
    const config = {
      host: sas.sr,
      sharedAccessSignature: sharedAccessSignature
    };

    /*Codes_SRS_NODE_JOB_CLIENT_16_005: [The `fromSharedAccessSignature` method shall return a new `JobClient` instance.]*/
    return new JobClient(new RestApiClient(config, packageJson.name + '/' + packageJson.version));
  }
}
github Azure / azure-iot-sdk-node / provisioning / transport / http / src / http.ts View on Github external
private _ensureRestApiClient(request: RegistrationRequest): void {
    if (!this._restApiClient) {
      this._restApiClient = new RestApiClient({ 'host' : request.provisioningHost , 'x509' : this._auth}, ProvisioningDeviceConstants.userAgent, this._httpBase);
    }
  }
github Azure / azure-iot-sdk-node / service / src / job_client.ts View on Github external
static fromConnectionString(connectionString: string): JobClient {
    /*Codes_SRS_NODE_JOB_CLIENT_16_002: [The `fromConnectionString` method shall throw a `ReferenceError` if `connectionString` is falsy.]*/
    if (!connectionString) throw new ReferenceError('connectionString cannot be \'' + connectionString + '\'');
    const cn = ConnectionString.parse(connectionString);
    const sas = SharedAccessSignature.create(cn.HostName, cn.SharedAccessKeyName, cn.SharedAccessKey, anHourFromNow());
    const config = {
      host: cn.HostName,
      sharedAccessSignature: sas.toString()
    };

    /*Codes_SRS_NODE_JOB_CLIENT_16_003: [The `fromConnectionString` method shall return a new `JobClient` instance.]*/
    return new JobClient(new RestApiClient(config, packageJson.name + '/' + packageJson.version));
  }
github lcarli / NodeRedIoTHub / node_modules / azure-iothub / lib / client.js View on Github external
if (!connStr)
            throw new ReferenceError('connStr is \'' + connStr + '\'');
        /*Codes_SRS_NODE_IOTHUB_CLIENT_16_016: [The `fromConnectionString` method shall use the `Transport` constructor passed as argument to instantiate a transport object if it's not falsy.]*/
        /*Codes_SRS_NODE_IOTHUB_CLIENT_16_017: [The `fromConnectionString` method shall use the default Transport (Amqp) if the `Transport` optional argument is falsy.]*/
        if (!transportCtor) {
            transportCtor = amqp_1.Amqp;
        }
        /*Codes_SRS_NODE_IOTHUB_CLIENT_16_015: [The `fromConnectionString` method shall create a new transport instance and pass it a config object formed from the connection string given as argument.]*/
        var cn = ConnectionString.parse(connStr);
        var config = {
            host: cn.HostName,
            keyName: cn.SharedAccessKeyName,
            sharedAccessSignature: azure_iot_common_1.SharedAccessSignature.create(cn.HostName, cn.SharedAccessKeyName, cn.SharedAccessKey, azure_iot_common_1.anHourFromNow())
        };
        /*Codes_SRS_NODE_IOTHUB_CLIENT_05_004: [The fromConnectionString method shall return a new instance of the Client object, as by a call to new Client(transport).]*/
        return new Client(new transportCtor(config), new azure_iot_http_base_1.RestApiClient(config, packageJson.name + '/' + packageJson.version));
    };
    /**
github Azure / azure-iot-sdk-node / device / core / src / device_method / method_client.ts View on Github external
getUserAgentString((userAgentString) => {
            const transportConfig: RestApiClient.TransportConfig = {
              host: creds.gatewayHostName,
              sharedAccessSignature: creds.sharedAccessSignature
            };

            this._restApiClient = new RestApiClient(transportConfig, userAgentString);
            callback();
          });
        }

azure-iot-http-base

HTTP operations used by Azure IoT device and service SDKs

MIT
Latest version published 2 years ago

Package Health Score

54 / 100
Full package analysis

Popular azure-iot-http-base functions

Similar packages