Skip to content

Commit 0dcbd0b

Browse files
author
aws
committed
Release of Version 1.7.0
1 parent 726d610 commit 0dcbd0b

File tree

75 files changed

+39874
-6378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+39874
-6378
lines changed

aws-greengrass-core-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aws-greengrass-core-sdk",
3-
"version": "1.6.1",
3+
"version": "1.7.0",
44
"main": "index.js",
55
"dependencies": {
66
"cbor": "5.0.1"

aws-greengrass-core-sdk/secretsmanager.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const KEY_VERSION_STAGE = 'VersionStage';
1313
const KEY_SECRET_ARN = 'ARN';
1414
const KEY_SECRET_NAME = 'Name';
1515
const KEY_CREATED_DATE = 'CreatedDate';
16+
const KEY_JSON_RESULT_FLAG = 'DeStringifyResultFlag';
1617

1718
const { envVars } = GreengrassCommon;
1819
const { SECRETS_MANAGER_FUNCTION_ARN } = envVars;
@@ -38,14 +39,14 @@ class SecretsManager {
3839
*
3940
* @callback secretsManagerCallback
4041
* @param err {Error} The error object returned from the request. Set to <tt>null</tt> if the request is successful.
41-
* @param data {String} The json-serialized data returned from the request. Set to <tt>null</tt> if a request error occurs. This string can be parsed to get the Object with the following info:
42-
* data.ARN {String} The ARN of the secret.
43-
* data.Name {String} The friendly name of the secret.
44-
* data.VersionId {String} The unique identifier of this version of the secret.
45-
* data.SecretBinary {Buffer|TypedArray|Blob|String} The decrypted part of the protected secret information that was originally provided as binary data in the form of a byte array.
42+
* @param data {Object|String} data returned from the request. Return type is decided on DeStringifyResultFlag flag in request. Set to <tt>null</tt> if a request error occurs.
43+
* @param data.ARN {String} The ARN of the secret.
44+
* @param data.Name {String} The friendly name of the secret.
45+
* @param data.VersionId {String} The unique identifier of this version of the secret.
46+
* @param data.SecretBinary {Buffer|TypedArray|Blob|String} The decrypted part of the protected secret information that was originally provided as binary data in the form of a byte array.
4647
* The response parameter represents the binary data as a base64-encoded string.
47-
* data.SecretString {String} The decrypted part of the protected secret information that was originally provided as a string.
48-
* data.VersionStages {String[]} Specifies the secret version that you want to retrieve by the staging label attached to the version.
48+
* @param data.SecretString {String} The decrypted part of the protected secret information that was originally provided as a string.
49+
* @param data.VersionStages {String[]} Specifies the secret version that you want to retrieve by the staging label attached to the version.
4950
* <br/>Staging labels are used to keep track of different versions during the rotation process.
5051
*/
5152

@@ -56,6 +57,7 @@ class SecretsManager {
5657
* @param params.SecretId {String} Specifies the secret containing the version that you want to retrieve. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret.
5758
* @param params.VersionStage {String} Specifies the secret version that you want to retrieve by the staging label attached to the version.
5859
* <br/>Staging labels are used to keep track of different versions during the rotation process.
60+
* @param params.DeStringifyResultFlag {boolean} Optional Flag to decide the return type from getSecretValue. If set, it returns de-serialized data object, otherwise it returns stringified response.
5961
* @param callback {secretsManagerCallback} The callback.
6062
*
6163
* @example <caption>Retrieving a local secret value</caption>
@@ -74,6 +76,7 @@ class SecretsManager {
7476
const secretId = Util.getParameter(params, KEY_SECRET_ID);
7577
const versionId = Util.getParameter(params, KEY_VERSION_ID);
7678
const versionStage = Util.getParameter(params, KEY_VERSION_STAGE);
79+
const isJSONResultFlagSet = Util.getParameter(params, KEY_JSON_RESULT_FLAG);
7780

7881
if (secretId === undefined) {
7982
callback(new Error(`"${KEY_SECRET_ID}" is a required parameter`), null);
@@ -102,7 +105,11 @@ class SecretsManager {
102105
if (err) {
103106
callback(err, null); // an error occurred
104107
} else if (SecretsManager._is200Response(data.Payload)) {
105-
callback(null, data.Payload); // successful response
108+
// successful response
109+
if (isJSONResultFlagSet) {
110+
callback(null, JSON.parse(data.Payload));
111+
}
112+
callback(null, data.Payload);
106113
} else {
107114
callback(new Error(JSON.stringify(data.Payload)), null); // error response
108115
}

aws-greengrass-core-sdk/stream-manager/client.js

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ const cbor = require('cbor');
99
const net = require('net');
1010
const smData = require('aws-greengrass-core-sdk/stream-manager/data');
1111
const exceptions = require('./exceptions');
12+
const utilInternal = require('./utilInternal');
1213
const util = require('./util');
1314

1415
// Consts
15-
const PROTOCOL_VERSION = '1.0.0';
16-
const SDK_VERSION = '1.0.0';
16+
17+
// Version of the Java SDK.
18+
// NOTE: When you bump this version,
19+
// consider adding the old version to olderSupportedProtocolVersions list (if you intend to support it)
20+
const SDK_VERSION = '1.1.0';
21+
22+
// List of supported protocol protocol.
23+
// These are meant to be used for graceful degradation if the server does not support the current SDK version.
24+
const OLD_SUPPORTED_PROTOCOL_VERSIONS = ['1.0.0'];
25+
1726
const CONNECT_VERSION = 1;
1827

1928
const removeFromArray = (arr, f) => {
@@ -73,6 +82,7 @@ class StreamManagerClient {
7382
error: console.error,
7483
debug: console.debug,
7584
info: console.info,
85+
warn: console.warn,
7686
},
7787
};
7888

@@ -132,25 +142,26 @@ class StreamManagerClient {
132142
// Set high water mark so that we can read 1 full packet (1GB) at a time instead of needing to
133143
// try to read multiple times and combine the results. The HWM adjusts how much the socket will
134144
// buffer when reading.
135-
readableHighWaterMark: util.MAX_PACKET_SIZE,
145+
readableHighWaterMark: utilInternal.MAX_PACKET_SIZE,
136146
}, async () => {
137147
try {
138148
// Connection started
139149
this.#logger.debug(`Opening connection to ${this.host}:${this.port}`);
140150
this.#connected = false;
141151

142152
const request = new smData.ConnectRequest()
143-
.withProtocolVersion(PROTOCOL_VERSION)
153+
.withProtocolVersion(smData.VersionInfo.PROTOCOL_VERSION.asMap())
144154
.withSdkVersion(SDK_VERSION)
145155
.withAuthToken(this.#authToken)
146-
.withRequestId(util.uuidv4());
156+
.withOtherSupportedProtocolVersions(OLD_SUPPORTED_PROTOCOL_VERSIONS)
157+
.withRequestId(utilInternal.uuidv4());
147158

148159
// Write the connect version
149-
newSock.write(util.intToBuffer(CONNECT_VERSION, 1));
160+
newSock.write(utilInternal.intToBuffer(CONNECT_VERSION, 1));
150161

151162
// Write request to socket
152163
const frame = new smData.MessageFrame(smData.Operation.Connect, cbor.encode(request.asMap()));
153-
const byteFrame = util.encodeFrame(frame);
164+
const byteFrame = utilInternal.encodeFrame(frame);
154165
newSock.write(byteFrame.header);
155166
newSock.write(byteFrame.payload);
156167

@@ -233,7 +244,7 @@ class StreamManagerClient {
233244
this.__handleReadResponse(cbor.decodeFirstSync(frame.payload), frame);
234245
} else {
235246
// Read connect version
236-
const connectResponseVersion = util.intFromBuffer(await this.__readSocket(1, socket));
247+
const connectResponseVersion = utilInternal.intFromBuffer(await this.__readSocket(1, socket));
237248
if (connectResponseVersion !== CONNECT_VERSION) {
238249
this.#logger.error('Unexpected response from the server, Connect version:', connectResponseVersion);
239250
throw new exceptions.ConnectFailedException('Failed to establish connection with the server');
@@ -255,6 +266,14 @@ class StreamManagerClient {
255266
this.#logger.error('Received ConnectResponse with unexpected status', response.status);
256267
throw new exceptions.ConnectFailedException('Failed to establish connection with the server');
257268
}
269+
270+
if (response.protocolVersion !== smData.VersionInfo.PROTOCOL_VERSION.asMap()) {
271+
this.#logger.warn('SDK with version %s using Protocol version %s is not fully compatible with '
272+
+ 'Server with version %s. '
273+
+ 'Client has connected in a compatibility mode using protocol version %s. '
274+
+ 'Some features will not work as expected', SDK_VERSION, smData.VersionInfo.PROTOCOL_VERSION.asMap(),
275+
response.serverVersion, response.protocolVersion);
276+
}
258277
}
259278

260279
// Put ourselves back in the event loop to handle the next messages
@@ -271,8 +290,8 @@ class StreamManagerClient {
271290
}
272291

273292
async __readMessageFrame(socket) {
274-
const length = util.intFromBuffer(await this.__readSocket(4, socket));
275-
const operation = util.intFromBuffer(await this.__readSocket(1, socket));
293+
const length = utilInternal.intFromBuffer(await this.__readSocket(4, socket));
294+
const operation = utilInternal.intFromBuffer(await this.__readSocket(1, socket));
276295

277296
let op = smData.Operation.fromMap(operation);
278297
if (typeof op === 'undefined') {
@@ -292,6 +311,10 @@ class StreamManagerClient {
292311
const response = smData.CreateMessageStreamResponse.fromMap(data);
293312
this.#logger.debug('Received CreateMessageStreamResponse from server', frame);
294313
this.#requestMap[response.requestId](response);
314+
} else if (frame.operation === smData.Operation.UpdateMessageStreamResponse) {
315+
const response = smData.UpdateMessageStreamResponse.fromMap(data);
316+
this.#logger.debug('Received UpdateMessageStreamResponse from server', frame);
317+
this.#requestMap[response.requestId](response);
295318
} else if (frame.operation === smData.Operation.DeleteMessageStreamResponse) {
296319
const response = smData.DeleteMessageStreamResponse.fromMap(data);
297320
this.#logger.debug('Received DeleteMessageStreamResponse from server', frame);
@@ -308,6 +331,10 @@ class StreamManagerClient {
308331
const response = smData.DescribeMessageStreamResponse.fromMap(data);
309332
this.#logger.debug('Received DescribeMessageStreamResponse from server', frame);
310333
this.#requestMap[response.requestId](response);
334+
} else if (frame.operation === smData.Operation.UnknownOperationError) {
335+
this.#logger.error('Received response with UnknownOperation Error from server. You should update your server version');
336+
const response = smData.UnknownOperationError.fromMap(data);
337+
this.#requestMap[response.requestId](response);
311338
} else if (frame.operation === smData.Operation.Unknown) {
312339
this.#logger.error('Received response with unknown operation from server', frame);
313340
try {
@@ -330,10 +357,10 @@ class StreamManagerClient {
330357

331358
if (data.requestId === null) {
332359
// eslint-disable-next-line no-param-reassign
333-
data.requestId = util.uuidv4();
360+
data.requestId = utilInternal.uuidv4();
334361
}
335362

336-
const validation = util.isInvalid(data);
363+
const validation = utilInternal.isInvalid(data);
337364
if (validation) {
338365
throw new exceptions.ValidationException(validation);
339366
}
@@ -357,7 +384,7 @@ class StreamManagerClient {
357384

358385
// Write request to socket
359386
const frame = new smData.MessageFrame(operation, cbor.encode(data.asMap()));
360-
const byteFrame = util.encodeFrame(frame);
387+
const byteFrame = utilInternal.encodeFrame(frame);
361388
this.#socket.write(byteFrame.header);
362389
this.#socket.write(byteFrame.payload);
363390

@@ -369,7 +396,7 @@ class StreamManagerClient {
369396
if (!(options instanceof smData.ReadMessagesOptions)) {
370397
throw new exceptions.ValidationException('options argument to read_messages must be a ReadMessageOptions object');
371398
}
372-
const validation = util.isInvalid(options);
399+
const validation = utilInternal.isInvalid(options);
373400
if (validation) {
374401
throw new exceptions.ValidationException(validation);
375402
}
@@ -395,7 +422,7 @@ class StreamManagerClient {
395422
async appendMessage(streamName, data) {
396423
const request = new smData.AppendMessageRequest().withName(streamName).withPayload(data);
397424
const result = await this._sendAndReceive(smData.Operation.AppendMessage, request);
398-
util.throwOnErrorResponse(result);
425+
utilInternal.throwOnErrorResponse(result);
399426
return result.sequenceNumber;
400427
}
401428

@@ -411,7 +438,23 @@ class StreamManagerClient {
411438
}
412439
const request = new smData.CreateMessageStreamRequest().withDefinition(definition);
413440
const result = await this._sendAndReceive(smData.Operation.CreateMessageStream, request);
414-
util.throwOnErrorResponse(result);
441+
utilInternal.throwOnErrorResponse(result);
442+
}
443+
444+
/**
445+
* Updates a message stream with the new definition.
446+
* Minimum version requirements: StreamManager server version 1.1 (or AWS IoT Greengrass Core 1.11.0)
447+
*
448+
* @param definition {aws-greengrass-core-sdk.StreamManager.MessageStreamDefinition}
449+
* @returns {Promise<void>}
450+
*/
451+
async updateMessageStream(definition) {
452+
if (!(definition instanceof smData.MessageStreamDefinition)) {
453+
throw new exceptions.ValidationException('definition argument to update_stream must be a MessageStreamDefinition object');
454+
}
455+
const request = new smData.UpdateMessageStreamRequest().withDefinition(definition);
456+
const result = await this._sendAndReceive(smData.Operation.UpdateMessageStream, request);
457+
utilInternal.throwOnErrorResponse(result);
415458
}
416459

417460
/**
@@ -424,7 +467,7 @@ class StreamManagerClient {
424467
async deleteMessageStream(streamName) {
425468
const request = new smData.DeleteMessageStreamRequest().withName(streamName);
426469
const result = await this._sendAndReceive(smData.Operation.DeleteMessageStream, request);
427-
util.throwOnErrorResponse(result);
470+
utilInternal.throwOnErrorResponse(result);
428471
}
429472

430473
/**
@@ -452,7 +495,7 @@ class StreamManagerClient {
452495
StreamManagerClient.__validateReadMessagesOptions(options);
453496
const request = new smData.ReadMessagesRequest().withStreamName(streamName).withReadMessagesOptions(options);
454497
const result = await this._sendAndReceive(smData.Operation.ReadMessages, request);
455-
util.throwOnErrorResponse(result);
498+
utilInternal.throwOnErrorResponse(result);
456499
return result.messages;
457500
}
458501

@@ -464,7 +507,7 @@ class StreamManagerClient {
464507
async listStreams() {
465508
const request = new smData.ListStreamsRequest();
466509
const result = await this._sendAndReceive(smData.Operation.ListStreams, request);
467-
util.throwOnErrorResponse(result);
510+
utilInternal.throwOnErrorResponse(result);
468511
return result.streams;
469512
}
470513

@@ -478,7 +521,7 @@ class StreamManagerClient {
478521
async describeMessageStream(streamName) {
479522
const request = new smData.DescribeMessageStreamRequest().withName(streamName);
480523
const result = await this._sendAndReceive(smData.Operation.DescribeMessageStream, request);
481-
util.throwOnErrorResponse(result);
524+
utilInternal.throwOnErrorResponse(result);
482525
return result.messageStreamInfo;
483526
}
484527

@@ -517,4 +560,5 @@ module.exports = {
517560
...smData,
518561
StreamManagerClient: StreamManagerClient,
519562
...exceptions,
563+
util,
520564
};

0 commit comments

Comments
 (0)