Skip to content

Commit 31ae832

Browse files
authored
Merge pull request #33 from schwamster/next
Merge contains 2 changes: * resolved Issue #31 - plugin now supports the default enable property, that allows the user to disable the plugin * #32 - Support for new variableResolutionMode of the serverless framework
2 parents 644ce36 + 69a5c85 commit 31ae832

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

Readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ Since version 1.2.0 of this plugin you can use the following syntax to access th
143143

144144
${certificate:${self:custom.customCertificate.certificateName}:CertificateArn}
145145

146+
If you are on version >= 2.27.0 of serverless & have elected to use the new variable resolver: `variablesResolutionMode: 20210219`.
147+
You must use the new supported syntax which is:
148+
149+
${certificate:${self:custom.customCertificate.certificateName}.CertificateArn}
150+
146151
see the serverless [docs](https://serverless.com/framework/docs/providers/aws/guide/plugins#custom-variable-types) for more information
147152

148153
### License

index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ const fs = require('fs');
55
const path = require('path');
66
const YAML = require('yamljs');
77
const mkdirp = require('mkdirp');
8+
const semver = require('semver')
89
var packageJson = require('./package.json');
910

1011
const unsupportedRegionPrefixes = ['cn-'];
1112

1213
class CreateCertificatePlugin {
14+
getEchoTestValue(src) {
15+
return src.slice(5);
16+
}
1317
constructor(serverless, options) {
1418
this.serverless = serverless;
1519
this.options = options;
@@ -481,8 +485,24 @@ class CreateCertificatePlugin {
481485
}
482486

483487
getCertificateProperty(src) {
488+
if (!this.enabled) {
489+
return Promise.resolve('');
490+
}
484491
this.initializeVariables();
485-
let [s, domainName, property] = src.split(':');
492+
let s, domainName, property;
493+
let currentVersion = this.serverless.utils.getVersion();
494+
495+
if (semver.gte(currentVersion, '3.0.0') || (this.serverless.configurationInput && this.serverless.configurationInput.variablesResolutionMode === 20210219)) {
496+
// User has set variablesResolutionMode: 20210219 (https://github.com/serverless/serverless/pull/8987/files)
497+
// Nested paths must be resolved with '.' instead of ':'
498+
const srcAsArray = src.split(':')[1].split('.');
499+
property = srcAsArray.pop();
500+
domainName = srcAsArray.join('.');
501+
} else {
502+
// Deprecated once Serverless V3 released & new variable resolver becomes the default.
503+
[s, domainName, property] = src.split(':');
504+
}
505+
486506
return this.listCertificates()
487507
.then(({ CertificateSummaryList }) => {
488508
let cert = CertificateSummaryList.filter(({ DomainName }) => DomainName == domainName)[0];

package-lock.json

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-certificate-creator",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"description": "creates a certificate that can be used for custom domains for your api gateway",
55
"main": "index.js",
66
"scripts": {
@@ -13,6 +13,7 @@
1313
"chalk": "^2.4.2",
1414
"delay": "^4.3.0",
1515
"mkdirp": "^1.0.4",
16+
"semver": "^7.3.4",
1617
"yamljs": "^0.3.0"
1718
},
1819
"devDependencies": {},

0 commit comments

Comments
 (0)