@@ -26,6 +26,7 @@ package pkg
26
26
27
27
import (
28
28
"embed"
29
+ "encoding/json"
29
30
"errors"
30
31
"fmt"
31
32
"path/filepath"
@@ -44,6 +45,22 @@ import (
44
45
45
46
// Experimental must be set to true to enable !Rain::Module
46
47
var Experimental bool
48
+ var NoAnalytics bool
49
+ var HasRainSection bool
50
+
51
+ type analytics struct {
52
+ // Current Rain version
53
+ Version string
54
+
55
+ // Are we using experimental features?
56
+ Experimental bool
57
+
58
+ // Did we use any Rain modules?
59
+ HasModules bool
60
+
61
+ // Did the template have a Rain section?
62
+ HasRainSection bool
63
+ }
47
64
48
65
type transformContext struct {
49
66
nodeToTransform * yaml.Node
@@ -154,6 +171,8 @@ func processRainSection(t *cft.Template) bool {
154
171
// Now remove the Rain node from the template
155
172
t .RemoveSection (cft .Rain )
156
173
174
+ HasRainSection = true
175
+
157
176
return true
158
177
}
159
178
@@ -265,7 +284,27 @@ func Template(t cft.Template, rootDir string, fs *embed.FS) (cft.Template, error
265
284
retval .Node .Content = append (retval .Node .Content , templateNode )
266
285
}
267
286
268
- return retval , err
287
+ // Add analytics to Metadata
288
+ if ! NoAnalytics {
289
+ metadata , err := retval .GetSection (cft .Metadata )
290
+ if err != nil || metadata == nil {
291
+ metadata = node .AddMap (retval .Node .Content [0 ], string (cft .Metadata ))
292
+ }
293
+ awsToolsMetrics := node .AddMap (metadata , "AWSToolsMetrics" )
294
+ a := analytics {
295
+ Version : config .VERSION ,
296
+ HasModules : HasModules ,
297
+ Experimental : Experimental ,
298
+ HasRainSection : HasRainSection ,
299
+ }
300
+ s , _ := json .Marshal (& a )
301
+ awsToolsMetrics .Content = append (awsToolsMetrics .Content ,
302
+ & yaml.Node {Kind : yaml .ScalarNode , Value : "Rain" })
303
+ awsToolsMetrics .Content = append (awsToolsMetrics .Content ,
304
+ & yaml.Node {Kind : yaml .ScalarNode , Value : string (s )})
305
+ }
306
+
307
+ return retval , nil
269
308
}
270
309
271
310
// File opens path as a CloudFormation template and returns a cft.Template
0 commit comments