Skip to content
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

Add update_connection_pool action #326

Merged
Merged
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: 7 additions & 13 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-05-17 08:19:08 UTC using RuboCop version 1.63.5.
# on 2024-10-05 16:27:38 UTC using RuboCop version 1.66.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -33,7 +33,7 @@ Lint/UnderscorePrefixedVariableName:
Exclude:
- 'spec/lib/droplet_kit/client_spec.rb'

# Offense count: 35
# Offense count: 36
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AutoCorrect, IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Expand All @@ -55,12 +55,12 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 127
Max: 131

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 133
Max: 137

# Offense count: 6
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Expand Down Expand Up @@ -90,7 +90,7 @@ Naming/VariableNumber:
- 'spec/lib/droplet_kit/resources/firewall_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/load_balancer_resource_spec.rb'

# Offense count: 33
# Offense count: 34
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Expand All @@ -110,17 +110,11 @@ RSpec/ContextWording:
- 'spec/lib/droplet_kit/resources/vpc_resource_spec.rb'
- 'spec/support/resource_context.rb'

# Offense count: 120
# Offense count: 121
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 43

# Offense count: 37
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
# Include: **/*_spec*rb*, **/spec/**/*
RSpec/FilePath:
Enabled: false

# Offense count: 2
RSpec/IteratedExpectation:
Exclude:
Expand Down Expand Up @@ -179,7 +173,7 @@ Style/SymbolProc:
- 'lib/droplet_kit/resources/kubernetes_cluster_resource.rb'
- 'lib/tasks/resource_doc.rake'

# Offense count: 90
# Offense count: 91
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Actions supported:
* `client.databases.create_connection_pool(database_connection_pool, id: 'id')`
* `client.databases.find_connection_pool(id: 'id', name: 'name')`
* `client.databases.list_connection_pools(id: 'id')`
* `client.databases.update_connection_pool(database_connection_pool, id: 'id', name: 'name')`
* `client.databases.delete_connection_pool(id: 'id', name: 'name')`
* `client.databases.set_eviction_policy(database_eviction_policy, id: 'id')`
* `client.databases.get_eviction_policy(id: 'id')`
Expand Down
8 changes: 4 additions & 4 deletions lib/droplet_kit/mappings/database_connection_pool_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class DatabaseConnectionPoolMapping
root_key singular: 'pool', plural: 'pools', scopes: [:read]

property :name, scopes: %i[read create]
property :mode, scopes: %i[read create]
property :size, scopes: %i[read create]
property :db, scopes: %i[read create]
property :user, scopes: %i[read create]
property :mode, scopes: %i[read create update]
property :size, scopes: %i[read create update]
property :db, scopes: %i[read create update]
property :user, scopes: %i[read create update]
property :connection, scopes: [:read], include: DatabaseConnectionMapping
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/droplet_kit/resources/database_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ class DatabaseResource < ResourceKit::Resource
handler(200) { |response| DatabaseConnectionPoolMapping.extract_collection(response.body, :read) }
end

action :update_connection_pool, 'PUT /v2/databases/:id/pools/:name' do
body { |object| DatabaseConnectionPoolMapping.representation_for(:update, object) }
handler(204) { |response| true }
end

action :delete_connection_pool, 'DELETE /v2/databases/:id/pools/:name' do
handler(204) { |response| true }
end
Expand Down
21 changes: 21 additions & 0 deletions spec/lib/droplet_kit/resources/database_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,27 @@
end
end

describe '#update_connection_pool' do
context 'for a successful update of a database connection pool' do
let(:connection_pool_name) { 'backend-pool' }

it 'updates the database connection pool' do
database_connection_pool = DropletKit::DatabaseConnectionPool.new(
mode: 'transaction',
size: 10,
db: 'defaultdb',
user: 'doadmin'
)

json_body = DropletKit::DatabaseConnectionPoolMapping.representation_for(:update, database_connection_pool)
request = stub_do_api("/v2/databases/#{database_cluster_id}/pools/#{connection_pool_name}", :put).with(body: json_body).to_return(status: 204)
resource.update_connection_pool(database_connection_pool, id: database_cluster_id, name: connection_pool_name)

expect(request).to have_been_made
end
end
end

describe '#delete_connection_pool' do
let(:connection_pool_name) { 'backend-pool' }

Expand Down
Loading