Skip to content

Commit

Permalink
Don't pass config params through job
Browse files Browse the repository at this point in the history
  This prevents the management token from getting logged
  • Loading branch information
gburgett committed Mar 13, 2019
1 parent 6f96e37 commit 2caa4ea
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
19 changes: 18 additions & 1 deletion wcc-contentful/app/jobs/wcc/contentful/webhook_enable_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class WebhookEnableJob < ActiveJob::Base
self.queue_adapter = :async
queue_as :default

def perform(args)
def perform(args = {})
args = default_configuration.merge!(args)

client = WCC::Contentful::SimpleClient::Management.new(
args
)
Expand Down Expand Up @@ -43,6 +45,21 @@ def enable_webhook(client, app_url:, webhook_username: nil, webhook_password: ni

private

def default_configuration
return {} unless config = WCC::Contentful&.configuration

{
management_token: config.management_token,
app_url: config.app_url,
space: config.space,
environment: config.environment,
default_locale: config.default_locale,
adapter: config.http_adapter,
webhook_username: config.webhook_username,
webhook_password: config.webhook_password
}
end

def webhook_filters
filters = []

Expand Down
13 changes: 1 addition & 12 deletions wcc-contentful/lib/wcc/contentful/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,7 @@ class Engine < ::Rails::Engine
next unless config&.management_token.present?
next unless config.app_url.present?

if Rails.env.production?
WebhookEnableJob.set(wait: 10.seconds).perform_later(
management_token: config.management_token,
app_url: config.app_url,
space: config.space,
environment: config.environment,
default_locale: config.default_locale,
adapter: config.http_adapter,
webhook_username: config.webhook_username,
webhook_password: config.webhook_password
)
end
WebhookEnableJob.set(wait: 10.seconds).perform_later if Rails.env.production?
end

config.generators do |g|
Expand Down
29 changes: 29 additions & 0 deletions wcc-contentful/spec/jobs/wcc/contentful/webhook_enable_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,34 @@
management_token: 'testtoken'
})
end

it 'gets default client params from WCC::Contentful.configuration' do
defaults = {
management_token: 'testtoken',
app_url: 'testurl',
space: 'testspace',
environment: 'testenv',
default_locale: 'testlocale',
http_adapter: :http,
webhook_username: 'testwebhookusername',
webhook_password: 'testwebhookpassword'
}

allow(WCC::Contentful).to receive(:configuration)
.and_return(double(**defaults))

expect(job).to receive(:enable_webhook) do |client|
expect(client).to be_a WCC::Contentful::SimpleClient::Management

options = client.instance_variable_get('@options')
expect(options.except(:adapter)).to eq(defaults.except(:space, :management_token, :http_adapter))
expect(client.space).to eq('testspace')
expect(client.instance_variable_get('@access_token')).to eq('testtoken')
expect(options[:adapter]).to eq(:http)
end

# act
job.perform
end
end
end

0 comments on commit 2caa4ea

Please sign in to comment.