Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
AllCops:
TargetRubyVersion: 2.4
Style/Documentation:
Enabled: false
Style/BracesAroundHashParameters:
Expand All @@ -6,6 +8,12 @@ Style/CommentedKeyword:
Enabled: false
Style/BlockDelimiters:
EnforcedStyle: braces_for_chaining
Layout/LeadingCommentSpace:
Enabled: false
Layout/ClosingParenthesisIndentation:
Enabled: false
Layout/AlignArray:
Enabled: false
Metrics/LineLength:
Enabled: false
Metrics/CyclomaticComplexity:
Expand All @@ -18,15 +26,3 @@ Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Enabled: false
Layout/LeadingCommentSpace:
Enabled: false
Layout/FirstParameterIndentation:
Enabled: false
Layout/ClosingParenthesisIndentation:
Enabled: false
Layout/IndentArray:
Enabled: false
Layout/IndentHash:
Enabled: false
Layout/AlignArray:
Enabled: false
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# Copyright 2018 Comcast Cable Communications Management, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 2 additions & 0 deletions lib/vinyldns.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2018 Comcast Cable Communications Management, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
34 changes: 18 additions & 16 deletions lib/vinyldns/api.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2018 Comcast Cable Communications Management, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,6 +25,7 @@ def initialize(method, region = 'us-east-1', api_url = ENV['VINYLDNS_API_URL'],
@api_url = api_url
@method = method.upcase
raise(ArgumentError, 'Not a valid http request method') unless %w[GET HEAD POST PUT DELETE TRACE OPTIONS CONNECT PATCH].include?(@method)

@region = region
if @method == 'GET'
@content_type = content_type
Expand All @@ -32,11 +35,11 @@ def initialize(method, region = 'us-east-1', api_url = ENV['VINYLDNS_API_URL'],
# Generate a signed header for our HTTP requests
# http://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Sigv4/Signer.html
@signer = Aws::Sigv4::Signer.new(
service: 'VinylDNS',
region: 'us-east-1',
access_key_id: ENV['VINYLDNS_ACCESS_KEY_ID'],
secret_access_key: ENV['VINYLDNS_SECRET_ACCESS_KEY'],
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.
service: 'VinylDNS',
region: 'us-east-1',
access_key_id: ENV['VINYLDNS_ACCESS_KEY_ID'],
secret_access_key: ENV['VINYLDNS_SECRET_ACCESS_KEY'],
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.
)
end

Expand All @@ -45,27 +48,26 @@ def initialize(method, region = 'us-east-1', api_url = ENV['VINYLDNS_API_URL'],
# - a uri path. ex: 'zones/92cc1c82-e2fc-424b-a178-f24b18e3b67a' -- This will pull ingest.yourdomain.net's zone
def self.make_request(signed_object, uri, body = '')
signed_headers = signed_object.signer.sign_request(
http_method: signed_object.method,
url: uri == '/' ? "#{signed_object.api_url}#{uri}" : "#{signed_object.api_url}/#{uri}",
headers: { 'content-type' => signed_object.content_type },
body: body == '' ? body : body.to_json
http_method: signed_object.method,
url: uri == '/' ? "#{signed_object.api_url}#{uri}" : "#{signed_object.api_url}/#{uri}",
headers: { 'content-type' => signed_object.content_type },
body: body == '' ? body : body.to_json
)
url = URI(signed_object.api_url)
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true ? url.scheme == "https" : https.use_ssl = false
if ENV['VINYLDNS_VERIFY_SSL'] == false || ENV['VINYLDNS_VERIFY_SSL'] =~ /^false$/i
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
else
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
end
https.use_ssl = true ? url.scheme == 'https' : https.use_ssl = false
https.verify_mode = if ENV['VINYLDNS_VERIFY_SSL'] == false || ENV['VINYLDNS_VERIFY_SSL'] =~ /^false$/i
OpenSSL::SSL::VERIFY_NONE
else
OpenSSL::SSL::VERIFY_PEER
end
request = Net::HTTP::Post.new(uri == '/' ? uri : "/#{uri}") if signed_object.method == 'POST'
request = Net::HTTP::Put.new(uri == '/' ? uri : "/#{uri}") if signed_object.method == 'PUT'
request = Net::HTTP::Get.new(uri == '/' ? uri : "/#{uri}") if signed_object.method == 'GET'
request = Net::HTTP::Delete.new(uri == '/' ? uri : "/#{uri}") if signed_object.method == 'DELETE'
signed_headers.headers.each { |k, v| request[k] = v }
request['content-type'] = signed_object.content_type
request.body = body == '' ? body : body.to_json

response = https.request(request)
case response
when Net::HTTPSuccess
Expand Down
3 changes: 3 additions & 0 deletions lib/vinyldns/api/group/group.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2018 Comcast Cable Communications Management, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -21,6 +23,7 @@ def self.update(id, request_params)
# We use request_params here as require arguments as create arguments may differ from update
# Validations
raise(ArgumentError, 'Request Parameters must be a Hash') unless request_params.is_a? Hash

api_request_object = Vinyldns::API.new('put')
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}", request_params)
end
Expand Down
14 changes: 10 additions & 4 deletions lib/vinyldns/api/zone/zone.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2018 Comcast Cable Communications Management, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -22,11 +24,12 @@ def self.connect(name, distribution_email, group_id = nil, group_name_filter = n
raise(StandardError, 'Parameter group_object returned nil. This is a problem with the make_request or list_my_groups methods.') if group_object.nil?
raise(ArgumentError, 'No group found for your group_name_filter. Please re-check the spelling so it\'s exact.') if group_object.empty?
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

group_id = group_object.first['id']
elsif (group_id.nil? || group_id.empty?) && (group_name_filter.nil? || group_name_filter.empty?)
raise(ArgumentError, 'You must include a group_id or group_name_filter.')
end # Else, we just use the group_id
parameters = { adminGroupId: group_id, name: name, email: distribution_email}
parameters = { adminGroupId: group_id, name: name, email: distribution_email }
parameters.merge!(optional_args)
# Post to API
api_request_object = Vinyldns::API.new('post')
Expand All @@ -37,6 +40,7 @@ def self.update(id, request_params)
# We use request_params here as values required by create may differ from update
# Validations
raise(ArgumentError, 'Request Parameters must be a Hash') unless request_params.is_a? Hash

api_request_object = Vinyldns::API.new('put')
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}", request_params)
end
Expand Down Expand Up @@ -78,7 +82,7 @@ class RecordSet
@api_uri = 'zones'
@api_uri_addition = 'recordsets'

def self.create(zone_id, name, type, ttl, records_array, owner_group_id = "")
def self.create(zone_id, name, type, ttl, records_array, owner_group_id = '')
# Post
api_request_object = Vinyldns::API.new('post')
payload = { 'name': name, 'type': type, 'ttl': ttl, 'records': records_array, 'zoneId': zone_id, 'ownerGroupId': owner_group_id }
Expand All @@ -90,6 +94,7 @@ def self.update(zone_id, id, request_params)
# We use request_params here as values required by create may differ from update
# Validations
raise(ArgumentError, 'Request Parameters must be a Hash') unless request_params.is_a? Hash

api_request_object = Vinyldns::API.new('put')
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{zone_id}/recordsets/#{id}", request_params)
end
Expand Down Expand Up @@ -120,10 +125,11 @@ class BatchRecordChanges
@api_uri = 'zones'
@api_uri_addition = 'batchrecordchanges'

def self.create(changes_array, comments="", owner_group_id="")
def self.create(changes_array, comments = '', owner_group_id = '')
raise(ArgumentError, 'changes_array parameter must be an Array') unless changes_array.is_a? Array

api_request_object = Vinyldns::API.new('post')
payload = {'changes': changes_array, 'comments': comments, 'ownerGroupId': owner_group_id}
payload = { 'changes': changes_array, 'comments': comments, 'ownerGroupId': owner_group_id }
params = Vinyldns::Util.clean_request_payload(payload)
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{@api_uri_addition}", params)
end
Expand Down
4 changes: 3 additions & 1 deletion lib/vinyldns/util/util.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2018 Comcast Cable Communications Management, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,7 +14,7 @@
module Vinyldns
class Util
def self.clean_request_payload(payload)
payload.delete_if { |k,v| v.to_s.empty? }
payload.delete_if { |_k, v| v.to_s.empty? }
end
end
end
4 changes: 3 additions & 1 deletion lib/vinyldns/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2018 Comcast Cable Communications Management, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -8,5 +10,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
module Vinyldns
VERSION = '0.8.1'.freeze
VERSION = '0.8.1'
end
3 changes: 2 additions & 1 deletion spec/api_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2018 Comcast Cable Communications Management, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,6 +46,5 @@
describe 'Make Requests with ENV[\'VINYLDNS_VERIFY_SSL\']' do
#TODO
end

end
end
12 changes: 7 additions & 5 deletions spec/group_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2018 Comcast Cable Communications Management, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -10,18 +12,18 @@
require 'spec_helper'
RSpec.describe Vinyldns::API::Group do
before do
Vinyldns::API::Group.create("test-group", "[email protected]", [], [], "description")
Vinyldns::API::Group.create('test-group', '[email protected]', [], [], 'description')
end

after(:all) do
Vinyldns::API::Group.list_my_groups["groups"].each do |group|
Vinyldns::API::Group.delete(group["id"])
Vinyldns::API::Group.list_my_groups['groups'].each do |group|
Vinyldns::API::Group.delete(group['id'])
end
end

let(:first_group) do
Vinyldns::API::Group.list_my_groups["groups"].find do |group|
group["name"] == "test-group"
Vinyldns::API::Group.list_my_groups['groups'].find do |group|
group['name'] == 'test-group'
end
end

Expand Down
16 changes: 8 additions & 8 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2018 Comcast Cable Communications Management, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -24,7 +26,7 @@ module Helpers
def wait_until_zone_active(zone_id)
retries = MAX_RETRIES
zone_request = Vinyldns::API::Zone.get(zone_id)
while zone_request.class.name == ("Net::HTTPNotFound") && retries > 0
while zone_request.class.name == 'Net::HTTPNotFound' && retries.positive?
zone_request = Vinyldns::API::Zone.get(zone_id)
retries -= 1
sleep(RETRY_WAIT)
Expand All @@ -35,7 +37,7 @@ def wait_until_zone_active(zone_id)
def wait_until_zone_deleted(zone_id)
retries = MAX_RETRIES
zone_request = Vinyldns::API::Zone.delete(zone_id)
while zone_request.class.name != ("Net::HTTPNotFound") && retries > 0
while zone_request.class.name != 'Net::HTTPNotFound' && retries.positive?
zone_request = Vinyldns::API::Zone.get(zone_id)
retries -= 1
sleep(RETRY_WAIT)
Expand All @@ -46,7 +48,7 @@ def wait_until_zone_deleted(zone_id)
def wait_until_recordset_active(zone_id, recordset_id)
retries = MAX_RETRIES
recordset_request = Vinyldns::API::Zone::RecordSet.get(zone_id, recordset_id)
while recordset_request.class.name == ("Net::HTTPNotFound") && retries > 0
while recordset_request.class.name == 'Net::HTTPNotFound' && retries.positive?
recordset_request = Vinyldns::API::Zone::RecordSet.get(zone_id, recordset_id)
retries -= 1
sleep(RETRY_WAIT)
Expand All @@ -57,15 +59,13 @@ def wait_until_recordset_active(zone_id, recordset_id)
def wait_until_batch_change_completed(batch_change)
change = batch_change
retries = MAX_RETRIES
while !['Complete', 'Failed', 'PartialFailure'].include?(change['status']) && retries > 0
while !%w[Complete Failed PartialFailure].include?(change['status']) && retries.positive?
latest_change = Vinyldns::API::Zone::BatchRecordChanges.get(change['id'])
if(latest_change.class.name != "Net::HTTPNotFound")
change = latest_change
end
change = latest_change if latest_change.class.name != 'Net::HTTPNotFound'
retries -= 1
sleep(RETRY_WAIT)
end
return change
change
end
end

Expand Down
8 changes: 5 additions & 3 deletions spec/util_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright 2018 Comcast Cable Communications Management, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -9,10 +11,10 @@
# limitations under the License.
require 'spec_helper'
describe Vinyldns::Util do
it "removes empty key-value pairs" do
parameters = {one: "", two: 2, three: "three", four: nil}
it 'removes empty key-value pairs' do
parameters = { one: '', two: 2, three: 'three', four: nil }
result = Vinyldns::Util.clean_request_payload(parameters)

expect(result).to eq({two: 2, three: "three"})
expect(result).to eq({ two: 2, three: 'three' })
end
end
Loading