-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add support for reserved ipv6 api * fix rubocop warning + failing test * disable module length check on dropket_kit module/class * Update spec/lib/droplet_kit/resources/reserved_ipv6_resource_spec.rb Co-authored-by: Ben Tranter <[email protected]> * Update README.md Co-authored-by: Ben Tranter <[email protected]> --------- Co-authored-by: Ben Tranter <[email protected]>
- Loading branch information
1 parent
2a7e6e1
commit fcd19d2
Showing
16 changed files
with
902 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropletKit | ||
class ReservedIpv6Mapping | ||
include Kartograph::DSL | ||
|
||
kartograph do | ||
mapping ReservedIpv6 | ||
root_key plural: 'reserved_ipv6s', singular: 'reserved_ipv6', scopes: [:read] | ||
|
||
property :ip, scopes: [:read] | ||
property :region_slug, scopes: %i[read create] | ||
property :droplet, scopes: [:read], include: DropletMapping | ||
property :reserved_at, scopes: [:read] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropletKit | ||
class ReservedIpv6 < BaseModel | ||
attribute :ip | ||
attribute :droplet | ||
attribute :reserved_at | ||
# Used for creates | ||
attribute :region_slug | ||
|
||
def identifier | ||
ip | ||
end | ||
|
||
def self.from_identifier(identifier) | ||
new(ip: identifier) | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
lib/droplet_kit/resources/reserved_ipv6_action_resource.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropletKit | ||
class ReservedIpv6ActionResource < ResourceKit::Resource | ||
resources do | ||
default_handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) } | ||
default_handler(400) { |response| ErrorMapping.fail_with(FailedCreate, response.body) } | ||
|
||
action :assign, 'POST /v2/reserved_ipv6/:ip/actions' do | ||
body { |hash| { type: 'assign', droplet_id: hash[:droplet_id] }.to_json } | ||
handler(201, 200) { |response| ActionMapping.extract_single(response.body, :read) } | ||
end | ||
|
||
action :unassign, 'POST /v2/reserved_ipv6/:ip/actions' do | ||
body { |hash| { type: 'unassign' }.to_json } | ||
handler(201, 200) { |response| ActionMapping.extract_single(response.body, :read) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropletKit | ||
class ReservedIpv6Resource < ResourceKit::Resource | ||
resources do | ||
action :all, 'GET /v2/reserved_ipv6' do | ||
query_keys :per_page, :page | ||
handler(200) { |response| ReservedIpv6Mapping.extract_collection(response.body, :read) } | ||
end | ||
|
||
action :find, 'GET /v2/reserved_ipv6/:ip' do | ||
handler(200) { |response| ReservedIpv6Mapping.extract_single(response.body, :read) } | ||
handler(404) { |response| ErrorMapping.fail_with(Error, response.body) } | ||
end | ||
|
||
action :create, 'POST /v2/reserved_ipv6' do | ||
body { |object| ReservedIpv6Mapping.representation_for(:create, object) } | ||
handler(201) { |response| ReservedIpv6Mapping.extract_single(response.body, :read) } | ||
handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) } | ||
end | ||
|
||
action :delete, 'DELETE /v2/reserved_ipv6/:ip' do | ||
handler(404) { |response| ErrorMapping.fail_with(FailedDelete, response.body) } | ||
handler(202) { |response| ActionMapping.extract_single(response.body, :read) } | ||
handler(204) { |response| true } | ||
end | ||
end | ||
|
||
def all(*args) | ||
PaginatedResource.new(action(:all), self, *args) | ||
end | ||
end | ||
end |
Oops, something went wrong.