Socket
Socket
Sign inDemoInstall

serverless-layers

Package Overview
Dependencies
70
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.6.1 to 2.6.2

5

CHANGELOG.md

@@ -0,1 +1,6 @@

# 2.6.1 (2022-12-23)
- [dependabot mocha](https://github.com/agutoli/serverless-layers/commit/4aca58091e6bf0472e12814513fd800590ae5705)
- [Bugfix: Unable to attach layers to the existing lambda](https://github.com/agutoli/serverless-layers/issues/97)
- [Feature: Bucket ServerSideEncryption](https://github.com/agutoli/serverless-layers/commit/f4770bfb68bc12047e42e545bc1061cdb10accbe)
# 2.3.3 (2020-12-02)

@@ -2,0 +7,0 @@ - [Improvement: Layers output beautified](https://github.com/agutoli/serverless-layers/issues/48)

44

lib/aws/LayersService.js

@@ -63,23 +63,34 @@ "use strict";

var _this2 = this;
var params, response, deleteQueue;
var retainVersions,
params,
response,
deletionCandidates,
deleteQueue,
_args2 = arguments;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
retainVersions = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : 0;
params = {
LayerName: this.layerName
};
_context2.next = 3;
_context2.next = 4;
return this.awsRequest('Lambda:listLayerVersions', params, {
checkError: true
});
case 3:
case 4:
response = _context2.sent;
if (!(response.LayerVersions.length === 0)) {
_context2.next = 7;
if (!(response.LayerVersions.length <= retainVersions)) {
_context2.next = 8;
break;
}
this.plugin.log('Layers removal finished.');
this.plugin.log('Layers removal finished.\n');
return _context2.abrupt("return");
case 7:
deleteQueue = response.LayerVersions.map(function (layerVersion) {
case 8:
if (!this.plugin.settings.retainVersions) {
_context2.next = 15;
break;
}
deletionCandidates = this.selectVersionsToDelete(response.LayerVersions, retainVersions);
deleteQueue = deletionCandidates.map(function (layerVersion) {
_this2.plugin.log("Removing layer version: ".concat(layerVersion.Version));

@@ -93,8 +104,8 @@ return _this2.awsRequest('Lambda:deleteLayerVersion', {

});
_context2.next = 10;
_context2.next = 13;
return Promise.all(deleteQueue);
case 10:
_context2.next = 12;
return this.cleanUpLayers();
case 12:
case 13:
_context2.next = 15;
return this.cleanUpLayers(retainVersions);
case 15:
case "end":

@@ -110,2 +121,9 @@ return _context2.stop();

}()
}, {
key: "selectVersionsToDelete",
value: function selectVersionsToDelete(versions, retainVersions) {
return versions.sort(function (a, b) {
return parseInt(a.Version) === parseInt(b.Version) ? 0 : parseInt(a.Version) > parseInt(b.Version) ? -1 : 1;
}).slice(retainVersions);
}
}]);

@@ -112,0 +130,0 @@ return LayersService;

@@ -66,2 +66,9 @@ "use strict";

},
'after:deploy:deploy': function afterDeployDeploy() {
return BbPromise.bind(_this).then(function () {
return _this.init();
}).then(function () {
return _this.cleanUpLayerVersions();
});
},
'plugin:uninstall:uninstall': function pluginUninstallUninstall() {

@@ -215,8 +222,60 @@ return BbPromise.bind(_this).then(function () {

}, {
key: "initServices",
key: "cleanUpLayerVersions",
value: function () {
var _initServices = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(layerName, settings) {
var _cleanUpLayerVersions = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
var settings, layerName, currentSettings;
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
this.runtimes = new Runtimes(this);
settings = this.getSettings();
_context4.t0 = _regenerator["default"].keys(settings);
case 3:
if ((_context4.t1 = _context4.t0()).done) {
_context4.next = 19;
break;
}
layerName = _context4.t1.value;
currentSettings = settings[layerName];
this.logGroup(layerName);
if (!currentSettings.arn) {
_context4.next = 10;
break;
}
this.warn(" (skipped) arn: ".concat(currentSettings.arn));
return _context4.abrupt("continue", 3);
case 10:
if (currentSettings.retainVersions) {
_context4.next = 12;
break;
}
return _context4.abrupt("continue", 3);
case 12:
this.log('Cleaning up layer versions...');
_context4.next = 15;
return this.initServices(layerName, currentSettings);
case 15:
_context4.next = 17;
return this.cleanUpLayers(currentSettings.retainVersions);
case 17:
_context4.next = 3;
break;
case 19:
case "end":
return _context4.stop();
}
}, _callee4, this);
}));
function cleanUpLayerVersions() {
return _cleanUpLayerVersions.apply(this, arguments);
}
return cleanUpLayerVersions;
}()
}, {
key: "initServices",
value: function () {
var _initServices = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(layerName, settings) {
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
this.currentLayerName = layerName;

@@ -233,5 +292,5 @@ this.settings = settings;

case "end":
return _context4.stop();
return _context5.stop();
}
}, _callee4, this);
}, _callee5, this);
}));

@@ -255,2 +314,3 @@ function initServices(_x, _x2) {

forceInstall: false,
retainVersions: null,
dependencyInstall: true,

@@ -316,24 +376,24 @@ compileDir: '.serverless',

value: function () {
var _hasCustomHashChanged = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() {
var _hasCustomHashChanged = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6() {
var hashFileName, remoteHashFile, _JSON$parse, remoteHash;
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
return _regenerator["default"].wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
if (this.settings.customHash) {
_context5.next = 2;
_context6.next = 2;
break;
}
return _context5.abrupt("return", false);
return _context6.abrupt("return", false);
case 2:
hashFileName = 'customHash.json';
_context5.next = 5;
_context6.next = 5;
return this.bucketService.getFile(hashFileName);
case 5:
remoteHashFile = _context5.sent;
remoteHashFile = _context6.sent;
if (remoteHashFile) {
_context5.next = 11;
_context6.next = 11;
break;
}
this.log('no previous custom hash found, putting new remote hash');
_context5.next = 10;
_context6.next = 10;
return this.bucketService.putFile(hashFileName, JSON.stringify({

@@ -343,12 +403,12 @@ hash: this.settings.customHash

case 10:
return _context5.abrupt("return", true);
return _context6.abrupt("return", true);
case 11:
_JSON$parse = JSON.parse(remoteHashFile), remoteHash = _JSON$parse.hash;
if (!(remoteHash === this.settings.customHash)) {
_context5.next = 14;
_context6.next = 14;
break;
}
return _context5.abrupt("return", false);
return _context6.abrupt("return", false);
case 14:
_context5.next = 16;
_context6.next = 16;
return this.bucketService.putFile(hashFileName, JSON.stringify({

@@ -359,8 +419,8 @@ hash: this.settings.customHash

this.log('identified custom hash change!');
return _context5.abrupt("return", true);
return _context6.abrupt("return", true);
case 18:
case "end":
return _context5.stop();
return _context6.stop();
}
}, _callee5, this);
}, _callee6, this);
}));

@@ -375,28 +435,28 @@ function hasCustomHashChanged() {

value: function () {
var _main = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6() {
var _main = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() {
var _this$settings, arn, localDir, artifact, forceInstall, dependencyInstall, hasSettingsChanges, hasFoldersChanges, hasDepsChanges, hasZipChanged, hasCustomHashChanged, verifyChanges, existentLayerArn, skipInstallation, version;
return _regenerator["default"].wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
return _regenerator["default"].wrap(function _callee7$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
case 0:
_this$settings = this.settings, arn = _this$settings.arn, localDir = _this$settings.localDir, artifact = _this$settings.artifact, forceInstall = _this$settings.forceInstall, dependencyInstall = _this$settings.dependencyInstall; // static ARN
if (!arn) {
_context6.next = 4;
_context7.next = 4;
break;
}
this.relateLayerWithFunctions(arn);
return _context6.abrupt("return");
return _context7.abrupt("return");
case 4:
_context6.next = 6;
_context7.next = 6;
return this.runtimes.init();
case 6:
_context6.next = 8;
_context7.next = 8;
return this.dependencies.init();
case 8:
_context6.next = 10;
_context7.next = 10;
return this.localFolders.init();
case 10:
_context6.next = 12;
_context7.next = 12;
return this.hasSettingsChanges();
case 12:
hasSettingsChanges = _context6.sent;
hasSettingsChanges = _context7.sent;
// check if directories content has changed

@@ -406,9 +466,9 @@ // comparing hash md5 remote with local folder

if (!localDir) {
_context6.next = 18;
_context7.next = 18;
break;
}
_context6.next = 17;
_context7.next = 17;
return this.localFolders.hasFoldersChanges();
case 17:
hasFoldersChanges = _context6.sent;
hasFoldersChanges = _context7.sent;
case 18:

@@ -419,24 +479,24 @@ // check if dependencies has changed comparing

if (!dependencyInstall) {
_context6.next = 23;
_context7.next = 23;
break;
}
_context6.next = 22;
_context7.next = 22;
return this.runtimes.hasDependenciesChanges();
case 22:
hasDepsChanges = _context6.sent;
hasDepsChanges = _context7.sent;
case 23:
hasZipChanged = false;
if (!artifact) {
_context6.next = 28;
_context7.next = 28;
break;
}
_context6.next = 27;
_context7.next = 27;
return this.zipService.hasZipChanged();
case 27:
hasZipChanged = _context6.sent;
hasZipChanged = _context7.sent;
case 28:
_context6.next = 30;
_context7.next = 30;
return this.hasCustomHashChanged();
case 30:
hasCustomHashChanged = _context6.sent;
hasCustomHashChanged = _context7.sent;
// It checks if something has changed

@@ -449,6 +509,6 @@ verifyChanges = [hasZipChanged, hasDepsChanges, hasFoldersChanges, hasSettingsChanges, hasCustomHashChanged].some(function (x) {

// It returns the layer arn if exists.
_context6.next = 35;
_context7.next = 35;
return this.getLayerArn();
case 35:
existentLayerArn = _context6.sent;
existentLayerArn = _context7.sent;
// It improves readability

@@ -461,3 +521,3 @@ skipInstallation = !verifyChanges && !forceInstall && existentLayerArn;

if (!skipInstallation) {
_context6.next = 41;
_context7.next = 41;
break;

@@ -467,29 +527,29 @@ }

this.relateLayerWithFunctions(existentLayerArn);
return _context6.abrupt("return");
return _context7.abrupt("return");
case 41:
if (!(dependencyInstall && !artifact)) {
_context6.next = 44;
_context7.next = 44;
break;
}
_context6.next = 44;
_context7.next = 44;
return this.dependencies.install();
case 44:
if (!(localDir && !artifact)) {
_context6.next = 47;
_context7.next = 47;
break;
}
_context6.next = 47;
_context7.next = 47;
return this.localFolders.copyFolders();
case 47:
_context6.next = 49;
_context7.next = 49;
return this.zipService["package"]();
case 49:
_context6.next = 51;
_context7.next = 51;
return this.bucketService.uploadZipFile();
case 51:
_context6.next = 53;
_context7.next = 53;
return this.layersService.publishVersion();
case 53:
version = _context6.sent;
_context6.next = 56;
version = _context7.sent;
_context7.next = 56;
return this.bucketService.putFile(this.dependencies.getDepsPath());

@@ -500,5 +560,5 @@ case 56:

case "end":
return _context6.stop();
return _context7.stop();
}
}, _callee6, this);
}, _callee7, this);
}));

@@ -559,6 +619,6 @@ function main() {

value: function () {
var _getLayerArn = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() {
var _getLayerArn = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() {
var outputs, logicalId, arn;
return _regenerator["default"].wrap(function _callee7$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
return _regenerator["default"].wrap(function _callee8$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
case 0:

@@ -571,16 +631,16 @@ if (!this.cacheObject.layersArn) {

if (!this.cacheObject.layersArn[this.currentLayerName]) {
_context7.next = 3;
_context8.next = 3;
break;
}
return _context7.abrupt("return", this.cacheObject.layersArn[this.currentLayerName]);
return _context8.abrupt("return", this.cacheObject.layersArn[this.currentLayerName]);
case 3:
_context7.next = 5;
_context8.next = 5;
return this.cloudFormationService.getOutputs();
case 5:
outputs = _context7.sent;
outputs = _context8.sent;
if (outputs) {
_context7.next = 8;
_context8.next = 8;
break;
}
return _context7.abrupt("return", null);
return _context8.abrupt("return", null);
case 8:

@@ -592,8 +652,8 @@ logicalId = this.getOutputLogicalId();

this.cacheObject.layersArn[this.currentLayerName] = arn;
return _context7.abrupt("return", arn);
return _context8.abrupt("return", arn);
case 12:
case "end":
return _context7.stop();
return _context8.stop();
}
}, _callee7, this);
}, _callee8, this);
}));

@@ -703,7 +763,7 @@ function getLayerArn() {

value: function () {
var _finalizeDeploy = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() {
var _finalizeDeploy = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9() {
var _this6 = this;
var cliOpts;
return _regenerator["default"].wrap(function _callee8$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
return _regenerator["default"].wrap(function _callee9$(_context9) {
while (1) switch (_context9.prev = _context9.next) {
case 0:

@@ -730,5 +790,5 @@ cliOpts = this.provider.options;

case "end":
return _context8.stop();
return _context9.stop();
}
}, _callee8, this);
}, _callee9, this);
}));

@@ -766,4 +826,4 @@ function finalizeDeploy() {

key: "cleanUpLayers",
value: function cleanUpLayers() {
return this.layersService.cleanUpLayers();
value: function cleanUpLayers(retainVersions) {
return this.layersService.cleanUpLayers(retainVersions);
}

@@ -770,0 +830,0 @@ }, {

@@ -42,5 +42,5 @@ "use strict";

if (!data.isCompatible) {
_this.plugin.error('=============================================================');
_this.plugin.error("NOTE: You're currently using incompatible version [".concat(data.version.replace('\n', ''), "]"));
_this.plugin.error('=============================================================\n');
_this.plugin.warn('=============================================================');
_this.plugin.warn("WARN: The current environment and Lambda runtime don't match (current=".concat(data.version.replace('\n', ''), " vs runtime=").concat(runtime, ")."));
_this.plugin.warn('=============================================================\n');
}

@@ -47,0 +47,0 @@ });

{
"name": "serverless-layers",
"version": "2.6.1",
"version": "2.6.2",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -95,2 +95,3 @@ # serverless-layers

| customHash | `string` | | Can specify custom string, that once changed will force a new build of the layer
| retainVersions | `int` | `null` | Number of layer versions to keep, the rest versions will be removed after deployments |

@@ -207,2 +208,2 @@

Made with [contributors-img](https://contrib.rocks).
Made with [contributors-img](https://contrib.rocks).

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc