Repository navigation
add reserved ipv6 support #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bentranter
merged 5 commits into
digitalocean:main
from
vnegi-digitalocean:add-support-reserved-ipv6
Feb 26, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
32ee4dd
add support for reserved ipv6 api
vnegi-digitalocean d30c69a
fix rubocop warning + failing test
vnegi-digitalocean 844ee00
disable module length check on dropket_kit module/class
vnegi-digitalocean f64c50f
Update spec/lib/droplet_kit/resources/reserved_ipv6_resource_spec.rb
vnegi-digitalocean fb846d4
Update README.md
vnegi-digitalocean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.