Skip to content

Commit

Permalink
Merge commit 'e8c5be157770e2db3aad3dd024553f82cfdbbf2d' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
Azure IoT Builder committed Nov 15, 2017
2 parents d544d8c + e8c5be1 commit f069a58
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 40 deletions.
10 changes: 5 additions & 5 deletions provisioning/service/devdoc/provisioningserviceclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,19 @@ GET /registrations/<uri-encoded-id>?api-version=<version> HTTP/1.1
Authorization: <sharedAccessSignature>
``` **]**
### runBulkOperation(bulkOperation, bulkOperationCallback)
The `runBulkOperation` can perform CRUD operations on IndividualEnrollment objects in bulk.
### runBulkEnrollmentOperation(bulkEnrollmentOperation, bulkEnrollmentOperationCallback)
The `runBulkEnrollmentOperation` can perform CRUD operations on IndividualEnrollment objects in bulk.
**SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_038: [** The `runBulkOperation` method shall throw `ReferenceError` if the `bulkOperation` argument is falsy. **]**
**SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_038: [** The `runBulkEnrollmentOperation` method shall throw `ReferenceError` if the `bulkEnrollmentOperation` argument is falsy. **]**
**SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_039: [** The `runBulkOperation` method shall construct an HTTP request using information supplied by the caller as follows:
**SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_039: [** The `runBulkEnrollmentOperation` method shall construct an HTTP request using information supplied by the caller as follows:
```
POST /enrollments?api-version=<version> HTTP/1.1
Authorization: <sharedAccessSignature>
Accept: application/json
Content-Type: application/json; charset=utf-8

<stringified json string of the bulkOperation argument>
<stringified json string of the bulkEnrollmentOperation argument>
``` **]**
### Generic HTTP Requirements
Expand Down
16 changes: 8 additions & 8 deletions provisioning/service/samples/run_bulk_operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ badCreateBulkOperation.enrollments.push(enrollment2);
badCreateBulkOperation.enrollments.push(enrollment2);

//
// runBulkOperation has two different ways that errors can be indicated to the
// runBulkEnrollmentOperation has two different ways that errors can be indicated to the
// caller. The err parameter on the callback or through the result parameter
// on the callback.
//
// This first runBulkOperation will fail. The reason it fails is because we have
// a duplicate entry in the bulk array. This will NOT produce a BulkOperationResult.
// This first runBulkEnrollmentOperation will fail. The reason it fails is because we have
// a duplicate entry in the bulk array. This will NOT produce a BulkEnrollmentOperationResult.
//
serviceClient.runBulkOperation(badCreateBulkOperation, function(err, result) {
serviceClient.runBulkEnrollmentOperation(badCreateBulkOperation, function(err, result) {
if (err) {
console.log('The bulk operation result is: ' + err);
}
console.log('The value of the result operation should be undefined: ',JSON.stringify(result, null, 2));
//
// Get rid of the duplicate entry and put in an entry without an actual attestation.
// Some of the bulk create will work but we should get a BulkOperationResult
// Some of the bulk create will work but we should get a BulkEnrollmentOperationResult
// that indicates the third one failed.
//
badCreateBulkOperation.enrollments.splice(2,1);
badCreateBulkOperation.enrollments.push(enrollment3);
serviceClient.runBulkOperation(badCreateBulkOperation, function(err, result) {
serviceClient.runBulkEnrollmentOperation(badCreateBulkOperation, function(err, result) {
console.log('The err parameter should be null for this second bulkOperation call, err: ' + err);
console.log('The value of the result operation should indicate the third enrollment was bad: ' + JSON.stringify(result, null, 2));
serviceClient.getIndividualEnrollment(enrollment1.registrationId, function(err, completeEnrollment1) {
Expand All @@ -84,8 +84,8 @@ serviceClient.runBulkOperation(badCreateBulkOperation, function(err, result) {
};
deleteBulkOperation.enrollments.push(completeEnrollment1);
deleteBulkOperation.enrollments.push(completeEnrollment2);
serviceClient.runBulkOperation(deleteBulkOperation, function(err, result) {
console.log('The err parameter should be null for this delete runBulkOperation call, err: ' + err);
serviceClient.runBulkEnrollmentOperation(deleteBulkOperation, function(err, result) {
console.log('The err parameter should be null for this delete runBulkEnrollmentOperation call, err: ' + err);
console.log('The value of the result operation should indicate success and no errors: ' + JSON.stringify(result, null, 2));
});
}
Expand Down
30 changes: 23 additions & 7 deletions provisioning/service/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export interface X509Attestation {
* suitable for signing other certificates.
*/
signingCertificates: X509Certificates;
/**
* Primary and secondary CA reference. These will be names rather than
* actual certificates.
*/
caReferences: X509CAReferences;
}

/**
Expand Down Expand Up @@ -145,10 +150,21 @@ export interface X509Certificates {
secondary: X509CertificateWithInfo;
}

export interface X509CAReferences {
/**
* The name of the primary CA certificate.
*/
primary: string;
/**
* The name of the secondary CA certificate.
*/
secondary: string;
}

/**
* Bulk operation
*/
export interface BulkOperation {
export interface BulkEnrollmentOperation {
/**
* The mode property specifies the operation that will be performed upon all
* of the IndividualEnrollment elements in the enrollments property.
Expand All @@ -171,7 +187,7 @@ export type BulkOperationMode = 'create' | 'update' | 'updateIfMatchEtag' | 'del
/**
* Bulk operation result
*/
export interface BulkOperationResult {
export interface BulkEnrollmentOperationResult {
/**
* If isSuccessful is true then all CRUD operations for a bulkOperation
* were successful. Otherwise there will be at least one element in the
Expand All @@ -180,7 +196,7 @@ export interface BulkOperationResult {
isSuccessful: boolean;
/**
* Will provide information as to why particular CRUD operations failed for
* a runBulkOperation invocation. The array will be zero length if
* a runBulkEnrollmentOperation invocation. The array will be zero length if
* isSuccessful is true.
*/
errors: Array<DeviceRegistrationOperationError>;
Expand All @@ -191,7 +207,7 @@ export interface BulkOperationResult {
*/
export interface DeviceRegistrationOperationError {
/**
* The id of the the IndividualEnrollment object that was in error during a runBulkOperation invocation.
* The id of the the IndividualEnrollment object that was in error during a runBulkEnrollmentOperation invocation.
*/
registrationId: string;
/**
Expand Down Expand Up @@ -284,7 +300,7 @@ export interface IndividualEnrollment {
/**
* The initial twin document that will be created for this device upon its provisioning.
*/
initialTwinState: TwinState;
initialTwin: InitialTwin;
/**
* An opaque value suitable to uniquely identify a particular generation
* of this object for use during a CRUD operation.
Expand Down Expand Up @@ -332,7 +348,7 @@ export interface EnrollmentGroup {
/**
* The initial twin document that will be created for devices upon their provisioning.
*/
initialTwinState: TwinState;
initialTwin: InitialTwin;
/**
* An opaque value suitable to uniquely identify a particular generation
* of this object for use during a CRUD operation.
Expand Down Expand Up @@ -372,7 +388,7 @@ export interface TwinCollection {
/**
* Device twin state.
*/
export interface TwinState {
export interface InitialTwin {
tags: TwinCollection;
properties: {
desired: TwinCollection;
Expand Down
22 changes: 11 additions & 11 deletions provisioning/service/src/provisioningserviceclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { errors, SharedAccessSignature, ConnectionString } from 'azure-iot-common';
import { RestApiClient } from 'azure-iot-http-base';
import { QuerySpecification, Query, QueryCallback } from './query';
import { IndividualEnrollment, EnrollmentGroup, DeviceRegistrationState, BulkOperation, BulkOperationResult } from './interfaces';
import { IndividualEnrollment, EnrollmentGroup, DeviceRegistrationState, BulkEnrollmentOperation, BulkEnrollmentOperationResult } from './interfaces';

// tslint:disable-next-line:no-var-requires
const packageJson = require('../package.json');
Expand Down Expand Up @@ -147,15 +147,15 @@ export class ProvisioningServiceClient {
}

/**
* @method module:azure-iot-provisioning-service.ProvisioningServiceClient#runBulkOperation
* @method module:azure-iot-provisioning-service.ProvisioningServiceClient#runBulkEnrollmentOperation
* @description Runs a number CRUD operations on an array of enrollment records.
* @param {object} bulkOperation An object that specifies the single kind of CRUD operations on the array of IndividualEnrollment objects that are also part of the object.
* @param {object} bulkEnrollmentOperation An object that specifies the single kind of CRUD operations on the array of IndividualEnrollment objects that are also part of the object.
* @param {function} callback Invoked upon completion of the operation.
*/
public runBulkOperation(bulkOperation: BulkOperation, callback?: (err: Error, bulkOperationResult?: BulkOperationResult, response?: any) => void): void {
/*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_038: [The `runBulkOperation` method shall throw `ReferenceError` if the `bulkOperation` argument is falsy.] */
if (!bulkOperation) {
throw new ReferenceError('Required runBulkOperation property was null or undefined when calling bulkOperation.');
public runBulkEnrollmentOperation(bulkEnrollmentOperation: BulkEnrollmentOperation, callback?: (err: Error, bulkEnrollmentOperationResult?: BulkEnrollmentOperationResult, response?: any) => void): void {
/*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_038: [The `runBulkEnrollmentOperation` method shall throw `ReferenceError` if the `bulkEnrollmentOperation` argument is falsy.] */
if (!bulkEnrollmentOperation) {
throw new ReferenceError('Required bulkEnrollmentOperation parameter was falsy when calling runBulkEnrollmentOperation.');
}

const path = this._enrollmentsPrefix + this._versionQueryString();
Expand All @@ -165,20 +165,20 @@ export class ProvisioningServiceClient {
'Content-Type': 'application/json; charset=utf-8'
};

/*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_039: [** The `runBulkOperation` method shall construct an HTTP request using information supplied by the caller as follows:
/*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_039: [** The `runBulkEnrollmentOperation` method shall construct an HTTP request using information supplied by the caller as follows:
POST /enrollments?api-version=<version> HTTP/1.1
Authorization: <sharedAccessSignature>
Accept: application/json
Content-Type: application/json; charset=utf-8
<stringified json string of the bulkOperation argument>
<stringified json string of the bulkEnrollmentOperation argument>
] */
this._restApiClient.executeApiCall('POST', path, httpHeaders, bulkOperation, (err, bulkOperationResult, httpResponse) => {
this._restApiClient.executeApiCall('POST', path, httpHeaders, bulkEnrollmentOperation, (err, bulkEnrollmentOperationResult, httpResponse) => {
if (callback) {
if (err) {
callback(err);
} else {
callback(null, bulkOperationResult, httpResponse);
callback(null, bulkEnrollmentOperationResult, httpResponse);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion provisioning/service/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Query {
if (err) {
actualCallback(err);
} else {
this.continuationToken = response.headers['x-ms-continuation'];
this.continuationToken = response.headers['x-ms-continuation'] as string;
this.hasMoreResults = this.continuationToken !== undefined;

/*Codes_SRS_NODE_SERVICE_QUERY_16_007: [The `next` method shall call the `done` callback with a `null` error object, the results of the query and the response of the underlying transport if the request was successful.]*/
Expand Down
16 changes: 8 additions & 8 deletions provisioning/service/test/_provisioningserviceclient_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,24 +474,24 @@ describe('ProvisioningServiceClient', function() {
testGetAPI('getDeviceRegistrationState', '/registrations/');


describe('#runBulkOperation', function() {
/*Tests_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_038: [The `runBulkOperation` method shall throw `ReferenceError` if the `bulkOperation` argument is falsy.] */
describe('#runBulkEnrollmentOperation', function() {
/*Tests_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_038: [The `runBulkEnrollmentOperation` method shall throw `ReferenceError` if the `bulkEnrollmentOperation` argument is falsy.] */
[undefined, null].forEach(function(bo) {
testFalsyArg('runBulkOperation', 'bulkOperation', bo, ReferenceError);
testFalsyArg('runBulkEnrollmentOperation', 'bulkEnrollmentOperation', bo, ReferenceError);
});

var fakeBo = {mode: 'update', enrollments: [fakeEnrollment]};
testErrorCallback('runBulkOperation', fakeBo);
testErrorCallback('runBulkEnrollmentOperation', fakeBo);

/*Tests_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_039: [** The `runBulkOperation` method shall construct an HTTP request using information supplied by the caller as follows:
/*Tests_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_039: [** The `runBulkEnrollmentOperation` method shall construct an HTTP request using information supplied by the caller as follows:
POST /enrollments?api-version=<version> HTTP/1.1
Authorization: <sharedAccessSignature>
Accept: application/json
Content-Type: application/json; charset=utf-8
<stringified json string of the bulkOperation argument>
<stringified json string of the bulkEnrollmentOperation argument>
] */
it('Constructs a valid HTTP request for bulkOperation parameter', function(testCallback) {
it('Constructs a valid HTTP request for bulkEnrollmentOperation parameter', function(testCallback) {
var fakeHttpHelper = {
executeApiCall: function (method, path, httpHeaders, body, done) {
assert.equal(method, 'POST');
Expand All @@ -505,7 +505,7 @@ describe('ProvisioningServiceClient', function() {
};

var de = new ProvisioningServiceClient({ host: 'host', sharedAccessSignature: 'sas' }, fakeHttpHelper);
de.runBulkOperation(fakeBo, testCallback);
de.runBulkEnrollmentOperation(fakeBo, testCallback);
});
});
});

0 comments on commit f069a58

Please sign in to comment.