-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathaws_route53_plugin.rb
More file actions
185 lines (160 loc) · 4.48 KB
/
aws_route53_plugin.rb
File metadata and controls
185 lines (160 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name 'aws_route53_plugin'
type 'plugin'
rs_ca_ver 20161221
short_description "Amazon Web Services - Route53 Plugin"
long_description "Version: 1.0"
package "plugins/rs_aws_route53"
import "sys_log"
plugin "rs_aws_route53" do
endpoint do
default_scheme "https"
path "/2013-04-01"
request_content_type "application/xml"
end
type "hosted_zone" do
href_templates "$Id","{{Id}}","{{//CreateHostedZoneResponse/HostedZone/Id}}", "{{//GetHostedZoneResponse/HostedZone/Id}}"
provision "provision_resource"
delete "delete_resource"
field "create_hosted_zone_request" do
alias_for "CreateHostedZoneRequest"
type "composite"
required true
location "body"
end
output "Id","Name"
action "create" do
verb "POST"
path "/hostedzone"
output_path "//CreateHostedZoneResponse/HostedZone"
end
action "destroy" do
verb "DELETE"
path "$href"
end
action "get" do
verb "GET"
path "$href"
output_path "//GetHostedZoneResponse/HostedZone"
end
end
type "resource_recordset" do
href_templates "{{//ChangeInfo/Id}}", "{{//ChangeInfo/Id}}"
provision "provision_resource_recordset"
delete "delete_resource_recordset"
field "hosted_zone_id" do
type "string"
location "path"
required true
end
field "record_sets" do
type "composite"
required true
location 'header'
end
field 'action' do
type "string"
required false
location 'header'
end
field 'comment' do
type "string"
required false
location 'header'
end
output "Id", "Status","Comment","SubmittedAt"
action "create" do
verb "POST"
path "$hosted_zone_id/rrset/"
end
action "remove" do
verb "POST"
path "$hosted_zone_id/rrset/"
# this field contains all the ChangeResourceRecordSetsRequest
# document to be sent. See Limitation in the Readme
field "hosted_zone_id" do
location "path"
end
field "ChangeResourceRecordSetsRequest" do
alias_for "ChangeResourceRecordSetsRequest"
location "body"
end
end
action "get" do
verb "GET"
path "change/$Id"
output_path "//ChangeInfo"
end
end
end
resource_pool "route53" do
plugin $rs_aws_route53
host "route53.amazonaws.com"
auth "key", type: "aws" do
version 4
service 'route53'
region 'us-east-1'
access_key cred('AWS_ACCESS_KEY_ID')
secret_key cred('AWS_SECRET_ACCESS_KEY')
end
end
define provision_resource(@declaration) return @resource do
sub on_error: stop_debugging() do
$object = to_object(@declaration)
call sys_log.detail("object:"+ to_s($object))
$fields = $object["fields"]
call sys_log.detail("existing_fields:" + to_s($fields))
$type = $object["type"]
call sys_log.detail("fields:" + to_s($fields))
call start_debugging()
@operation = rs_aws_route53.$type.create($fields)
@resource = @operation.get()
call stop_debugging()
end
end
define delete_resource(@resource) do
sub on_error: stop_debugging() do
call start_debugging()
@resource.destroy()
call stop_debugging()
end
end
define provision_resource_recordset(@declaration) return @resource do
sub on_error: stop_debugging() do
$object = to_object(@declaration)
$fields = $object["fields"]
$change_resource_record_sets_request = {
"xmlns": "https://route53.amazonaws.com/doc/2013-04-01/",
"ChangeBatch": [{
"Changes": [{
"Change": [{
"Action": [upcase($object['fields']['action'])],
"ResourceRecordSet": [ $object['fields']['record_sets'] ]
}]
}],
"Comment": [$object['fields']['comment']]
}]
}
$fields['ChangeResourceRecordSetsRequest']=$change_resource_record_sets_request
call start_debugging()
@operation = rs_aws_route53.resource_recordset.create($fields)
@resource = @operation.get()
call stop_debugging()
end
end
# this is a noop definition, but required by the resource_recordset delete field.
define delete_resource_recordset(@declaration) do
#
end
define start_debugging() do
if $$debugging == false || logic_and($$debugging != false, $$debugging != true)
initiate_debug_report()
$$debugging = true
end
end
define stop_debugging() do
if $$debugging == true
$debug_report = complete_debug_report()
call sys_log.detail($debug_report)
$$debugging = false
end
end