dnsdeploy 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: 436c4fe88d39f8f420272553dee3f69e7d1864b2
4
+ data.tar.gz: 3acf085a2e88226dd0b9d95df1dd627348deb6fd
5
+ SHA512:
6
+ metadata.gz: a58056300b6c3f37bb94a9a7c25b3391fd3dc91de0a57c13ce63d99095380f2d14e83d59d445658e57a0ef29b7223f1c472436288106764c9e00be5a115d9184
7
+ data.tar.gz: 36e3c7f223fedbaa7ac13dad82a110eae51d0ce73f73d223eb95c6d9bd6c22cac3941ebf0bcbdeaa2ba434562227a854a3e8993c9c5997a7cd7e6a7fb5c3b4ab
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dnsdeploy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 beanieboi
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,29 @@
1
+ # Dnsdeploy
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'dnsdeploy'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install dnsdeploy
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/dnsdeploy/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/dns_deploy ADDED
@@ -0,0 +1,7 @@
1
+ require_relative '../lib/dnsdeploy'
2
+
3
+ records_file = ARGV.first
4
+
5
+ deployer = Dnsdeploy::Base.new(records_file)
6
+ deployer.validate
7
+ deployer.update_records
data/dnsdeploy.gemspec ADDED
@@ -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 'dnsdeploy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dnsdeploy"
8
+ spec.version = Dnsdeploy::VERSION
9
+ spec.authors = ["beanieboi"]
10
+ spec.email = ["beanie@benle.de"]
11
+ spec.summary = %q{Wrapper between DNSimple and records.json}
12
+ spec.description = %q{Wrapper between DNSimple and records.json - deploy your DNS records}
13
+ spec.homepage = "https://www.codeship.io"
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_runtime_dependency "dnsimple-ruby", "~> 1.5"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.3"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "pry", "~> 0.10"
27
+ end
@@ -0,0 +1,17 @@
1
+ class String
2
+ COLORS = { red: 31,
3
+ green: 32,
4
+ yellow: 33,
5
+ blue: 34,
6
+ pink: 35
7
+ }
8
+
9
+ # colorization
10
+ def colorize(color_code)
11
+ "\e[#{color_code}m#{self}\e[0m"
12
+ end
13
+
14
+ COLORS.each do |color, code|
15
+ define_method(color) { colorize(code) }
16
+ end
17
+ end
@@ -0,0 +1,45 @@
1
+ module Dnsdeploy
2
+ class Base
3
+ def initialize(records_file)
4
+ @records_file = File.new(records_file)
5
+ end
6
+
7
+ def self.update_records(records_file)
8
+ self.new(records_file).update_records
9
+ end
10
+
11
+ def validate
12
+ JSON.load(@records_file.read)
13
+ puts "#{@records_file.path} is valid json".green
14
+ rescue => e
15
+ puts "unable to parse #{@records_file.path}".red
16
+ end
17
+
18
+ def update_records
19
+ local.domains.each do |domain|
20
+ puts "[Processing] Domain #{domain.name}"
21
+
22
+ # Delete records on DNSimple
23
+ DNSimple::Record.all(domain).collect(&:destroy)
24
+
25
+ # create records
26
+ local.records(domain).each do |record|
27
+ puts "[CREATE] #{record}".green
28
+ begin
29
+ DNSimple::Record.create(record.domain, record.name, record.record_type,
30
+ record.content, { ttl: record.ttl, prio: record.prio })
31
+ rescue DNSimple::RequestError => e
32
+ puts "[ERROR] #{e} #{record}".red
33
+ @exit = 1
34
+ end
35
+ end
36
+
37
+ exit(@exit) if @exit
38
+ end
39
+ end
40
+
41
+ def local
42
+ @local ||= Dnsdeploy::Local.new(@records_file)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,42 @@
1
+ require 'singleton'
2
+
3
+ module Dnsdeploy
4
+ class Local
5
+ def initialize(records_file_path)
6
+ @records_file_path = records_file_path
7
+ end
8
+
9
+ def all_records
10
+ @all_records ||= json.map do |record_set|
11
+ domain = dnsimple_domain(record_set['zone'])
12
+ create_records(domain, record_set['records'])
13
+ end.flatten
14
+ end
15
+
16
+ def records(domain)
17
+ all_records.select { |r| r.domain.name == domain.name }
18
+ end
19
+
20
+ def domains
21
+ @domains ||= json.map do |record_set|
22
+ domain = dnsimple_domain(record_set['zone'])
23
+ end
24
+ end
25
+
26
+ def create_records(domain, json_records)
27
+ json_records.map do |record|
28
+ Record.new(domain: domain, name: record['name'], record_type: record['type'],
29
+ content: record['value'], ttl: record['ttl'], prio: record['prio'])
30
+ end
31
+ end
32
+
33
+ def json
34
+ @json ||= JSON.load(@records_file_path.read)
35
+ end
36
+
37
+ def dnsimple_domain(zone)
38
+ @dnsimple_domains ||= {}
39
+ @dnsimple_domains[zone] ||= DNSimple::Domain.all.select { |d| d.name == zone }.first
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ module Dnsdeploy
2
+ class Record < DNSimple::Record
3
+ def to_s
4
+ "#{self.name}.#{self.domain.name} #{self.record_type} #{self.content} (ttl: #{self.ttl})"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Dnsdeploy
2
+ VERSION = "0.0.1"
3
+ end
data/lib/dnsdeploy.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'json'
2
+ require 'dnsimple'
3
+
4
+ require_relative 'dnsdeploy/version'
5
+ require_relative 'dnsdeploy/local'
6
+ require_relative 'dnsdeploy/record'
7
+ require_relative 'dnsdeploy/base'
8
+ require_relative 'core_ext/string'
9
+
10
+ DNSimple::Client.username = ENV['DNSIMPLE_USERNAME']
11
+ DNSimple::Client.api_token = ENV['DNSIMPLE_API_TOKEN']
12
+
13
+ module Dnsdeploy
14
+ end
@@ -0,0 +1,8 @@
1
+ [
2
+ { "zone": "example.com",
3
+ "records": [
4
+ { "name": "", "type": "MX", "value": "alt1.aspmx.l.google.com", "prio": 5, "ttl":300 },
5
+ { "name": "", "type": "MX", "value": "alt2.aspmx.l.google.com", "prio": 5, "ttl":300 }
6
+ ]
7
+ }
8
+ ]
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsdeploy::Base do
4
+ let(:domain) { DNSimple::Domain.new name: random_domain }
5
+ let(:name) { random_string }
6
+ let(:record_type) { random_string }
7
+ let(:content) { random_string }
8
+ let(:ttl) { random_number }
9
+ let(:prio) { random_number }
10
+ let(:local) { double(:local, domains: [domain], records: [record]) }
11
+ let(:record) { Dnsdeploy::Record.new(domain: domain, name: name, record_type: record_type,
12
+ content: content, ttl: ttl, prio: prio ) }
13
+ let(:records_file) { 'spec/assets/records.json' }
14
+
15
+ subject(:base) { described_class.new(records_file) }
16
+
17
+ before do
18
+ allow(DNSimple::Record).to receive(:all).and_return([])
19
+ allow(Dnsdeploy::Local).to receive(:new).and_return local
20
+ end
21
+
22
+ it "should create records" do
23
+ expect(DNSimple::Record).to receive(:create).with(domain, name, record_type, content, {ttl: ttl, prio: prio })
24
+ base.update_records
25
+ end
26
+ end
@@ -0,0 +1,76 @@
1
+ require 'bundler'
2
+ require 'json'
3
+ Bundler.require
4
+
5
+ require_relative '../lib/dnsdeploy'
6
+
7
+ RSpec.configure do |config|
8
+ # These two settings work together to allow you to limit a spec run
9
+ # to individual examples or groups you care about by tagging them with
10
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
11
+ # get run.
12
+ config.filter_run :focus
13
+ config.run_all_when_everything_filtered = true
14
+
15
+ # Many RSpec users commonly either run the entire suite or an individual
16
+ # file, and it's useful to allow more verbose output when running an
17
+ # individual spec file.
18
+ if config.files_to_run.one?
19
+ # Use the documentation formatter for detailed output,
20
+ # unless a formatter has already been configured
21
+ # (e.g. via a command-line flag).
22
+ config.default_formatter = 'doc'
23
+ end
24
+
25
+ # Print the 10 slowest examples and example groups at the
26
+ # end of the spec run, to help surface which specs are running
27
+ # particularly slow.
28
+ config.profile_examples = 10
29
+
30
+ # Run specs in random order to surface order dependencies. If you find an
31
+ # order dependency and want to debug it, you can fix the order by providing
32
+ # the seed, which is printed after each run.
33
+ # --seed 1234
34
+ config.order = :random
35
+
36
+ # Seed global randomization in this process using the `--seed` CLI option.
37
+ # Setting this allows you to use `--seed` to deterministically reproduce
38
+ # test failures related to randomization by passing the same `--seed` value
39
+ # as the one that triggered the failure.
40
+ Kernel.srand config.seed
41
+
42
+ # rspec-expectations config goes here. You can use an alternate
43
+ # assertion/expectation library such as wrong or the stdlib/minitest
44
+ # assertions if you prefer.
45
+ config.expect_with :rspec do |expectations|
46
+ # Enable only the newer, non-monkey-patching expect syntax.
47
+ # For more details, see:
48
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
49
+ expectations.syntax = :expect
50
+ end
51
+
52
+ # rspec-mocks config goes here. You can use an alternate test double
53
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
54
+ config.mock_with :rspec do |mocks|
55
+ # Enable only the newer, non-monkey-patching expect syntax.
56
+ # For more details, see:
57
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
58
+ mocks.syntax = :expect
59
+
60
+ # Prevents you from mocking or stubbing a method that does not exist on
61
+ # a real object. This is generally recommended.
62
+ mocks.verify_partial_doubles = true
63
+ end
64
+ end
65
+
66
+ def random_string letters=rand(10)+10
67
+ [*('a'..'z')].sample(letters).join
68
+ end
69
+
70
+ def random_domain
71
+ [random_string, ".", random_string(2)].join
72
+ end
73
+
74
+ def random_number
75
+ rand 10000
76
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dnsdeploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - beanieboi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dnsimple-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
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.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ description: Wrapper between DNSimple and records.json - deploy your DNS records
84
+ email:
85
+ - beanie@benle.de
86
+ executables:
87
+ - dns_deploy
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/dns_deploy
98
+ - dnsdeploy.gemspec
99
+ - lib/core_ext/string.rb
100
+ - lib/dnsdeploy.rb
101
+ - lib/dnsdeploy/base.rb
102
+ - lib/dnsdeploy/local.rb
103
+ - lib/dnsdeploy/record.rb
104
+ - lib/dnsdeploy/version.rb
105
+ - spec/assets/records.json
106
+ - spec/dnsdeploy/base_spec.rb
107
+ - spec/spec_helper.rb
108
+ homepage: https://www.codeship.io
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.2.2
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Wrapper between DNSimple and records.json
132
+ test_files:
133
+ - spec/assets/records.json
134
+ - spec/dnsdeploy/base_spec.rb
135
+ - spec/spec_helper.rb