line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CCfn { |
2
|
14
|
|
|
14
|
|
208323
|
use Moose; |
|
14
|
|
|
|
|
3193417
|
|
|
14
|
|
|
|
|
101
|
|
3
|
|
|
|
|
|
|
extends 'Cfn'; |
4
|
|
|
|
|
|
|
|
5
|
14
|
|
|
14
|
|
96432
|
use Cfn; |
|
14
|
|
|
|
|
48
|
|
|
14
|
|
|
|
|
513
|
|
6
|
14
|
|
|
14
|
|
5892
|
use CCfnX::DynamicValue; |
|
14
|
|
|
|
|
43
|
|
|
14
|
|
|
|
|
5849
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has stash => ( |
9
|
|
|
|
|
|
|
is => 'ro', |
10
|
|
|
|
|
|
|
isa => 'HashRef', |
11
|
|
|
|
|
|
|
default => sub { {} }, |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Holds the mappings from logical output name, to the output name that will be sent and retrieved from cloudformation |
15
|
|
|
|
|
|
|
# This is done to support characters in the output names that cloudformation doesn't |
16
|
|
|
|
|
|
|
has output_mappings => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
isa => 'HashRef[Str]', |
19
|
|
|
|
|
|
|
default => sub { {} }, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
has debug => (is => 'ro', default => sub { return $ENV{ CLOUDDEPLOY_DEBUG } ? 1 : 0 }); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Small helper to map a Moose class (parameters have a type) to a CloudFormation type |
24
|
|
|
|
|
|
|
sub _moose_to_cfn_class { |
25
|
|
|
|
|
|
|
return { |
26
|
|
|
|
|
|
|
Str => 'String', |
27
|
|
|
|
|
|
|
Int => 'Number', |
28
|
|
|
|
|
|
|
Num => 'Number', |
29
|
0
|
|
0
|
0
|
|
0
|
}->{ $_[0] } || 'String'; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# When the object is instanced, we want any of the attributes declared in the class to be created |
33
|
|
|
|
|
|
|
# That means that attributes with Resource, Output, Condition or Output roles are "attached" to the object |
34
|
|
|
|
|
|
|
# This is done to make the newly created object represent all that the user has declared "in the class" when |
35
|
|
|
|
|
|
|
# they call ->new |
36
|
|
|
|
|
|
|
# All these attributes are normally created with CCfnX::Shortcuts, but can really be created by hand (not recommended) |
37
|
|
|
|
|
|
|
sub BUILD { |
38
|
32
|
|
|
32
|
0
|
55932
|
my $self = shift; |
39
|
32
|
|
|
|
|
180
|
my $class_meta = $self->meta; |
40
|
32
|
|
|
|
|
683
|
my @attrs = $class_meta->get_all_attributes; |
41
|
32
|
|
|
|
|
2310
|
foreach my $att (@attrs) { |
42
|
531
|
|
|
|
|
330427
|
my $name = $att->name; |
43
|
531
|
100
|
|
|
|
1606
|
if ($att->does('CCfnX::Meta::Attribute::Trait::Resource')) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
44
|
73
|
|
|
|
|
17226
|
$self->addResource($name, $self->$name); |
45
|
|
|
|
|
|
|
} elsif ($att->does('CCfnX::Meta::Attribute::Trait::Output')){ |
46
|
4
|
|
|
|
|
2245
|
$self->addOutput($name, $self->$name); |
47
|
|
|
|
|
|
|
} elsif ($att->does('CCfnX::Meta::Attribute::Trait::Condition')){ |
48
|
0
|
|
|
|
|
0
|
$self->addCondition($name, $self->$name); |
49
|
|
|
|
|
|
|
} elsif ($att->does('CCfnX::Meta::Attribute::Trait::Metadata')){ |
50
|
4
|
|
|
|
|
4847
|
$self->Metadata->{ $name } = Cfn::Value->new(Value => $self->$name); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
32
|
|
|
|
|
18785
|
my $params_meta = $self->params->meta; |
55
|
32
|
|
|
|
|
967
|
@attrs = $params_meta->get_all_attributes; |
56
|
32
|
|
|
|
|
1902
|
foreach my $param (@attrs) { |
57
|
271
|
50
|
|
|
|
50164
|
if ($param->does('CCfnX::Meta::Attribute::Trait::StackParameter')) { |
58
|
0
|
|
|
|
|
0
|
my $type = $param->type_constraint->name; |
59
|
0
|
|
|
|
|
0
|
$self->addParameter($param->name, _moose_to_cfn_class($type)); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub get_stackversion_from_metadata { |
66
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
67
|
0
|
|
|
|
|
0
|
$self->Metadata->{ StackVersion }; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
before as_hashref => sub { |
71
|
|
|
|
|
|
|
my $self = shift; |
72
|
|
|
|
|
|
|
# This triggers any actions that the class |
73
|
|
|
|
|
|
|
# wants to do while building the cloudformation |
74
|
|
|
|
|
|
|
$self->build(); |
75
|
|
|
|
|
|
|
}; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
around addOutput => sub { |
78
|
|
|
|
|
|
|
my ($orig, $self, $name, $output) = @_; |
79
|
|
|
|
|
|
|
my $new_name = $name; |
80
|
|
|
|
|
|
|
$new_name =~ s/\W//g; |
81
|
|
|
|
|
|
|
if (defined $self->Outputs->{ $new_name }) { |
82
|
|
|
|
|
|
|
die "The output name clashed with an existing output name. Be aware that outputs are stripped of all non-alphanumeric chars before being declared"; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
if ($new_name ne $name) { |
85
|
|
|
|
|
|
|
$self->output_mappings->{ $new_name } = $name; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
$self->$orig($new_name, $output); |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
|
90
|
14
|
|
|
14
|
|
6838
|
use Data::Graph::Util qw//; |
|
14
|
|
|
|
|
7097
|
|
|
14
|
|
|
|
|
1360
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _creation_order { |
93
|
2
|
|
|
2
|
|
7013
|
my ($self) = @_; |
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
5
|
my $graph = {}; |
96
|
2
|
|
|
|
|
66
|
foreach my $resource ($self->ResourceList) { |
97
|
20
|
|
|
|
|
483
|
$graph->{ $resource } = $self->Resource($resource)->dependencies; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
53
|
my @result = Data::Graph::Util::toposort($graph, [ sort $self->ResourceList ]); |
101
|
|
|
|
|
|
|
|
102
|
2
|
|
|
|
|
524
|
return reverse @result; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
7
|
0
|
|
sub build {} |
106
|
|
|
|
|
|
|
|
107
|
14
|
|
|
14
|
|
131
|
use Module::Runtime qw//; |
|
14
|
|
|
|
|
34
|
|
|
14
|
|
|
|
|
1206
|
|
108
|
|
|
|
|
|
|
sub get_deployer { |
109
|
0
|
|
|
0
|
0
|
|
my ($self, $params, @roles) = @_; |
110
|
0
|
|
|
|
|
|
Module::Runtime::require_module($_) for ('CCfnX::Deployment', @roles); |
111
|
0
|
|
|
|
|
|
my $dep = CCfnX::Deployment->new_with_roles({ %$params, origin => $self }, @roles); |
112
|
0
|
|
|
|
|
|
return $dep; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
package CCfnX::Meta::Attribute::Trait::RefValue { |
117
|
14
|
|
|
14
|
|
83
|
use Moose::Role; |
|
14
|
|
|
|
|
32
|
|
|
14
|
|
|
|
|
123
|
|
118
|
|
|
|
|
|
|
Moose::Util::meta_attribute_alias('RefValue'); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
package CCfnX::Meta::Attribute::Trait::StackParameter { |
122
|
14
|
|
|
14
|
|
66741
|
use Moose::Role; |
|
14
|
|
|
|
|
33
|
|
|
14
|
|
|
|
|
101
|
|
123
|
|
|
|
|
|
|
Moose::Util::meta_attribute_alias('StackParameter'); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
package CCfnX::Meta::Attribute::Trait::Resource { |
127
|
14
|
|
|
14
|
|
63738
|
use Moose::Role; |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
58
|
|
128
|
|
|
|
|
|
|
Moose::Util::meta_attribute_alias('Resource'); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
package CCfnX::Meta::Attribute::Trait::Metadata { |
132
|
14
|
|
|
14
|
|
62677
|
use Moose::Role; |
|
14
|
|
|
|
|
34
|
|
|
14
|
|
|
|
|
61
|
|
133
|
|
|
|
|
|
|
Moose::Util::meta_attribute_alias('Metadata'); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
package CCfnX::Meta::Attribute::Trait::Condition { |
137
|
14
|
|
|
14
|
|
63028
|
use Moose::Role; |
|
14
|
|
|
|
|
33
|
|
|
14
|
|
|
|
|
59
|
|
138
|
|
|
|
|
|
|
Moose::Util::meta_attribute_alias('Condition'); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
package CCfnX::Meta::Attribute::Trait::Output { |
142
|
14
|
|
|
14
|
|
63000
|
use Moose::Role; |
|
14
|
|
|
|
|
49
|
|
|
14
|
|
|
|
|
59
|
|
143
|
|
|
|
|
|
|
Moose::Util::meta_attribute_alias('Output'); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
package CCfnX::Meta::Attribute::Trait::PostOutput { |
147
|
14
|
|
|
14
|
|
62952
|
use Moose::Role; |
|
14
|
|
|
|
|
35
|
|
|
14
|
|
|
|
|
60
|
|
148
|
|
|
|
|
|
|
Moose::Util::meta_attribute_alias('PostOutput'); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
package CCfnX::Meta::Attribute::Trait::Attached { |
152
|
14
|
|
|
14
|
|
64213
|
use Moose::Role; |
|
14
|
|
|
|
|
33
|
|
|
14
|
|
|
|
|
60
|
|
153
|
|
|
|
|
|
|
Moose::Util::meta_attribute_alias('Attached'); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
package CCfnX::Meta::Attribute::Trait::Attachable { |
157
|
14
|
|
|
14
|
|
62407
|
use Moose::Role; |
|
14
|
|
|
|
|
36
|
|
|
14
|
|
|
|
|
61
|
|
158
|
14
|
|
|
14
|
|
68541
|
use CCfnX::Deployment; |
|
14
|
|
|
|
|
49
|
|
|
14
|
|
|
|
|
2898
|
|
159
|
|
|
|
|
|
|
Moose::Util::meta_attribute_alias('Attachable'); |
160
|
|
|
|
|
|
|
has type => (is => 'ro', isa => 'Str', required => 1); |
161
|
|
|
|
|
|
|
has generates_params => (is => 'ro', isa => 'ArrayRef[Str]', required => 1); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub get_info { |
164
|
0
|
|
|
0
|
0
|
|
my ($self, $name, $key) = @_; |
165
|
0
|
0
|
|
|
|
|
die "Please specify a name for Attachment " . $self->name if (not defined $name); |
166
|
0
|
|
|
|
|
|
my $dep = CCfnX::Deployment->new_with_roles({ name => $name }, 'CCfnX::CloudFormationDeployer', 'CCfnX::PersistentDeployment'); |
167
|
0
|
|
|
|
|
|
$dep->get_from_mongo; |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
my $output; |
170
|
0
|
|
|
|
|
|
eval { $output = $dep->output($key) }; |
|
0
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
return $output; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |