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
41 changes: 31 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ If you decide to contribute, please read over our [contributor documentation](CO
"latestSync"=>"2017-12-04T19:35:53Z"}],
"maxItems"=>5}


## All Available Methods

* Below method arguments with "=" next to them indicate a default value. You do not have to specify "argmuentX = nil', just know if you don't set it nil will be used.

### Vinyldns::API

- new(method, region = 'us-east-1', api_url = ENV['VINYLDNS_API_URL'], content_type = 'application/x-www-form-urlencoded')
- Required for make_request, but not before any of the Vinyldns::API::* methods.

- make_request(signed_object, uri, body = '')
- HTTP requests that fail are returned as: ```#<Net::HTTPUnauthorized 401 Unauthorized readbody=true>```

Expand All @@ -95,7 +95,7 @@ If you decide to contribute, please read over our [contributor documentation](CO
- Zone API Reference > Zone Model details all available options
- request_params must be a hash of values permitted by the API. See the API reference linked to above.
- Updates are NOT immediate.

- delete(id)

- get(id)
Expand All @@ -121,23 +121,43 @@ If you decide to contribute, please read over our [contributor documentation](CO

- get(zone_id, id)

- search(zone_id, name_filter = nil, max_items=10, start_from = nil)
- If name_filter is not set, it will pull an alphabetical list of zones you have access to.
- search(zone_id, name_filter = nil, max_items=10, start_from = nil, ignore_access)
- If name_filter is not set, it will pull an alphabetical list of zones.
- If ignore_access is true, it will return zones regardless of your access to them.

- get_change(zone_id, id, change_id)
- Use Vinyldns::API::Zone.list_changes to obtain change_id

### Vinyldns::API::Zone::BatchRecordChanges

[No Zone ID needed for these]

- create(changes_array, comments)
- create(changes_array, comments, owner_group_id, scheduled_time, allow_manual_review)
- changes must be an array of Add or DeleteRecordSet hashes.
- scheduled_time only allowed if manual batch change review and scheduled batch changes are supported in the VinylDNS instance
- allow_manual_review default is true, can be set to false to fail rather than sending to review if there are soft errors in the batch change.

- get(id)
- user_recent

- user_recent(ignore_access, approvalStatus)
- Summary information for the most recent 100 batch changes created by the user.
- If ignore_access is true, it will return batch changes whether you created them or not. Filter only applies for VinylDNS super and support admins.
- approval_status is a filter, can be one of AutoApproved, PendingReview, ManuallyApproved or Rejected.

- cancel(id)
- Requires manual batch change to be enabled in VinylDNS instance.
- Only for the creator of the batch change.
- Batch Change must have an approval status of PendingReview.

- approve(id, review_comment)
- Requires manual batch change to be enabled in VinylDNS instance.
- For VinylDNS super and support admins only.
- Batch Change must have an approval status of PendingReview.

- reject(id, review_comment)
- Requires manual batch change to be enabled in VinylDNS instance.
- For VinylDNS super and support admins only.
- Batch Change must have an approval status of PendingReview.

### Vinyldns::API::Group

Expand All @@ -161,4 +181,5 @@ If you decide to contribute, please read over our [contributor documentation](CO
- get_group_activity(id, max_items = 5, start_from = nil)

# Maintainers
* [Britney Wright](https://github.com/BritneyWright)
* [Nathan Pierce](https://github.com/NorseGaud)
49 changes: 39 additions & 10 deletions lib/vinyldns/api/zone/zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@ def self.get(id)
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{id}")
end

def self.search(name_filter = nil, max_items = 5, start_from = nil)
def self.get_by_name(name)
api_request_object = Vinyldns::API.new('get')
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/name/#{name}")
end

def self.search(name_filter: nil, max_items: 5, start_from: nil, ignore_access: false)
api_request_object = Vinyldns::API.new('get')
params = {"maxItems": max_items, "nameFilter": name_filter, "startFrom": start_from, "ignoreAccess": ignore_access}
query = Vinyldns::Util.clean_query_params(params)
# UNI.encode matches all symbols that must be replaced with codes
Vinyldns::API.make_request(api_request_object, "#{@api_uri}?#{URI.encode_www_form([['nameFilter', name_filter], ['maxItems', max_items], ['startFrom', start_from]])}")
Vinyldns::API.make_request(api_request_object, "#{@api_uri}#{query}")
end

def self.sync(id)
Expand Down Expand Up @@ -104,11 +111,12 @@ def self.get(zone_id, id)
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{zone_id}/#{@api_uri_addition}/#{id}")
end

def self.search(zone_id, name_filter = nil, max_items = 10, start_from = nil)
def self.search(zone_id, name_filter=nil, max_items=10, start_from=nil)
api_request_object = Vinyldns::API.new('get')
# UNI.encode matches all symbols that must be replaced with codes
parameters = "?maxItems=#{max_items}#{name_filter.nil? ? '' : "&recordNameFilter=#{name_filter}"}#{start_from.nil? ? '' : "&start_from=#{start_from}"}"
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{zone_id}/#{@api_uri_addition}#{parameters}")
params = {"maxItems": max_items, "recordNameFilter": name_filter, "startFrom": start_from}
query = Vinyldns::Util.clean_query_params(params)
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{zone_id}/#{@api_uri_addition}#{query}")
end

def self.get_change(zone_id, id, change_id) # Use Vinyldns::API::Zone.list_changes to obtain change_id
Expand All @@ -120,22 +128,43 @@ 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 = "", scheduled_time = nil, allow_manual_review = true)
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, 'scheduledTime': scheduled_time}
params = Vinyldns::Util.clean_request_payload(payload)
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{@api_uri_addition}", params)
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{@api_uri_addition}?allowManualReview=#{allow_manual_review}", params)
end

def self.get(id)
api_request_object = Vinyldns::API.new('get')
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{@api_uri_addition}/#{id}")
end

def self.user_recent
def self.user_recent(ignore_access: false, approval_status: nil)
api_request_object = Vinyldns::API.new('get')
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{@api_uri_addition}")
params = {"ignoreAccess": ignore_access, "approvalStatus": approval_status}
query = Vinyldns::Util.clean_query_params(params)
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{@api_uri_addition}#{query}")
end

def self.cancel(id)
api_request_object = Vinyldns::API.new('post')
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{@api_uri_addition}/#{id}/cancel")
end

def self.approve(id, review_comment=nil)
api_request_object = Vinyldns::API.new('post')
payload = {'reviewComment': review_comment}
params = Vinyldns::Util.clean_request_payload(payload)
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{@api_uri_addition}/#{id}/approve", params)
end

def self.reject(id, review_comment=nil)
api_request_object = Vinyldns::API.new('post')
payload = {'reviewComment': review_comment}
params = Vinyldns::Util.clean_request_payload(payload)
Vinyldns::API.make_request(api_request_object, "#{@api_uri}/#{@api_uri_addition}/#{id}/reject", params)
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/vinyldns/util/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@ class Util
def self.clean_request_payload(payload)
payload.delete_if { |k,v| v.to_s.empty? }
end

def self.clean_query_params(params)
params.delete_if { |k,v| v.to_s.empty? }
query_string = "?"
query_string += params.map { |k,v| "#{k}=#{v}"}.join('&')
end
end
end
2 changes: 1 addition & 1 deletion spec/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
it 'can not make http request with bad uri' do
api_request_object = Vinyldns::API.new('GEt')
# Requires you to have at least one zone for your user/group
expect(Vinyldns::API.make_request(api_request_object, 'maxItems=1').class.name).to eq('Net::HTTPUnauthorized')
expect(Vinyldns::API.make_request(api_request_object, 'maxItems=1').class.name).to eq('Net::HTTPNotFound')
end

describe 'Make Requests with ENV[\'VINYLDNS_VERIFY_SSL\']' do
Expand Down
55 changes: 42 additions & 13 deletions spec/zone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,59 @@
require 'spec_helper'
describe Vinyldns::API::Zone do

let(:group) {
Vinyldns::API::Group.create("test-group", "[email protected]", [], [], "description")
}
before(:each) do
@group = Vinyldns::API::Group.create("test2-group", "[email protected]", [], [], "description")

Vinyldns::API::Zone.search["zones"].each do |zone|
Vinyldns::API::Zone.delete(zone["id"])
wait_until_zone_deleted(zone["id"])
end
end


after(:each) do
Vinyldns::API::Zone.search["zones"].each do |zone|
Vinyldns::API::Zone.delete(zone["id"])
wait_until_zone_deleted(zone["id"])
end

Vinyldns::API::Group.list_my_groups["groups"].each do |g|
Vinyldns::API::Group.delete(g["id"])
end
end

after(:all) do
Vinyldns::API::Zone.search["zones"].each do |zone|
Vinyldns::API::Zone.delete(zone["id"])
wait_until_zone_deleted(zone["id"])
end

Vinyldns::API::Group.list_my_groups["groups"].each do |g|
Vinyldns::API::Group.delete(g["id"])
end
end

describe '.connect' do
it 'responds with the new zone' do
connection = Vinyldns::API::Zone.connect('ok', group['email'], group['id'])
connection = Vinyldns::API::Zone.connect('ok', @group['email'], @group['id'])
wait_until_zone_active(connection['zone']['id'])
expect(connection['status']).to eq('Pending')
end
it 'responds with 409 Conflict if the zone already exists' do
connection = Vinyldns::API::Zone.connect('ok', group['email'], group['id'])
connection = Vinyldns::API::Zone.connect('ok', @group['email'], @group['id'])
wait_until_zone_active(connection['zone']['id'])
expect(Vinyldns::API::Zone.connect('ok', group['email'], group['id']).class.name).to eq('Net::HTTPConflict')
expect(Vinyldns::API::Zone.connect('ok', @group['email'], @group['id']).class.name).to eq('Net::HTTPConflict')
end
it 'raises error when group_id AND group_name_filter are nil arguments' do
expect { Vinyldns::API::Zone.connect('dummy', group['email']) }.to raise_error(ArgumentError)
expect { Vinyldns::API::Zone.connect('dummy', @group['email']) }.to raise_error(ArgumentError)
end
it 'raises error when Group.search is used and group_name doesn\'t find anything' do
expect { Vinyldns::API::Zone.connect('dummy', group['email'], nil, 'test09999999').message }.to raise_error(ArgumentError, 'No group found for your group_name_filter. Please re-check the spelling so it\'s exact.')
expect { Vinyldns::API::Zone.connect('dummy', @group['email'], nil, 'test09999999').message }.to raise_error(ArgumentError, 'No group found for your group_name_filter. Please re-check the spelling so it\'s exact.')
end
end
describe '.update' do
it 'can PUT & receives 400 Bad Request with "Missing Zone.name"' do
connection = Vinyldns::API::Zone.connect('ok', group['email'], group['id'])
connection = Vinyldns::API::Zone.connect('ok', @group['email'], @group['id'])
expect(Vinyldns::API::Zone.update(connection['zone']['id'], { email: 'new-email' }).body).to include('Missing Zone')
end
it 'raises error when request_params argument is not hash' do
Expand All @@ -54,17 +71,23 @@
end
describe '.get' do
it 'does not raise an error' do
connection = Vinyldns::API::Zone.connect('ok', group['email'], group['id'])
connection = Vinyldns::API::Zone.connect('ok', @group['email'], @group['id'])
request = wait_until_zone_active(connection['zone']['id'])
expect(Vinyldns::API::Zone.get(request['zone']['id']).class.name).to eq('Hash')
end
end
describe '.search' do
it 'returns zones' do
connection = Vinyldns::API::Zone.connect('ok', group['email'], group['id'])
it "returns user's zones" do
connection = Vinyldns::API::Zone.connect('ok', @group['email'], @group['id'])
request = wait_until_zone_active(connection['zone']['id'])
expect(Vinyldns::API::Zone.search["zones"].length).to eq(1)
end

it 'returns all zones' do
connection = Vinyldns::API::Zone.connect('ok', @group['email'], @group['id'])
request = wait_until_zone_active(connection['zone']['id'])
expect(Vinyldns::API::Zone.search(ignore_access: true)["zones"].length).to eq(3)
end
end
end

Expand Down Expand Up @@ -178,7 +201,6 @@
], 'vinyldns-ruby gem testing'
)
expect(request.class.name).to eq("Net::HTTPBadRequest")
expect(request.body).to include("does not exist in VinylDNS")
end
it 'can POST' do
request = Vinyldns::API::Zone::BatchRecordChanges.create(
Expand Down Expand Up @@ -268,4 +290,11 @@
expect { Vinyldns::API::Zone::BatchRecordChanges.get(batch_change['id']) }.to_not raise_error
end
end
describe '.cancel' do
it 'cannot cancel a batch change that is not pending review' do
batch_change = Vinyldns::API::Zone::BatchRecordChanges.user_recent['batchChanges'].first
cancel_batch_change = Vinyldns::API::Zone::BatchRecordChanges.cancel(batch_change['id'])
expect(cancel_batch_change.class).to eq(Net::HTTPNotFound)
end
end
end