UNPKG

15.8 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.10.0
2(function() {
3 var CloudFormationTemplateContext, CoffeeScript, fs, path, vm,
4 bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
5 slice = [].slice;
6
7 fs = require('fs');
8
9 vm = require('vm');
10
11 path = require('path');
12
13 CoffeeScript = require('coffee-script');
14
15 CloudFormationTemplateContext = (function() {
16 function CloudFormationTemplateContext() {
17 this.Metadata = bind(this.Metadata, this);
18 this.Description = bind(this.Description, this);
19 this.Condition = bind(this.Condition, this);
20 this.Output = bind(this.Output, this);
21 this.Mapping = bind(this.Mapping, this);
22 this._resourceByType = bind(this._resourceByType, this);
23 this.DeclareResource = bind(this.DeclareResource, this);
24 this._buildCall = bind(this._buildCall, this);
25 this._paramByType = bind(this._paramByType, this);
26 this._resources = {};
27 this._parameters = {};
28 this._mappings = null;
29 this._outputs = {};
30 this._description = null;
31 this._conditions = null;
32 this._metadatas = null;
33 this.Params = {};
34 this.Resources = {};
35 this.Mappings = {};
36 this.Conditions = {};
37 this.AWS = {
38 AutoScaling: {
39 AutoScalingGroup: null,
40 LaunchConfiguration: null,
41 ScalingPolicy: null,
42 LifecycleHook: null,
43 ScheduledAction: null,
44 Trigger: null
45 },
46 CloudFormation: {
47 Authentication: null,
48 CustomResource: null,
49 Stack: null,
50 WaitCondition: null,
51 WaitConditionHandle: null
52 },
53 CloudFront: {
54 Distribution: null
55 },
56 CloudWatch: {
57 Alarm: null
58 },
59 CodeDeploy: {
60 Application: null,
61 DeploymentConfig: null,
62 DeploymentGroup: null
63 },
64 CodePipeline: {
65 Pipeline: null,
66 CustomActionType: null
67 },
68 Config: {
69 ConfigRule: null,
70 ConfigurationRecorder: null,
71 DeliveryChannel: null
72 },
73 DirectoryService: {
74 MicrosoftAD: null,
75 SimpleAD: null
76 },
77 CloudTrail: {
78 Trail: null
79 },
80 DataPipeline: {
81 Pipeline: null
82 },
83 DynamoDB: {
84 Table: null
85 },
86 EC2: {
87 CustomerGateway: null,
88 DHCPOptions: null,
89 EIP: null,
90 EIPAssociation: null,
91 Instance: null,
92 InternetGateway: null,
93 NatGateway: null,
94 NetworkAcl: null,
95 NetworkAclEntry: null,
96 NetworkInterface: null,
97 PlacementGroup: null,
98 Route: null,
99 RouteTable: null,
100 SecurityGroup: null,
101 SecurityGroupIngress: null,
102 SecurityGroupEgress: null,
103 Subnet: null,
104 SubnetNetworkAclAssociation: null,
105 SubnetRouteTableAssociation: null,
106 SpotFleet: null,
107 Volume: null,
108 VolumeAttachment: null,
109 VPC: null,
110 VPCDHCPOptionsAssociation: null,
111 VPCEndpoint: null,
112 VPCGatewayAttachment: null,
113 VPNConnection: null,
114 VPNGateway: null
115 },
116 ECR: {
117 Repository: null
118 },
119 ECS: {
120 Cluster: null,
121 Service: null,
122 TaskDefinition: null
123 },
124 ElastiCache: {
125 CacheCluster: null,
126 ParameterGroup: null,
127 ReplicationGroup: null,
128 SecurityGroup: null,
129 SecurityGroupIngress: null,
130 SubnetGroup: null
131 },
132 ElasticBeanstalk: {
133 Application: null,
134 ApplicationVersion: null,
135 Environment: null,
136 ConfigurationTemplate: null
137 },
138 ElasticLoadBalancing: {
139 LoadBalancer: null
140 },
141 Elasticsearch: {
142 Domain: null
143 },
144 EFS: {
145 FileSystem: null,
146 MountTarget: null
147 },
148 EMR: {
149 Cluster: null,
150 InstanceGroupConfig: null,
151 Step: null
152 },
153 GameLift: {
154 Alias: null,
155 Build: null,
156 Fleet: null
157 },
158 IAM: {
159 AccessKey: null,
160 Group: null,
161 InstanceProfile: null,
162 ManagedPolicy: null,
163 Policy: null,
164 Role: null,
165 User: null,
166 UserToGroupAddition: null
167 },
168 Kinesis: {
169 Stream: null
170 },
171 KMS: {
172 Key: null
173 },
174 Logs: {
175 Destination: null,
176 LogGroup: null,
177 LogStream: null,
178 MetricFilter: null,
179 SubscriptionFilter: null
180 },
181 Lambda: {
182 Alias: null,
183 EventSourceMapping: null,
184 Function: null,
185 Permission: null,
186 Version: null
187 },
188 OpsWorks: {
189 App: null,
190 Instance: null,
191 Layer: null,
192 Stack: null
193 },
194 Redshift: {
195 Cluster: null,
196 ClusterParameterGroup: null,
197 ClusterSecurityGroup: null,
198 ClusterSubnetGroup: null
199 },
200 RDS: {
201 DBCluster: null,
202 DBClusterParameterGroup: null,
203 DBInstance: null,
204 DBParameterGroup: null,
205 DBSubnetGroup: null,
206 DBSecurityGroup: null,
207 DBSecurityGroupIngress: null,
208 EventSubscription: null,
209 OptionGroup: null
210 },
211 Route53: {
212 RecordSet: null,
213 RecordSetGroup: null,
214 HostedZone: null,
215 HealthCheck: null
216 },
217 SDB: {
218 Domain: null
219 },
220 S3: {
221 Bucket: null,
222 BucketPolicy: null
223 },
224 SNS: {
225 Topic: null,
226 TopicPolicy: null
227 },
228 SQS: {
229 Queue: null,
230 QueuePolicy: null
231 },
232 SSM: {
233 Document: null
234 },
235 WAF: {
236 ByteMatchSet: null,
237 IPSet: null,
238 Rule: null,
239 SqlInjectionMatchSet: null,
240 WebACL: null
241 },
242 WorkSpaces: {
243 Workspace: null
244 }
245 };
246 this.Param = {
247 String: (function(_this) {
248 return function(name, arg1, arg2) {
249 return _this._paramByType('String', name, arg1, arg2);
250 };
251 })(this),
252 Number: (function(_this) {
253 return function(name, arg1, arg2) {
254 return _this._paramByType('Number', name, arg1, arg2);
255 };
256 })(this),
257 CommaDelimitedList: (function(_this) {
258 return function(name, arg1, arg2) {
259 return _this._paramByType('CommaDelimitedList', name, arg1, arg2);
260 };
261 })(this),
262 AWS: (function(_this) {
263 return function(type, name, arg1, arg2) {
264 return _this._paramByType("AWS::" + type, name, arg1, arg2);
265 };
266 })(this),
267 AWSList: (function(_this) {
268 return function(type, name, arg1, arg2) {
269 return _this._paramByType("List<AWS::" + type + ">", name, arg1, arg2);
270 };
271 })(this)
272 };
273 this._buildCall(null, null, 'AWS', this.AWS);
274 }
275
276 CloudFormationTemplateContext.prototype._paramByType = function(type, name, arg1, arg2) {
277 var result;
278 result = {};
279 if (arg1 == null) {
280 result[name] = {};
281 } else if (arg2 == null) {
282 result[name] = typeof arg1 === 'string' ? {
283 Description: arg1
284 } : arg1;
285 } else {
286 result[name] = arg2;
287 result[name].Description = arg1;
288 }
289 result[name].Type = type;
290 this._set(result, this._parameters);
291 return this.Params[name] = {
292 Ref: name
293 };
294 };
295
296 CloudFormationTemplateContext.prototype._buildCall = function(parent, lastKey, awsType, leaf) {
297 var key, val;
298 if (leaf != null) {
299 for (key in leaf) {
300 val = leaf[key];
301 this._buildCall(leaf, key, awsType + "::" + key, val);
302 }
303 return;
304 }
305 return parent[lastKey] = (function(_this) {
306 return function(name, props) {
307 return _this._resourceByType(awsType, name, props);
308 };
309 })(this);
310 };
311
312 CloudFormationTemplateContext.prototype.DeclareResource = function(name) {
313 var base;
314 return (base = this.Resources)[name] != null ? base[name] : base[name] = {
315 Ref: name
316 };
317 };
318
319 CloudFormationTemplateContext.prototype._resourceByType = function(type, name, props) {
320 var result;
321 result = {};
322 if (((props != null ? props.Metadata : void 0) != null) || ((props != null ? props.Properties : void 0) != null) || ((props != null ? props.DependsOn : void 0) != null) || ((props != null ? props.UpdatePolicy : void 0) != null) || ((props != null ? props.CreationPolicy : void 0) != null) || ((props != null ? props.Condition : void 0) != null)) {
323 result[name] = props;
324 result[name].Type = type;
325 } else {
326 result[name] = {
327 Type: type,
328 Properties: props
329 };
330 }
331 this._set(result, this._resources);
332 return this.DeclareResource(name);
333 };
334
335 CloudFormationTemplateContext.prototype._set = function(source, target) {
336 var key, results, val;
337 results = [];
338 for (key in source) {
339 val = source[key];
340 results.push(target[key] = val);
341 }
342 return results;
343 };
344
345 CloudFormationTemplateContext.prototype.Mapping = function(name, map) {
346 var result;
347 if (this._mappings == null) {
348 this._mappings = {};
349 }
350 result = {};
351 result[name] = map;
352 return this._set(result, this._mappings);
353 };
354
355 CloudFormationTemplateContext.prototype.Output = function() {
356 var args, name, result;
357 name = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
358 result = {};
359 if (args.length === 1) {
360 result[name] = {
361 Value: args[0]
362 };
363 }
364 if (args.length === 2) {
365 result[name] = {
366 Description: args[0],
367 Value: args[1]
368 };
369 }
370 return this._set(result, this._outputs);
371 };
372
373 CloudFormationTemplateContext.prototype.Condition = function(name, intrinsicfn) {
374 var result;
375 if (this._conditions == null) {
376 this._conditions = {};
377 }
378 result = {};
379 result[name] = intrinsicfn;
380 return this._set(result, this._conditions);
381 };
382
383 CloudFormationTemplateContext.prototype.Description = function(d) {
384 return this._description = d;
385 };
386
387 CloudFormationTemplateContext.prototype.Metadata = function(o) {
388 if (this._metadatas == null) {
389 this._metadatas = {};
390 }
391 return this._set(o, this._metadatas);
392 };
393
394 CloudFormationTemplateContext.prototype.Tag = function(key, val) {
395 return {
396 Key: key,
397 Value: val
398 };
399 };
400
401 CloudFormationTemplateContext.prototype.Join = function() {
402 var args, delimiter;
403 delimiter = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
404 if (args.length === 1 && (args[0] instanceof Array)) {
405 return {
406 'Fn::Join': [delimiter, args[0]]
407 };
408 } else {
409 return {
410 'Fn::Join': [delimiter, args]
411 };
412 }
413 };
414
415 CloudFormationTemplateContext.prototype.FindInMap = function() {
416 var args;
417 args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
418 return {
419 'Fn::FindInMap': args
420 };
421 };
422
423 CloudFormationTemplateContext.prototype.GetAtt = function() {
424 var args;
425 args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
426 return {
427 'Fn::GetAtt': args
428 };
429 };
430
431 CloudFormationTemplateContext.prototype.Base64 = function(arg) {
432 return {
433 'Fn::Base64': arg
434 };
435 };
436
437 CloudFormationTemplateContext.prototype.GetAZs = function(arg) {
438 return {
439 'Fn::GetAZs': arg
440 };
441 };
442
443 CloudFormationTemplateContext.prototype.Select = function() {
444 var args, index;
445 index = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
446 if (args.length === 1 && (args[0] instanceof Array)) {
447 return {
448 'Fn::Select': [index, args[0]]
449 };
450 } else {
451 return {
452 'Fn::Select': [index, args]
453 };
454 }
455 };
456
457 CloudFormationTemplateContext.prototype.And = function() {
458 var conditions;
459 conditions = 1 <= arguments.length ? slice.call(arguments, 0) : [];
460 return {
461 'Fn::And': conditions
462 };
463 };
464
465 CloudFormationTemplateContext.prototype.Equals = function(value_1, value_2) {
466 return {
467 'Fn::Equals': [value_1, value_2]
468 };
469 };
470
471 CloudFormationTemplateContext.prototype.If = function(condition, value_if_true, value_if_false) {
472 return {
473 'Fn::If': [condition, value_if_true, value_if_false]
474 };
475 };
476
477 CloudFormationTemplateContext.prototype.Not = function(condition) {
478 return {
479 'Fn::Not': [condition]
480 };
481 };
482
483 CloudFormationTemplateContext.prototype.Or = function() {
484 var conditions;
485 conditions = 1 <= arguments.length ? slice.call(arguments, 0) : [];
486 return {
487 'Fn::Or': conditions
488 };
489 };
490
491 CloudFormationTemplateContext.prototype.AccountId = {
492 Ref: 'AWS::AccountId'
493 };
494
495 CloudFormationTemplateContext.prototype.NotificationARNs = {
496 Ref: 'AWS::NotificationARNs'
497 };
498
499 CloudFormationTemplateContext.prototype.NoValue = {
500 Ref: 'AWS::NoValue'
501 };
502
503 CloudFormationTemplateContext.prototype.Region = {
504 Ref: 'AWS::Region'
505 };
506
507 CloudFormationTemplateContext.prototype.StackId = {
508 Ref: 'AWS::StackId'
509 };
510
511 CloudFormationTemplateContext.prototype.StackName = {
512 Ref: 'AWS::StackName'
513 };
514
515 CloudFormationTemplateContext.prototype.InitScript = function(arg) {
516 var chunks, compiled, existsSyncFunc, match, pattern, text;
517 existsSyncFunc = fs.existsSync != null ? fs.existsSync : path.existsSync;
518 if (!existsSyncFunc(arg)) {
519 text = arg;
520 } else {
521 text = fs.readFileSync(arg).toString();
522 }
523 chunks = [];
524 pattern = /((.|\n)*?)%{([^}?]+)}?((.|\n)*)/;
525 match = text.match(pattern);
526 while (match) {
527 chunks.push(match[1]);
528 compiled = CoffeeScript.compile(match[3], {
529 bare: true
530 });
531 chunks.push(eval(compiled));
532 text = match[4];
533 match = text.match(pattern);
534 }
535 if (text && text.length > 0) {
536 chunks.push(text);
537 }
538 return this.Base64(this.Join('', chunks));
539 };
540
541 return CloudFormationTemplateContext;
542
543 })();
544
545 module.exports.CloudFormationTemplateContext = CloudFormationTemplateContext;
546
547 module.exports = function(func) {
548 var context, template;
549 context = new CloudFormationTemplateContext;
550 func.apply(context, [context]);
551 template = {
552 AWSTemplateFormatVersion: '2010-09-09'
553 };
554 if (context._description != null) {
555 template.Description = context._description;
556 }
557 template.Parameters = context._parameters;
558 if (context._mappings != null) {
559 template.Mappings = context._mappings;
560 }
561 template.Resources = context._resources;
562 template.Outputs = context._outputs;
563 if (context._conditions != null) {
564 template.Conditions = context._conditions;
565 }
566 if (context._metadatas != null) {
567 template.Metadata = context._metadatas;
568 }
569 return template;
570 };
571
572 require('pkginfo')(module, 'version');
573
574}).call(this);