Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
for (let index = 0; index < propsCount; index++) {
const item = props.getItem(index);
if (!!item) {
/*Codes_SRS_NODE_IOTHUB_AMQPMSG_16_013: [If one of the property key is `IoThub-status`, this property is reserved and shall be forced to an `int` `rhea` type.]*/
const val = (item.key === 'IoThub-status') ? rheaTypes.wrap_int(parseInt(item.value)) : item.value;
amqpMessage.application_properties[item.key] = val;
}
}
}
}
/*Codes_SRS_NODE_IOTHUB_AMQPMSG_05_005: [If message.getData() is truthy, the AmqpMessage object shall have a property named body with the value returned from message.getData().]*/
const body = message.getData();
if (body !== undefined) {
amqpMessage.body = rheaMessage.data_section(message.getBytes());
}
/*Codes_SRS_NODE_IOTHUB_AMQPMSG_05_006: [The generated AmqpMessage object shall be returned to the caller.]*/
return amqpMessage;
}
let requestMessage = new AmqpMessage();
/*Codes_SRS_NODE_PROVISIONING_AMQP_06_003: [ The `registrationRequest` will send a body in the message which contains a stringified JSON object with a `registrationId` property.] */
let requestBody: DeviceRegistration = {registrationId: request.registrationId};
/*Codes_SRS_NODE_PROVISIONING_AMQP_06_004: [The `registrationRequest` will, if utilizing TPM attestation, send a `tpm` property with the endorsement and storage key in the JSON body.] */
if (this._endorsementKey) {
requestBody.tpm = {endorsementKey: this._endorsementKey.toString('base64')};
if (this._storageRootKey) {
requestBody.tpm.storageRootKey = this._storageRootKey.toString('base64');
}
}
/*Codes_SRS_NODE_PROVISIONING_AMQP_06_005: [The `registrationRequest` will, if utilizing custom allocation data, send a `payload` property in the JSON body.] */
if (request.payload) {
requestBody.payload = request.payload;
}
requestMessage.body = rheaMessage.data_section(Buffer.from(JSON.stringify(requestBody)));
requestMessage.application_properties = {};
requestMessage.application_properties[MessagePropertyNames.OperationType] = DeviceOperations.Register;
requestMessage.application_properties[MessagePropertyNames.ForceRegistration] = !!request.forceRegistration;
requestMessage.correlation_id = correlationId;
debug('initial registration request: ' + JSON.stringify(requestMessage));
this._operations[requestMessage.correlation_id] = callback;
this._senderLink.send(requestMessage, (err) => {
if (err) {
delete this._operations[requestMessage.correlation_id];
const translatedError = translateError('registration failure', err);
/*Codes_SRS_NODE_PROVISIONING_AMQP_06_007: [If the `registrationRequest` send request is rejected with an `InternalError` or `ThrottlingError`, the result.status value will be set with `registering` and the callback will be invoked with *no* error object.] */
if ((translatedError instanceof errors.InternalServerError) || ((translatedError as AmqpTransportError) instanceof errors.ThrottlingError)) {
debug('retryable error on registration: ' + err.name);
let retryAfterInMilliseconds: number;
/*Codes_SRS_NODE_PROVISIONING_AMQP_06_009: [If the `registrationRequest` rejection error contains the info property`retry-after`, it will be interpreted as the number of seconds that should elapse before the next attempted operation. Otherwise default.] */