New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@uhuru/awsiot-thing-creator

Package Overview
Dependencies
Maintainers
4
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uhuru/awsiot-thing-creator - npm Package Compare versions

Comparing version 1.0.1-beta.10 to 1.0.1-beta.11

3

dist/index.d.ts

@@ -1,3 +0,2 @@

import { AWSIoTThingCreator } from './thing-creator.js';
export { AWSIoTThingCreator };
export * from './thing-creator';
//# sourceMappingURL=index.d.ts.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
exports.__esModule = true;
exports.AWSIoTThingCreator = void 0;
var process_1 = __importDefault(require("process"));
var ts_command_line_args_1 = require("ts-command-line-args");
var url_1 = require("url");
// eslint-disable-next-line import/no-unresolved
var thing_creator_js_1 = require("./thing-creator.js");
exports.AWSIoTThingCreator = thing_creator_js_1.AWSIoTThingCreator;
function main() {
var args = (0, ts_command_line_args_1.parse)({
'aws-access-key-id': String,
'aws-secret-access-key': String,
'aws-iot-region': String,
'aws-iot-thing-name': String,
'thing-attribute-payload': { type: String, optional: true },
'thing-type-name': { type: String, optional: true }
});
var config = {
awsAccessKeyId: args['aws-access-key-id'],
awsIotRegion: args['aws-iot-region'],
awsSecretAccessKey: args['aws-secret-access-key'],
configSavePath: '../../ports/awsiot',
thingAttributePayload: args['thing-attribute-payload'],
thingName: args['aws-iot-thing-name'],
thingTypeName: args['thing-type-name']
};
var creator = new thing_creator_js_1.AWSIoTThingCreator(config);
return creator.createThing()["catch"](function (error) {
console.error(error.message);
throw new Error('Failed to create thing.');
});
}
if (process_1["default"].argv[1] === (0, url_1.fileURLToPath)(__filename)) {
main()["catch"](function (error) {
console.error(error);
process_1["default"].exit(1);
});
}
__exportStar(require("./thing-creator"), exports);
//# sourceMappingURL=index.js.map

@@ -37,4 +37,9 @@ export declare class AWSIoTThingCreator {

private downloadCertificate;
private createKeysAndCerts;
private attachPolicy;
private checkIfAlreadyExist;
private createThing;
private attachPrincipalToThing;
createThingWithoutCerts(): Promise<void>;
createThing(): Promise<{
attachCertsToThing(): Promise<{
config: {

@@ -54,3 +59,18 @@ host: string;

} | undefined>;
createThingWithCerts(): Promise<{
config: {
host: string;
port: number;
clientId: string;
thingName: string;
caCert: string;
clientCert: string;
privateKey: string;
topic: string;
};
clientPem: string;
privateKey: string;
rootPem: any;
} | undefined>;
}
//# sourceMappingURL=thing-creator.d.ts.map

@@ -243,47 +243,9 @@ "use strict";

};
AWSIoTThingCreator.prototype.createThingWithoutCerts = function () {
return __awaiter(this, void 0, void 0, function () {
var thingName, isDuplicated, createThingCmd;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
thingName = this.thingName;
return [4 /*yield*/, this.existThing()];
case 1:
isDuplicated = _a.sent();
if (isDuplicated) {
throw new Error(thingName + " already exists. Please choose another thing name.");
}
createThingCmd = new client_iot_1.CreateThingCommand({
thingName: thingName,
thingTypeName: this.thingTypeName,
attributePayload: this.thingAttributePayload
});
return [4 /*yield*/, this.iotClient.send(createThingCmd)["catch"](function (error) {
throw new Error("Failed to create " + thingName + ", reason: " + error.message);
})];
case 2:
_a.sent();
return [2 /*return*/];
}
});
});
};
AWSIoTThingCreator.prototype.createThing = function () {
AWSIoTThingCreator.prototype.createKeysAndCerts = function () {
var _a;
return __awaiter(this, void 0, void 0, function () {
var thingName, policyName, isDuplicated, createKeysAndCertificateCmd, keysAndCert, certificatePem, privateKey, getPolicyCmd, attachPrincipalPolicyCmd, createThingCmd, attachThingPrincipalCmd, config, rootPem;
var _this = this;
var createKeysAndCertificateCmd, keysAndCert, certificatePem, privateKey;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
thingName = this.thingName;
policyName = this.policyName;
console.log("Creating thing: " + thingName);
return [4 /*yield*/, this.existThing()];
case 1:
isDuplicated = _b.sent();
if (isDuplicated) {
throw new Error(thingName + " already exists. Please choose another thing name.");
}
createKeysAndCertificateCmd = new client_iot_1.CreateKeysAndCertificateCommand({

@@ -296,3 +258,3 @@ setAsActive: true

})];
case 2:
case 1:
keysAndCert = _b.sent();

@@ -307,2 +269,19 @@ certificatePem = (keysAndCert === null || keysAndCert === void 0 ? void 0 : keysAndCert.certificatePem) || '';

}
return [2 /*return*/, {
certificateArn: keysAndCert.certificateArn,
certificatePem: certificatePem,
privateKey: privateKey
}];
}
});
});
};
AWSIoTThingCreator.prototype.attachPolicy = function (target) {
return __awaiter(this, void 0, void 0, function () {
var policyName, getPolicyCmd, attachPrincipalPolicyCmd;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
policyName = this.policyName;
getPolicyCmd = new client_iot_1.GetPolicyCommand({ policyName: policyName });

@@ -331,7 +310,7 @@ return [4 /*yield*/, this.iotClient.send(getPolicyCmd)["catch"](function () { return __awaiter(_this, void 0, void 0, function () {

}); })];
case 3:
_b.sent();
case 1:
_a.sent();
attachPrincipalPolicyCmd = new client_iot_1.AttachPolicyCommand({
policyName: policyName,
target: keysAndCert.certificateArn
target: target
});

@@ -341,4 +320,34 @@ return [4 /*yield*/, this.iotClient.send(attachPrincipalPolicyCmd)["catch"](function (error) {

})];
case 4:
_b.sent();
case 2:
_a.sent();
return [2 /*return*/];
}
});
});
};
AWSIoTThingCreator.prototype.checkIfAlreadyExist = function () {
return __awaiter(this, void 0, void 0, function () {
var thingName, isDuplicated;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
thingName = this.thingName;
return [4 /*yield*/, this.existThing()];
case 1:
isDuplicated = _a.sent();
if (isDuplicated) {
throw new Error(thingName + " already exists. Please choose another thing name.");
}
return [2 /*return*/];
}
});
});
};
AWSIoTThingCreator.prototype.createThing = function () {
return __awaiter(this, void 0, void 0, function () {
var thingName, createThingCmd;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
thingName = this.thingName;
createThingCmd = new client_iot_1.CreateThingCommand({

@@ -352,7 +361,19 @@ thingName: thingName,

})];
case 5:
_b.sent();
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
AWSIoTThingCreator.prototype.attachPrincipalToThing = function (principal) {
return __awaiter(this, void 0, void 0, function () {
var thingName, attachThingPrincipalCmd;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
thingName = this.thingName;
attachThingPrincipalCmd = new client_iot_1.AttachThingPrincipalCommand({
thingName: thingName,
principal: keysAndCert.certificateArn
principal: principal
});

@@ -362,19 +383,53 @@ return [4 /*yield*/, this.iotClient.send(attachThingPrincipalCmd)["catch"](function (error) {

})];
case 6:
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
AWSIoTThingCreator.prototype.createThingWithoutCerts = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.checkIfAlreadyExist()];
case 1:
_a.sent();
return [4 /*yield*/, this.createThing()];
case 2:
_a.sent();
return [2 /*return*/];
}
});
});
};
AWSIoTThingCreator.prototype.attachCertsToThing = function () {
return __awaiter(this, void 0, void 0, function () {
var _a, certificatePem, privateKey, certificateArn, config, rootPem;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, this.createKeysAndCerts()];
case 1:
_a = _b.sent(), certificatePem = _a.certificatePem, privateKey = _a.privateKey, certificateArn = _a.certificateArn;
return [4 /*yield*/, this.attachPolicy(certificateArn)];
case 2:
_b.sent();
if (!this.envPaths.config) return [3 /*break*/, 8];
return [4 /*yield*/, this.attachPrincipalToThing(certificateArn)];
case 3:
_b.sent();
if (!this.envPaths.config) return [3 /*break*/, 5];
return [4 /*yield*/, this.writeFileAll({
configSavePath: this.envPaths.config,
thingName: thingName,
thingName: this.thingName,
certificatePem: certificatePem,
privateKey: privateKey
})];
case 7:
case 4:
_b.sent();
return [3 /*break*/, 11];
case 8: return [4 /*yield*/, this.getConfigObject()];
case 9:
return [3 /*break*/, 8];
case 5: return [4 /*yield*/, this.getConfigObject()];
case 6:
config = _b.sent();
return [4 /*yield*/, this.downloadCertificate(this.awsCertificationAuthorityUrl)];
case 10:
case 7:
rootPem = _b.sent();

@@ -387,3 +442,3 @@ return [2 /*return*/, {

}];
case 11: return [2 /*return*/];
case 8: return [2 /*return*/];
}

@@ -393,2 +448,21 @@ });

};
AWSIoTThingCreator.prototype.createThingWithCerts = function () {
return __awaiter(this, void 0, void 0, function () {
var thingName;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
thingName = this.thingName;
console.log("Creating thing: " + thingName);
return [4 /*yield*/, this.checkIfAlreadyExist()];
case 1:
_a.sent();
return [4 /*yield*/, this.createThing()];
case 2:
_a.sent();
return [2 /*return*/, this.attachCertsToThing()];
}
});
});
};
return AWSIoTThingCreator;

@@ -395,0 +469,0 @@ }());

{
"name": "@uhuru/awsiot-thing-creator",
"version": "1.0.1-beta.10",
"version": "1.0.1-beta.11",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/thing-creator.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc