lusnoc 1.0.1.134629 → 1.0.2.417513

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d41d26d751d0c33f77cfd692c36d78327f16ac6ca23cf07f4688192038e74f42
4
- data.tar.gz: 669c67d00e35b4853e855940bf1f940e753c5dd53c2df863e2c235227bb7f1e9
3
+ metadata.gz: 74de0bd4a421afdc2d99137d88f32ff846f577be0f279ab670bd82206c9ed15c
4
+ data.tar.gz: 1ed7ae2763fc6d09e297a54d248876221244e71c555a9cf61d8bff64aaebfea0
5
5
  SHA512:
6
- metadata.gz: 6c8eb0b142f5dd30c3873c6e3785fdb5ed59ce4c85d0ffd99e2c22e08d328839a83c883bfdc82df9ce1eeba9305ab144835a217d48d032ad34c82ed12f17a350
7
- data.tar.gz: af4afbf1c9104bef1366e150527239ee0e029df5ea0f60cac2df39ccc6318702b443b31c3800d075a0f41552b924e82bc09d75712021a0eba3a1a4376af0b1e1
6
+ metadata.gz: f2971db111ccc87498b571096567f7dbe5608c9ea944d418e065c3780ff54122e0a75d9a856b48ac2a81c901676d729804d7f4809e603698afab12849beba4cf
7
+ data.tar.gz: a8760b8dbd7c809f98b03f72bfcf205da57b8139df2c3a627cedc4c3433e6188ba650e9e2f43f75ed4adc1f4f4bf2206bbd13aa1d4c0f18d65d3485e2a3d96bf
@@ -6,10 +6,20 @@ module Lusnoc
6
6
 
7
7
  attr_accessor :url, :acl_token, :logger, :http_timeout
8
8
 
9
+ # Get the most appropriate consul agent value from env
10
+ # Parse the environment variable `CONSUL_HTTP_ADDR` and prefixes it with http:// if needed
11
+ # Return default http://localhost:8500 if not found
12
+ def self.parse_consul_addr
13
+ ret = ENV['CONSUL_HTTP_ADDR'] || 'http://localhost:8500'
14
+ ret = "http://#{ret}" unless ret.start_with?('http://', 'https://')
15
+ ret
16
+ end
17
+
18
+
9
19
  # Override defaults for configuration
10
20
  # @param url [String] consul's connection URL
11
21
  # @param acl_token [String] a connection token used when making requests to consul
12
- def initialize(url = 'http://localhost:8500', acl_token = nil)
22
+ def initialize(url = Configuration.parse_consul_addr, acl_token = ENV['CONSUL_HTTP_TOKEN'])
13
23
  @url = url
14
24
  @acl_token = acl_token
15
25
  @logger = Logger.new(STDOUT, level: Logger::INFO, progname: 'Lusnoc')
@@ -1,6 +1,6 @@
1
1
  module Lusnoc
2
2
 
3
- VERSION = '1.0.1'.freeze
3
+ VERSION = '1.0.2'.freeze
4
4
 
5
5
  end
6
6
 
data/lib/lusnoc.rb CHANGED
@@ -26,10 +26,9 @@ module Lusnoc
26
26
 
27
27
  def http_get(url, timeout: Lusnoc.configuration.http_timeout)
28
28
  uri = URI(url)
29
-
30
29
  with_http(uri, timeout: timeout) do |http|
31
30
  req = Net::HTTP::Get.new(uri)
32
-
31
+ req["X-Consul-Token"] = Lusnoc.configuration.acl_token if Lusnoc.configuration.acl_token&.present?
33
32
  # configure http and request before send
34
33
  yield(http, req) if block_given?
35
34
  http.request(req)
@@ -39,13 +38,12 @@ module Lusnoc
39
38
  def http_put(url, value = nil, timeout: Lusnoc.configuration.http_timeout)
40
39
  uri = URI(url)
41
40
  data = value.is_a?(String) ? value : JSON.generate(value) unless value.nil?
42
-
43
41
  with_http(uri, timeout: timeout) do |http|
44
42
  req = Net::HTTP::Put.new(uri).tap do |r|
45
43
  r.body = data
46
44
  r['Content-Type'] = 'application/json'
47
45
  end
48
-
46
+ req["X-Consul-Token"] = Lusnoc.configuration.acl_token if Lusnoc.configuration.acl_token&.present?
49
47
  # configure http and request before send
50
48
  yield(http, req) if block_given?
51
49
  http.request(req)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lusnoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1.134629
4
+ version: 1.0.2.417513
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samoilenko Yuri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-03 00:00:00.000000000 Z
11
+ date: 2026-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler