vinyldns-ruby 0.8.0

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.
@@ -0,0 +1,73 @@
1
+ # Copyright 2018 Comcast Cable Communications Management, LLC
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
5
+ # Unless required by applicable law or agreed to in writing, software
6
+ # distributed under the License is distributed on an "AS IS" BASIS,
7
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+ require 'vinyldns/api/zone/zone'
11
+ require 'vinyldns/api/group/group'
12
+ require 'net/http'
13
+ require 'openssl'
14
+ require 'json'
15
+ require 'aws-sigv4'
16
+ module Vinyldns
17
+ class API
18
+ # Make sure we can access parameters of the object
19
+ attr_accessor :api_url, :method, :region, :body, :content_type, :signer
20
+ # Required arguments:
21
+ # - method
22
+ def initialize(method, region = 'us-east-1', api_url = ENV['VINYLDNS_API_URL'], content_type = 'application/x-www-form-urlencoded')
23
+ @api_url = api_url
24
+ @method = method.upcase
25
+ raise(ArgumentError, 'Not a valid http request method') unless %w[GET HEAD POST PUT DELETE TRACE OPTIONS CONNECT PATCH].include?(@method)
26
+ @region = region
27
+ if @method == 'GET'
28
+ @content_type = content_type
29
+ elsif @method == 'POST' || @method == 'PUT'
30
+ @content_type = 'application/json'
31
+ end
32
+ # Generate a signed header for our HTTP requests
33
+ # http://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Sigv4/Signer.html
34
+ @signer = Aws::Sigv4::Signer.new(
35
+ service: 'VinylDNS',
36
+ region: 'us-east-1',
37
+ access_key_id: ENV['VINYLDNS_ACCESS_KEY_ID'],
38
+ secret_access_key: ENV['VINYLDNS_SECRET_ACCESS_KEY'],
39
+ apply_checksum_header: false # Required for posting body in make_request : http://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Sigv4/Signer.html : If the 'X-Amz-Content-Sha256' header is set, the :body is optional and will not be read.
40
+ )
41
+ end
42
+
43
+ # Required arguments:
44
+ # - a signed object. ex: Vinyldns::API.new('get/POST/dElETe')
45
+ # - a uri path. ex: 'zones/92cc1c82-e2fc-424b-a178-f24b18e3b67a' -- This will pull ingest.yourdomain.net's zone
46
+ def self.make_request(signed_object, uri, body = '')
47
+ signed_headers = signed_object.signer.sign_request(
48
+ http_method: signed_object.method,
49
+ url: uri == '/' ? "#{signed_object.api_url}#{uri}" : "#{signed_object.api_url}/#{uri}",
50
+ headers: { 'content-type' => signed_object.content_type },
51
+ body: body == '' ? body : body.to_json
52
+ )
53
+ url = URI(signed_object.api_url)
54
+ https = Net::HTTP.new(url.host, url.port)
55
+ https.use_ssl = true
56
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE # SSL not signed? Don't care!
57
+ request = Net::HTTP::Post.new(uri == '/' ? uri : "/#{uri}") if signed_object.method == 'POST'
58
+ request = Net::HTTP::Put.new(uri == '/' ? uri : "/#{uri}") if signed_object.method == 'PUT'
59
+ request = Net::HTTP::Get.new(uri == '/' ? uri : "/#{uri}") if signed_object.method == 'GET'
60
+ signed_headers.headers.each { |k, v| request[k] = v }
61
+ request['content-type'] = signed_object.content_type
62
+ request.body = body == '' ? body : body.to_json
63
+ response = https.request(request)
64
+ case response
65
+ when Net::HTTPSuccess
66
+ JSON.parse(response.body)
67
+ else
68
+ return response
69
+ #"HTTP Error: #{response.code} #{response.message} : #{response.body}"
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,62 @@
1
+ # Copyright 2018 Comcast Cable Communications Management, LLC
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
5
+ # Unless required by applicable law or agreed to in writing, software
6
+ # distributed under the License is distributed on an "AS IS" BASIS,
7
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+ module Vinyldns
11
+ class API
12
+ class Group
13
+ @api_uri = 'groups'
14
+
15
+ def self.create(name, distribution_email, members_array, admins_array, description = '')
16
+ api_request_object = Vinyldns::API.new('post')
17
+ Vinyldns::API.make_request(api_request_object, @api_uri, { 'name': name, 'email': distribution_email, 'description': description, 'members': members_array, 'admins': admins_array })
18
+ end
19
+
20
+ def self.update(id, request_params)
21
+ # We use request_params here as require arguments as create arguments may differ from update
22
+ # Validations
23
+ raise(ArgumentError, 'Request Parameters must be a Hash') unless request_params.is_a? Hash
24
+ api_request_object = Vinyldns::API.new('put')
25
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}", request_params)
26
+ end
27
+
28
+ def self.delete(id)
29
+ api_request_object = Vinyldns::API.new('delete')
30
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}")
31
+ end
32
+
33
+ def self.get(id)
34
+ api_request_object = Vinyldns::API.new('get')
35
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}")
36
+ end
37
+
38
+ def self.list_my_groups(name_filter = nil, max_items = 5, start_from = nil)
39
+ api_request_object = Vinyldns::API.new('get')
40
+ # URI.encode matches all symbols that must be replaced with codes
41
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}?#{URI.encode_www_form([['groupNameFilter', name_filter], ['maxItems', max_items], ['startFrom', start_from]])}")
42
+ end
43
+
44
+ def self.list_group_admins(id)
45
+ api_request_object = Vinyldns::API.new('get')
46
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}/admins")
47
+ end
48
+
49
+ def self.list_group_members(id, max_items = 5, start_from = nil)
50
+ api_request_object = Vinyldns::API.new('get')
51
+ # UNI.encode matches all symbols that must be replaced with codes
52
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}/members?maxItems=#{max_items}#{start_from.nil? ? '' : "&startFrom=#{start_from}"}")
53
+ end
54
+
55
+ def self.get_group_activity(id, max_items = 5, start_from = nil)
56
+ api_request_object = Vinyldns::API.new('get')
57
+ # UNI.encode matches all symbols that must be replaced with codes
58
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}/activity?maxItems=#{max_items}#{start_from.nil? ? '' : "&startFrom=#{start_from}"}")
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,136 @@
1
+ # Copyright 2018 Comcast Cable Communications Management, LLC
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
5
+ # Unless required by applicable law or agreed to in writing, software
6
+ # distributed under the License is distributed on an "AS IS" BASIS,
7
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+ module Vinyldns
11
+ class API
12
+ class Zone
13
+ @api_uri = 'zones'
14
+
15
+ def self.connect(name, distribution_email, group_id = nil, group_name_filter = nil)
16
+ # Find the group ID using the group_name
17
+ if (group_id.nil? || group_id.empty?) && (!group_name_filter.nil? && !group_name_filter.empty?)
18
+ # Obtain admin group ID for body
19
+ group_object = Vinyldns::API::Group.list_my_groups(group_name_filter)['groups']
20
+ ## Validation
21
+ raise(StandardError, 'Parameter group_object returned nil. This is a problem with the make_request or list_my_groups methods.') if group_object.nil?
22
+ raise(ArgumentError, 'No group found for your group_name_filter. Please re-check the spelling so it\'s exact.') if group_object.empty?
23
+ raise(ArgumentError, 'Your group_name_filter used returned more than one group. Please re-check the spelling so it\'s exact.') if group_object.count > 1
24
+ group_id = group_object.first['id']
25
+ elsif (group_id.nil? || group_id.empty?) && (group_name_filter.nil? || group_name_filter.empty?)
26
+ raise(ArgumentError, 'You must include a group_id or group_name_filter.')
27
+ end # Else, we just use the group_id
28
+
29
+ # Post to API
30
+ api_request_object = Vinyldns::API.new('post')
31
+ Vinyldns::API.make_request(api_request_object, @api_uri, { adminGroupId: group_id, name: name, email: distribution_email })
32
+ end
33
+
34
+ def self.update(id, request_params)
35
+ # We use request_params here as values required by create may differ from update
36
+ # Validations
37
+ raise(ArgumentError, 'Request Parameters must be a Hash') unless request_params.is_a? Hash
38
+ api_request_object = Vinyldns::API.new('put')
39
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}", request_params)
40
+ end
41
+
42
+ def self.delete(id)
43
+ api_request_object = Vinyldns::API.new('delete')
44
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}")
45
+ end
46
+
47
+ def self.get(id)
48
+ api_request_object = Vinyldns::API.new('get')
49
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}")
50
+ end
51
+
52
+ def self.search(name_filter = nil, max_items = 5, start_from = nil)
53
+ api_request_object = Vinyldns::API.new('get')
54
+ # UNI.encode matches all symbols that must be replaced with codes
55
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}?#{URI.encode_www_form([['nameFilter', name_filter], ['maxItems', max_items], ['startFrom', start_from]])}")
56
+ end
57
+
58
+ def self.sync(id)
59
+ api_request_object = Vinyldns::API.new('post')
60
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}/sync")
61
+ end
62
+
63
+ # Warning: Being deprecated, use list_changes
64
+ # def self.history(id)
65
+ # api_request_object = Vinyldns::API.new('get')
66
+ # Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}/history")
67
+ # end
68
+
69
+ def self.list_changes(id, max_items = 5, start_from = nil)
70
+ api_request_object = Vinyldns::API.new('get')
71
+ # UNI.encode matches all symbols that must be replaced with codes
72
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}/changes?maxItems=#{max_items}#{start_from.nil? ? '' : "&startFrom=#{start_from}"}")
73
+ end
74
+
75
+ class RecordSet
76
+ @api_uri = 'zones'
77
+ @api_uri_addition = 'recordsets'
78
+
79
+ def self.create(zone_id, name, type, ttl, records_array)
80
+ # Post
81
+ api_request_object = Vinyldns::API.new('post')
82
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{zone_id}/#{@api_uri_addition}", { 'name': name, 'type': type, 'ttl': ttl, 'records': records_array, 'zoneId': zone_id })
83
+ end
84
+
85
+ def self.update(zone_id, request_params)
86
+ # We use request_params here as values required by create may differ from update
87
+ # Validations
88
+ raise(ArgumentError, 'Request Parameters must be a Hash') unless request_params.is_a? Hash
89
+ api_request_object = Vinyldns::API.new('put')
90
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{zone_id}", request_params)
91
+ end
92
+
93
+ def self.delete(zone_id, id)
94
+ api_request_object = Vinyldns::API.new('delete')
95
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{zone_id}/#{@api_uri_addition}/#{id}")
96
+ end
97
+
98
+ def self.get(zone_id, id)
99
+ api_request_object = Vinyldns::API.new('get')
100
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{zone_id}/#{@api_uri_addition}/#{id}")
101
+ end
102
+
103
+ def self.search(zone_id, name_filter = nil, max_items = 10, start_from = nil)
104
+ api_request_object = Vinyldns::API.new('get')
105
+ # UNI.encode matches all symbols that must be replaced with codes
106
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{zone_id}/#{@api_uri_addition}?#{name_filter.nil? ? '' : URI.encode_www_form(['recordNameFilter', name_filter], ['maxItems', max_items], ['startFrom', start_from])}")
107
+ end
108
+
109
+ def self.get_change(zone_id, id, change_id) # Use Vinyldns::API::Zone.list_changes to obtain change_id
110
+ api_request_object = Vinyldns::API.new('get')
111
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{zone_id}/#{@api_uri_addition}/#{id}/changes/#{change_id}")
112
+ end
113
+ end
114
+ class BatchRecordChanges
115
+ @api_uri = 'zones'
116
+ @api_uri_addition = 'batchrecordchanges'
117
+
118
+ def self.create(changes_array, comments = nil)
119
+ raise(ArgumentError, 'changes_array parameter must be an Array') unless changes_array.is_a? Array
120
+ api_request_object = Vinyldns::API.new('post')
121
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{@api_uri_addition}", { 'comments': comments.nil? ? 'Posted with Vinyldns-Ruby Gem' : comments, 'changes': changes_array })
122
+ end
123
+
124
+ def self.get(id)
125
+ api_request_object = Vinyldns::API.new('get')
126
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{@api_uri_addition}/#{id}")
127
+ end
128
+
129
+ def self.user_recent
130
+ api_request_object = Vinyldns::API.new('get')
131
+ Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{@api_uri_addition}")
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,12 @@
1
+ # Copyright 2018 Comcast Cable Communications Management, LLC
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
5
+ # Unless required by applicable law or agreed to in writing, software
6
+ # distributed under the License is distributed on an "AS IS" BASIS,
7
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+ module Vinyldns
11
+ VERSION = '0.8.0'.freeze
12
+ end
data/vinyldns.gemspec ADDED
@@ -0,0 +1,46 @@
1
+ # Copyright 2018 Comcast Cable Communications Management, LLC
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
5
+ # Unless required by applicable law or agreed to in writing, software
6
+ # distributed under the License is distributed on an "AS IS" BASIS,
7
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+
11
+ # -*- encoding: utf-8 -*-
12
+
13
+ lib = File.expand_path('lib', __dir__)
14
+
15
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
16
+ require 'vinyldns/version'
17
+ Gem::Specification.new do |gem|
18
+ gem.name = 'vinyldns-ruby'
19
+ gem.version = Vinyldns::VERSION
20
+ gem.summary = 'Ruby gem for VinylDNS'
21
+ gem.description = 'Ruby gem containing methods to perform various API requests in VinylDNS'
22
+ gem.authors = ['Nathan Pierce']
23
+ gem.email = 'nathan_pierce@comcast.com'
24
+ gem.homepage = 'https://github.com/vinyldns/vinyldns-ruby'
25
+ gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ gem.licenses = ['Apache-2.0']
27
+
28
+ # `git submodule --quiet foreach --recursive pwd`.split($/).each do |submodule|
29
+ # submodule.sub!("#{Dir.pwd}/",'')
30
+ # Dir.chdir(submodule) do
31
+ # `git ls-files`.split($/).map do |subpath|
32
+ # gem.files << File.join(submodule,subpath)
33
+ # end
34
+ # end
35
+ # end
36
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
37
+ gem.require_paths = ['lib']
38
+ gem.add_runtime_dependency 'aws-sigv4', '~> 1.0'
39
+ gem.add_development_dependency 'bundler', '~> 1.13'
40
+ gem.add_development_dependency 'rake', '~> 12.0'
41
+ gem.add_development_dependency 'rspec', '3.7.0'
42
+ # Dependencies
43
+ # Licensed uses the the libgit2 bindings for Ruby provided by rugged. rugged has its own dependencies - cmake and pkg-config - which you may need to install before you can install Licensed.
44
+ # For example, on macOS with Homebrew: brew install cmake pkg-config and on Ubuntu: apt-get install cmake pkg-config.
45
+ gem.add_development_dependency 'licensed', '1.0.0'
46
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vinyldns-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Pierce
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sigv4
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
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.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
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.7.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.7.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: licensed
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.0
83
+ description: Ruby gem containing methods to perform various API requests in VinylDNS
84
+ email: nathan_pierce@comcast.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".licensed.json"
91
+ - ".licenses/rubygem/bundler.txt"
92
+ - ".licenses/rubygem/vinyldns-ruby.txt"
93
+ - ".rspec"
94
+ - ".rubocop.yml"
95
+ - CODE_OF_CONDUCT.md
96
+ - CONTRIBUTING.md
97
+ - Gemfile
98
+ - ISSUE_TEMPLATE.md
99
+ - LICENSE
100
+ - Makefile
101
+ - PULL_REQUEST_TEMPLATE.md
102
+ - README.md
103
+ - Rakefile
104
+ - lib/vinyldns.rb
105
+ - lib/vinyldns/api.rb
106
+ - lib/vinyldns/api/group/group.rb
107
+ - lib/vinyldns/api/zone/zone.rb
108
+ - lib/vinyldns/version.rb
109
+ - vinyldns.gemspec
110
+ homepage: https://github.com/vinyldns/vinyldns-ruby
111
+ licenses:
112
+ - Apache-2.0
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.7.4
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Ruby gem for VinylDNS
134
+ test_files: []