nifcloud-dns 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4893b7a56be1d7c24db622293a5d3b53aed82b921d3243202403fa9476655fad
4
+ data.tar.gz: 236176efb848f099a954467719d1f61864af3e2935d266499b310ce75cf9ece6
5
+ SHA512:
6
+ metadata.gz: 3ffe5a806a43683cce44e31051507f3117847af7e93f3cd2942617b54640568055d8931f6017ea0e6db481274d33dde712c94b32bc8a5a1f23c9594f2fe73973
7
+ data.tar.gz: c52f6bfbb6355cbcba3835438042cddf28d6faf0d9e5d889f991512cd07912bf4da36a4487b8e6216696718689b0caa9133942e08abcbeb43de5e6b1d94fed39
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ vendor/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in nifcloud-dns.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nifcloud-dns (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.7.0)
12
+ rspec-core (~> 3.7.0)
13
+ rspec-expectations (~> 3.7.0)
14
+ rspec-mocks (~> 3.7.0)
15
+ rspec-core (3.7.1)
16
+ rspec-support (~> 3.7.0)
17
+ rspec-expectations (3.7.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.7.0)
20
+ rspec-mocks (3.7.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-support (3.7.1)
24
+ ruby-hmac (0.4.0)
25
+ xml-simple (1.1.5)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.16)
32
+ nifcloud-dns!
33
+ rake (~> 10.0)
34
+ rspec (~> 3.0)
35
+ ruby-hmac
36
+ xml-simple
37
+
38
+ BUNDLED WITH
39
+ 1.16.1
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Nifcloud::DNS
2
+
3
+ You can control nifcloud DNS with ruby.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ $ gem install nifcloud-dns
9
+ ```
10
+
11
+ ## Usage
12
+ Export credentials into environment variables.
13
+ `export ACCESS_KEY=xxx && export SECRET_KEY=xxx`
14
+
15
+ Or set as an arguments.
16
+ `Nifcloud::DNS::Record.new('access_key', 'secret_key', 'your-domain.com')`
17
+
18
+ * Create A record.
19
+
20
+ ```
21
+ record = Nifcloud::DNS::Record.new 'your-domain.com'
22
+ res = record.add('www1', 'A', '192.168.100.1')
23
+ ```
24
+
25
+ * List records.
26
+
27
+ ```
28
+ record = Nifcloud::DNS::Record.new 'your-domain.com'
29
+ res = record.list
30
+ ```
31
+
32
+ * Delete A record.
33
+
34
+ ```
35
+ record = Nifcloud::DNS::Record.new 'your-domain.com'
36
+ res = record.del('www1', 'A', '192.168.100.1')
37
+ ```
38
+
39
+ * List zones.
40
+
41
+ ```
42
+ zone = Nifcloud::DNS::Zone.new
43
+ res = zone.list
44
+ ```
45
+
46
+ ## Test
47
+
48
+ Please register your test domain (`yourdomain.com`) into nifcloud DNS before starting the test.
49
+
50
+ * export ACCESS_KEY=xxx
51
+ * export SECRET_KEY=xxx
52
+ * export ZONE=yourdomain.com
53
+ * bundle exec rake spec
54
+
55
+ ## Development
56
+
57
+ 1. Setup
58
+ * bundle install --path vendor
59
+ 2. Fix or write codes ex) lib/nifcloud/dns/record.rb
60
+ 3. Check features by repl
61
+ * bundle console
62
+ 4. Build a gem
63
+ * bundle exec rake build
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kakakikikeke/nifcloud-dns.
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nifcloud/dns"
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(__FILE__)
data/bin/setup ADDED
@@ -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,19 @@
1
+ module Nifcloud
2
+ class Auth
3
+ ALGORITHM = 'HmacSHA1'
4
+
5
+ def initialize(access_key, secret_key)
6
+ @access_key = access_key || ENV['ACCESS_KEY']
7
+ @secret_key = secret_key || ENV['SECRET_KEY']
8
+ end
9
+
10
+ def signature_header
11
+ @time = Time.now.httpdate
12
+ hmac = HMAC::SHA1.new(@secret_key).update(@time)
13
+ signature = Base64.encode64("#{hmac.digest}")
14
+ "NIFTY3-HTTPS NiftyAccessKeyId=#{@access_key},Algorithm=#{ALGORITHM},Signature=#{signature.chomp}"
15
+ end
16
+
17
+ attr_reader :time
18
+ end
19
+ end
@@ -0,0 +1,60 @@
1
+ require "nifcloud/auth"
2
+ require "nifcloud/dns/response"
3
+
4
+ module Nifcloud
5
+ class Client < Auth
6
+ ENDPOINT = 'https://dns.api.cloud.nifty.com/'
7
+ VERSION = '2012-12-12N2013-12-16'
8
+ AUTHORIZATION_HEADER = 'X-Nifty-Authorization'
9
+ DATE_HEADER = 'X-Nifty-Date'
10
+ NAMESPACE = 'https://route53.amazonaws.com/doc/2012-12-12/'
11
+
12
+ def initialize(access_key, secret_key)
13
+ super(access_key, secret_key)
14
+ @http, @req, @uri = nil
15
+ end
16
+
17
+ def get path
18
+ init path
19
+ @req = Net::HTTP::Get.new @uri.request_uri
20
+ init_header
21
+ res = call
22
+ Nifcloud::DNS::Response.new(XmlSimple.xml_in(res.body), res.code, res.body)
23
+ end
24
+
25
+ def post(path, body)
26
+ init path
27
+ @req = Net::HTTP::Post.new @uri.request_uri
28
+ @req.body = body
29
+ @req.content_type = 'text/xml'
30
+ init_header
31
+ res = call
32
+ Nifcloud::DNS::Response.new(XmlSimple.xml_in(res.body), res.code, res.body)
33
+ end
34
+
35
+ def delete path
36
+ init path
37
+ @req = Net::HTTP::Delete.new @uri.request_uri
38
+ init_header
39
+ res = call
40
+ Nifcloud::DNS::Response.new(XmlSimple.xml_in(res.body), res.code, res.body)
41
+ end
42
+
43
+ private
44
+
45
+ def init path
46
+ @uri = URI.parse("#{ENDPOINT}#{VERSION}/#{path}")
47
+ @http = Net::HTTP.new(@uri.host, @uri.port)
48
+ @http.use_ssl = true
49
+ end
50
+
51
+ def init_header
52
+ @req[AUTHORIZATION_HEADER] = signature_header
53
+ @req[DATE_HEADER] = @time
54
+ end
55
+
56
+ def call
57
+ @http.request(@req)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+ require "nifcloud/dns/version"
3
+ require "nifcloud/dns/zone"
4
+ require "nifcloud/dns/record"
5
+
6
+ module Nifcloud
7
+ module DNS
8
+ end
9
+ end
@@ -0,0 +1,55 @@
1
+ require "nifcloud/client"
2
+
3
+ module Nifcloud
4
+ module DNS
5
+ class Record < Client
6
+ RECORD_SET_WITH_ID = 'hostedzone/%s/rrset'
7
+
8
+ def initialize(zone_id, access_key: nil, secret_key: nil)
9
+ super(access_key, secret_key)
10
+ @zone_id = zone_id
11
+ end
12
+
13
+ def list
14
+ get(RECORD_SET_WITH_ID % @zone_id)
15
+ end
16
+
17
+ def add(name, type, value, ttl: 86400, comment: '')
18
+ post(RECORD_SET_WITH_ID % @zone_id, xml('CREATE', name, type, value, ttl, comment))
19
+ end
20
+
21
+ def del(name, type, value, ttl: 86400, comment: '')
22
+ post(RECORD_SET_WITH_ID % @zone_id, xml('DELETE', name, type, value, ttl, comment))
23
+ end
24
+
25
+ private
26
+
27
+ def xml(action, name, type, value, ttl, comment)
28
+ body = { '@xmlns' => Nifcloud::Client::NAMESPACE,
29
+ 'ChangeBatch' => {
30
+ 'Comment' => ['content' => comment],
31
+ 'Changes' => [
32
+ 'Change' => {
33
+ 'Action' => ['content' => action],
34
+ 'ResourceRecordSet' => {
35
+ 'Name' => ['content' => name],
36
+ 'Type' => ['content' => type],
37
+ 'TTL' => ['content' => ttl],
38
+ 'ResourceRecords' => {
39
+ 'Value' => ['content' => value]
40
+ }
41
+ }
42
+ }
43
+ ]
44
+ }
45
+ }
46
+ options = {
47
+ 'AttrPrefix' => true,
48
+ 'RootName' => 'ChangeResourceRecordSetsRequest',
49
+ 'ContentKey' => 'content'
50
+ }
51
+ XmlSimple.xml_out(body, options)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,13 @@
1
+ module Nifcloud
2
+ module DNS
3
+ class Response
4
+ def initialize(body, code, raw)
5
+ @body = body
6
+ @code = code
7
+ @raw = raw
8
+ end
9
+
10
+ attr_reader :body, :code, :raw
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ require 'time'
2
+ require 'base64'
3
+ require 'hmac-sha1'
4
+ require 'net/https'
5
+ require 'rexml/document'
6
+ require 'xmlsimple'
7
+
8
+ module Nifcloud
9
+ module DNS
10
+ VERSION = "0.1.0"
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ require "nifcloud/client"
2
+
3
+ module Nifcloud
4
+ module DNS
5
+ class Zone < Client
6
+ HOSTED_ZONE = 'hostedzone'
7
+ HOSTED_ZONE_WITH_ID = 'hostedzone/%s'
8
+
9
+ def initialize(access_key: nil, secret_key: nil)
10
+ super(access_key, secret_key)
11
+ end
12
+
13
+ def list
14
+ get HOSTED_ZONE
15
+ end
16
+
17
+ def show zone_id
18
+ get(HOSTED_ZONE_WITH_ID % zone_id)
19
+ end
20
+
21
+ def add(zone, comment: '')
22
+ body = { '@xmlns' => Nifcloud::Client::NAMESPACE,
23
+ 'Name' => ['content' => zone],
24
+ 'CallerReference' => ['content' => ''],
25
+ 'HostedZoneConfig' => ['content' => ''],
26
+ 'Comment' => ['content' => comment]
27
+ }
28
+ options = {
29
+ 'AttrPrefix' => true,
30
+ 'RootName' => 'CreateHostedZoneRequest',
31
+ 'ContentKey' => 'content'
32
+ }
33
+ post(HOSTED_ZONE, XmlSimple.xml_out(body, options))
34
+ end
35
+
36
+ def del zone_id
37
+ delete(HOSTED_ZONE_WITH_ID % zone_id)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nifcloud/dns/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nifcloud-dns"
8
+ spec.version = Nifcloud::DNS::VERSION
9
+ spec.authors = ["kakakikikeke"]
10
+ spec.email = ["cdl.yoshinaka@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby SDK for nifcloud DNS.}
13
+ spec.description = %q{You can control nifcloud DNS with ruby.}
14
+ spec.homepage = "https://github.com/kakakikikeke/nifcloud-dns"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "ruby-hmac"
27
+ spec.add_development_dependency "xml-simple"
28
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nifcloud-dns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kakakikikeke
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-hmac
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: xml-simple
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: You can control nifcloud DNS with ruby.
84
+ email:
85
+ - cdl.yoshinaka@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/nifcloud/auth.rb
100
+ - lib/nifcloud/client.rb
101
+ - lib/nifcloud/dns.rb
102
+ - lib/nifcloud/dns/record.rb
103
+ - lib/nifcloud/dns/response.rb
104
+ - lib/nifcloud/dns/version.rb
105
+ - lib/nifcloud/dns/zone.rb
106
+ - nifcloud-dns.gemspec
107
+ homepage: https://github.com/kakakikikeke/nifcloud-dns
108
+ licenses: []
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.7.6
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Ruby SDK for nifcloud DNS.
130
+ test_files: []