UNPKG

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