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

Allow setting credentials as lambda #254

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion lib/temporal/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Configuration
Execution = Struct.new(:namespace, :task_queue, :timeouts, :headers, :search_attributes, keyword_init: true)

attr_reader :timeouts, :error_handlers
attr_accessor :connection_type, :converter, :use_error_serialization_v2, :host, :port, :credentials, :identity,
attr_writer :credentials
attr_accessor :connection_type, :converter, :use_error_serialization_v2, :host, :port, :identity,
:logger, :metrics_adapter, :namespace, :task_queue, :headers, :search_attributes, :header_propagators,
:payload_codec

Expand Down Expand Up @@ -100,6 +101,12 @@ def timeouts=(new_timeouts)
@timeouts = DEFAULT_TIMEOUTS.merge(new_timeouts)
end

def credentials
return @credentials.call if @credentials.is_a?(Proc)

@credentials
end

def for_connection
Connection.new(
type: connection_type,
Expand Down
16 changes: 15 additions & 1 deletion spec/unit/lib/temporal/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,19 @@ def inject!(_); end
subject.identity = new_identity
expect(subject.for_connection).to have_attributes(identity: new_identity)
end

it 'default credentials' do
expect(subject.for_connection).to have_attributes(credentials: :this_channel_is_insecure)
end

it 'override credentials' do
subject.credentials = :test_credentials
expect(subject.for_connection).to have_attributes(credentials: :test_credentials)
end

it 'override credentials with lambda' do
subject.credentials = -> { :test_credentials }
expect(subject.for_connection).to have_attributes(credentials: :test_credentials)
end
end
end
end