• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

silvermine / cloudformation-custom-resources / 25378473900

05 May 2026 01:12PM UTC coverage: 0.0%. Remained the same
25378473900

push

github

web-flow
Merge pull request #29 from MrMarCode/MrMarCode/upgrade-node-24

Mr mar code/upgrade node 24

0 of 117 branches covered (0.0%)

Branch coverage included in aggregate %.

0 of 270 new or added lines in 6 files covered. (0.0%)

6 existing lines in 3 files now uncovered.

0 of 356 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/BaseResource.js
1
'use strict';
2

NEW
3
const _ = require('underscore'),
×
NEW
4
      https = require('https');
×
5

6
class BaseResource {
7

8
   constructor(evt) {
9
      this._event = evt;
×
10
   }
11

12
   async handleCreate() {
NEW
13
      const props = this.normalizeResourceProperties(this._event.ResourceProperties, true);
×
14

15
      console.log('handling creation of "%s": %j', this._event.LogicalResourceId, this._event.ResourceProperties);
×
16

NEW
17
      try {
×
NEW
18
         const atts = await this.doCreate(props);
×
19

NEW
20
         return await this.respond(atts);
×
21
      } catch(err) {
NEW
22
         return this.sendError(err);
×
23
      }
24
   }
25

26
   async handleUpdate() {
NEW
27
      const resourceID = this._event.PhysicalResourceId,
×
NEW
28
            props = this.normalizeResourceProperties(this._event.ResourceProperties, true),
×
NEW
29
            oldProps = this.normalizeResourceProperties(this._event.OldResourceProperties);
×
30

31
      console.log('handling update of "%s" (%s): %j', this._event.LogicalResourceId, resourceID, props);
×
32

NEW
33
      try {
×
NEW
34
         const atts = await this.doUpdate(resourceID, props, oldProps);
×
35

NEW
36
         return await this.respond(atts);
×
37
      } catch(err) {
NEW
38
         return this.sendError(err);
×
39
      }
40
   }
41

42
   async handleDelete() {
NEW
43
      const resourceID = this._event.PhysicalResourceId,
×
NEW
44
            props = this.normalizeResourceProperties(this._event.ResourceProperties, false);
×
45

46
      console.log('handling delete of "%s" (%s): %j', this._event.LogicalResourceId, resourceID, props);
×
47

NEW
48
      try {
×
NEW
49
         const atts = await this.doDelete(resourceID, props);
×
50

NEW
51
         return await this.respond(atts);
×
52
      } catch(err) {
NEW
53
         return this.sendError(err);
×
54
      }
55
   }
56

57
   async doCreate() {
NEW
58
      return {};
×
59
   }
60

61
   async doUpdate() {
NEW
62
      return {};
×
63
   }
64

65
   async doDelete() {
NEW
66
      return {};
×
67
   }
68

69
   normalizeResourceProperties(props) {
UNCOV
70
      return props;
×
71
   }
72

73
   /**
74
    * See http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-responses.html
75
    */
76
   async respond(atts) {
NEW
77
      const resp = this._createResponse('SUCCESS', atts.PhysicalResourceId, _.omit(atts, 'PhysicalResourceId'));
×
78

79
      return this._sendResponse(resp);
×
80
   }
81

82
   _randomResourceID() {
83
      return `${this._event.LogicalResourceId}-${Math.random().toString(36).replace(/[^a-z]+/g, '')}`;
×
84
   }
85

86
   async sendError(err) {
NEW
87
      const resp = this._createResponse('FAILED', null, null, err.message);
×
88

89
      console.log('ERROR:', err, err.stack);
×
90

91
      return this._sendResponse(resp);
×
92
   }
93

94
   _createResponse(status, resourceID, data, reason) {
95
      return {
×
96
         StackId: this._event.StackId,
97
         RequestId: this._event.RequestId,
98
         LogicalResourceId: this._event.LogicalResourceId,
99
         PhysicalResourceId: resourceID || this._event.PhysicalResourceId || this._randomResourceID(),
×
100
         Status: status,
101
         Reason: reason || undefined,
×
102
         Data: data,
103
      };
104
   }
105

106
   _sendResponse(resp) {
NEW
107
      const body = JSON.stringify(resp),
×
NEW
108
            parsedURL = new URL(this._event.ResponseURL);
×
109

110
      console.log('Sending response to S3:', body);
×
111

NEW
112
      const opts = {
×
113
         hostname: parsedURL.hostname,
114
         port: 443,
115
         path: `${parsedURL.pathname}${parsedURL.search}`,
116
         method: 'PUT',
117
         headers: {
118
            'Content-Type': '',
119
            'Content-Length': body.length,
120
         },
121
      };
122

NEW
123
      return new Promise((resolve, reject) => {
×
NEW
124
         const req = https.request(opts, (response) => {
×
NEW
125
            response.resume();
×
NEW
126
            console.log('PUT response status:', response.statusCode);
×
NEW
127
            console.log('PUT response headers:', JSON.stringify(response.headers));
×
NEW
128
            resolve(resp);
×
129
         });
130

NEW
131
         req.on('error', (err) => {
×
NEW
132
            console.log('ERROR sending PUT request', err, err.stack);
×
NEW
133
            reject(err);
×
134
         });
135

NEW
136
         req.on('end', () => {
×
NEW
137
            console.log('end request');
×
138
         });
139

NEW
140
         req.write(body);
×
NEW
141
         req.end();
×
142
      });
143
   }
144

145
}
146

NEW
147
module.exports = BaseResource;
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc