Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect the timezone and extensions #1582

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,21 @@ class ServerlessPlugin {
command = this.serverless.processedInput.commands.join(' ');
}

let timezone;
try {
timezone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
} catch {
// Pass silently
}

const payload = {
cli: 'sls',
v: 2, // Bref version
c: command,
ci: ci.isCI,
install: userConfig.get('meta.created_at'),
uid: userConfig.get('frameworkId'), // anonymous user ID created by the Serverless Framework
tz: timezone,
};
const config = this.serverless.configurationInput;
/** @type {string[]} */
Expand All @@ -315,6 +323,39 @@ class ServerlessPlugin {
.filter(Boolean);
}

// PHP extensions
const extensionLayers = [];
const allLayers = [];
if (config.provider && config.provider.layers && Array.isArray(config.provider.layers)) {
allLayers.push(...config.provider.layers);
}
Object.values(config.functions || {}).forEach((f) => {
if (f.layers && Array.isArray(f.layers)) {
allLayers.push(...f.layers);
}
});
if (allLayers.length > 0) {
const layerRegex = /^arn:aws:lambda:[^:]+:403367587399:layer:([^:]+)-php-[^:]+:[^:]+$/;
/** @type {string[]} */
// @ts-ignore
const extensionLayerArns = allLayers
.filter((layer) => {
return typeof layer === 'string'
&& layer.includes('403367587399');
});
for (const layer of extensionLayerArns) {
// Extract the layer name from the ARN.
// The ARN looks like this: arn:aws:lambda:us-east-2:403367587399:layer:amqp-php-81:12
const match = layer.match(layerRegex);
if (match && match[1] && ! extensionLayers.includes(match[1])) {
extensionLayers.push(match[1]);
}
}
}
if (extensionLayers.length > 0) {
payload.ext = extensionLayers;
}

// Send as a UDP packet to 108.128.197.71:8888
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
Expand Down
Loading