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

Update keyword arguments for Ruby 3.0 #2651

Merged
merged 1 commit into from
Feb 1, 2022
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
2 changes: 1 addition & 1 deletion app/controllers/v3/service_plan_visibility_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def update_visibility(opts={})
message = ServicePlanVisibilityUpdateMessage.new(hashed_params[:body])
bad_request!(message.errors.full_messages) unless message.valid?

updated_service_plan = V3::ServicePlanVisibilityUpdate.new.update(service_plan, message, opts)
updated_service_plan = V3::ServicePlanVisibilityUpdate.new.update(service_plan, message, **opts)
event_repository.record_service_plan_update_visibility_event(service_plan, message.audit_hash)
updated_service_plan
rescue V3::ServicePlanVisibilityUpdate::UnprocessableRequest => e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def cp_r_to_blobstore(*args)
error_handling { wrapped_client.cp_r_to_blobstore(*args) }
end

def download_from_blobstore(*args)
def download_from_blobstore(*args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get where these kwargs are coming from...

Copy link
Member Author

@sethboyles sethboyles Jan 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are used here:

def download_from_blobstore(source_key, destination_path, mode: nil)
FileUtils.mkdir_p(File.dirname(destination_path))
File.open(destination_path, 'wb') do |file|
(@cdn || files).get(partitioned_key(source_key)) do |*chunk|
file.write(chunk[0])
end
file.chmod(mode) if mode
end
end

Due to the multi-layer wrapping of these classes, each method needs to conform to the same signature

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See here for where they get wrapped:

def provide_fog(options, directory_key, root_dir)
cdn_uri = HashUtils.dig(options[:cdn], :uri)
cdn = CloudController::Blobstore::Cdn.make(cdn_uri)
client = FogClient.new(
connection_config: options.fetch(:fog_connection),
directory_key: directory_key,
cdn: cdn,
root_dir: root_dir,
min_size: options[:minimum_size],
max_size: options[:maximum_size],
storage_options: options[:fog_aws_storage_options]
)
logger = Steno.logger('cc.blobstore')
# work around https://github.com/fog/fog/issues/3137
# and Fog raising an EOFError SocketError intermittently
# and https://github.com/fog/fog-aws/issues/264
# and https://github.com/fog/fog-aws/issues/265
# and intermittent GCS blobstore download errors
errors = [Excon::Errors::BadRequest, Excon::Errors::SocketError, SystemCallError,
Excon::Errors::InternalServerError, Excon::Errors::ServiceUnavailable,
Google::Apis::ServerError, Google::Apis::TransmissionError
]
retryable_client = RetryableClient.new(client: client, errors: errors, logger: logger)
Client.new(ErrorHandlingClient.new(SafeDeleteClient.new(retryable_client, root_dir)))
end

error_handling { wrapped_client.download_from_blobstore(*args) }
end

Expand Down
6 changes: 3 additions & 3 deletions lib/cloud_controller/clock/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def start_inline_jobs
interval: @config.get(:diego_sync, :frequency_in_seconds),
timeout: @timeout_calculator.calculate(:diego_sync),
}
@clock.schedule_frequent_inline_job(clock_opts) do
@clock.schedule_frequent_inline_job(**clock_opts) do
Jobs::Diego::Sync.new
end
end
Expand All @@ -68,7 +68,7 @@ def start_frequent_jobs
name: job_config[:name],
interval: @config.get(job_config[:name].to_sym, :frequency_in_seconds),
}
@clock.schedule_frequent_worker_job(clock_opts) do
@clock.schedule_frequent_worker_job(**clock_opts) do
klass = job_config[:class]
klass.new(@config.get(job_config[:name].to_sym, :expiration_in_seconds))
end
Expand All @@ -83,7 +83,7 @@ def start_daily_jobs
priority: cleanup_config[:priority] || Clock::HIGH_PRIORITY
}

@clock.schedule_daily_job(clock_opts) do
@clock.schedule_daily_job(**clock_opts) do
klass = cleanup_config[:class]

if cleanup_config[:arg_from_config]
Expand Down
2 changes: 1 addition & 1 deletion lib/cloud_controller/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def create_seed_domains(config, system_org)
router_group_guid: find_routing_guid(domain),
internal: domain['internal']
}
SharedDomain.find_or_create(attrs.compact)
SharedDomain.find_or_create(**attrs.compact)
end

if CloudController::DomainDecorator.new(system_domain).has_sub_domain?(test_domains: domains.map { |domain_hash| domain_hash['name'] })
Expand Down
16 changes: 8 additions & 8 deletions lib/services/service_brokers/v2/response_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def parse_provision(path, response)
end

validator = CommonErrorValidator.new(validator)
validator.validate(unvalidated_response.to_hash)
validator.validate(**unvalidated_response.to_hash)
end

def parse_bind(path, response, opts={})
Expand Down Expand Up @@ -65,7 +65,7 @@ def parse_bind(path, response, opts={})
end

validator = CommonErrorValidator.new(validator)
validator.validate(unvalidated_response.to_hash)
validator.validate(**unvalidated_response.to_hash)
end

def parse_unbind(path, response)
Expand Down Expand Up @@ -93,7 +93,7 @@ def parse_unbind(path, response)
end

validator = CommonErrorValidator.new(validator)
validator.validate(unvalidated_response.to_hash)
validator.validate(**unvalidated_response.to_hash)
end

def parse_deprovision(path, response)
Expand Down Expand Up @@ -122,7 +122,7 @@ def parse_deprovision(path, response)
end

validator = CommonErrorValidator.new(validator)
validator.validate(unvalidated_response.to_hash)
validator.validate(**unvalidated_response.to_hash)
end

def parse_catalog(path, response)
Expand All @@ -140,7 +140,7 @@ def parse_catalog(path, response)
end

validator = CommonErrorValidator.new(validator)
validator.validate(unvalidated_response.to_hash)
validator.validate(**unvalidated_response.to_hash)
end

def parse_update(path, response)
Expand All @@ -167,7 +167,7 @@ def parse_update(path, response)
end

validator = CommonErrorValidator.new(validator)
validator.validate(unvalidated_response.to_hash)
validator.validate(**unvalidated_response.to_hash)
end

def parse_fetch_state(path, response)
Expand Down Expand Up @@ -195,7 +195,7 @@ def parse_fetch_state(path, response)
CommonErrorValidator.new(FailingValidator.new(Errors::ServiceBrokerBadResponse))
end

validator.validate(unvalidated_response.to_hash)
validator.validate(**unvalidated_response.to_hash)
end

def parse_fetch_parameters(path, response, schema)
Expand All @@ -211,7 +211,7 @@ def parse_fetch_parameters(path, response, schema)

validator = CommonErrorValidator.new(validator)

validator.validate(unvalidated_response.to_hash)
validator.validate(**unvalidated_response.to_hash)
end

def parse_fetch_instance_parameters(path, response)
Expand Down
4 changes: 2 additions & 2 deletions middleware/block_v3_only_roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
module CloudFoundry
module Middleware
class BlockV3OnlyRoles
def initialize(app, logger:)
def initialize(app, opts)
@app = app
@logger = logger
@logger = opts[:logger]
end

def call(env)
Expand Down
14 changes: 7 additions & 7 deletions middleware/rate_limiter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def create_new_request_count(user_guid, reset_interval_in_minutes)
class RateLimiter
include CloudFoundry::Middleware::ClientIp

def initialize(app, logger:, per_process_general_limit:, global_general_limit:, per_process_unauthenticated_limit:, global_unauthenticated_limit:, interval:)
def initialize(app, opts)
@app = app
@logger = logger
@per_process_general_limit = per_process_general_limit
@global_general_limit = global_general_limit
@per_process_unauthenticated_limit = per_process_unauthenticated_limit
@global_unauthenticated_limit = global_unauthenticated_limit
@interval = interval
@logger = opts[:logger]
@per_process_general_limit = opts[:per_process_general_limit]
@global_general_limit = opts[:global_general_limit]
@per_process_unauthenticated_limit = opts[:per_process_unauthenticated_limit]
@global_unauthenticated_limit = opts[:global_unauthenticated_limit]
@interval = opts[:interval]
@request_counter = RequestCounter.instance
end

Expand Down
4 changes: 2 additions & 2 deletions middleware/service_broker_rate_limiter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def release(user_guid)
end

class ServiceBrokerRateLimiter
def initialize(app, logger:)
def initialize(app, opts)
@app = app
@logger = logger
@logger = opts[:logger]
@request_counter = ServiceBrokerRequestCounter.instance
end

Expand Down
2 changes: 1 addition & 1 deletion spec/api/documentation/buildpack_cache_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
end

before do
TestConfig.override(blobstore_config)
TestConfig.override(**blobstore_config)
end

after do
Expand Down
4 changes: 2 additions & 2 deletions spec/performance/packages_controller_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
let(:n) { 10 }

before do
TestConfig.override({
TestConfig.override(
db: {
log_level: 'debug',
}
# logging.level: 'debug2'
})
)
allow_user_read_access_for(user, spaces: user_spaces)
n.times do |i|
app = VCAP::CloudController::AppModel.make(space: user_spaces.sample, guid: "app-guid-#{i}")
Expand Down
2 changes: 1 addition & 1 deletion spec/request/domains_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@

context 'when the domain is in the list of reserved private domains' do
before do
TestConfig.override({ reserved_private_domains: File.join(Paths::FIXTURES, 'config/reserved_private_domains.dat') })
TestConfig.override(reserved_private_domains: File.join(Paths::FIXTURES, 'config/reserved_private_domains.dat'))
end

it 'returns a 422 with a error message about reserved domains' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
end

before do
TestConfig.override(staging_config)
TestConfig.override(**staging_config)
allow(VCAP::CloudController::BlobDispatcher).to receive(:new).and_return(blob_dispatcher)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/request/packages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@
before do
space.organization.add_user(user)
space.add_developer(user)
TestConfig.override(test_config_overrides)
TestConfig.override(**test_config_overrides)
end

shared_examples :upload_bits_successfully do
Expand Down
6 changes: 3 additions & 3 deletions spec/request/service_brokers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ def expect_empty_list(user_headers)
context 'when job succeeds with warnings' do
context 'when warning is a UAA problem' do
let(:broker) do
TestConfig.override({ uaa_client_name: nil, uaa_client_secret: nil })
TestConfig.override(uaa_client_name: nil, uaa_client_secret: nil)
create_broker_successfully(global_broker_request_body, with: admin_headers, execute_all_jobs: true)
end

Expand All @@ -729,7 +729,7 @@ def expect_empty_list(user_headers)

context 'when warning is a catalog problem (deactivated plan, but there is a service instance)' do
let!(:broker) do
TestConfig.override({})
TestConfig.override
create_broker_successfully(global_broker_request_body, with: admin_headers, execute_all_jobs: true)
end

Expand Down Expand Up @@ -1138,7 +1138,7 @@ def expect_empty_list(user_headers)
context 'when job succeeds with warnings' do
context 'when warning is a UAA problem' do
before do
TestConfig.override({ uaa_client_name: nil, uaa_client_secret: nil })
TestConfig.override(uaa_client_name: nil, uaa_client_secret: nil)
create_broker_successfully(global_broker_request_body, with: admin_headers)
execute_all_jobs(expected_successes: 1, expected_failures: 0)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/request_spec_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ def expect_filtered_resources(endpoint, filter, list)
it 'returns the correct response status and resources' do
email = Sham.email
user_name = Sham.name
headers = set_user_with_header_as_role({
headers = set_user_with_header_as_role(
role: role,
org: org,
space: space,
user: user,
scopes: expected_codes_and_responses[role][:scopes],
user_name: user_name,
email: email,
})
)

api_call.call(headers)

Expand Down
2 changes: 1 addition & 1 deletion spec/support/bootstrap/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def override(**overrides)
end

def reset
override({})
override
end

def config
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared_examples/controllers/resource_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

before do
@resource_pool = VCAP::CloudController::ResourcePool.new(
VCAP::CloudController::Config.new(resource_pool: resource_pool_config)
VCAP::CloudController::Config.new({ resource_pool: resource_pool_config })
)
allow(VCAP::CloudController::ResourcePool).to receive(:instance).and_return(@resource_pool)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/support/shared_examples/jobs/create_binding_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
context 'asynchronous response' do
context 'computes the maximum duration' do
before do
TestConfig.override({
TestConfig.override(
broker_client_max_async_poll_duration_minutes: 90009
})
)
subject.perform
end

Expand Down Expand Up @@ -141,7 +141,7 @@
context 'the maximum duration' do
it 'recomputes the value' do
subject.maximum_duration_seconds = 90009
TestConfig.override({ broker_client_max_async_poll_duration_minutes: 8088 })
TestConfig.override(broker_client_max_async_poll_duration_minutes: 8088)
subject.perform
expect(subject.maximum_duration_seconds).to eq(8088.minutes)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/support/shared_examples/jobs/delete_binding_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@

context 'computes the maximum duration' do
before do
TestConfig.override({
TestConfig.override(
broker_client_max_async_poll_duration_minutes: 90009
})
)
subject.perform
end

Expand Down Expand Up @@ -130,7 +130,7 @@
context 'the maximum duration' do
it 'recomputes the value' do
subject.maximum_duration_seconds = 90009
TestConfig.override({ broker_client_max_async_poll_duration_minutes: 8088 })
TestConfig.override(broker_client_max_async_poll_duration_minutes: 8088)
subject.perform
expect(subject.maximum_duration_seconds).to eq(8088.minutes)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/actions/task_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module VCAP::CloudController
RSpec.describe TaskCreate do
subject(:task_create_action) { TaskCreate.new(config) }
let(:config) do
Config.new(
Config.new({
maximum_app_disk_in_mb: 4096,
default_app_memory: 1024,
default_app_disk_in_mb: 1024
)
})
end

describe '#create' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module VCAP::CloudController

before do
Fog.unmock!
TestConfig.override(staging_config)
TestConfig.override(**staging_config)
end
after { FileUtils.rm_rf(workspace) }

Expand Down Expand Up @@ -152,7 +152,7 @@ def upload_droplet

before do
Fog.unmock!
TestConfig.override(staging_config)
TestConfig.override(**staging_config)
end
after { FileUtils.rm_rf(workspace) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module VCAP::CloudController
let(:one_hour_in_nanoseconds) { (1.hour.to_i * 1e9).to_i }

before do
TestConfig.override({ kubernetes: nil })
TestConfig.override(kubernetes: nil)

allow(VCAP::CloudController::Metrics::StatsdUpdater).to receive(:new).and_return(statsd_updater)
end
Expand Down Expand Up @@ -190,7 +190,7 @@ module VCAP::CloudController
describe 'authentication' do
context 'when running in Kubernetes' do
before do
TestConfig.override({ kubernetes: { host_url: 'example.com' } })
TestConfig.override(kubernetes: { host_url: 'example.com' })
end

context 'when missing authentication' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module VCAP::CloudController
describe 'PUT /v2/app/:id/bits' do
before do
TestConfig.override(
config_override.merge(
**config_override.merge(
directories: { tmpdir: File.dirname(valid_zip.path) },
kubernetes: {}
)
Expand Down
Loading