applb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 790eeaf3f1533e9cc837cf7fdd54bc13bed473c1
4
+ data.tar.gz: d4d9a8d487ccda353d5aee0f049a6ba514dfe0e2
5
+ SHA512:
6
+ metadata.gz: 5793611e0570b1986e5170db44eaf3eb1a5c5ca6244ada4ab48c97463bb8e03ec0b5d789930cf548fc7a32a9b2e0f10356e9d3086105574a3cdb4cfba6be832c
7
+ data.tar.gz: 11952dc988389246326dd7ee2aceda31a07633258fcc952c1d06a9a14a1f2791351e460702fb6bd72ebf31a3d6f08fc9f8085c11ad0652f2beb795fc0f0c4c31
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ spec/aws_config.yml
11
+ ALBfile
12
+ *~
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - 2.3.3
5
+ before_install:
6
+ - openssl aes-256-cbc -K $encrypted_be43a4149bae_key -iv $encrypted_be43a4149bae_iv
7
+ -in aws_config.yml.enc -out spec/aws_config.yml -d
8
+ - gem install bundler
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
12
+ env:
13
+ global:
14
+ - AWS_REGION=ap-northeast-1
15
+ - TEST_INTERVAL=3
16
+ - secure: GV7hFFW47ZPlB5Ws+yfDFP+3Z05769T2M/iggP/PFsGlfUzLRLgZsmxj72azNhkP3btiTZ0Ish8GOPoUPXb8ArVUMt4Ci9+f5JfWjXlNMWiga907GOIyAIskQsJN9UDlpcH5J49o1oL0APr74FB8pwFs5L+LiIdbUTHVZEQGWnM1kUkefWRS/WiawRL+p5WA8KJ+u3mwf+7yOmiS06OMzpU+1yjnZBTVg63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5JJLk5EJARFBo3IOpWqfcBpF7BHCEPi1r8htqP6zT1ejrE0G0pRy9wUcaLVnK+TgmTHTGiTWtd7UYG0=
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in applb.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 shinya-watanabe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,255 @@
1
+ # Applb
2
+
3
+ [![Build Status](https://travis-ci.org/wata-gh/applb.svg)](https://travis-ci.org/wata-gh/applb)
4
+
5
+ Applb is a tool to manage ELB v2(ALB).
6
+ It defines the state of ELB v2(ALB) using DSL, and updates ELB v2(ALB) according to DSL.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'applb'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install applb
23
+
24
+ ## Usage
25
+
26
+ ```
27
+ export AWS_ACCESS_KEY_ID='...'
28
+ export AWS_SECRET_ACCESS_KEY='...'
29
+ export AWS_REGION='ap-northeast-1'
30
+ applb -e -o ALBfile # export ELB v2(ALB)
31
+ vi ALBFile
32
+ applb -a --dry-run
33
+ applb -a # apply `ALBfile` to ELB
34
+ ```
35
+
36
+ ## Help
37
+
38
+ ```
39
+ Usage: applb [options]
40
+ -h, --help Show help
41
+ -v, --debug Show debug log
42
+ -a, --apply apply DSL
43
+ -e, --export export to DSL
44
+ -n, --dry-run dry run
45
+ -f, --file FILE use selected DSL file
46
+ -s, --split split export DSL file to 1 per VPC
47
+ --split-more
48
+ split export DSL file to 1 per load balancer
49
+ --no-color
50
+ no color
51
+ -i, --include-names NAMES include ELB v2(ALB) names
52
+ -x, --exclude-names NAMES exclude ELB v2(ALB) names by regex
53
+ ```
54
+
55
+ ## ALBfile
56
+
57
+ ```ruby
58
+ require 'other/albfile'
59
+
60
+ ec2 "vpc-XXXXXXXX" do
61
+ elb_v2 "my-app-load-balancer" do
62
+ subnets(
63
+ "subnet-XXXXXXXX",
64
+ "subnet-YYYYYYYY",
65
+ )
66
+
67
+ security_groups(
68
+ "sg-XXXXXXXX",
69
+ "sg-YYYYYYYY",
70
+ )
71
+
72
+ scheme("internet-facing") # internal or internet-facing
73
+
74
+ ip_address_type("ipv4") # ipv4 or dualstack
75
+
76
+ attributes do
77
+ # currently applb does not create bucket and set bucket policy.
78
+ # you must create and set bucket policy by yourself.
79
+ access_logs({
80
+ s3_enabled: false,
81
+ s3_bucket: nil,
82
+ s3_prefix: nil,
83
+ })
84
+ idle_timeout timeout_seconds: 60
85
+ deletion_protection enabled: false
86
+ end
87
+
88
+ target_groups do
89
+ target_group "my-target-group" do
90
+ protocol "HTTP" # HTTP or HTTPS
91
+ port 80
92
+ vpc_id "vpc-XXXXXXXX"
93
+ health_check_interval_seconds 30
94
+ health_check_path "/healthcheck"
95
+ health_check_port "traffic-port" # specify port number or use traffic-port which indicates the port on which each target receives traffic from the load balancer.
96
+ health_check_protocol "HTTP" # HTTP or HTTPS
97
+ health_check_timeout_seconds 5
98
+ healthy_threshold_count 5
99
+ unhealthy_threshold_count 2
100
+ matcher http_code: "200"
101
+ end
102
+
103
+ target_group "my-target-group2" do
104
+ protocol "HTTP"
105
+ port 80
106
+ vpc_id "vpc-XXXXXXXX"
107
+ health_check_interval_seconds 30
108
+ health_check_path "/healthcheck"
109
+ health_check_port "traffic-port"
110
+ health_check_protocol "HTTP"
111
+ health_check_timeout_seconds 5
112
+ healthy_threshold_count 5
113
+ unhealthy_threshold_count 2
114
+ matcher http_code: "200" # if needs multiple values set like 200,302 or 200-299
115
+ end
116
+ end
117
+
118
+ listeners do
119
+ # https sample
120
+ listener do
121
+ # if multiple certificates is needed, call certificates method multiple times.
122
+ # eg.
123
+ # certificates certificate_arn: "[certificate arn1]"
124
+ # certificates certificate_arn: "[certificate arn2]"
125
+ certificates certificate_arn: "arn:aws:acm:ap-northeast-1:XXXXXXXXXXXX:certificate/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
126
+ ssl_policy "ELBSecurityPolicy-2015-05"
127
+ port 443
128
+ protocol "HTTPS" # HTTP or HTTPS
129
+
130
+ default_actions(
131
+ target_group_name: "my-target-group", # set target_group_name defined above
132
+ # [optional]
133
+ # needs this to avoid unnecessary call of create_target_group.
134
+ target_group_arn: "arn:aws:elasticloadbalancing:ap-northeast-1:XXXXXXXXXXXX:targetgroup/my-target-group/XXXXXXXXXXXXXXXX",
135
+ type: "forward",
136
+ )
137
+
138
+ rules do
139
+ # no rules
140
+ end
141
+ end
142
+
143
+ # http sample
144
+ listener do
145
+ port 80
146
+ protocol "HTTP"
147
+
148
+ default_actions(
149
+ target_group_name: "my-target-group",
150
+ # [optional]
151
+ # needs this to avoid unnecessary call of create_target_group.
152
+ target_group_arn: "arn:aws:elasticloadbalancing:ap-northeast-1:XXXXXXXXXXXX:targetgroup/my-target-group/XXXXXXXXXXXXXXXX",
153
+ type: "forward",
154
+ )
155
+
156
+ rules do
157
+ rule do
158
+ # caution!
159
+ # rule_arn is needed to update rule_arn.
160
+ # after created rule_arn you are strongly recommended to write rule_arn.
161
+ rule_arn "arn:aws:elasticloadbalancing:ap-northeast-1:XXXXXXXXXXXX:listener-rule/app/my-app-load-balancer/XXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXX"
162
+ # caution!
163
+ # currently priority is used by set_rule_priorities one by one.
164
+ # this means if priority is conflicted each other, applb fails to modify rule.
165
+ # so it is recommended to modify priority number that is not used yet.
166
+ priority "3"
167
+
168
+ actions(
169
+ target_group_name: "my-target-group2",
170
+ # [optional]
171
+ # needs this to avoid unnecessary call of create_target_group.
172
+ target_group_arn: "arn:aws:elasticloadbalancing:ap-northeast-1:XXXXXXXXXXXX:targetgroup/my-target-group2/XXXXXXXXXXXXXXXX",
173
+ type: "forward",
174
+ )
175
+
176
+ conditions(
177
+ field: "path-pattern",
178
+ values: ["/admin/*"], # * for 0 or more characters and ? for exactly 1 character
179
+ )
180
+ end
181
+
182
+ rule do
183
+ rule_arn "arn:aws:elasticloadbalancing:ap-northeast-1:XXXXXXXXXXXX:listener-rule/app/my-app-load-balancer/XXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXX""
184
+ priority "4"
185
+
186
+ actions(
187
+ target_group_name: "my-target-group2",
188
+ # [optional]
189
+ # needs this to avoid unnecessary call of create_target_group.
190
+ target_group_arn: "arn:aws:elasticloadbalancing:ap-northeast-1:XXXXXXXXXXXX:targetgroup/my-target-group2/XXXXXXXXXXXXXXXX",
191
+ type: "forward",
192
+ )
193
+
194
+ conditions(
195
+ field: "path-pattern",
196
+ values: ["/user/*"],
197
+ )
198
+ end
199
+ end
200
+ end
201
+ end
202
+ end
203
+ end
204
+ ```
205
+
206
+ ## Use template
207
+
208
+ ```
209
+ template "target_groups" do
210
+ target_groups do
211
+ target_group "my-target-group" do
212
+ protocol "HTTP"
213
+ port context.port || 80 # use default 80 or override context value
214
+ vpc_id "vpc-XXXXXXXX"
215
+ health_check_interval_seconds 30
216
+ health_check_path "/healthcheck"
217
+ health_check_port "traffic-port"
218
+ health_check_protocol "HTTP"
219
+ health_check_timeout_seconds 5
220
+ healthy_threshold_count 5
221
+ unhealthy_threshold_count 2
222
+ matcher http_code: "200"
223
+ end
224
+ end
225
+
226
+ ec2 "vpc-XXXXXXXXX" do
227
+ elb_v2 "my-app-load-balancer" do
228
+ subnets(
229
+ "subnet-XXXXXXXX",
230
+ "subnet-YYYYYYYY",
231
+ )
232
+ end
233
+
234
+ include_template "target_groups", port: 80
235
+ end
236
+ end
237
+ ```
238
+
239
+ ## Test
240
+
241
+ set your AWS arn for [spec/aws_config.yml.sample](https://github.com/wata-gh/applb/blob/master/spec/aws_config.yml.sample) and rename to spec/aws_config.yml.
242
+
243
+ ## Similar tools
244
+
245
+ * [Codenize.tools](http://codenize.tools/)
246
+
247
+ ## Contributing
248
+
249
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wata-gh/applb.
250
+
251
+
252
+ ## License
253
+
254
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
255
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'applb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'applb'
8
+ spec.version = Applb::VERSION
9
+ spec.authors = ['wata']
10
+ spec.email = ['wata.gm@gmail.com']
11
+
12
+ spec.summary = %q{Codenize ELB v2 (ALB)}
13
+ spec.description = %q{Manage ALB by DSL}
14
+ spec.homepage = 'http://github.com/wata-gh/applb'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'aws-sdk', '~> 2'
25
+ spec.add_dependency 'hashie'
26
+ spec.add_dependency 'diffy'
27
+ spec.add_dependency 'term-ansicolor'
28
+
29
+ spec.add_development_dependency 'bundler'
30
+ spec.add_development_dependency 'rake'
31
+ spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'pry-byebug'
33
+ end
@@ -0,0 +1,2 @@
1
+ x����e} �[쬣
2
+ �߯���@�Q'�T(S(����쮈S(�:��v�)�~ .1x6B?%�2���W�4�mUX�o��;��l;_$([�˻���D�H<{�`����[����4n0��g��,r�z����+����h,�$������#D��*#����m���0�g{­6[~|�4ƀ��1�%�x�g�h�Y���Ύ�9sn��ij|�Ek�g�<�&b:6���w���a?���~;kht��W���*] ÌhI7��VQ){w�?aik��a�I�A�C�^�Z_�挍
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "applb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+ require 'applb/cli'
4
+
5
+ Applb::CLI.start(ARGV)
@@ -0,0 +1,14 @@
1
+ require 'logger'
2
+ require 'applb/version'
3
+
4
+ module Applb
5
+ def self.logger
6
+ @logger ||=
7
+ begin
8
+ $stdout.sync = true
9
+ Logger.new($stdout).tap do |l|
10
+ l.level = Logger::INFO
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,80 @@
1
+ require 'applb'
2
+ require 'optparse'
3
+ require 'pathname'
4
+
5
+ module Applb
6
+ class CLI
7
+ def self.start(argv)
8
+ new(argv).run
9
+ end
10
+
11
+ def initialize(argv)
12
+ @argv = argv.dup
13
+ @help = argv.empty?
14
+ @filepath = 'ALBfile'
15
+ @options = {
16
+ color: true,
17
+ includes: [],
18
+ excludes: [],
19
+ }
20
+ parser.order!(@argv)
21
+ end
22
+
23
+ def run
24
+ if @help
25
+ puts parser.help
26
+ elsif @apply
27
+ Apply.new(@filepath, @options).run
28
+ elsif @export
29
+ Export.new(@filepath, @options).run
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def parser
36
+ @parser ||= OptionParser.new do |opts|
37
+ opts.version = VERSION
38
+ opts.on('-h', '--help', 'Show help') { @help = true }
39
+ opts.on('-v', '--debug', 'Show debug log') { Applb.logger.level = Logger::DEBUG }
40
+ opts.on('-a', '--apply', 'apply DSL') { @apply = true }
41
+ opts.on('-e', '--export', 'export to DSL') { @export = true }
42
+ opts.on('-n', '--dry-run', 'dry run') { @options[:dry_run] = true }
43
+ opts.on('-f', '--file FILE', 'use selected DSL file') { |v| @filepath = v }
44
+ opts.on('-s', '--split', 'split export DSL file to 1 per VPC') { @options[:split] = true }
45
+ opts.on('', '--split-more', 'split export DSL file to 1 per load balancer') { @options[:split_more] = true }
46
+ opts.on('', '--no-color', 'no color') { @options[:color] = false }
47
+ opts.on('-i', '--include-names NAMES', 'include ELB v2(ALB) names', Array) { |v| @options[:includes] = v }
48
+ opts.on('-x', '--exclude-names NAMES', 'exclude ELB v2(ALB) names by regex', Array) do |v|
49
+ @options[:excludes] = v.map! do |name|
50
+ name =~ /\A\/(.*)\/\z/ ? Regexp.new($1) : Regexp.new("\A#{Regexp.escape(name)}\z")
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ class Apply
57
+ def initialize(filepath, options)
58
+ @filepath = filepath
59
+ @options = options
60
+ end
61
+
62
+ def run
63
+ require 'applb/client'
64
+ result = Client.new(@filepath, @options).apply
65
+ end
66
+ end
67
+
68
+ class Export
69
+ def initialize(filepath, options)
70
+ @filepath = filepath
71
+ @options = options
72
+ end
73
+
74
+ def run
75
+ require 'applb/client'
76
+ result = Client.new(@filepath, @options).export
77
+ end
78
+ end
79
+ end
80
+ end