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 http_proxy and create_table_enabled config options #496

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,10 @@ Listed below are all configuration options.
* `http_read_timeout`:The number of seconds to wait for HTTP response
data. Default option value is `nil`. If not specified effected value
is `60`
* `http_proxy`: A proxy to send requests through. Default option value is `nil`.
* `create_table_enabled`: if `true`, Dynamoid creates table if table not exist;
if `false`, Dynamoid logs error message for not able to create table in DynamoDB.
Default is `false`


## Concurrency
Expand Down
7 changes: 6 additions & 1 deletion lib/dynamoid/adapter_plugin/aws_sdk_v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AwsSdkV3
}
BATCH_WRITE_ITEM_REQUESTS_LIMIT = 25

CONNECTION_CONFIG_OPTIONS = %i[endpoint region http_continue_timeout http_idle_timeout http_open_timeout http_read_timeout].freeze
CONNECTION_CONFIG_OPTIONS = %i[endpoint region http_continue_timeout http_idle_timeout http_open_timeout http_read_timeout http_proxy].freeze

attr_reader :table_cache

Expand Down Expand Up @@ -282,6 +282,11 @@ def batch_delete_item(options)
# @option options [Boolean] sync Wait for table status to be ACTIVE?
# @since 1.0.0
def create_table(table_name, key = :id, options = {})
unless Dynamoid.config.create_table_enabled
Dynamoid.logger.error "Table #{table_name} is not created as create_table_enabled is disabled"
return false
end

Dynamoid.logger.info "Creating #{table_name} table. This could take a while."
CreateTable.new(client, table_name, key, options).call
true
Expand Down
2 changes: 2 additions & 0 deletions lib/dynamoid/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ module Config
option :http_idle_timeout, default: nil # - default: 5
option :http_open_timeout, default: nil # - default: 15
option :http_read_timeout, default: nil # - default: 60
option :http_proxy, default: nil
option :create_table_enabled, default: true

# The default logger for Dynamoid: either the Rails logger or just stdout.
#
Expand Down
6 changes: 5 additions & 1 deletion spec/dynamoid/adapter_plugin/aws_sdk_v3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1242,11 +1242,15 @@ def dynamo_request(table_name, scan_hash = {}, select_opts = {})

before do
Dynamoid.configure.http_open_timeout = 30
Dynamoid.configure.http_proxy = 'http://proxy'
end

after { Dynamoid.configure.http_proxy = nil }

it 'not nil options entried' do
expect(subject.keys).to contain_exactly(:endpoint, :log_formatter, :log_level, :logger, :http_open_timeout)
expect(subject.keys).to contain_exactly(:endpoint, :log_formatter, :log_level, :logger, :http_open_timeout, :http_proxy)
expect(subject[:http_open_timeout]).to eq 30
expect(subject[:http_proxy]).to eq 'http://proxy'
end
end
end