1
0
mirror of https://github.com/bumi/rack-lightning synced 2025-06-16 07:18:12 +00:00

Support easier config loading from variables

This makes it easier to load credentials and macaroon options from a
(environment) variable instead of a file.
This commit is contained in:
bumi 2018-11-21 21:00:10 +01:00
parent b8f6a848cc
commit 0b9fe9179d
2 changed files with 23 additions and 2 deletions

View File

@ -51,6 +51,25 @@ The middleware accepts the following configuration options:
* `address`: the address of the lnd gRPC service( default: localhost:10009)
* `credentials_path`: path to the tls.cert (default: ~/.lnd/tls.cert)
* `macaroon_path`: path to the macaroon path (default: ~/.lnd/data/chain/bitcoin/testnet/admin.macaroon)
* `credentials`: instead of configuring a `credentials_path` you can pass the content of the tls.cert directly
* `macaroon`: instead of configuring a `macaroon_path` you can pass the hex content of the macaroon directly
### How to pass credentials or macaroon data from a variable like a environment varibale?
The tls.cert and the macaroon config can be loaded from a variable:
```ruby
ENV['LND_CREDENTIALS'] = "the content of your tls.cert file"
ENV['LND_MACAROON'] = "the hex encoded content of your macaroon file"
# you can get the macaroon content like this:
# ::File.read(::File.expand_path("/path/to/admin.macaroon")).each_byte.map { |b| b.to_s(16).rjust(2,'0') }.join
Example = Rack::Builder.new {
use Rack::Lightning, { macaroon: ENV['LND_MACAROON'], credentials: ENV['LND_CREDENTIALS'] }
run Proc.new { |env| ['200', {'Content-Type' => 'text/html'}, ['get rack\'d']] }
}.to_app
```
## What is the Lightning Network?

View File

@ -14,8 +14,10 @@ module Rack
@options[:address] ||= 'localhost:10009'
@options[:timeout] ||= 5
@options[:credentials] ||= ::File.read(::File.expand_path(@options[:credentials_path] || "~/.lnd/tls.cert"))
macaroon_binary ||= ::File.read(::File.expand_path(@options[:macaroon_path] || "~/.lnd/data/chain/bitcoin/testnet/admin.macaroon"))
@options[:macaroon] = macaroon_binary.each_byte.map { |b| b.to_s(16).rjust(2,'0') }.join
@options[:macaroon] ||= begin
macaroon_binary = ::File.read(::File.expand_path(@options[:macaroon_path] || "~/.lnd/data/chain/bitcoin/testnet/admin.macaroon"))
macaroon_binary.each_byte.map { |b| b.to_s(16).rjust(2,'0') }.join
end
@lnd_client = Lnrpc::Lightning::Stub.new(@options[:address], GRPC::Core::ChannelCredentials.new(@options[:credentials]))
end