Skip to content

Commit bcdbc64

Browse files
committed
Fix duplicate notification in webhook
1 parent b89d969 commit bcdbc64

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

provider/aws/system.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ func (p *Provider) Sync(name string) error {
631631

632632
func (p *Provider) SystemUpdate(opts structs.SystemUpdateOptions) error {
633633
changes := map[string]string{}
634+
hasOtherChange := false
634635

635636
// carry forward values from original custom topic resources
636637
params := map[string]string{
@@ -646,21 +647,25 @@ func (p *Provider) SystemUpdate(opts structs.SystemUpdateOptions) error {
646647
for k, v := range opts.Parameters {
647648
params[k] = v
648649
}
650+
hasOtherChange = true
649651
}
650652

651653
if v, has := params["WhiteList"]; has {
652654
p.WhiteListSpecified = len(v) > 0
653655
p.SyncInstancesIpInSecurityGroup()
656+
hasOtherChange = true
654657
}
655658

656659
if opts.Count != nil {
657660
params["InstanceCount"] = strconv.Itoa(*opts.Count)
658661
changes["count"] = strconv.Itoa(*opts.Count)
662+
hasOtherChange = true
659663
}
660664

661665
if opts.Type != nil {
662666
params["InstanceType"] = *opts.Type
663667
changes["type"] = *opts.Type
668+
hasOtherChange = true
664669
}
665670

666671
var template []byte
@@ -695,6 +700,17 @@ func (p *Provider) SystemUpdate(opts structs.SystemUpdateOptions) error {
695700

696701
// if there is a version update then record it
697702
if v, ok := changes["version"]; ok {
703+
if !hasOtherChange {
704+
rDetails, err := p.SystemGet()
705+
if err != nil {
706+
return err
707+
}
708+
709+
// check rack already in that version or not
710+
if rDetails.Version == v {
711+
return nil
712+
}
713+
}
698714
_, err := p.dynamodb().PutItem(&dynamodb.PutItemInput{
699715
Item: map[string]*dynamodb.AttributeValue{
700716
"id": {S: aws.String(v)},

provider/aws/templates/resource/webhook.tmpl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,24 @@
1919
"var https = require(\"https\");",
2020
"var url = require(\"url\");",
2121
"exports.handler = (event, context, cb) => {",
22-
" var req = https.request(Object.assign(url.parse(process.env.WEBHOOK_URL), { method:\"POST\" }), function(res) {;",
23-
" cb(null);",
22+
" var req = https.request(",
23+
" Object.assign(url.parse(process.env.WEBHOOK_URL), { method: \"POST\" }),",
24+
" function (res) {",
25+
" let data = '';",
26+
" res.on('data', (chunk) => {",
27+
" data += chunk;",
28+
" });",
29+
" res.on('end', () => {",
30+
" cb(null, 'ok');",
31+
" });",
32+
" }",
33+
" );",
34+
" req.on('error', (e) => {",
35+
" cb(e);",
2436
" });",
2537
" req.write(event.Records[0].Sns.Message);",
2638
" req.end();",
27-
"}"
39+
"};"
2840
] ] }
2941
},
3042
"Environment": { "Variables": { "WEBHOOK_URL": { "Ref": "Url" } } },

0 commit comments

Comments
 (0)