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

Tristan instacart/add basic ssl support #73

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Temporal.configure do |config|
config.port = 7233
config.namespace = 'ruby-samples'
config.task_queue = 'hello-world'
config.channel_creds = :this_channel_is_insecure
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Ruby folks are ok with full names, let's probably call this just credentials unless you think it might conflict with some other config we'd want to add in the future

end
```

Expand Down Expand Up @@ -103,6 +104,24 @@ activities. To set it up locally, download and boot the Docker Compose file from
> docker-compose up
```

### Connecting via SSL

In many production deployments you will end up connecting to your Temporal Services via SSL. In which
case you must read the public cert of the CA that issued your Temporal server's SSL cert and create
an instance of GRPC Channel Credentials.

Configure your Temporal connection:

```ruby
Temporal.configure do |config|
config.host = 'temporal-prod.mycompany.com'
config.port = 7233
config.namespace = 'ruby-samples'
config.task_queue = 'hello-world'
config.channel_creds = GRPC::Core::ChannelCredentials.new(CA_CERT)
end
```

## Workflows

A workflow is defined using pure Ruby code, however it should contain only a high-level
Expand Down
6 changes: 5 additions & 1 deletion lib/temporal/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def self.generate
thread_id = Thread.current.object_id
identity = "#{thread_id}@#{hostname}"

client_class.new(host, port, identity)
if Temporal.configuration.client_type == :grpc
client_class.new(host, port, identity, Temporal.configuration.grpc_ssl_config)
else
client_class.new(host, port, identity)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a test case for this?

end
end
end
7 changes: 4 additions & 3 deletions lib/temporal/client/grpc_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ class GRPCClient
close: Temporal::Api::Enums::V1::HistoryEventFilterType::HISTORY_EVENT_FILTER_TYPE_CLOSE_EVENT,
}.freeze

def initialize(host, port, identity)
def initialize(host, port, identity, grpc_ssl_config)
@url = "#{host}:#{port}"
@identity = identity
@channel_creds = grpc_ssl_config
@poll = true
@poll_mutex = Mutex.new
@poll_request = nil
Expand Down Expand Up @@ -388,12 +389,12 @@ def cancel_polling_request

private

attr_reader :url, :identity, :poll_mutex, :poll_request
attr_reader :url, :channel_creds, :identity, :poll_mutex, :poll_request

def client
@client ||= Temporal::Api::WorkflowService::V1::WorkflowService::Stub.new(
url,
:this_channel_is_insecure,
channel_creds,
Copy link
Contributor

Choose a reason for hiding this comment

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

And this?

timeout: 60
)
end
Expand Down
11 changes: 10 additions & 1 deletion lib/temporal/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module Temporal
class Configuration
attr_reader :timeouts, :error_handlers
attr_accessor :client_type, :host, :port, :logger, :metrics_adapter, :namespace, :task_queue, :headers
attr_accessor :channel_creds, :client_type, :host, :port, :logger, :metrics_adapter, :namespace, :task_queue, :headers

# We want an infinite execution timeout for cron schedules and other perpetual workflows.
# We choose an 10-year execution timeout because that's the maximum the cassandra DB supports,
Expand Down Expand Up @@ -32,6 +32,7 @@ def initialize
@namespace = DEFAULT_NAMESPACE
@task_queue = DEFAULT_TASK_QUEUE
@headers = DEFAULT_HEADERS
@channel_creds = nil
@error_handlers = []
end

Expand All @@ -50,5 +51,13 @@ def task_list=(name)
def timeouts=(new_timeouts)
@timeouts = DEFAULT_TIMEOUTS.merge(new_timeouts)
end

def grpc_ssl_config
if @channel_creds.nil?
:this_channel_is_insecure
Copy link
Contributor

Choose a reason for hiding this comment

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

also would be great to have a spec for this and also put the value in a constant

else
@channel_creds
end
end
end
end
2 changes: 1 addition & 1 deletion spec/unit/lib/temporal/grpc_client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe Temporal::Client::GRPCClient do
subject { Temporal::Client::GRPCClient.new(nil, nil, nil) }
subject { Temporal::Client::GRPCClient.new(nil, nil, nil, :this_channel_is_insecure) }
let(:grpc_stub) { double('grpc stub') }
let(:namespace) { 'test-namespace' }
let(:workflow_id) { SecureRandom.uuid }
Expand Down