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:
parent
b8f6a848cc
commit
0b9fe9179d
19
README.md
19
README.md
@ -51,6 +51,25 @@ The middleware accepts the following configuration options:
|
|||||||
* `address`: the address of the lnd gRPC service( default: localhost:10009)
|
* `address`: the address of the lnd gRPC service( default: localhost:10009)
|
||||||
* `credentials_path`: path to the tls.cert (default: ~/.lnd/tls.cert)
|
* `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)
|
* `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?
|
## What is the Lightning Network?
|
||||||
|
|
||||||
|
@ -14,8 +14,10 @@ module Rack
|
|||||||
@options[:address] ||= 'localhost:10009'
|
@options[:address] ||= 'localhost:10009'
|
||||||
@options[:timeout] ||= 5
|
@options[:timeout] ||= 5
|
||||||
@options[:credentials] ||= ::File.read(::File.expand_path(@options[:credentials_path] || "~/.lnd/tls.cert"))
|
@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] ||= begin
|
||||||
@options[:macaroon] = macaroon_binary.each_byte.map { |b| b.to_s(16).rjust(2,'0') }.join
|
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]))
|
@lnd_client = Lnrpc::Lightning::Stub.new(@options[:address], GRPC::Core::ChannelCredentials.new(@options[:credentials]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user