Skip to content

Commit

Permalink
Support put token in common amqp base.
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyvercolano committed Mar 23, 2017
1 parent bd8b733 commit 5e5c4a5
Show file tree
Hide file tree
Showing 16 changed files with 992 additions and 147 deletions.
47 changes: 43 additions & 4 deletions common/transport/amqp/devdoc/amqp_requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ A string containing the version of the SDK used for telemetry purposes**]**
### connect(done)
Establishes a connection using the AMQP protocol with the IoT Hub instance.
**SRS_NODE_COMMON_AMQP_06_001: [** The connect method shall accept 3 parameters:
**SRS_NODE_COMMON_AMQP_06_001: [** The `connect` method shall accept 3 parameters:
A uri that will be used for the connection.
A possibly undefined sslOptions structure.
A done callback.
**]**
**SRS_NODE_COMMON_AMQP_06_002: [** The connect method shall throw a ReferenceError if the uri parameter has not been supplied.**]**
**SRS_NODE_COMMON_AMQP_06_002: [** The `connect` method shall throw a ReferenceError if the uri parameter has not been supplied.**]**
**SRS_NODE_COMMON_AMQP_16_002: [**The connect method shall establish a connection with the IoT hub instance and if given as argument call the `done` callback with a null error object in the case of success and a `results.Connected` object.**]**
**SRS_NODE_COMMON_AMQP_16_002: [**The `connect` method shall establish a connection with the IoT hub instance and if given as argument call the `done` callback with a null error object in the case of success and a `results.Connected` object.**]**
**SRS_NODE_COMMON_AMQP_16_003: [**If given as an argument, the connect method shall call the `done` callback with a standard `Error` object if the connection fails.**]**
**SRS_NODE_COMMON_AMQP_16_003: [**If given as an argument, the connect method shall call the `done` callback with a standard `Error` object if the connection or link/listener establishment fails.**]**
### disconnect(done)
Expand Down Expand Up @@ -117,5 +117,44 @@ Configures an AmqpReceiver object to use the endpoint passed as a parameter and
**SRS_NODE_COMMON_AMQP_16_030: [** The `detachReceiverLink` method shall call the `done` callback with no arguments if the link for this endpoint doesn't exist. **]**
**SRS_NODE_COMMON_AMQP_16_031: [** The `detachReceiverLink` method shall call the `done` callback with an `Error` object if there was an error while detaching the link. **]**

# putToken(audience, token, putTokenCallback)

**SRS_NODE_COMMON_AMQP_06_016: [** The `putToken` method shall throw a ReferenceError if the `audience` argument is falsy. **]**
**SRS_NODE_COMMON_AMQP_06_017: [** The `putToken` method shall throw a ReferenceError if the `token` argument is falsy. **]**
**SRS_NODE_COMMON_AMQP_06_018: [** The `putToken` method shall call the `putTokenCallback` callback (if provided) with a `NotConnectedError` object if the amqp client is not connected when the method is called. **]**
**SRS_NODE_COMMON_AMQP_06_022: [** The `putToken` method shall call the `putTokenCallback` callback (if provided) with a `NotConnectedError` object if the `initializeCBS` has NOT been invoked. **]**
**SRS_NODE_COMMON_AMQP_06_005: [** The `putToken` method shall construct an amqp message that contains the following application properties:
'operation': 'put-token'
'type': 'servicebus.windows.net:sastoken'
'name': <audience>

and system properties of

'to': '$cbs'
'messageId': <uuid>
'reply_to': 'cbs'

and a body containing <sasToken>. **]**

**SRS_NODE_COMMON_AMQP_06_015: [** The `putToken` method shall send this message over the `$cbs` sender link. **]**
**SRS_NODE_COMMON_AMQP_06_006: [** The `putToken` method shall call `putTokenCallback` (if supplied) if the `send` generates an error such that no response from the service will be forthcoming. **]**
**SRS_NODE_COMMON_AMQP_06_007: [** The `putToken` method will time out the put token operation if no response is returned within a configurable number of seconds. **]**
**SRS_NODE_COMMON_AMQP_06_008: [** The `putToken` method will invoke the `putTokenCallback` (if supplied) with an error object if the put token operation timed out. **]**

#initializeCBS(initializeCBSCallback)

**SRS_NODE_COMMON_AMQP_06_021: [** If given as an argument, the `initializeCBS` method shall call `initializeCBSCallback` with a `NotConnectedError` object if amqp client is not connnected. **]**
**SRS_NODE_COMMON_AMQP_06_009: [** The `initializeCBS` method shall establish a sender link to the `$cbs` endpoint for sending put token operations, utilizing a custom policy `{encoder: function(body) { return body;}}` which forces the amqp layer to send the token as an amqp value in the body. **]**
**SRS_NODE_COMMON_AMQP_06_010: [** The `initializeCBS` method shall establish a receiver link to the cbs endpoint. **]**
**SRS_NODE_COMMON_AMQP_06_011: [** The `initializeCBS` method shall set up a listener for responses to put tokens. **]**
**SRS_NODE_COMMON_AMQP_06_019: [** If given as an argument, the `initializeCBS` method shall call `initializeCBSCallback` with a standard `Error` object if the link/listener establishment fails. **]**
**SRS_NODE_COMMON_AMQP_06_020: [** If given as an argument, the `initializeCBS` method shall call `initializeCBSCallback` with a null error object if successful. **]**
# $cbs listener
**SRS_NODE_COMMON_AMQP_06_013: [** A put token response of 200 will invoke `putTokenCallback` with null parameters. **]**
**SRS_NODE_COMMON_AMQP_06_014: [** A put token response not equal to 200 will invoke `putTokenCallback` with an error object of UnauthorizedError. **]**
**SRS_NODE_COMMON_AMQP_06_012: [** All responses shall be completed. **]**
### All methods
**SRS_NODE_COMMON_AMQP_16_011: [** All methods should treat the `done` callback argument as optional and not throw if it is not passed as argument. **]**
Loading

0 comments on commit 5e5c4a5

Please sign in to comment.