cfhighlander 0.2.1 → 0.3.0.alpha.1528936037
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +199 -82
- data/bin/cfhighlander +1 -1
- data/bin/{highlander.rb → cfhighlander.rb} +39 -23
- data/cfndsl_ext/sg.rb +29 -2
- data/hl_ext/mapping_helper.rb +6 -4
- data/lib/{highlander.compiler.rb → cfhighlander.compiler.rb} +26 -18
- data/lib/{highlander.dsl.base.rb → cfhighlander.dsl.base.rb} +3 -2
- data/lib/cfhighlander.dsl.params.rb +108 -0
- data/lib/cfhighlander.dsl.subcomponent.rb +274 -0
- data/lib/{highlander.dsl.rb → cfhighlander.dsl.template.rb} +111 -63
- data/lib/cfhighlander.factory.rb +45 -0
- data/lib/cfhighlander.factory.templatefinder.rb +248 -0
- data/lib/{highlander.helper.rb → cfhighlander.helper.rb} +2 -2
- data/lib/{highlander.mapproviders.rb → cfhighlander.mapproviders.rb} +1 -1
- data/lib/cfhighlander.model.component.rb +177 -0
- data/lib/cfhighlander.model.templatemeta.rb +25 -0
- data/lib/{highlander.publisher.rb → cfhighlander.publisher.rb} +3 -3
- data/lib/{highlander.validator.rb → cfhighlander.validator.rb} +1 -1
- data/lib/util/zip.util.rb +1 -1
- data/templates/cfndsl.component.template.erb +15 -14
- metadata +38 -15
- data/lib/highlander.dsl.component.rb +0 -243
- data/lib/highlander.dsl.params.rb +0 -113
- data/lib/highlander.factory.rb +0 -359
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16a118e3b352f9d1a3c87f8f2703a990a362c3a46d419f9c8c3a6db2bb6c8ded
|
4
|
+
data.tar.gz: 98ce45d749072b5614d9541a43474ffc98eca86983a0d4bb3a38f0967f8b7701
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efc14c3f56f84ff302a049a82e3e619a150c1bc5825345ed859899412ad06fa8bc7edc385d908fc11a381e197eaf65451ff6ba6156c99fabc49f2f8f3bf52153
|
7
|
+
data.tar.gz: e139dab1ac33468f77380ff9fec1e8646fa526db0e48bee5b2be4181db2d09edebdc59e05c1bfec48ff79a4bb56aa0d61cbd690b1fb9283f2f9a58f5f45349c8
|
data/README.md
CHANGED
@@ -1,24 +1,27 @@
|
|
1
1
|
[](https://travis-ci.com/theonestack/cfhighlander)
|
2
2
|
|
3
|
-
#
|
3
|
+
# Cfhighlander
|
4
4
|
|
5
|
-
|
5
|
+
Cfhighlander is DSL processor that enables composition and orchestration of Amazon CloudFormation templates
|
6
6
|
written using [CfnDsl](https://github.com/cfndsl/cfndsl) in an abstract way. It tries to tackle problem of merging multiple templates into master
|
7
7
|
template in an elegant way, so higher degree of template reuse can be achieved. It does so by formalising commonly
|
8
|
-
used patterns via DSL statements. For an example, passing output of one stack into other stack is
|
9
|
-
|
8
|
+
used cfndsl template composition patterns via DSL statements. For an example, passing output of one stack into other stack is done
|
9
|
+
automatically if parameter and output names are the same,
|
10
|
+
rather than wiring them manually in 'master' cfndsl template. For this example to
|
10
11
|
work, parent component will have to pull in both component rendering output values, and component pulling them in
|
11
|
-
as parameters.
|
12
|
-
|
12
|
+
as parameters. Cfhighlander allows for greater reuse of component templates by allowing references to templates
|
13
|
+
via git urls, and s3 urls. [Theonestack](https://github.com/theonestack) has several prebuilt component templates to use,
|
14
|
+
with repositories from this org being one of the default sources for searching component templates.
|
13
15
|
|
14
|
-
Highlander DSL produces CloudFormation templates in
|
16
|
+
Highlander DSL produces CloudFormation templates in 4 phases
|
15
17
|
|
16
18
|
- Processing referenced component's configuration and resolving configuration exports
|
19
|
+
- Wiring parameters from components to their inner components
|
17
20
|
- Producing [CfnDsl](https://github.com/cfndsl/cfndsl) templates for all components and subcomponents as intermediary
|
18
21
|
step
|
19
22
|
- Producing resulting CloudFormation templates using configuration and templates generated in two previous phases.
|
20
23
|
|
21
|
-
Each phase above is executable as stand-alone through CLI, making development of Highlander templates easier by enabling
|
24
|
+
Each phase (aside from parameter wiring) above is executable as stand-alone through CLI, making development of Highlander templates easier by enabling
|
22
25
|
debugging of produced configuration and cfndsl templates.
|
23
26
|
|
24
27
|
|
@@ -41,14 +44,14 @@ this file defines map used within component itself
|
|
41
44
|
**Component** is basic building block of highlander systems. Components have following roles
|
42
45
|
|
43
46
|
- Define (include) other components
|
44
|
-
-
|
47
|
+
- Provide values for their inner component parameters
|
45
48
|
- Define how their configuration affects other components
|
46
49
|
- Define sources of their inner components
|
47
50
|
- Define publish location for both component source code and compiled CloudFormation templates
|
48
51
|
- Define cfndsl template used for building CloudFormation resources
|
49
52
|
|
50
53
|
|
51
|
-
**Outer component** is component that defines other component via
|
54
|
+
**Outer component** is component that defines other component via cfhighlander dsl `Component` statement. Defined component
|
52
55
|
is called **inner component**. Components defined under same outer component are **sibling components**
|
53
56
|
|
54
57
|
## Usage
|
@@ -58,30 +61,30 @@ For both ways, highlander is distributed as ruby gem
|
|
58
61
|
|
59
62
|
|
60
63
|
```bash
|
61
|
-
$ gem install
|
62
|
-
$
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
$ gem install cfhighlander
|
65
|
+
$ cfhighlander help
|
66
|
+
cfhighlander commands:
|
67
|
+
cfhighlander cfcompile component[@version] -f, --format=FORMAT # Compile Highlander component to CloudFormation templates
|
68
|
+
cfhighlander cfpublish component[@version] -f, --format=FORMAT # Publish CloudFormation template for component, and it' referenced subcomponents
|
69
|
+
cfhighlander configcompile component[@version] # Compile Highlander components configuration
|
70
|
+
cfhighlander dslcompile component[@version] -f, --format=FORMAT # Compile Highlander component configuration and create cfndsl templates
|
71
|
+
cfhighlander help [COMMAND] # Describe available commands or one specific command
|
72
|
+
cfhighlander publish component[@version] [-v published_version] # Publish CloudFormation template for component, and it' referenced subcomponents
|
70
73
|
|
71
74
|
```
|
72
75
|
### Working directory
|
73
76
|
|
74
77
|
All templates and configuration generated are placed in `$WORKDIR/out` directory. Optionally, you can alter working directory
|
75
|
-
via `
|
78
|
+
via `CFHIGHLANDER_WORKDIR` environment variable.
|
76
79
|
|
77
80
|
### Commands
|
78
81
|
|
79
82
|
To get full list of options for any of cli commands use `highlander help command_name` syntax
|
80
83
|
|
81
84
|
```bash
|
82
|
-
$
|
85
|
+
$ cfhighlander help publish
|
83
86
|
Usage:
|
84
|
-
|
87
|
+
cfhighlander publish component[@version] [-v published_version]
|
85
88
|
|
86
89
|
Options:
|
87
90
|
[--dstbucket=DSTBUCKET] # Distribution S3 bucket
|
@@ -89,13 +92,13 @@ Options:
|
|
89
92
|
-v, [--version=VERSION] # Distribution component version, defaults to latest
|
90
93
|
|
91
94
|
Publish CloudFormation template for component,
|
92
|
-
and it' referenced subcomponents
|
95
|
+
and it's referenced subcomponents
|
93
96
|
|
94
97
|
```
|
95
98
|
|
96
99
|
#### Silent mode
|
97
100
|
|
98
|
-
|
101
|
+
Cfhighlander DSL processor has built-in support for packaging and deploying AWS Lambda functions. Some of these lambda
|
99
102
|
functions may require shell command to be executed (e.g. pulling library dependencies) prior their packaging in ZIP archive format.
|
100
103
|
Such commands are potential security risk, as they allow execution of arbitrary code, so for this reason user agreement is required
|
101
104
|
e.g:
|
@@ -136,15 +139,14 @@ cfndsl templates. Check component configuration section for more details.
|
|
136
139
|
|
137
140
|
#### dslcompile
|
138
141
|
|
139
|
-
*dslcompile* will produce intermediary cfndsl templates. This is useful for debugging
|
142
|
+
*dslcompile* will produce intermediary cfndsl templates. This is useful for debugging cfhighlander components
|
140
143
|
|
141
144
|
#### publish
|
142
145
|
|
143
|
-
*publish* command publishes
|
146
|
+
*publish* command publishes cfhighlander components source code to s3 location (compared to *cfpublish* which is publishing
|
144
147
|
compiled cloudformation templates). Same CLI / DSL options apply as for *cfpublish* command. Version defaults to `latest`
|
145
148
|
|
146
149
|
|
147
|
-
|
148
150
|
## Component configuration
|
149
151
|
|
150
152
|
There are 4 levels of component configuration
|
@@ -169,7 +171,7 @@ This configuration level overrides component's own config file.
|
|
169
171
|
- Outer component explicit configuration. You can pass `config` named parameter to `Component` statement, such as
|
170
172
|
|
171
173
|
```ruby
|
172
|
-
|
174
|
+
CfhighlanderTemplate do
|
173
175
|
|
174
176
|
# ...
|
175
177
|
# some dsl code
|
@@ -250,6 +252,47 @@ included via Ruby `require` function in compiled Cfndsl template.
|
|
250
252
|
|
251
253
|
## Component DSL
|
252
254
|
|
255
|
+
### Inner components or subcomponents
|
256
|
+
|
257
|
+
Inner components or subcomponents are defined via `Component` DSL statement
|
258
|
+
|
259
|
+
```ruby
|
260
|
+
CfhighlanderTemplate do
|
261
|
+
|
262
|
+
# Example1 : Include component by template name only
|
263
|
+
Component 'vpc'
|
264
|
+
|
265
|
+
# Example2 : Include component by template name, version and give it a name
|
266
|
+
Component template: 'ecs@master.snapshot'
|
267
|
+
|
268
|
+
end
|
269
|
+
|
270
|
+
```
|
271
|
+
|
272
|
+
**Conditional components** - If you want to add top level paramater as feature toggle for one of the inner
|
273
|
+
components, just mark it as conditional, using `conditional:` named parameter. In addition to this, default
|
274
|
+
value for feature toggle can be supplied using `enabled:` named parameter
|
275
|
+
|
276
|
+
|
277
|
+
```ruby
|
278
|
+
|
279
|
+
# Include vpc and 2 ecs clusters with feature flags
|
280
|
+
CfhighlanderTemplate do
|
281
|
+
|
282
|
+
# vpc component
|
283
|
+
Component 'vpc'
|
284
|
+
|
285
|
+
# Ecs Cluster 1 has feature toggle, enabled by default
|
286
|
+
Component name: 'ecs1', template: 'ecs', conditional: true
|
287
|
+
|
288
|
+
# Ecs Cluster 2 has feature toggle, and is explicitly disabled by default
|
289
|
+
Component name: 'ec2', template: 'ecs', conditional: true, enabled: false
|
290
|
+
|
291
|
+
end
|
292
|
+
|
293
|
+
```
|
294
|
+
|
295
|
+
|
253
296
|
|
254
297
|
### Parameters
|
255
298
|
|
@@ -257,7 +300,7 @@ Parameters block is used to define CloudFormation template parameters, and metad
|
|
257
300
|
are wired with outer or sibling components.
|
258
301
|
|
259
302
|
```ruby
|
260
|
-
|
303
|
+
CfhighlanderTemplate do
|
261
304
|
Parameters do
|
262
305
|
##
|
263
306
|
## parameter definitions here
|
@@ -270,81 +313,117 @@ Parameter block supports following parameters
|
|
270
313
|
|
271
314
|
#### ComponentParam
|
272
315
|
|
273
|
-
`ComponentParam` - Component parameter
|
274
|
-
|
275
|
-
|
316
|
+
`ComponentParam` - Component parameter exposes parameter to be wired from outer component. Cfhighlander's
|
317
|
+
autowiring mechanism will try and find any stack outputs from other components defined by outer components with name
|
318
|
+
matching. If there is no explicit value provided, or autowired from outputs, parameter will be propagated to outer component.
|
319
|
+
|
320
|
+
Propagated parameter will be prefixed with component name **if it is not defined as global parameter**. Otherwise,
|
321
|
+
parameter name is kept in full.
|
322
|
+
|
323
|
+
Example below demonstrates 3 different ways of providing parameter values from outer to inner component.
|
324
|
+
|
325
|
+
- Provide value explicitly
|
326
|
+
- Provide value explicitly as output of another component
|
327
|
+
- Autowire value from output of another component with the same name
|
328
|
+
- Propagate parameter to outer component
|
276
329
|
|
277
330
|
```ruby
|
278
331
|
|
279
|
-
# Inner Component
|
280
|
-
|
332
|
+
# Inner Component 1
|
333
|
+
CfhighlanderTemplate do
|
281
334
|
Name 's3'
|
282
335
|
Parameters do
|
283
336
|
ComponentParam 'BucketName','highlander.example.com.au'
|
337
|
+
ComponentParam 'BucketName2',''
|
338
|
+
ComponentParam 'BucketName3',''
|
339
|
+
ComponentParam 'BucketName4','', isGlobal: false # default value is false
|
340
|
+
ComponentParam 'BucketName5','', isGlobal: true
|
284
341
|
end
|
342
|
+
|
285
343
|
end
|
344
|
+
|
286
345
|
```
|
287
346
|
|
288
347
|
```ruby
|
289
|
-
#
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
parameters:{'BucketName' => 'outer.example.com.au'}
|
348
|
+
# Inner Component 2
|
349
|
+
CfhighlanderTemplate do
|
350
|
+
Name 'nameproducer'
|
351
|
+
|
352
|
+
# has output 'bucket name defined in cfdnsl
|
295
353
|
end
|
296
|
-
```
|
297
354
|
|
298
|
-
#### StackParam
|
299
355
|
|
300
|
-
|
301
|
-
|
356
|
+
# -- contents of cfndsl
|
357
|
+
CloudFormation do
|
302
358
|
|
359
|
+
Condition 'AlwaysFalse', FnEquals('true','false')
|
360
|
+
S3_Bucket :resourcetovalidateproperly do
|
361
|
+
Condition 'AlwaysFalse'
|
362
|
+
end
|
303
363
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
Component template:'s3',name:'s3'
|
364
|
+
Output('BucketName') do
|
365
|
+
Value('highlanderbucketautowired.example.com.au')
|
366
|
+
end
|
308
367
|
end
|
368
|
+
|
369
|
+
|
309
370
|
```
|
310
371
|
|
311
372
|
```ruby
|
312
|
-
#
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
373
|
+
# Outer component
|
374
|
+
CfhighlanderTemplate do
|
375
|
+
Component 'nameproducer'
|
376
|
+
Component 's3' do
|
377
|
+
parameter name: 'BucketName2', value: 'nameproducer.BucketName'
|
378
|
+
parameter name: 'BucketName3', value: 'mybucket.example.cfhighlander.org'
|
379
|
+
end
|
319
380
|
end
|
381
|
+
|
320
382
|
```
|
321
383
|
|
322
384
|
|
323
|
-
Example above translates to following
|
385
|
+
Example above translates to following wiring of parameters in cfndsl template
|
324
386
|
```ruby
|
325
387
|
CloudFormation do
|
326
388
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
Parameter('s3BucketName') do
|
333
|
-
Type 'String'
|
334
|
-
Default 'highlander.example.com.au'
|
389
|
+
# Parameter that was propagated
|
390
|
+
Parameter('s3BucketName4') do
|
391
|
+
Type 'String'
|
392
|
+
Default ''
|
393
|
+
NoEcho false
|
335
394
|
end
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
'EnvironmentName' => Ref('EnvironmentName'),
|
342
|
-
|
343
|
-
'BucketName' => Ref('s3BucketName'),
|
344
|
-
|
345
|
-
})
|
395
|
+
|
396
|
+
Parameter('BucketName5') do
|
397
|
+
Type 'String'
|
398
|
+
Default ''
|
399
|
+
NoEcho false
|
346
400
|
end
|
401
|
+
|
402
|
+
CloudFormation_Stack('s3') do
|
403
|
+
TemplateURL './s3.compiled.yaml'
|
404
|
+
Parameters ({
|
405
|
+
|
406
|
+
# Paramater that was auto-wired
|
407
|
+
'BucketName' => {"Fn::GetAtt":["nameproducer","Outputs.BucketName"]},
|
408
|
+
|
409
|
+
# Parameter that was explicitly wired as output param from another component
|
410
|
+
'BucketName2' => {"Fn::GetAtt":["nameproducer","Outputs.BucketName"]},
|
411
|
+
|
412
|
+
# Paramater that was explicitly provided
|
413
|
+
'BucketName3' => 'mybucket.example.cfhighlander.org',
|
414
|
+
|
415
|
+
# Reference to parameter that was propagated. isGlobal: false when defining
|
416
|
+
# parameter, so parameter name is prefixed with component name
|
417
|
+
'BucketName4' => {"Ref":"s3BucketName4"},
|
418
|
+
|
419
|
+
# Reference to parameter that was propagated. isGlobal: true when defining
|
420
|
+
# parameter, so parameter name is not prefixed, but rather propagated as-is
|
421
|
+
'BucketName5' => {"Ref":"BucketName5"},
|
422
|
+
|
423
|
+
})
|
424
|
+
end
|
347
425
|
end
|
426
|
+
|
348
427
|
```
|
349
428
|
|
350
429
|
|
@@ -358,7 +437,7 @@ This DSL statements takes a full body, as Mapping name, Map key, and value key n
|
|
358
437
|
|
359
438
|
```ruby
|
360
439
|
# Inner component
|
361
|
-
|
440
|
+
CfhighlanderTemplate do
|
362
441
|
Name 's3'
|
363
442
|
Parameters do
|
364
443
|
MappingParam 'BucketName' do
|
@@ -370,17 +449,13 @@ end
|
|
370
449
|
```
|
371
450
|
|
372
451
|
|
373
|
-
#### OutputParam
|
374
|
-
|
375
|
-
TBD
|
376
|
-
|
377
452
|
### DependsOn
|
378
453
|
|
379
454
|
`DependsOn` - this will include any globally exported libraries from given
|
380
455
|
template. E.g.
|
381
456
|
|
382
457
|
```ruby
|
383
|
-
|
458
|
+
CfhighlanderTemplate do
|
384
459
|
Name 's3'
|
385
460
|
DependsOn 'vpc@1.0.3'
|
386
461
|
end
|
@@ -398,14 +473,56 @@ so extension methods can be consumed within cfndsl template.
|
|
398
473
|
#### Referencing
|
399
474
|
|
400
475
|
|
401
|
-
## Finding and
|
476
|
+
## Finding templates and creating components
|
477
|
+
|
478
|
+
|
479
|
+
Templates are located by default in following locations
|
480
|
+
|
481
|
+
- `$WD`
|
482
|
+
- `$WD/$componentname`
|
483
|
+
- `$WD/components/$componentname`
|
484
|
+
- `~/.cfhighlander/components/componentname/componentversion`
|
485
|
+
- `https://github.com/cfhighlander/theonestack/hl-component-$componentname` on `master` branch
|
486
|
+
|
487
|
+
Location of component templates can be given as git/github repo:
|
488
|
+
|
489
|
+
```ruby
|
490
|
+
|
491
|
+
CfhighlanderTemplate do
|
492
|
+
|
493
|
+
# pulls directly from master branch of https://github.com/theonestack/hl-component-vpc
|
494
|
+
Component name: 'vpc0', template: 'vpc'
|
495
|
+
|
496
|
+
# specify branch github.com: or github: work. You specify branch with hash
|
497
|
+
Component name: 'vpc1', template: 'github:theonestack/hl-component-vpc#master'
|
498
|
+
|
499
|
+
# you can use git over ssh
|
500
|
+
# Component name: 'vpc2', template: 'git:git@github.com:theonestack/hl-component-vpc.git'
|
501
|
+
|
502
|
+
# use git over https
|
503
|
+
Component name: 'vpc3', template: 'git:https://github.com/theonestack/hl-component-sns.git'
|
504
|
+
|
505
|
+
# specify .snapshot to always clone fresh copy
|
506
|
+
Component name: 'vpc4', template: 'git:https://github.com/theonestack/hl-component-sns.git#master.snapshot'
|
507
|
+
|
508
|
+
# by default, if not found locally, highlander will search for https://github.com/theonestack/component-$componentname
|
509
|
+
# in v${version} branch (or tag for that matter)
|
510
|
+
Component name: 'vpc5', template: 'vpc@1.0.4'
|
511
|
+
|
512
|
+
end
|
513
|
+
|
514
|
+
```
|
515
|
+
|
402
516
|
|
403
517
|
## Rendering CloudFormation templates
|
404
518
|
|
405
519
|
|
520
|
+
```bash
|
521
|
+
$ cfhighlander cfcompile [component] [-v distributedversion]
|
522
|
+
```
|
406
523
|
|
407
524
|
## Global Extensions
|
408
525
|
|
409
526
|
Any extensions placed within `cfndsl_ext` folder will be
|
410
527
|
available in cfndsl templates of all components. Any extensions placed within `hl_ext` folder are
|
411
|
-
available in
|
528
|
+
available in cfhighlander templates of all components.
|
data/bin/cfhighlander
CHANGED
@@ -9,10 +9,10 @@
|
|
9
9
|
|
10
10
|
require 'thor'
|
11
11
|
require 'rubygems'
|
12
|
-
require_relative '../lib
|
13
|
-
require_relative '../lib/
|
14
|
-
require_relative '../lib/
|
15
|
-
require_relative '../lib/
|
12
|
+
require_relative '../lib/cfhighlander.compiler'
|
13
|
+
require_relative '../lib/cfhighlander.factory'
|
14
|
+
require_relative '../lib/cfhighlander.publisher'
|
15
|
+
require_relative '../lib/cfhighlander.validator'
|
16
16
|
|
17
17
|
class HighlanderCli < Thor
|
18
18
|
|
@@ -22,15 +22,15 @@ class HighlanderCli < Thor
|
|
22
22
|
|
23
23
|
desc 'configcompile component[@version]', 'Compile Highlander components configuration'
|
24
24
|
|
25
|
-
def configcompile(
|
25
|
+
def configcompile(template_name)
|
26
26
|
|
27
27
|
# find and load component
|
28
|
-
component_loader =
|
29
|
-
component = component_loader.
|
28
|
+
component_loader = Cfhighlander::Factory::ComponentFactory.new
|
29
|
+
component = component_loader.loadComponentFromTemplate(template_name)
|
30
30
|
component.load
|
31
31
|
|
32
32
|
# compile cfndsl template
|
33
|
-
component_compiler =
|
33
|
+
component_compiler = Cfhighlander::Compiler::ComponentCompiler.new(component)
|
34
34
|
component_compiler.writeConfig(true)
|
35
35
|
end
|
36
36
|
|
@@ -50,7 +50,7 @@ class HighlanderCli < Thor
|
|
50
50
|
component = build_component(options, component_name)
|
51
51
|
|
52
52
|
# compile cfndsl template
|
53
|
-
component_compiler =
|
53
|
+
component_compiler = Cfhighlander::Compiler::ComponentCompiler.new(component)
|
54
54
|
component_compiler.silent_mode = options[:quiet]
|
55
55
|
out_format = options[:format]
|
56
56
|
component_compiler.compileCfnDsl out_format
|
@@ -71,16 +71,27 @@ class HighlanderCli < Thor
|
|
71
71
|
method_option :quiet, :type => :boolean, :default => false, :aliases => '-q',
|
72
72
|
:desc => 'Silently agree on user prompts (e.g. Package lambda command)'
|
73
73
|
|
74
|
-
def cfcompile(component_name)
|
74
|
+
def cfcompile(component_name = nil)
|
75
|
+
|
76
|
+
if component_name.nil?
|
77
|
+
candidates = Dir["*.cfhighlander.rb"]
|
78
|
+
if candidates.size == 0
|
79
|
+
self.help('cfcompile')
|
80
|
+
exit -1
|
81
|
+
else
|
82
|
+
component_name = candidates[0].gsub('.cfhighlander.rb','')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
75
86
|
component = build_component(options, component_name)
|
76
87
|
|
77
88
|
# compile cloud formation
|
78
|
-
component_compiler =
|
89
|
+
component_compiler = Cfhighlander::Compiler::ComponentCompiler.new(component)
|
79
90
|
component_compiler.silent_mode = options[:quiet]
|
80
91
|
out_format = options[:format]
|
81
92
|
component_compiler.compileCloudFormation out_format
|
82
93
|
if options[:validate]
|
83
|
-
component_validator =
|
94
|
+
component_validator = Cfhighlander::Cloudformation::Validator.new(component)
|
84
95
|
component_validator.validate(component_compiler.cfn_template_paths, out_format)
|
85
96
|
end
|
86
97
|
component_compiler
|
@@ -103,7 +114,7 @@ class HighlanderCli < Thor
|
|
103
114
|
|
104
115
|
def cfpublish(component_name)
|
105
116
|
compiler = cfcompile(component_name)
|
106
|
-
publisher =
|
117
|
+
publisher = Cfhighlander::Publisher::ComponentPublisher.new(compiler.component, false)
|
107
118
|
publisher.publishFiles(compiler.cfn_template_paths + compiler.lambda_src_paths)
|
108
119
|
end
|
109
120
|
|
@@ -117,37 +128,35 @@ class HighlanderCli < Thor
|
|
117
128
|
method_option :version, :type => :string, :required => false, :default => nil, :aliases => '-v',
|
118
129
|
:desc => 'Distribution component version, defaults to latest'
|
119
130
|
|
120
|
-
def publish(
|
131
|
+
def publish(template_name)
|
121
132
|
component_version = options[:version]
|
122
133
|
distribution_bucket = options[:dstbucket]
|
123
134
|
distribution_prefix = options[:dstprefix]
|
124
135
|
|
125
136
|
# find and load component
|
126
|
-
component_loader =
|
127
|
-
component = component_loader.
|
137
|
+
component_loader = Cfhighlander::Factory::ComponentFactory.new
|
138
|
+
component = component_loader.loadComponentFromTemplate(template_name)
|
128
139
|
component.version = component_version
|
129
140
|
component.distribution_bucket = distribution_bucket unless distribution_bucket.nil?
|
130
141
|
component.distribution_prefix = distribution_prefix unless distribution_prefix.nil?
|
131
142
|
component.load
|
132
143
|
|
133
|
-
publisher =
|
144
|
+
publisher = Cfhighlander::Publisher::ComponentPublisher.new(component, true)
|
134
145
|
publisher.publishComponent
|
135
146
|
end
|
136
147
|
|
137
148
|
end
|
138
149
|
|
139
150
|
# build component from passed cli options
|
140
|
-
def build_component(options,
|
141
|
-
|
142
|
-
ENV['HIGHLANDER_WORKDIR'] = Dir.pwd
|
143
|
-
end
|
151
|
+
def build_component(options, template_name)
|
152
|
+
|
144
153
|
component_version = options[:version]
|
145
154
|
distribution_bucket = options[:dstbucket]
|
146
155
|
distribution_prefix = options[:dstprefix]
|
147
156
|
|
148
157
|
# find and load component
|
149
|
-
component_loader =
|
150
|
-
component = component_loader.
|
158
|
+
component_loader = Cfhighlander::Factory::ComponentFactory.new
|
159
|
+
component = component_loader.loadComponentFromTemplate(template_name)
|
151
160
|
component.version = component_version unless component_version.nil?
|
152
161
|
component.distribution_bucket = distribution_bucket unless distribution_bucket.nil?
|
153
162
|
component.distribution_prefix = distribution_prefix unless distribution_prefix.nil?
|
@@ -155,4 +164,11 @@ def build_component(options, component_name)
|
|
155
164
|
component
|
156
165
|
end
|
157
166
|
|
167
|
+
if ENV['CFHIGHLANDER_WORKDIR'].nil?
|
168
|
+
ENV['CFHIGHLANDER_WORKDIR'] = Dir.pwd
|
169
|
+
end
|
170
|
+
if ENV['HIGHLANDER_WORKDIR'].nil?
|
171
|
+
ENV['HIGHLANDER_WORKDIR'] = Dir.pwd
|
172
|
+
end
|
173
|
+
|
158
174
|
HighlanderCli.start
|
data/cfndsl_ext/sg.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'netaddr'
|
1
2
|
|
2
3
|
def sg_create_rules (x, ip_blocks={})
|
3
4
|
rules = []
|
@@ -15,12 +16,38 @@ end
|
|
15
16
|
|
16
17
|
|
17
18
|
def lookup_ips_for_sg (ips, ip_block_name={})
|
19
|
+
cidr = []
|
18
20
|
if ip_block_name == 'stack'
|
19
21
|
cidr = [FnJoin( "", [ "10.", Ref('StackOctet'), ".", "0.0/16" ] )]
|
20
22
|
elsif ips.has_key? ip_block_name
|
21
|
-
|
23
|
+
ips[ip_block_name].each do |ip|
|
24
|
+
if (ips.include?(ip) || ip_block_name == 'stack')
|
25
|
+
cidr += lookup_ips_for_sg(ips, ip) unless ip == ip_block_name
|
26
|
+
else
|
27
|
+
if ip == 'stack'
|
28
|
+
cidr << [FnJoin( "", [ "10.", Ref('StackOctet'), ".", "0.0/16" ] )]
|
29
|
+
elsif(isCidr(ip))
|
30
|
+
cidr << ip
|
31
|
+
else
|
32
|
+
STDERR.puts("WARN: ip #{ip} is not a valid CIDR. Ignoring IP")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
22
36
|
else
|
23
|
-
|
37
|
+
if isCidr(ip_block_name)
|
38
|
+
cidr = [ip_block_name]
|
39
|
+
else
|
40
|
+
STDERR.puts("WARN: ip #{ip_block_name} is not a valid CIDR. Ignoring IP")
|
41
|
+
end
|
24
42
|
end
|
25
43
|
cidr
|
26
44
|
end
|
45
|
+
|
46
|
+
def isCidr(block)
|
47
|
+
begin
|
48
|
+
NetAddr::CIDR.create(block)
|
49
|
+
return block.include?('/')
|
50
|
+
rescue NetAddr::ValidationError
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
end
|
data/hl_ext/mapping_helper.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
require_relative '../lib/
|
1
|
+
require_relative '../lib/cfhighlander.mapproviders'
|
2
2
|
|
3
3
|
# Return mapping provider as class
|
4
|
-
def mappings_provider(provider_name)
|
4
|
+
def mappings_provider(provider_name, is_legacy = false)
|
5
5
|
return nil if provider_name.nil?
|
6
6
|
provider = nil
|
7
|
-
|
7
|
+
module_name = is_legacy ? 'Highlander': 'Cfhighlander'
|
8
|
+
providers = Object.const_get(module_name).const_get('MapProviders')
|
8
9
|
begin
|
9
10
|
providers.const_get(provider_name)
|
10
11
|
rescue NameError => e
|
11
|
-
if e.to_s.include?
|
12
|
+
if e.to_s.include? "uninitialized constant #{module_name}::MapProviders::"
|
13
|
+
return mappings_provider(provider_name, true) unless is_legacy
|
12
14
|
return nil
|
13
15
|
end
|
14
16
|
STDERR.puts(e.to_s)
|