eco-helpers 2.0.46 → 2.0.47
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -1
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api/common/session/s3_uploader.rb +4 -2
- data/lib/eco/api/usecases/default_cases/clean_unknown_tags_case.rb +37 -1
- data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +109 -0
- data/lib/eco/api/usecases/default_cases/samples.rb +12 -0
- data/lib/eco/api/usecases/default_cases.rb +1 -0
- data/lib/eco/cli/config/default/usecases.rb +3 -0
- data/lib/eco/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2471c3dc047c0a9ec3c2f1e374d09e4ab9920bd92a54b52a1a0bb0647f869712
|
4
|
+
data.tar.gz: 21e3bb5e42b843ee896a4690df358c081accc2338f7afe4aa91acada0755e681
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e73fdfd9ea00ab63ef8fb49fb4dfd52de2c186f93d9fe6464507ea26acc4a8641ea46dd36f99e5c8bf9d1082537518dfd7404a28b43a6fd93cbdce52acd8b367
|
7
|
+
data.tar.gz: eb9f056454037f0ae46632b27f7a3e0b2922f0d0b4452eebe23ff34f1c205ce87a45693bcc9a8ff981e91acb0fdada9fd2e37c3a79cb2ab7898d7e0e4aad581e
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [2.0.47] - 2022-02-xx
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- `Eco::API::UseCases::DefaultCases::CleanUnknownTags`
|
8
|
+
- It is possible to extend or override `register_tags`
|
9
|
+
- New command option `-include-register-tags` (will not ignore register tags; they will be removed too)
|
10
|
+
- `Eco::API::UseCases::DefaultCases::Samples::Sftp`
|
11
|
+
- Default sample case to list, get and archive SFTP remote files
|
12
|
+
### Changed
|
13
|
+
- upgraded `ecoportal-api-v2` dependency
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
- `Eco::API::Common::Session::S3Uploader#upload_file`: check if file exists before opening.
|
17
|
+
|
4
18
|
## [2.0.46] - 2021-12-24
|
5
19
|
|
6
20
|
### Added
|
@@ -9,7 +23,7 @@ All notable changes to this project will be documented in this file.
|
|
9
23
|
- added also counter of failed to retrieve oozes
|
10
24
|
- added also counter of double ups in search pagination
|
11
25
|
- counter for updated pages and pages that failed update
|
12
|
-
- `Eco::API::Session#enviro_name`: to identify in
|
26
|
+
- `Eco::API::Session#enviro_name`: to identify in which environment we are running
|
13
27
|
|
14
28
|
### Changed
|
15
29
|
- upgraded `ecoportal-api-v2` dependency
|
data/eco-helpers.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
|
32
32
|
|
33
33
|
spec.add_dependency 'ecoportal-api', '>= 0.8.4', '< 0.9'
|
34
|
-
spec.add_dependency 'ecoportal-api-v2', '>= 0.8.
|
34
|
+
spec.add_dependency 'ecoportal-api-v2', '>= 0.8.24', '< 0.9'
|
35
35
|
spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
|
36
36
|
spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
|
37
37
|
spec.add_dependency 'dotenv', '>= 2.7.6', '< 2.8'
|
@@ -32,8 +32,10 @@ module Eco
|
|
32
32
|
# @param path [String] the target file to be uploaded
|
33
33
|
# @return [String] S3 path to the uploaded `path` file
|
34
34
|
def upload_file(path)
|
35
|
-
File.
|
36
|
-
|
35
|
+
if File.exist?(path)
|
36
|
+
File.open(path, "rb") do |f|
|
37
|
+
upload(File.basename(path), f)
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
@@ -2,6 +2,8 @@ class Eco::API::UseCases::DefaultCases::CleanUnknownTags < Eco::API::Common::Loa
|
|
2
2
|
name "clean-unknown-tags"
|
3
3
|
type :transform
|
4
4
|
|
5
|
+
UNKNOWN_LOCS_FILE = "unknown_locations.txt"
|
6
|
+
|
5
7
|
REGISTER_TAGS = [
|
6
8
|
"EVENT", "INJURY", "RISK", "CONTRACTOR", "PERMIT",
|
7
9
|
"AUDIT", "JSEA",
|
@@ -20,18 +22,52 @@ class Eco::API::UseCases::DefaultCases::CleanUnknownTags < Eco::API::Common::Loa
|
|
20
22
|
people.each do |person|
|
21
23
|
unknown_tags = person.filter_tags.select {|tag| !tag?(tag)}
|
22
24
|
person.filter_tags -= unknown_tags
|
25
|
+
unknown_tag!(*unknown_tags)
|
23
26
|
update.add(person)
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
30
|
private
|
28
31
|
|
32
|
+
def unknown_tag!(*tags)
|
33
|
+
tags.each do |value|
|
34
|
+
unless unknown.include?(value)
|
35
|
+
unknown << value
|
36
|
+
File.open(unknown_tags_file, 'a') do |fd|
|
37
|
+
fd.write("#{value}\n")
|
38
|
+
end
|
39
|
+
puts "Custom detected: '#{value}'"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def register_tags
|
45
|
+
REGISTER_TAGS
|
46
|
+
end
|
47
|
+
|
48
|
+
def unknown
|
49
|
+
@unknown ||= []
|
50
|
+
end
|
51
|
+
|
29
52
|
def tag?(value)
|
30
|
-
tagtree.tag?(value)
|
53
|
+
tagtree.tag?(value).yield_self do |is_loc|
|
54
|
+
next true if is_loc
|
55
|
+
if clean_register_tags?
|
56
|
+
register_tags.any? {|reg| value == reg}
|
57
|
+
end
|
58
|
+
end
|
31
59
|
end
|
32
60
|
|
33
61
|
def tagtree
|
34
62
|
@tagtree ||= ASSETS.config.tagtree
|
35
63
|
end
|
36
64
|
|
65
|
+
def unknown_tags_file
|
66
|
+
File.join(".","#{session.enviro_name}_#{UNKNOWN_LOCS_FILE}")
|
67
|
+
end
|
68
|
+
|
69
|
+
def clean_register_tags?
|
70
|
+
!options.dig(:usecase, :include_register_tags)
|
71
|
+
end
|
72
|
+
|
37
73
|
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loaders::UseCase
|
2
|
+
name "sftp-sample"
|
3
|
+
type :other
|
4
|
+
|
5
|
+
attr_reader :session
|
6
|
+
|
7
|
+
def main(session, options, usecase)
|
8
|
+
@session = session
|
9
|
+
options[:end_get] = false
|
10
|
+
raise "The SFTP is not configured" unless session.sftp?
|
11
|
+
case options.dig(:sftp, :command)
|
12
|
+
when :list
|
13
|
+
list_folder
|
14
|
+
when :get
|
15
|
+
get_files
|
16
|
+
when :get_last
|
17
|
+
get_last
|
18
|
+
when :archive
|
19
|
+
archive_files
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def file_pattern
|
26
|
+
raise "You should redefine the file_pattern function as a RegEx expression that matches the target remote file"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Ex: "/IN/Personnel"
|
30
|
+
def remote_subfolder
|
31
|
+
raise "You should redefine remote_subfolder as the folder where the target file sits"
|
32
|
+
end
|
33
|
+
|
34
|
+
def archive_subfolder
|
35
|
+
"Archive"
|
36
|
+
end
|
37
|
+
|
38
|
+
def with_remote_files
|
39
|
+
sftp.files(remote_folder, pattern: file_pattern).each do |remote_file|
|
40
|
+
yield(remote_file) if block_given?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def list_folder
|
45
|
+
puts "Listing remote folder: '#{remote_folder}':"
|
46
|
+
with_remote_files {|file| puts file.longname}
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_files
|
50
|
+
with_remote_files.tap do |files|
|
51
|
+
unless files.empty?
|
52
|
+
file_names = files.map {|file| to_remote_path(file.name)}
|
53
|
+
puts "Getting the following files:"
|
54
|
+
puts file_names
|
55
|
+
sftp.download(file_names, local_folder: local_folder)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_last
|
61
|
+
with_remote_files.last.tap do |file|
|
62
|
+
if file
|
63
|
+
file_name = to_remote_path(file.name)
|
64
|
+
puts "Getting the following file: #{file_name}"
|
65
|
+
sftp.download(file_name, local_folder: local_folder)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def archive_files
|
71
|
+
with_remote_files do |file|
|
72
|
+
source = to_remote_path(file.name) # should probably be file.longname
|
73
|
+
dest = to_remote_path("#{archive_subfolder}/#{file.name}")
|
74
|
+
move_file(source, dest)
|
75
|
+
end.tap do |files|
|
76
|
+
puts "Moved the file(s) to the #{archive_subfolder} folder" unless files.empty?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def move_file(source, dest)
|
81
|
+
sftp.move(source, dest, 0x0001) do |response|
|
82
|
+
if response.ok?
|
83
|
+
puts "#{source}\n -to-> #{dest}"
|
84
|
+
else
|
85
|
+
puts "Could not move file #{source}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def to_remote_path(file)
|
91
|
+
remote_folder + "/" + file
|
92
|
+
end
|
93
|
+
|
94
|
+
def local_folder
|
95
|
+
"."
|
96
|
+
end
|
97
|
+
|
98
|
+
def remote_folder
|
99
|
+
@remote_folder ||= sftp_config.remote_folder + remote_subfolder
|
100
|
+
end
|
101
|
+
|
102
|
+
def sftp_config
|
103
|
+
session.config.sftp
|
104
|
+
end
|
105
|
+
|
106
|
+
def sftp
|
107
|
+
session.sftp
|
108
|
+
end
|
109
|
+
end
|
@@ -90,6 +90,9 @@ ASSETS.cli.config do |cnf|
|
|
90
90
|
desc = "Cleans from filter_tags those tags that are not present in the tagtree (as per tagtree.json file)."
|
91
91
|
desc += " It will preserve standard register tags of most common registers (i.e. EVENT, RISK)."
|
92
92
|
cases.add("-clean-unknown-tags", :transform, desc, case_name: "clean-unknown-tags")
|
93
|
+
.add_option("-include-register-tags", "Will also try to remove register tags") do |options|
|
94
|
+
options.deep_merge!(usecase: {include_register_tags: true})
|
95
|
+
end
|
93
96
|
|
94
97
|
desc = "Removes the landing page or sets it to -page-id"
|
95
98
|
cases.add("-reset-landing-page", :transform, desc, case_name: "reset-landing-page")
|
data/lib/eco/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eco-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.47
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
requirements:
|
137
137
|
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: 0.8.
|
139
|
+
version: 0.8.24
|
140
140
|
- - "<"
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: '0.9'
|
@@ -146,7 +146,7 @@ dependencies:
|
|
146
146
|
requirements:
|
147
147
|
- - ">="
|
148
148
|
- !ruby/object:Gem::Version
|
149
|
-
version: 0.8.
|
149
|
+
version: 0.8.24
|
150
150
|
- - "<"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0.9'
|
@@ -546,6 +546,8 @@ files:
|
|
546
546
|
- lib/eco/api/usecases/default_cases/remove_account_trans_case.rb
|
547
547
|
- lib/eco/api/usecases/default_cases/reset_landing_page_case.rb
|
548
548
|
- lib/eco/api/usecases/default_cases/restore_db_case.rb
|
549
|
+
- lib/eco/api/usecases/default_cases/samples.rb
|
550
|
+
- lib/eco/api/usecases/default_cases/samples/sftp_case.rb
|
549
551
|
- lib/eco/api/usecases/default_cases/set_default_tag_case.rb
|
550
552
|
- lib/eco/api/usecases/default_cases/set_supervisor_case.rb
|
551
553
|
- lib/eco/api/usecases/default_cases/supers_cyclic_identify_case.rb
|