route53_a_record 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ecfc85b3a64a280000ce590b59fca2270b162e7d
4
+ data.tar.gz: 90c46029cbaf7f35fc37475c84454af71811d41e
5
+ SHA512:
6
+ metadata.gz: a51d04f99b99a62eb4a75f635dad45a023c57ac59446dbe06b78987f92089f8530dbb52fec0ff7f9c0b9ff6c74f67fbd131c5479516bb6501481cae4d794b43a
7
+ data.tar.gz: 23ba7edc0cfb0ce8405fae08176bb4e5ee63e3b1ed7a96f2b233d4d6ef8323936d188c7c0dd97180be9990b566bd34623d22ca76248decfb563de6d8478e6d60
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in route53_a_record.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 kgalli
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Route53ARecord
2
+
3
+ Create, update or delete route53 A records.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'route53_a_record'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install route53_a_record
20
+
21
+ ## Usage
22
+
23
+ ### Create, Update, or Delete an A Record
24
+
25
+ ```ruby
26
+ require 'route53_a_record'
27
+
28
+ # aws credentials
29
+ aws_region = 'eu-central1'
30
+ aws_access_key_id = 'AKIAIOSFODNN7EXAMPLE'
31
+ aws_secret_access_key = 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
32
+
33
+ # aws hosted zone and a like properties
34
+ aws_hosted_zone = 'K5NPEL7EXAMPLE'
35
+ aws_hosted_zone_a_entry = '10.1.1.1'
36
+ aws_hosted_zone_domain = 'route53.example.com'
37
+
38
+ # The Route53ARecord::Record is used to cescribe the record you want
39
+ # to create, update or delete. The last parameter is the `ttl` which defaults
40
+ # to `15` (seconds) if not specified.
41
+ record = Route53ARecord::Record.new(aws_hosted_zone, aws_hosted_zone_domain, aws_hosted_zone_a_entry, 30)
42
+
43
+ # The `Route53ARecord::Handler` is used to perform the creation or
44
+ # update if the given `Route53ARecord::Record`. It provides a
45
+ # parameter overwrite which has to be used for updates. If it is
46
+ # set to `false` updates will raise an exception. The default is `true`.
47
+ handler = Route53ARecord::Handler.new(aws_region, aws_access_key_id, aws_secret_access_key, true)
48
+
49
+ # to create the A record
50
+ handler.create(record)
51
+
52
+
53
+ # to delete the A record
54
+ handler.delete(record)
55
+ ```
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( https://github.com/[my-github-username]/route53_a_record/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ task default: 'test'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "spec"
7
+ t.pattern = "spec/**/*_spec.rb"
8
+ end
@@ -0,0 +1,61 @@
1
+ require 'aws-sdk'
2
+
3
+ module Route53ARecord
4
+ class Handler
5
+ attr_accessor :overwrite
6
+
7
+ def initialize(region, access_key_id, secret_access_key, overwrite = true)
8
+ @region = region
9
+ @access_key_id = access_key_id
10
+ @secret_access_key = secret_access_key
11
+ @overwrite = overwrite
12
+ end
13
+
14
+ def create(resource_a_record)
15
+ action = action_based_on_overwrite
16
+ aws_client.change_resource_record_sets(a_record_change_hash(action, resource_a_record))
17
+ end
18
+
19
+ def delete(resource_a_record)
20
+ aws_client.change_resource_record_sets(a_record_change_hash("DELETE", resource_a_record))
21
+ end
22
+
23
+ private
24
+
25
+ def action_based_on_overwrite
26
+ @overwrite ? 'UPSERT' : 'CREATE'
27
+ end
28
+
29
+ def aws_client
30
+ Aws::Route53::Client.new(
31
+ region: @region,
32
+ access_key_id: @access_key_id,
33
+ secret_access_key: @secret_access_key
34
+ )
35
+ end
36
+
37
+ def a_record_change_hash(action, resource_a_record)
38
+ {
39
+ hosted_zone_id: resource_a_record.hosted_zone_id,
40
+ change_batch: {
41
+ changes: [
42
+ {
43
+ action: action,
44
+ resource_record_set: {
45
+ name: resource_a_record.name,
46
+ type: "A",
47
+ ttl: resource_a_record.ttl,
48
+ resource_records: [
49
+ {
50
+ value: resource_a_record.value
51
+ }
52
+ ]
53
+ }
54
+ }
55
+ ]
56
+ }
57
+ }
58
+ end
59
+ end
60
+ end
61
+
@@ -0,0 +1,17 @@
1
+ module Route53ARecord
2
+ class Record
3
+ attr_reader :hosted_zone_id, :name, :value, :ttl
4
+
5
+ def initialize(hosted_zone_id, name, value, ttl = 5)
6
+ @hosted_zone_id = hosted_zone_id
7
+ @name = name
8
+ @value = value
9
+ @ttl = ttl
10
+ end
11
+
12
+ def type
13
+ 'A'
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,3 @@
1
+ module Route53ARecord
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'route53_a_record/version'
2
+ require 'route53_a_record/record'
3
+ require 'route53_a_record/handler'
4
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'route53_a_record/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "route53_a_record"
8
+ spec.version = Route53ARecord::VERSION
9
+ spec.authors = ["kgalli"]
10
+ spec.email = ["mail@kgalli.de"]
11
+ spec.summary = %q{Create, update and delete route53 A records.}
12
+ spec.description = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "aws-sdk", "~> 2.1.14"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.5.1"
26
+
27
+ end
@@ -0,0 +1,70 @@
1
+ require 'test_helper'
2
+
3
+ describe Route53ARecord::Handler do
4
+
5
+ let(:rh) { Route53ARecord::Handler.new('my_region', 'my_access_key_id', 'my_secret_access_key') }
6
+ let(:rh_overwrite_false) { Route53ARecord::Handler.new('my_region', 'my_access_key_id', 'my_secret_access_key', false) }
7
+ describe '#initialize' do
8
+
9
+ it 'assigns the aws region and credentials' do
10
+ rh.instance_variable_get(:@region).must_equal 'my_region'
11
+ rh.instance_variable_get(:@access_key_id).must_equal 'my_access_key_id'
12
+ rh.instance_variable_get(:@secret_access_key).must_equal 'my_secret_access_key'
13
+ end
14
+
15
+ it 'does not allow access to aws credentials' do
16
+ proc { rh.access_key_id }.must_raise NoMethodError
17
+ proc { rh.secret.access_key }.must_raise NoMethodError
18
+ end
19
+
20
+ it 'assigns default true for overwrite' do
21
+ rh.instance_variable_get(:@overwrite).must_equal true
22
+ end
23
+
24
+ it 'overwrites the default for overwrite' do
25
+ rh_overwrite_false.instance_variable_get(:@overwrite).must_equal false
26
+ end
27
+ end
28
+
29
+ describe '#action_based_on_overwrite' do
30
+
31
+ it 'returns UPSERT if overwrite is allowed' do
32
+ rh.send(:action_based_on_overwrite).must_equal 'UPSERT'
33
+ end
34
+
35
+ it 'returns CREATE if overwrite is denied' do
36
+ rh_overwrite_false.send(:action_based_on_overwrite).must_equal 'CREATE'
37
+ end
38
+ end
39
+
40
+ describe '#aws_client' do
41
+
42
+ it 'assigns the region and aws credentials' do
43
+ rh.send(:aws_client).config[:region].must_equal 'my_region'
44
+ rh.send(:aws_client).config[:access_key_id].must_equal 'my_access_key_id'
45
+ rh.send(:aws_client).config[:secret_access_key].must_equal 'my_secret_access_key'
46
+ end
47
+ end
48
+
49
+ describe '#a_record_change_hash' do
50
+
51
+ let(:a_record) { Route53ARecord::Record.new('aws_hosted_zone_id', 'resource_a_record_name', 'resource_a_record_value', 15) }
52
+ let(:create_record) { {
53
+ hosted_zone_id: "aws_hosted_zone_id", change_batch: {
54
+ changes: [
55
+ { action: "CREATE",
56
+ resource_record_set: {
57
+ name: "resource_a_record_name", type: "A", ttl: 15,
58
+ resource_records: [ { value: "resource_a_record_value" } ]
59
+ }
60
+ }
61
+ ]
62
+ }
63
+ }}
64
+
65
+ it 'replaces placeholder values by a ResourceARecord' do
66
+ rh.send(:a_record_change_hash, 'CREATE', a_record).must_equal create_record
67
+ end
68
+ end
69
+ end
70
+
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ describe Route53ARecord::Record do
4
+
5
+ let(:rr) { Route53ARecord::Record.new('hosted_zone_id', 'name', 'value') }
6
+
7
+ describe '#initialize' do
8
+
9
+ it 'assigns given values' do
10
+ rr.hosted_zone_id.must_equal 'hosted_zone_id'
11
+ rr.name.must_equal 'name'
12
+ rr.value.must_equal 'value'
13
+ rr.ttl.must_equal 5
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ require 'route53_a_record'
2
+ require 'minitest/spec'
3
+ require 'minitest/autorun'
4
+ require 'minitest/pride'
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: route53_a_record
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kgalli
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.14
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.14
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 5.5.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 5.5.1
69
+ description: ''
70
+ email:
71
+ - mail@kgalli.de
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/route53_a_record.rb
82
+ - lib/route53_a_record/handler.rb
83
+ - lib/route53_a_record/record.rb
84
+ - lib/route53_a_record/version.rb
85
+ - route53_a_record.gemspec
86
+ - spec/handler_spec.rb
87
+ - spec/record_spec.rb
88
+ - spec/test_helper.rb
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.3
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Create, update and delete route53 A records.
113
+ test_files:
114
+ - spec/handler_spec.rb
115
+ - spec/record_spec.rb
116
+ - spec/test_helper.rb