briefbag 1.0.0 → 1.0.2
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 +5 -5
- data/README.md +3 -3
- data/briefbag.gemspec +7 -8
- data/lib/briefbag/configuration.rb +7 -16
- data/lib/briefbag/diplomat.rb +2 -8
- data/lib/briefbag/version.rb +1 -1
- data/lib/tasks/settings.rake +53 -10
- metadata +20 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66b7c96c40783d727444f581e65f520eaadd8b4d249e2887ffc9d0ed20b40dbc
|
4
|
+
data.tar.gz: f6e0ef37c64612473441876a50eb0fa5b1270c726774aef289a1c687fa4957e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4e9e34c7455c10f69898525de740da05e3bde3776c818afc527768c05af05bd25fa374df28a1e12768034bcbd51b6509666a847e7ef82f1626adac8c1fb2f6a
|
7
|
+
data.tar.gz: ce47693102526f590fbd87b88f2b33b86cc562e76814953b5a8e9d221a8453f8c1371483c565a3633a81402234908c3ef7b2033baf1d415ae12c374fb8fca65d
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.2@briefbag
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## 0.0.1 - 2023-
|
3
|
+
## 0.0.1 - 2023-02-03
|
4
4
|
|
5
5
|
* Briefbag was born
|
6
6
|
|
7
|
-
##
|
7
|
+
## 0.0.2 - 2023-03-15
|
8
8
|
|
9
|
-
*
|
9
|
+
* Fix bugs
|
10
10
|
|
11
|
-
##
|
11
|
+
## 1.0.2 - 2023-03-16
|
12
12
|
|
13
|
-
*
|
13
|
+
* Refactoring: delete anyway config, using yml from ruby, change params and upd docs, implementation rake tasks
|
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/briefbag)
|
4
4
|
[![Gem](https://img.shields.io/gem/dt/briefbag.svg)](https://rubygems.org/gems/briefbag)
|
5
5
|
|
6
6
|
|
@@ -75,7 +75,7 @@ Or install it yourself as:
|
|
75
75
|
- **consul_token(string)** - *(optional)* If you use ACL Token.
|
76
76
|
- **consul_folder(string)** *(required)* Name config folder in consul.
|
77
77
|
- **environment(string)** - *(optional)* Default value ${development}. Environment in consul.
|
78
|
-
- **
|
78
|
+
- **config_path(string)** - *(required)* Сonfig path to your config file. for example path to yml file: 'config/application.yml'
|
79
79
|
|
80
80
|
```ruby
|
81
81
|
require 'briefbag'
|
@@ -86,7 +86,7 @@ params_config = {
|
|
86
86
|
consul_token: '233b604b-b92e-48c8-a253-5f11514e4b50',
|
87
87
|
consul_folder: 'briefbag',
|
88
88
|
environment: 'test',
|
89
|
-
|
89
|
+
config_path: 'config/some_config.yml'
|
90
90
|
}
|
91
91
|
configs = Briefbag::Configuration.new(params_config).call
|
92
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 = '>= 2.
|
16
|
+
spec.required_ruby_version = '>= 2.4.2'
|
17
17
|
|
18
18
|
spec.metadata = {
|
19
19
|
'homepage_uri' => spec.homepage,
|
@@ -33,16 +33,15 @@ 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 '
|
37
|
-
spec.add_dependency 'diplomat', '>=2.6.4'
|
36
|
+
spec.add_dependency 'diplomat', '>= 2.4.4'
|
38
37
|
spec.add_dependency 'hash_to_struct', '>=1.0.0'
|
39
|
-
spec.add_dependency 'rainbow', '
|
40
|
-
spec.add_dependency 'rake', '
|
38
|
+
spec.add_dependency 'rainbow', '>= 2.2.2'
|
39
|
+
spec.add_dependency 'rake', '>= 13.0.3'
|
41
40
|
|
42
|
-
spec.add_development_dependency 'bundler', '~> 2.
|
41
|
+
spec.add_development_dependency 'bundler', '~> 2.3.26'
|
43
42
|
spec.add_development_dependency 'byebug', '~> 11.1.3'
|
44
|
-
spec.add_development_dependency 'faker', '~>
|
43
|
+
spec.add_development_dependency 'faker', '~> 2.12.0'
|
45
44
|
spec.add_development_dependency 'rake', '~> 13.0.6'
|
46
45
|
spec.add_development_dependency 'rspec', '~> 3.12.0'
|
47
|
-
spec.add_development_dependency 'rubocop', '~> 1.
|
46
|
+
spec.add_development_dependency 'rubocop', '~> 1.10.0'
|
48
47
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'briefbag/diplomat'
|
4
|
-
require 'anyway_config'
|
5
4
|
require 'rainbow'
|
6
5
|
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_path
|
11
11
|
|
12
12
|
MESSAGES = {
|
13
13
|
notice_yml: 'NOTICE! Your app is using configs from yml file',
|
@@ -20,7 +20,7 @@ module Briefbag
|
|
20
20
|
}.freeze
|
21
21
|
|
22
22
|
def initialize(config)
|
23
|
-
@
|
23
|
+
@config_path = config[:config_path]
|
24
24
|
@config = config
|
25
25
|
end
|
26
26
|
|
@@ -44,24 +44,15 @@ module Briefbag
|
|
44
44
|
|
45
45
|
def file_config
|
46
46
|
Briefbag.warning_message(MESSAGES[:notice_yml])
|
47
|
-
|
48
|
-
data = Anyway::Config.for(config_name.to_sym, env_prefix: config[:environment])
|
47
|
+
data = YAML.load_file(config_path)
|
49
48
|
|
50
|
-
return HashToStruct.struct(data.deep_symbolize_keys) if defined?(Rails)
|
49
|
+
return HashToStruct.struct(data.deep_symbolize_keys)[config[:environment]] if defined?(Rails)
|
51
50
|
|
52
|
-
HashToStruct.struct(symbolize_all_keys(data))
|
51
|
+
HashToStruct.struct(symbolize_all_keys(data))[config[:environment]]
|
53
52
|
end
|
54
53
|
|
55
54
|
def file_exist?
|
56
|
-
@file_exist ||= File.exist?(
|
57
|
-
end
|
58
|
-
|
59
|
-
def yaml_file
|
60
|
-
@yaml_file ||= "./config/#{config_name}.yml"
|
61
|
-
end
|
62
|
-
|
63
|
-
def local_keys
|
64
|
-
@local_keys ||= YAML.safe_load(File.read(yaml_file))[environment].keys
|
55
|
+
@file_exist ||= File.exist?(config_path)
|
65
56
|
end
|
66
57
|
|
67
58
|
def symbolize_all_keys(h) # rubocop:disable Naming/MethodParameterName
|
data/lib/briefbag/diplomat.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'diplomat'
|
4
4
|
require 'socket'
|
5
|
+
require 'yaml'
|
5
6
|
|
6
7
|
module Briefbag
|
7
8
|
class Diplomat
|
@@ -22,7 +23,6 @@ module Briefbag
|
|
22
23
|
|
23
24
|
def configuration
|
24
25
|
::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,15 +39,9 @@ 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
|
-
|
48
42
|
def mapping_hash
|
49
43
|
consul_data.each_with_object({}) do |item, hash|
|
50
|
-
hash[item[:key].split('/').last.to_sym] =
|
44
|
+
hash[item[:key].split('/').last.to_sym] = ::YAML.safe_load(item[:value])
|
51
45
|
end
|
52
46
|
end
|
53
47
|
|
data/lib/briefbag/version.rb
CHANGED
data/lib/tasks/settings.rake
CHANGED
@@ -1,21 +1,64 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'briefbag'
|
4
|
+
require 'byebug'
|
5
|
+
require 'rails'
|
6
|
+
|
3
7
|
namespace :settings do
|
4
8
|
desc 'create application.yml from consul data'
|
9
|
+
task :consul2yml,
|
10
|
+
[:consul_host, :consul_port, :consul_token, :consul_folder, :environment, :config_path] do |_t, args|
|
11
|
+
diplomat_config = Briefbag::Diplomat.new(
|
12
|
+
consul_host: args[:consul_host],
|
13
|
+
consul_port: args[:consul_port].to_i,
|
14
|
+
consul_token: args[:consul_token],
|
15
|
+
consul_folder: args[:consul_folder],
|
16
|
+
environment: args[:environment]
|
17
|
+
)
|
5
18
|
|
6
|
-
|
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
|
19
|
+
data = diplomat_config.call
|
14
20
|
|
15
|
-
|
16
|
-
|
21
|
+
return warn Rainbow('Consul is down').red unless data.success?
|
22
|
+
|
23
|
+
yml_file = "#{Rails.root}/#{args[:config_path]}"
|
24
|
+
if Rails.env.development? && !File.exist?(yml_file)
|
25
|
+
configs = { "#{args[:environment]}": data.consul_data.deep_symbolize_keys }
|
26
|
+
warn Rainbow("Create #{args[:config_path]}").green
|
27
|
+
File.write(yml_file, configs.deep_stringify_keys.to_yaml)
|
28
|
+
warn Rainbow("Done! File #{args[:config_path]} created!").green
|
29
|
+
else
|
30
|
+
warn Rainbow("Skip! File #{args[:config_path]} exists.").red
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'Transfer configs file in consul from/to projects'
|
35
|
+
task :transfer_config, [:consul_url, :consul_token, :project, :from_env, :to_env] do |_t, args|
|
36
|
+
project = args[:project]
|
37
|
+
from = args[:from_env]
|
38
|
+
to = args[:to_env]
|
39
|
+
|
40
|
+
Diplomat.configure do |config|
|
41
|
+
config.url = args[:consul_url]
|
42
|
+
config.options = {
|
43
|
+
ssl: { version: :TLSv1_2 },
|
44
|
+
headers: {
|
45
|
+
'X-Consul-Token' => args[:consul_token]
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
keys = Diplomat::Kv.get("#{from}/#{project}", keys: true)
|
50
|
+
keys.delete_at(0) # delete self name folder
|
51
|
+
config_names = keys.map { |k| k.split('/').last }
|
52
|
+
|
53
|
+
config_names.each do |config_name|
|
54
|
+
warn Rainbow("Start read data for key: #{config_name}").yellow
|
55
|
+
config = Diplomat::Kv.get("#{from}/#{project}/#{config_name}")
|
56
|
+
Diplomat::Kv.put("#{to}/#{project}/#{config_name}", config)
|
57
|
+
warn Rainbow("Success transfer data for key: #{config_name}").green
|
58
|
+
end
|
17
59
|
end
|
18
60
|
|
61
|
+
|
19
62
|
desc 'create application.yml from template'
|
20
63
|
task template2yml: :environment do
|
21
64
|
p 'ya rake task'
|
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: briefbag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
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-03-19 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
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: diplomat
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - ">="
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.
|
19
|
+
version: 2.4.4
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - ">="
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.
|
26
|
+
version: 2.4.4
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: hash_to_struct
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,44 +42,44 @@ dependencies:
|
|
56
42
|
name: rainbow
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - "
|
45
|
+
- - ">="
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
47
|
+
version: 2.2.2
|
62
48
|
type: :runtime
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- - "
|
52
|
+
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
54
|
+
version: 2.2.2
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rake
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- - "
|
59
|
+
- - ">="
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: 13.0.
|
61
|
+
version: 13.0.3
|
76
62
|
type: :runtime
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - "
|
66
|
+
- - ">="
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: 13.0.
|
68
|
+
version: 13.0.3
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: bundler
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: 2.
|
75
|
+
version: 2.3.26
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: 2.
|
82
|
+
version: 2.3.26
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: byebug
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +100,14 @@ dependencies:
|
|
114
100
|
requirements:
|
115
101
|
- - "~>"
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
103
|
+
version: 2.12.0
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
108
|
- - "~>"
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
110
|
+
version: 2.12.0
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: rake
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,14 +142,14 @@ dependencies:
|
|
156
142
|
requirements:
|
157
143
|
- - "~>"
|
158
144
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
145
|
+
version: 1.10.0
|
160
146
|
type: :development
|
161
147
|
prerelease: false
|
162
148
|
version_requirements: !ruby/object:Gem::Requirement
|
163
149
|
requirements:
|
164
150
|
- - "~>"
|
165
151
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.
|
152
|
+
version: 1.10.0
|
167
153
|
description:
|
168
154
|
email:
|
169
155
|
- mmseleznev@gmail.com
|
@@ -204,14 +190,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
204
190
|
requirements:
|
205
191
|
- - ">="
|
206
192
|
- !ruby/object:Gem::Version
|
207
|
-
version: 2.
|
193
|
+
version: 2.4.2
|
208
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
195
|
requirements:
|
210
196
|
- - ">="
|
211
197
|
- !ruby/object:Gem::Version
|
212
198
|
version: '0'
|
213
199
|
requirements: []
|
214
|
-
rubygems_version: 3.
|
200
|
+
rubygems_version: 3.0.9
|
215
201
|
signing_key:
|
216
202
|
specification_version: 4
|
217
203
|
summary: Briefbag manage your config
|