Skip to content

Commit

Permalink
Merge pull request #1 from iamAzeem/feature-tls-support
Browse files Browse the repository at this point in the history
Added TLS support.
  • Loading branch information
iamazeem committed Jun 11, 2020
2 parents 917fb18 + 84d3639 commit 1520ab7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* **Incoming Message Format**: Support for binary or JSON format (`Content-Type`: `application/octet-stream` or `application/json`)
* **Outgoing Message Format**: Support for binary or JSON format
* **Message Types**: Single or Batch
* **TLS Support**: Use `<transport tls> ... </transport>` section in configuration and `https://` URL protocol prefix. See this [example](https://docs.fluentd.org/plugin-helper-overview/api-plugin-helper-server#configuration-example) for more details.

## Installation

Expand Down Expand Up @@ -44,6 +45,13 @@ $ bundle
* Default value: `binary`.
* **tag** (string) (required): The tag for the event.

### \<transport\> section (optional) (single)

* **protocol** (enum) (optional):
* Available values: tcp, tls
* Default value: `tcp`.
* See [example](https://docs.fluentd.org/plugin-helper-overview/api-plugin-helper-server#configuration-example).

### Example

```
Expand Down
2 changes: 1 addition & 1 deletion fluent-plugin-protobuf-http.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
spec.email = ['[email protected]']

spec.summary = 'fluentd HTTP Input Plugin for Protocol Buffers'
spec.description = 'fluentd HTTP Input Plugin for Protocol Buffers with Single and Batch Messages Support]'
spec.description = 'fluentd HTTP Input Plugin for Protocol Buffers with Single and Batch Messages Support'
spec.homepage = 'https://github.com/iamAzeem/fluent-plugin-protobuf-http'
spec.license = 'Apache-2.0'

Expand Down
17 changes: 15 additions & 2 deletions lib/fluent/plugin/in_protobuf_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class ProtobufHttpInput < Fluent::Plugin::Input
desc 'The tag for the event.'
config_param :tag, :string

config_section :transport, required: false, multi: false, init: true, param_name: :transport_config do
config_argument :protocol, :enum, list: %i[tcp tls], default: :tcp
end

def initialize
super

Expand Down Expand Up @@ -136,9 +140,18 @@ def start
compile_protos
populate_msgclass_lookup

log.info("Starting protobuf server [#{@bind}:#{@port}]...")
# TLS check
proto = :tcp
tls_opts = nil
if @transport_config && @transport_config.protocol == :tls
proto = :tls
tls_opts = @transport_config.to_h
end

log.info("Starting protobuf #{proto == :tcp ? 'HTTP' : 'HTTPS'} server [#{@bind}:#{@port}]...")
log.debug("TLS configuration:\n#{tls_opts}") if tls_opts

http_server_create_http_server(:protobuf_server, addr: @bind, port: @port, logger: log) do |server|
http_server_create_http_server(:protobuf_server, addr: @bind, port: @port, logger: log, proto: proto, tls_opts: tls_opts) do |server|
server.post("/#{tag}") do |req|
peeraddr = "#{req.peeraddr[2]}:#{req.peeraddr[1]}".freeze # ip:port
serialized_msg = req.body.freeze
Expand Down

0 comments on commit 1520ab7

Please sign in to comment.