briefbag 1.0.4 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +3 -15
- data/README.md +6 -22
- data/briefbag.gemspec +7 -6
- data/lib/briefbag/configuration.rb +19 -11
- data/lib/briefbag/diplomat.rb +9 -3
- data/lib/briefbag/version.rb +1 -1
- data/lib/tasks/settings.rake +12 -54
- metadata +32 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1be8501bb6bbcee9ee98221feb919745d30cc8319a4d1d8f4f93040659cf2e3a
|
4
|
+
data.tar.gz: 55809c1db40392f2e6836f1953ab98ae9a9940501238ea3bca8dc88b3c06c791
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db8c18c6927fad881e74965149dc488efdc1928690cb529f691ff7bb9591b1f3ccf5eb0fa4a43582e7b2b208cbd2bfaeadd4c5269aa31113b65c0ca8d102cfb2
|
7
|
+
data.tar.gz: 05f06c368ae3b839f8274dc374b867d502365a7513651ae122ae0ffc9c18f219122237134d755406599550b886c7f39095b4da914683ab410eabfcd581c1abec
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.1.2@briefbag
|
data/CHANGELOG.md
CHANGED
@@ -1,21 +1,9 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## 0.0.1 - 2023-
|
3
|
+
## 0.0.1 - 2023-01-22
|
4
4
|
|
5
5
|
* Briefbag was born
|
6
6
|
|
7
|
-
##
|
7
|
+
## 2.0.1 - 2023-01-22
|
8
8
|
|
9
|
-
*
|
10
|
-
|
11
|
-
## 1.0.2 - 2023-03-16
|
12
|
-
|
13
|
-
* Refactoring: delete anyway config, using yml from ruby, change params and upd docs, implementation rake tasks
|
14
|
-
|
15
|
-
## 1.0.3 - 2023-03-16
|
16
|
-
|
17
|
-
* Fix bugs byebug
|
18
|
-
|
19
|
-
## 1.0.4 - 2023-11-13
|
20
|
-
|
21
|
-
* Add function copy configs add task copy config
|
9
|
+
* update gem Briefbag to new ruby 3.1.2
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Briefbag
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/briefbag.svg)](https://badge.fury.io/rb/
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/briefbag.svg)](https://badge.fury.io/rb/dadatas)
|
4
4
|
[![Gem](https://img.shields.io/gem/dt/briefbag.svg)](https://rubygems.org/gems/briefbag)
|
5
5
|
|
6
6
|
|
@@ -27,9 +27,11 @@ And what if you need to share the configuration file with colleagues, or use thi
|
|
27
27
|
Consul comes to the rescue. Thanks to him, you can act config and undress in different stands.
|
28
28
|
Generation `.yml` file there are 2 rake tasks: rake
|
29
29
|
|
30
|
-
|
30
|
+
- **rake settings:consul2yml** - Get key/value variables from consul to `.yml` file
|
31
|
+
- **rake settings:template2yml** - Generate basic `.yml` for your app. Based on it, you can fill it with any values
|
31
32
|
|
32
33
|
|
34
|
+
Need add to you Rakefile
|
33
35
|
```ruby
|
34
36
|
|
35
37
|
require 'briefbag'
|
@@ -38,24 +40,6 @@ spec = Gem::Specification.find_by_name 'briefbag'
|
|
38
40
|
load "#{spec.gem_dir}/lib/tasks/settings.rake"
|
39
41
|
```
|
40
42
|
|
41
|
-
- **rake settings:consul2yml** - Get key/value variables from consul to `.yml` file
|
42
|
-
- **rake settings:transfer_config** - Transfer all collection configs in new consul folder
|
43
|
-
|
44
|
-
```shell
|
45
|
-
#rake settings:consul2yml[consul_host,consul_port,consul_token, my_project, environment,config_folder]
|
46
|
-
rake settings:consul2yml['127.0.0.1',8500,'consul_token','my_project','development',"config/configuration.yml"]
|
47
|
-
```
|
48
|
-
|
49
|
-
```shell
|
50
|
-
#rake settings:consul2yml[consul_host,consul_port,consul_token, my_project, from_path, to_path]
|
51
|
-
rake settings:transfer_config['127.0.0.1',8500,'consul_token','my_project','from','to']
|
52
|
-
```
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
43
|
#### Notifications:
|
60
44
|
If you use `.yml` .You will see:
|
61
45
|
> NOTICE! Your app using configs from yml file
|
@@ -91,7 +75,7 @@ Or install it yourself as:
|
|
91
75
|
- **consul_token(string)** - *(optional)* If you use ACL Token.
|
92
76
|
- **consul_folder(string)** *(required)* Name config folder in consul.
|
93
77
|
- **environment(string)** - *(optional)* Default value ${development}. Environment in consul.
|
94
|
-
- **
|
78
|
+
- **config_name(string)** - *(optional)* Default value ${application}. Config name in your application for example path to yml file: 'config/application.yml' you need use name 'application'.
|
95
79
|
|
96
80
|
```ruby
|
97
81
|
require 'briefbag'
|
@@ -102,7 +86,7 @@ params_config = {
|
|
102
86
|
consul_token: '233b604b-b92e-48c8-a253-5f11514e4b50',
|
103
87
|
consul_folder: 'briefbag',
|
104
88
|
environment: 'test',
|
105
|
-
|
89
|
+
config_name: 'some_config'
|
106
90
|
}
|
107
91
|
configs = Briefbag::Configuration.new(params_config).call
|
108
92
|
=> #<struct database=#<struct adapter="postgresql", host="localhost", port=5432, database="tets_dev", username="postgres", password=""...
|
data/briefbag.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.summary = 'Briefbag manage your config'
|
14
14
|
spec.homepage = 'https://github.com/MichaelHitchens/briefbag'
|
15
15
|
spec.license = 'MIT'
|
16
|
-
spec.required_ruby_version = '>=
|
16
|
+
spec.required_ruby_version = '>= 3.1.2'
|
17
17
|
|
18
18
|
spec.metadata = {
|
19
19
|
'homepage_uri' => spec.homepage,
|
@@ -33,15 +33,16 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.require_paths = ['lib']
|
34
34
|
|
35
35
|
# Requires Ruby faraday to http request
|
36
|
-
spec.add_dependency '
|
36
|
+
spec.add_dependency 'anyway_config', '~> 2.3.1'
|
37
|
+
spec.add_dependency 'diplomat', '>=2.6.4'
|
37
38
|
spec.add_dependency 'hash_to_struct', '>=1.0.0'
|
38
|
-
spec.add_dependency 'rainbow', '
|
39
|
-
spec.add_dependency 'rake', '
|
39
|
+
spec.add_dependency 'rainbow', '~> 3.1.1'
|
40
|
+
spec.add_dependency 'rake', '~> 13.0.6'
|
40
41
|
|
41
42
|
spec.add_development_dependency 'bundler', '~> 2.3.26'
|
42
43
|
spec.add_development_dependency 'byebug', '~> 11.1.3'
|
43
|
-
spec.add_development_dependency 'faker', '~>
|
44
|
+
spec.add_development_dependency 'faker', '~> 3.1.1'
|
44
45
|
spec.add_development_dependency 'rake', '~> 13.0.6'
|
45
46
|
spec.add_development_dependency 'rspec', '~> 3.12.0'
|
46
|
-
spec.add_development_dependency 'rubocop', '~> 1.
|
47
|
+
spec.add_development_dependency 'rubocop', '~> 1.44.1'
|
47
48
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'briefbag/diplomat'
|
4
|
+
require 'anyway_config'
|
4
5
|
require 'rainbow'
|
5
6
|
require 'hash_to_struct'
|
6
|
-
require 'yaml'
|
7
7
|
|
8
8
|
module Briefbag
|
9
9
|
class Configuration
|
10
|
-
attr_reader :config, :
|
10
|
+
attr_reader :config, :config_name
|
11
11
|
|
12
12
|
MESSAGES = {
|
13
13
|
notice_yml: 'NOTICE! Your app is using configs from yml file',
|
@@ -20,17 +20,16 @@ module Briefbag
|
|
20
20
|
}.freeze
|
21
21
|
|
22
22
|
def initialize(config)
|
23
|
-
@
|
23
|
+
@config_name = config[:config_name] || 'application'
|
24
24
|
@config = config
|
25
25
|
end
|
26
26
|
|
27
27
|
def call
|
28
|
-
return file_config if file_exist?
|
29
|
-
|
30
28
|
diplomat = Briefbag::Diplomat.new(config).call
|
31
|
-
return
|
29
|
+
return file_config if file_exist? && config[:environment].eql?('development')
|
32
30
|
|
33
|
-
diplomat_config(diplomat[:consul_data])
|
31
|
+
return diplomat_config(diplomat[:consul_data]) if diplomat.success?
|
32
|
+
return Briefbag.aborting_message(MESSAGES[:error_consul]) unless diplomat.success?
|
34
33
|
rescue StandardError
|
35
34
|
return Briefbag.aborting_message(MESSAGES[:error_yml]) unless file_exist?
|
36
35
|
|
@@ -44,15 +43,24 @@ module Briefbag
|
|
44
43
|
|
45
44
|
def file_config
|
46
45
|
Briefbag.warning_message(MESSAGES[:notice_yml])
|
47
|
-
|
46
|
+
Anyway::Settings.default_config_path = 'config'
|
47
|
+
data = Anyway::Config.for(config_name.to_sym, env_prefix: config[:environment])
|
48
48
|
|
49
|
-
return HashToStruct.struct(data.deep_symbolize_keys)
|
49
|
+
return HashToStruct.struct(data.deep_symbolize_keys) if defined?(Rails)
|
50
50
|
|
51
|
-
HashToStruct.struct(symbolize_all_keys(data))
|
51
|
+
HashToStruct.struct(symbolize_all_keys(data))
|
52
52
|
end
|
53
53
|
|
54
54
|
def file_exist?
|
55
|
-
@file_exist ||= File.exist?(
|
55
|
+
@file_exist ||= File.exist?(yaml_file)
|
56
|
+
end
|
57
|
+
|
58
|
+
def yaml_file
|
59
|
+
@yaml_file ||= "./config/#{config_name}.yml"
|
60
|
+
end
|
61
|
+
|
62
|
+
def local_keys
|
63
|
+
@local_keys ||= YAML.safe_load(File.read(yaml_file))[environment].keys
|
56
64
|
end
|
57
65
|
|
58
66
|
def symbolize_all_keys(h) # rubocop:disable Naming/MethodParameterName
|
data/lib/briefbag/diplomat.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'diplomat'
|
4
4
|
require 'socket'
|
5
|
-
require 'yaml'
|
6
5
|
|
7
6
|
module Briefbag
|
8
7
|
class Diplomat
|
@@ -23,6 +22,7 @@ module Briefbag
|
|
23
22
|
|
24
23
|
def configuration
|
25
24
|
::Diplomat.configure do |conf|
|
25
|
+
# Set up a custom Consul URL
|
26
26
|
conf.url = url_build
|
27
27
|
break if config[:consul_token].nil?
|
28
28
|
|
@@ -39,9 +39,15 @@ module Briefbag
|
|
39
39
|
::Diplomat::Kv.get_all(consul_folder)
|
40
40
|
end
|
41
41
|
|
42
|
+
def json_parsing(value)
|
43
|
+
return JSON.parse(value.force_encoding('UTF-8')) if value.encoding.eql? 'ASCII-8BIT'
|
44
|
+
|
45
|
+
JSON.parse(value)
|
46
|
+
end
|
47
|
+
|
42
48
|
def mapping_hash
|
43
49
|
consul_data.each_with_object({}) do |item, hash|
|
44
|
-
hash[item[:key].split('/').last.to_sym] =
|
50
|
+
hash[item[:key].split('/').last.to_sym] = json_parsing(item[:value])
|
45
51
|
end
|
46
52
|
end
|
47
53
|
|
@@ -61,7 +67,7 @@ module Briefbag
|
|
61
67
|
end
|
62
68
|
|
63
69
|
def url_build
|
64
|
-
Object.const_get("URI::HTTP#{port.eql?(443) ? 'S' : ''}").build(host
|
70
|
+
Object.const_get("URI::HTTP#{port.eql?(443) ? 'S' : ''}").build(host:, port:)
|
65
71
|
end
|
66
72
|
|
67
73
|
def check_consul
|
data/lib/briefbag/version.rb
CHANGED
data/lib/tasks/settings.rake
CHANGED
@@ -1,65 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'briefbag'
|
4
|
-
require 'rails'
|
5
|
-
|
6
3
|
namespace :settings do
|
7
4
|
desc 'create application.yml from consul data'
|
8
|
-
task :consul2yml,
|
9
|
-
[:consul_host, :consul_port, :consul_token, :consul_folder, :environment, :config_path] do |_t, args|
|
10
|
-
diplomat_config = Briefbag::Diplomat.new(
|
11
|
-
consul_host: args[:consul_host],
|
12
|
-
consul_port: args[:consul_port].to_i,
|
13
|
-
consul_token: args[:consul_token],
|
14
|
-
consul_folder: args[:consul_folder],
|
15
|
-
environment: args[:environment]
|
16
|
-
)
|
17
|
-
|
18
|
-
data = diplomat_config.call
|
19
|
-
|
20
|
-
return warn Rainbow('Consul is down').red unless data.success?
|
21
|
-
|
22
|
-
yml_file = "#{Rails.root}/#{args[:config_path]}"
|
23
|
-
if Rails.env.development? && !File.exist?(yml_file)
|
24
|
-
configs = { "#{args[:environment]}": data.consul_data.deep_symbolize_keys }
|
25
|
-
warn Rainbow("Create #{args[:config_path]}").green
|
26
|
-
File.write(yml_file, configs.deep_stringify_keys.to_yaml)
|
27
|
-
warn Rainbow("Done! File #{args[:config_path]} created!").green
|
28
|
-
else
|
29
|
-
warn Rainbow("Skip! File #{args[:config_path]} exists.").red
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
desc 'Transfer configs file in consul from/to projects'
|
34
|
-
task :transfer_config, [:consul_host, :consul_port, :consul_token, :from, :to] do |_t, args|
|
35
|
-
url = URI::HTTP.build(host: args[:consul_host], port: args[:consul_port])
|
36
|
-
|
37
|
-
from = args[:from]
|
38
|
-
to = args[:to]
|
39
|
-
|
40
|
-
Diplomat.configure do |config|
|
41
|
-
config.url = url
|
42
|
-
config.options = {
|
43
|
-
ssl: { version: :TLSv1_2 },
|
44
|
-
headers: {
|
45
|
-
'X-Consul-Token' => args[:consul_token]
|
46
|
-
}
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
|
-
keys = Diplomat::Kv.get(from.to_s, keys: true)
|
51
|
-
keys.delete_at(0) # delete self name folder
|
52
|
-
config_names = keys.map { |k| k.split('/').last }
|
53
5
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
6
|
+
# task :consul2yml [:consul_host, :consul_port, :consul_token, :consul_folder, :environment] do |_t, args|
|
7
|
+
# ss = Briefbag::Diplomat.new(consul_host: args[:consul_host],
|
8
|
+
# consul_port: args[:consul_port],
|
9
|
+
# consul_token: args[:consul_token],
|
10
|
+
# consul_folder: args[:consul_folder],
|
11
|
+
# environment: args[:environment]).call
|
12
|
+
# puts ss
|
13
|
+
# end
|
14
|
+
|
15
|
+
task consul2yml: :environment do
|
16
|
+
p 'ya rake task'
|
60
17
|
end
|
61
18
|
|
62
19
|
desc 'create application.yml from template'
|
63
20
|
task template2yml: :environment do
|
21
|
+
p 'ya rake task'
|
64
22
|
end
|
65
23
|
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: briefbag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Hitchens
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: anyway_config
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.3.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.3.1
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: diplomat
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
33
|
+
version: 2.6.4
|
20
34
|
type: :runtime
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
40
|
+
version: 2.6.4
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: hash_to_struct
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,30 +56,30 @@ dependencies:
|
|
42
56
|
name: rainbow
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: 3.1.1
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 3.1.1
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- - "
|
73
|
+
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: 13.0.
|
75
|
+
version: 13.0.6
|
62
76
|
type: :runtime
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - "
|
80
|
+
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: 13.0.
|
82
|
+
version: 13.0.6
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: bundler
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +114,14 @@ dependencies:
|
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
117
|
+
version: 3.1.1
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
124
|
+
version: 3.1.1
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: rake
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +156,14 @@ dependencies:
|
|
142
156
|
requirements:
|
143
157
|
- - "~>"
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version: 1.
|
159
|
+
version: 1.44.1
|
146
160
|
type: :development
|
147
161
|
prerelease: false
|
148
162
|
version_requirements: !ruby/object:Gem::Requirement
|
149
163
|
requirements:
|
150
164
|
- - "~>"
|
151
165
|
- !ruby/object:Gem::Version
|
152
|
-
version: 1.
|
166
|
+
version: 1.44.1
|
153
167
|
description:
|
154
168
|
email:
|
155
169
|
- mmseleznev@gmail.com
|
@@ -190,14 +204,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
204
|
requirements:
|
191
205
|
- - ">="
|
192
206
|
- !ruby/object:Gem::Version
|
193
|
-
version:
|
207
|
+
version: 3.1.2
|
194
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
209
|
requirements:
|
196
210
|
- - ">="
|
197
211
|
- !ruby/object:Gem::Version
|
198
212
|
version: '0'
|
199
213
|
requirements: []
|
200
|
-
rubygems_version: 3.
|
214
|
+
rubygems_version: 3.3.26
|
201
215
|
signing_key:
|
202
216
|
specification_version: 4
|
203
217
|
summary: Briefbag manage your config
|