eco-helpers 0.6.13 → 0.6.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/eco-helpers.gemspec +1 -1
  3. data/lib/eco/api.rb +1 -2
  4. data/lib/eco/api/common/people/person_entry.rb +1 -1
  5. data/lib/eco/api/common/people/person_factory.rb +3 -3
  6. data/lib/eco/api/common/session/base_session.rb +14 -2
  7. data/lib/eco/api/common/session/environment.rb +9 -7
  8. data/lib/eco/api/common/version_patches/external_person.rb +16 -2
  9. data/lib/eco/api/common/version_patches/internal_person.rb +17 -0
  10. data/lib/eco/api/session.rb +13 -19
  11. data/lib/eco/api/session/batch.rb +4 -17
  12. data/lib/eco/api/session/batch_job.rb +4 -13
  13. data/lib/eco/api/session/{job_group.rb → batch_jobs.rb} +6 -8
  14. data/lib/eco/api/session/batch_status.rb +3 -7
  15. data/lib/eco/api/session/config.rb +186 -0
  16. data/lib/eco/api/session/config/api.rb +49 -0
  17. data/lib/eco/api/session/config/apis.rb +91 -0
  18. data/lib/eco/api/session/config/files.rb +32 -0
  19. data/lib/eco/api/session/config/logger.rb +56 -0
  20. data/lib/eco/api/session/config/mailer.rb +67 -0
  21. data/lib/eco/api/session/config/people.rb +95 -0
  22. data/lib/eco/api/session/config/s3_storage.rb +64 -0
  23. data/lib/eco/api/session/config/use_cases.rb +33 -0
  24. data/lib/eco/api/session/job_groups.rb +4 -6
  25. data/lib/eco/api/session/task.rb +2 -13
  26. data/lib/eco/version.rb +1 -1
  27. metadata +18 -11
  28. data/lib/eco/api/session_config.rb +0 -187
  29. data/lib/eco/api/session_config/api.rb +0 -47
  30. data/lib/eco/api/session_config/apis.rb +0 -89
  31. data/lib/eco/api/session_config/files.rb +0 -30
  32. data/lib/eco/api/session_config/logger.rb +0 -54
  33. data/lib/eco/api/session_config/mailer.rb +0 -65
  34. data/lib/eco/api/session_config/people.rb +0 -93
  35. data/lib/eco/api/session_config/s3_storage.rb +0 -62
  36. data/lib/eco/api/session_config/use_cases.rb +0 -31
@@ -0,0 +1,33 @@
1
+ module Eco
2
+ module API
3
+ class Session
4
+ class Config
5
+ class UseCases < Hash
6
+ attr_reader :config
7
+
8
+ def initialize(root:)
9
+ super(nil)
10
+ @root = root
11
+ @config = @root
12
+ end
13
+
14
+ # CUSTOM USE CASES
15
+ def add
16
+ new_group = Eco::API::UseCases::UseGroup.new
17
+ yield(new_group, config)
18
+
19
+ self["use_group"] ||= Eco::API::UseCases::UseGroup.new
20
+ group = self["use_group"]
21
+ group = group ? group.merge(new_group) : group
22
+ self["use_group"] = group
23
+ end
24
+
25
+ def use_group
26
+ self["use_group"] ||= Eco::API::UseCases::UseGroup.new
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -4,10 +4,8 @@ module Eco
4
4
  class JobGroups < API::Common::Session::BaseSession
5
5
  DELAY_BETWEEN_GROUPS = 2
6
6
 
7
- def initialize(session:)
8
- raise("JobGroups requires a session object") unless session.is_a?(API::Session)
9
- super(session.enviro)
10
- @session = session
7
+ def initialize(e)
8
+ super(e)
11
9
  reset
12
10
  end
13
11
 
@@ -26,9 +24,9 @@ module Eco
26
24
  end
27
25
 
28
26
  def new(name, order: :last)
29
- raise("Can't create job group named #{'name'} because it already exists.") if exists?(name)
27
+ fatal "Can't create job group named '#{name}' because it already exists." if exists?(name)
30
28
 
31
- group = BatchJobs.new(name, session: @session)
29
+ group = BatchJobs.new(enviro, name: name)
32
30
  @groups[name] = group
33
31
 
34
32
  if order == :last
@@ -7,20 +7,9 @@ module Eco
7
7
  SAVE_FILE_MODE = [:save]
8
8
  API_MODE = [:api, :api_get]
9
9
 
10
- attr_reader :batch
11
-
12
- def initialize(root, env)
13
- super(env)
14
- @root = root
15
- end
16
-
17
- def batch
18
- @root&.batch
19
- end
20
-
21
10
  def file_people(filename = enviro.config.people.cache)
22
11
  logger.info("Going to get all the people via API")
23
- people = batch.get_people
12
+ people = session.batch.get_people
24
13
  file = file_manager.save_json(people, filename, :timestamp)
25
14
  logger.info("#{people.length} people loaded and saved locally to #{file}.")
26
15
  Eco::API::Organization::People.new(people)
@@ -53,7 +42,7 @@ module Eco
53
42
  when use_api?(modifier)
54
43
  # no previous file: use API to get all people
55
44
  logger.info("Going to get all the people via API")
56
- people = batch.get_people
45
+ people = session.batch.get_people
57
46
 
58
47
  if save_file?(modifier) && people && people.length > 0
59
48
  file = file_manager.save_json(people, filename, :timestamp)
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "0.6.13"
2
+ VERSION = "0.6.15"
3
3
  end
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: 0.6.13
4
+ version: 0.6.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -80,6 +80,9 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.3.6
83
+ - - "<"
84
+ - !ruby/object:Gem::Version
85
+ version: 0.4.0
83
86
  type: :runtime
84
87
  prerelease: false
85
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,6 +93,9 @@ dependencies:
90
93
  - - ">="
91
94
  - !ruby/object:Gem::Version
92
95
  version: 0.3.6
96
+ - - "<"
97
+ - !ruby/object:Gem::Version
98
+ version: 0.4.0
93
99
  - !ruby/object:Gem::Dependency
94
100
  name: faker
95
101
  requirement: !ruby/object:Gem::Requirement
@@ -249,6 +255,7 @@ files:
249
255
  - lib/eco/api/common/session/s3_uploader.rb
250
256
  - lib/eco/api/common/version_patches.rb
251
257
  - lib/eco/api/common/version_patches/external_person.rb
258
+ - lib/eco/api/common/version_patches/internal_person.rb
252
259
  - lib/eco/api/eco_faker.rb
253
260
  - lib/eco/api/organization.rb
254
261
  - lib/eco/api/organization/people.rb
@@ -261,19 +268,19 @@ files:
261
268
  - lib/eco/api/session.rb
262
269
  - lib/eco/api/session/batch.rb
263
270
  - lib/eco/api/session/batch_job.rb
271
+ - lib/eco/api/session/batch_jobs.rb
264
272
  - lib/eco/api/session/batch_status.rb
265
- - lib/eco/api/session/job_group.rb
273
+ - lib/eco/api/session/config.rb
274
+ - lib/eco/api/session/config/api.rb
275
+ - lib/eco/api/session/config/apis.rb
276
+ - lib/eco/api/session/config/files.rb
277
+ - lib/eco/api/session/config/logger.rb
278
+ - lib/eco/api/session/config/mailer.rb
279
+ - lib/eco/api/session/config/people.rb
280
+ - lib/eco/api/session/config/s3_storage.rb
281
+ - lib/eco/api/session/config/use_cases.rb
266
282
  - lib/eco/api/session/job_groups.rb
267
283
  - lib/eco/api/session/task.rb
268
- - lib/eco/api/session_config.rb
269
- - lib/eco/api/session_config/api.rb
270
- - lib/eco/api/session_config/apis.rb
271
- - lib/eco/api/session_config/files.rb
272
- - lib/eco/api/session_config/logger.rb
273
- - lib/eco/api/session_config/mailer.rb
274
- - lib/eco/api/session_config/people.rb
275
- - lib/eco/api/session_config/s3_storage.rb
276
- - lib/eco/api/session_config/use_cases.rb
277
284
  - lib/eco/api/usecases.rb
278
285
  - lib/eco/api/usecases/base_case.rb
279
286
  - lib/eco/api/usecases/case_data.rb
@@ -1,187 +0,0 @@
1
- module Eco
2
- module API
3
- class SessionConfig < Hash
4
- BaseParser = Eco::API::Common::People::BaseParser
5
- BaseCase = Eco::API::UseCases::BaseCase
6
-
7
- def initialize()
8
- super(nil)
9
- self["org"] = {}
10
- end
11
-
12
- def reopen
13
- yield(self)
14
- end
15
-
16
- def apis
17
- self["apis"] ||= SessionConfig::Apis.new(root: self)
18
- end
19
-
20
- def logger
21
- self["logger"] ||= SessionConfig::Logger.new(root: self)
22
- end
23
-
24
- def s3storage
25
- self["s3_storage"] ||= SessionConfig::S3Storage.new(root: self)
26
- end
27
-
28
- def files
29
- self["files"] ||= SessionConfig::Files.new(root: self)
30
- end
31
-
32
- def mailer
33
- self["mailer"] ||= SessionConfig::Mailer.new(root: self)
34
- end
35
-
36
- def org
37
- self["org"]
38
- end
39
-
40
- def people
41
- self["people"] ||= SessionConfig::People.new(root: self)
42
- end
43
-
44
- def usecases
45
- self["usecases"] ||= SessionConfig::UseCases.new(root: self)
46
- end
47
-
48
- # LOGGER
49
- def log_console_level=(value)
50
- logger.console_level= value
51
- end
52
-
53
- def log_file_level=(value)
54
- logger.file_level = value
55
- end
56
-
57
- def log_file=(file)
58
- logger.file = file
59
- end
60
-
61
- def timestamp_console=(value)
62
- logger.timestamp_console = value
63
- end
64
-
65
- def log_connection=(value)
66
- logger.log_connection = value
67
- end
68
-
69
- # API
70
- def dry_run!
71
- self["dry-run"] = true
72
- end
73
-
74
- def dry_run?
75
- self["dry-run"]
76
- end
77
-
78
- def run_mode=(mode)
79
- apis.active_api.mode = mode
80
- end
81
-
82
- def run_mode_local?
83
- apis.active_api.local?
84
- end
85
-
86
- def run_mode_remote?
87
- apis.active_api.remote?
88
- end
89
-
90
- def apis?
91
- apis.apis?
92
- end
93
-
94
- def add_api(name, **kargs)
95
- apis.add(name, **kargs)
96
- self
97
- end
98
-
99
- def active_api(name)
100
- apis.active_name = name
101
- self
102
- end
103
-
104
- def api(logger = ::Logger.new(IO::NULL))
105
- apis.api(logger)
106
- end
107
-
108
- def policy_groups
109
- policy_groups = api&.policy_groups.to_a.compact
110
- Eco::API::Organization::PolicyGroups.new(policy_groups)
111
- end
112
-
113
- # FILES
114
- def working_directory=(path)
115
- files.working_directory = path
116
- end
117
-
118
- def file_timestamp_pattern=(pattern)
119
- files.timestamp_pattern = pattern
120
- end
121
-
122
- def file_manager
123
- Eco::API::Common::Session::FileManager.new(self)
124
- end
125
-
126
- def require(file)
127
- require_relative "#{File.expand_path(file_manager.dir.file(file))}"
128
- end
129
-
130
- # ORG
131
- def tagtree=(file)
132
- org["tagtree"] = file
133
- end
134
-
135
- # PEOPLE
136
- def discarded_people_file=(value)
137
- people.discarded_file = value
138
- end
139
-
140
- def people_cache=(file)
141
- people.cache = file
142
- end
143
-
144
- def requests_backup_folder=(folder)
145
- people.requests_folder = folder
146
- end
147
-
148
- # PERSON FIELDS MAPPER
149
- def person_fields_mapper=(file)
150
- people.fields_mapper = file
151
- end
152
-
153
- def default_schema=(name)
154
- people.default_schema = name
155
- end
156
-
157
- # ACCOUNT PRESETS
158
- def presets_custom=(file)
159
- people.presets_custom = file
160
- end
161
-
162
- def presets_map=(file)
163
- people.presets_map = file
164
- end
165
-
166
- # CUSTOM PERSON PARSERS
167
- def person_parser(format: :csv, &block)
168
- people.add_parser(format: format, &block)
169
- end
170
-
171
- # CUSTOM USE CASES
172
- def use_cases(&block)
173
- usecases.add(&block)
174
- end
175
-
176
- end
177
- end
178
- end
179
-
180
- require_relative 'session_config/api'
181
- require_relative 'session_config/apis'
182
- require_relative 'session_config/logger'
183
- require_relative 'session_config/mailer'
184
- require_relative 'session_config/s3_storage'
185
- require_relative 'session_config/files'
186
- require_relative 'session_config/people'
187
- require_relative 'session_config/use_cases'
@@ -1,47 +0,0 @@
1
- module Eco
2
- module API
3
- class SessionConfig
4
- class Api < Hash
5
-
6
- def initialize(key:, host:, version:, mode: :local, root:)
7
- super(nil)
8
- @root = root
9
- self["key"] = key
10
- self["host"] = host
11
- self["version"] = version
12
- self["mode"] = mode
13
- end
14
-
15
- def key
16
- self["key"]
17
- end
18
-
19
- def host
20
- self["host"]
21
- end
22
-
23
- def mode=(mode)
24
- self["mode"] = (mode == :remote)? :remote : :local
25
- end
26
-
27
- def mode
28
- self["mode"]
29
- end
30
-
31
- def local?
32
- mode == :local
33
- end
34
-
35
- def remote?
36
- !local?
37
- end
38
-
39
- def version
40
- self["version"]
41
- end
42
-
43
-
44
- end
45
- end
46
- end
47
- end
@@ -1,89 +0,0 @@
1
- module Eco
2
- module API
3
- class SessionConfig
4
- class Apis < Hash
5
-
6
- def initialize(root:)
7
- super(nil)
8
- @root = root
9
- end
10
-
11
- def apis
12
- self["apis"] ||= {}
13
- end
14
-
15
- def apis?
16
- apis.keys.length > 0
17
- end
18
-
19
- def defined?(name)
20
- apis.key?(name)
21
- end
22
-
23
- def any_defined?(*names)
24
- [names].flatten.any? do |name|
25
- self.defined?(name)
26
- end
27
- end
28
-
29
- def add(name, key:, host:, version: :internal, mode: :local)
30
- apis[name] = SessionConfig::Api.new(
31
- key: key,
32
- host: host,
33
- version: version,
34
- mode: mode,
35
- root: self
36
- )
37
- self
38
- end
39
-
40
- def active_name=(name)
41
- raise "'#{name}' Api environment not defined" if !apis[name]
42
- self["active-name"] = name
43
- self["active-api"] = apis[name]
44
- self
45
- end
46
-
47
- def active_name
48
- self["active-name"]
49
- end
50
-
51
- # you can create multiple apis under same root_name (same org)
52
- def active_root_name
53
- active_name.split("-").first
54
- end
55
-
56
- def active_api
57
- self["active-api"]
58
- end
59
-
60
- def service_up?
61
- api_klass = (active_api.version == :external)? Ecoportal::API::External : Ecoportal::API::Internal
62
- @api_test ||= api_klass.new("foobar", host: active_api.host, logger: ::Logger.new(IO::NULL))
63
- status = @api_test.client.get("/policy_groups").status
64
- # 401 Unauthorized "Permission denied. API key may be invalid."
65
- status == 401
66
- end
67
-
68
- def api(logger = ::Logger.new(IO::NULL), force_new: false)
69
- key = active_api.key
70
- host = active_api.host
71
- mode = active_api.mode
72
- version = active_api.version
73
- return @api if (!force_new) && @api && key == @key && host == @host && @mode == mode && version == @version
74
-
75
- api_klass = (version == :external)? Ecoportal::API::External : Ecoportal::API::Internal
76
-
77
- @api = api_klass.new(key, host: host, logger: logger)
78
- @key = key; @host = host; @mode = mode; @version = version
79
- @api
80
- end
81
-
82
- def new_api(logger = ::Logger.new(IO::NULL))
83
- api(logger, force_new: true)
84
- end
85
-
86
- end
87
- end
88
- end
89
- end