eco-helpers 2.0.17 → 2.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/lib/eco-helpers.rb +1 -0
- data/lib/eco/api/common/version_patches/exception.rb +8 -4
- data/lib/eco/api/session/config/apis.rb +80 -14
- data/lib/eco/api/usecases/default_cases/abstract_policygroup_abilities_case.rb +3 -3
- data/lib/eco/cli/config/default/workflow.rb +9 -5
- data/lib/eco/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 678fc1c610a5aafd8321a74367a6aaca67aa70bf159f638209b45da0361bb575
|
4
|
+
data.tar.gz: 280a74a3a3877c5d58bfbe84d0f6a8f8b6f8eda5c68f376fea87522b03a59e42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30c74c7aa8b7f59a4610cb4da804714a165a095d6280b756dcec17df37a81f2b5438a7178cc279750e5f97a43ae6d0041e464d9ed7965af39c39fc71ce4efc99
|
7
|
+
data.tar.gz: 1abe7f74b0a0452565c1add7778086030372f63912fe2c6279a2d40eb9f908d07746421507241d4905bbdf546e944899fa0f63fa3e3fe086caf1663c83a2624d
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## [2.0.
|
4
|
+
## [2.0.18] - 2021-05-25
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- **`-one-off`** option to not having to type the `-api-key` every time you launch one-off scripts
|
8
|
+
- `-api-key` will store the key to the `./.env_one_off` file (supports update and multi-environment)
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
### Fixed
|
12
|
+
- patched `Exception#patch_full_message` to do not enter into a cyclic error rescue
|
13
|
+
- also rescue on `workflow.rescue`
|
14
|
+
|
15
|
+
## [2.0.17] - 2021-05-25
|
5
16
|
|
6
17
|
Specific changes due to eP **release `1.5.9.70`** (_Policy Group Abilities_)
|
7
18
|
- And some improvements as well as new tools
|
data/lib/eco-helpers.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
class ::Exception
|
2
2
|
def patch_full_message
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
begin
|
4
|
+
msg = []
|
5
|
+
msg << "\n#{backtrace.first} \n#{message} (#{self.class.to_s})"
|
6
|
+
backtrace[1..-1].each_with_index {|bt, i| msg << "#{" "*8}#{i+1}: from #{bt}"}
|
7
|
+
msg.join("\n")
|
8
|
+
rescue Exception => e
|
9
|
+
puts "Something is wrong with 'patch_full_message': #{e}"
|
10
|
+
end
|
7
11
|
end
|
8
12
|
end
|
9
13
|
|
@@ -40,20 +40,6 @@ module Eco
|
|
40
40
|
self
|
41
41
|
end
|
42
42
|
|
43
|
-
# Method to support CLI one-off API requests
|
44
|
-
def one_off
|
45
|
-
if SCR.get_arg("-api-key")
|
46
|
-
key = SCR.get_arg("-api-key", with_param: true)
|
47
|
-
enviro = SCR.get_arg("-enviro") ? SCR.get_arg("-enviro", with_param: true) : "live"
|
48
|
-
host = "#{enviro}.ecoportal.com"
|
49
|
-
org = SCR.get_arg("-org") ? SCR.get_arg("-org", with_param: true) : raise("You should specify -org NAME when using -api-key")
|
50
|
-
org = org.downcase.split(/[^a-z]+/).join("_")
|
51
|
-
org = org.to_sym
|
52
|
-
add(org, key: key, host: host)
|
53
|
-
return org
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
43
|
def active_api
|
58
44
|
self["active-api"]
|
59
45
|
end
|
@@ -96,6 +82,86 @@ module Eco
|
|
96
82
|
self["user_key"]
|
97
83
|
end
|
98
84
|
|
85
|
+
# Method to support CLI one-off API requests
|
86
|
+
def one_off
|
87
|
+
if one_off?
|
88
|
+
add(one_off_org, key: one_off_key, host: "#{one_off_enviro}.ecoportal.com")
|
89
|
+
return one_off_org
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def one_off?
|
96
|
+
@is_one_off ||= SCR.get_arg("-api-key") || SCR.get_arg("-one-off")
|
97
|
+
end
|
98
|
+
|
99
|
+
def one_off_key
|
100
|
+
return @one_off_key if instance_variable_defined?(:@one_off_key)
|
101
|
+
if one_off?
|
102
|
+
Dotenv.load("./.env_one_off")
|
103
|
+
SCR.get_arg("-api-key", with_param: true).yield_self do |key|
|
104
|
+
one_off_key_env(key)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def one_off_key_env(key)
|
110
|
+
if one_off?
|
111
|
+
if key
|
112
|
+
env_file_set_var("./.env_one_off", one_off_key_env_var, key)
|
113
|
+
key
|
114
|
+
else
|
115
|
+
Dotenv.load("./.env_one_off")
|
116
|
+
ENV[one_off_key_env_var].tap do |k|
|
117
|
+
raise "At least the first time, you should provide the -api-key" unless k
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def one_off_key_env_var
|
124
|
+
@one_off_key_env_var ||= "#{one_off_org}_KEY"
|
125
|
+
end
|
126
|
+
|
127
|
+
def one_off_org
|
128
|
+
return @one_off_org if instance_variable_defined?(:@one_off_org)
|
129
|
+
unless org = SCR.get_arg("-org", with_param: true)
|
130
|
+
raise("You should specify -org NAME when using -api-key or -one-off")
|
131
|
+
end
|
132
|
+
@one_off_org ||= "#{org.downcase.split(/[^a-z]+/).join("_")}_#{one_off_enviro.gsub(".", "_")}".to_sym
|
133
|
+
end
|
134
|
+
|
135
|
+
def one_off_enviro
|
136
|
+
return @one_off_enviro if instance_variable_defined?(:@one_off_enviro)
|
137
|
+
enviro = SCR.get_arg("-enviro") ? SCR.get_arg("-enviro", with_param: true) : "live"
|
138
|
+
@one_off_enviro ||= enviro.downcase
|
139
|
+
end
|
140
|
+
|
141
|
+
def env_file_set_var(file, var, value)
|
142
|
+
begin
|
143
|
+
pattern = /"#{var}=(?<value>[^ \r\n]+)"/
|
144
|
+
File.open(file, "w+") do |fd|
|
145
|
+
found = false
|
146
|
+
fd.each_line do |line|
|
147
|
+
if match = line.match(pattern)
|
148
|
+
found = true
|
149
|
+
# IO::SEEK_CUR => Seeks to _amount_ plus current position
|
150
|
+
fd.seek(-(line.length + 1), IO::SEEK_CUR)
|
151
|
+
fd.write line.gsub(match[:value], value)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
fd << "#{var}=#{value}" unless found
|
156
|
+
end
|
157
|
+
rescue StandardError => e
|
158
|
+
puts "#{e}"
|
159
|
+
return false
|
160
|
+
end
|
161
|
+
return true
|
162
|
+
end
|
163
|
+
|
164
|
+
|
99
165
|
end
|
100
166
|
end
|
101
167
|
end
|
@@ -106,10 +106,10 @@ class Eco::API::UseCases::DefaultCases::AbstractPolicyGroupAbilities < Eco::API:
|
|
106
106
|
|
107
107
|
# Scope Relevant Raw Data
|
108
108
|
case
|
109
|
-
when sp >= 80
|
109
|
+
when sp >= 3 # >= 80
|
110
110
|
sing
|
111
|
-
when sp < 15
|
112
|
-
|
111
|
+
#when sp < 15
|
112
|
+
# mult
|
113
113
|
else # combine
|
114
114
|
all_abilities = sing[:abilities].keys | mult[:abilities].keys
|
115
115
|
data = {count: sing[:count] + mult[:count], abilities: {}}
|
@@ -6,11 +6,15 @@ ASSETS.cli.config do |config|
|
|
6
6
|
|
7
7
|
# default rescue
|
8
8
|
wf.rescue do |exception, io|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
begin
|
10
|
+
next io if rescued
|
11
|
+
rescued = true
|
12
|
+
|
13
|
+
io.session.logger.debug(exception.patch_full_message)
|
14
|
+
wf.run(:close, io: io)
|
15
|
+
rescue Exception => e
|
16
|
+
puts "Some problem in workflow.rescue: #{e}"
|
17
|
+
end
|
14
18
|
io
|
15
19
|
end
|
16
20
|
|
data/lib/eco/version.rb
CHANGED