eco-helpers 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/README.md +20 -0
- data/eco-helpers.gemspec +34 -0
- data/lib/eco-helpers.rb +15 -0
- data/lib/eco/api.rb +13 -0
- data/lib/eco/api/common.rb +10 -0
- data/lib/eco/api/common/people.rb +17 -0
- data/lib/eco/api/common/people/base_parser.rb +16 -0
- data/lib/eco/api/common/people/default_parsers.rb +40 -0
- data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +28 -0
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +33 -0
- data/lib/eco/api/common/people/default_parsers/multi_parser.rb +33 -0
- data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +23 -0
- data/lib/eco/api/common/people/default_parsers/select_parser.rb +29 -0
- data/lib/eco/api/common/people/entries.rb +120 -0
- data/lib/eco/api/common/people/person_entry.rb +380 -0
- data/lib/eco/api/common/people/person_factory.rb +114 -0
- data/lib/eco/api/common/people/person_modifier.rb +62 -0
- data/lib/eco/api/common/people/person_parser.rb +140 -0
- data/lib/eco/api/common/people/types.rb +47 -0
- data/lib/eco/api/common/session.rb +15 -0
- data/lib/eco/api/common/session/base_session.rb +46 -0
- data/lib/eco/api/common/session/environment.rb +47 -0
- data/lib/eco/api/common/session/file_manager.rb +90 -0
- data/lib/eco/api/common/session/logger.rb +105 -0
- data/lib/eco/api/common/session/mailer.rb +92 -0
- data/lib/eco/api/common/session/s3_uploader.rb +110 -0
- data/lib/eco/api/common/version_patches.rb +11 -0
- data/lib/eco/api/common/version_patches/external_person.rb +11 -0
- data/lib/eco/api/eco_faker.rb +59 -0
- data/lib/eco/api/organization.rb +13 -0
- data/lib/eco/api/organization/account.rb +23 -0
- data/lib/eco/api/organization/people.rb +118 -0
- data/lib/eco/api/organization/policy_groups.rb +51 -0
- data/lib/eco/api/organization/preferences.rb +28 -0
- data/lib/eco/api/organization/preferences_reference.json +23 -0
- data/lib/eco/api/organization/presets.rb +138 -0
- data/lib/eco/api/organization/presets_backup.rb +220 -0
- data/lib/eco/api/organization/presets_values.json +10 -0
- data/lib/eco/api/organization/tag_tree.rb +134 -0
- data/lib/eco/api/organization_old.rb +73 -0
- data/lib/eco/api/session.rb +180 -0
- data/lib/eco/api/session/batch.rb +132 -0
- data/lib/eco/api/session/batch_job.rb +152 -0
- data/lib/eco/api/session/batch_jobs.rb +131 -0
- data/lib/eco/api/session/batch_status.rb +138 -0
- data/lib/eco/api/session/task.rb +92 -0
- data/lib/eco/api/session_config.rb +179 -0
- data/lib/eco/api/session_config/api.rb +47 -0
- data/lib/eco/api/session_config/apis.rb +78 -0
- data/lib/eco/api/session_config/files.rb +30 -0
- data/lib/eco/api/session_config/logger.rb +54 -0
- data/lib/eco/api/session_config/mailer.rb +65 -0
- data/lib/eco/api/session_config/people.rb +89 -0
- data/lib/eco/api/session_config/s3_bucket.rb +62 -0
- data/lib/eco/api/session_config/use_cases.rb +30 -0
- data/lib/eco/api/usecases.rb +12 -0
- data/lib/eco/api/usecases/base_case.rb +14 -0
- data/lib/eco/api/usecases/case_data.rb +13 -0
- data/lib/eco/api/usecases/default_cases.rb +53 -0
- data/lib/eco/api/usecases/default_cases/change_email_case.rb +47 -0
- data/lib/eco/api/usecases/default_cases/create_details_case.rb +29 -0
- data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +49 -0
- data/lib/eco/api/usecases/default_cases/delete_case.rb +20 -0
- data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +24 -0
- data/lib/eco/api/usecases/default_cases/hris_case.rb +67 -0
- data/lib/eco/api/usecases/default_cases/new_email_case.rb +26 -0
- data/lib/eco/api/usecases/default_cases/new_id_case.rb +26 -0
- data/lib/eco/api/usecases/default_cases/refresh_presets.rb +25 -0
- data/lib/eco/api/usecases/default_cases/reinvite_case.rb +22 -0
- data/lib/eco/api/usecases/default_cases/remove_account_case.rb +36 -0
- data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +24 -0
- data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +44 -0
- data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +39 -0
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +36 -0
- data/lib/eco/api/usecases/default_cases/update_details_case.rb +30 -0
- data/lib/eco/api/usecases/default_cases/upsert_account_case.rb +35 -0
- data/lib/eco/api/usecases/use_case.rb +177 -0
- data/lib/eco/api/usecases/use_group.rb +104 -0
- data/lib/eco/cli.rb +9 -0
- data/lib/eco/cli/input.rb +109 -0
- data/lib/eco/cli/input_multi.rb +137 -0
- data/lib/eco/cli/root.rb +8 -0
- data/lib/eco/cli/session.rb +9 -0
- data/lib/eco/cli/session/batch.rb +9 -0
- data/lib/eco/common.rb +7 -0
- data/lib/eco/common/base_cli.rb +116 -0
- data/lib/eco/common/language.rb +9 -0
- data/lib/eco/data.rb +9 -0
- data/lib/eco/data/crypto.rb +7 -0
- data/lib/eco/data/crypto/encryption.rb +318 -0
- data/lib/eco/data/files.rb +10 -0
- data/lib/eco/data/files/directory.rb +93 -0
- data/lib/eco/data/files/file_pattern.rb +32 -0
- data/lib/eco/data/files/helpers.rb +90 -0
- data/lib/eco/data/mapper.rb +54 -0
- data/lib/eco/data/random.rb +10 -0
- data/lib/eco/data/random/distribution.rb +133 -0
- data/lib/eco/data/random/fake.rb +320 -0
- data/lib/eco/data/random/values.rb +80 -0
- data/lib/eco/language.rb +12 -0
- data/lib/eco/language/curry.rb +28 -0
- data/lib/eco/language/hash_transform.rb +68 -0
- data/lib/eco/language/hash_transform_modifier.rb +114 -0
- data/lib/eco/language/match.rb +30 -0
- data/lib/eco/language/match_modifier.rb +190 -0
- data/lib/eco/language/models.rb +11 -0
- data/lib/eco/language/models/attribute_parser.rb +38 -0
- data/lib/eco/language/models/collection.rb +181 -0
- data/lib/eco/language/models/modifier.rb +68 -0
- data/lib/eco/language/models/wrap.rb +114 -0
- data/lib/eco/language/values_at.rb +159 -0
- data/lib/eco/lexic/dictionary.rb +33 -0
- data/lib/eco/lexic/dictionary/dictionary.txt +355484 -0
- data/lib/eco/lexic/dictionary/tags.json +38 -0
- data/lib/eco/scripting.rb +30 -0
- data/lib/eco/scripting/README.md +11 -0
- data/lib/eco/scripting/arguments.rb +40 -0
- data/lib/eco/tester.rb +97 -0
- data/lib/eco/version.rb +3 -0
- metadata +325 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class SessionConfig
|
4
|
+
class People < Hash
|
5
|
+
|
6
|
+
def initialize(root:)
|
7
|
+
super(nil)
|
8
|
+
@root = root
|
9
|
+
end
|
10
|
+
|
11
|
+
def cache=(file)
|
12
|
+
self["cache"] = file
|
13
|
+
end
|
14
|
+
|
15
|
+
def cache
|
16
|
+
self["cache"]
|
17
|
+
end
|
18
|
+
|
19
|
+
# api queried logs
|
20
|
+
def requests_folder=(folder)
|
21
|
+
self["requests_folder"] = folder
|
22
|
+
end
|
23
|
+
|
24
|
+
def requests_folder
|
25
|
+
self["requests_folder"]
|
26
|
+
end
|
27
|
+
|
28
|
+
# people to exclude from update feeds
|
29
|
+
def discarded_file=(file)
|
30
|
+
self["discarded_file"] = file
|
31
|
+
end
|
32
|
+
|
33
|
+
def discarded_file
|
34
|
+
self["discarded_file"]
|
35
|
+
end
|
36
|
+
|
37
|
+
# internal-external fields map
|
38
|
+
def fields_mapper=(file)
|
39
|
+
self["fields_mapper"] = file
|
40
|
+
end
|
41
|
+
|
42
|
+
def fields_mapper
|
43
|
+
self["fields_mapper"]
|
44
|
+
end
|
45
|
+
|
46
|
+
# person model
|
47
|
+
def default_schema=(name)
|
48
|
+
self["default_schema"] = name
|
49
|
+
end
|
50
|
+
|
51
|
+
def default_schema
|
52
|
+
self["default_schema"]
|
53
|
+
end
|
54
|
+
|
55
|
+
def presets_custom=(file)
|
56
|
+
self["presets_custom"] = file
|
57
|
+
end
|
58
|
+
|
59
|
+
def presets_custom
|
60
|
+
self["presets_custom"]
|
61
|
+
end
|
62
|
+
|
63
|
+
def presets_map=(file)
|
64
|
+
self["presets_map"] = file
|
65
|
+
end
|
66
|
+
|
67
|
+
def presets_map
|
68
|
+
self["presets_map"]
|
69
|
+
end
|
70
|
+
|
71
|
+
# CUSTOM PERSON PARSERS
|
72
|
+
def person_parser(format: :csv)
|
73
|
+
self["parsers"] ||= Eco::API::Common::People::PersonParser.new
|
74
|
+
new_parsers = Eco::API::Common::People::PersonParser.new
|
75
|
+
|
76
|
+
yield(new_parsers, self)
|
77
|
+
|
78
|
+
parsers = self["parsers"][format]
|
79
|
+
self["parsers"][format] = parsers ? parsers.merge(new_parsers) : new_parsers
|
80
|
+
end
|
81
|
+
|
82
|
+
def parser(format: :csv)
|
83
|
+
self.dig("parsers", format)
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class SessionConfig
|
4
|
+
class S3Bucket < Hash
|
5
|
+
|
6
|
+
def initialize(root:)
|
7
|
+
super(nil)
|
8
|
+
@root = root
|
9
|
+
end
|
10
|
+
|
11
|
+
def name=(value)
|
12
|
+
self["name"] = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def name
|
16
|
+
self["name"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def prefix=(value)
|
20
|
+
self["prefix"] = value
|
21
|
+
end
|
22
|
+
|
23
|
+
def prefix
|
24
|
+
self["prefix"]
|
25
|
+
end
|
26
|
+
|
27
|
+
def access_key_id=(key)
|
28
|
+
self["access_key_id"] = key
|
29
|
+
end
|
30
|
+
|
31
|
+
def access_key_id
|
32
|
+
self["access_key_id"]
|
33
|
+
end
|
34
|
+
|
35
|
+
def secret_access_key=(key)
|
36
|
+
self["secret_access_key"] = key
|
37
|
+
end
|
38
|
+
|
39
|
+
def secret_access_key
|
40
|
+
self["secret_access_key"]
|
41
|
+
end
|
42
|
+
|
43
|
+
def region=(region)
|
44
|
+
self["region"] = region
|
45
|
+
end
|
46
|
+
|
47
|
+
def region
|
48
|
+
self["region"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def target_directories=(value)
|
52
|
+
self["target_directories"] = [value].flatten
|
53
|
+
end
|
54
|
+
|
55
|
+
def target_directories
|
56
|
+
self["target_directories"]
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class SessionConfig
|
4
|
+
class UseCases < Hash
|
5
|
+
|
6
|
+
def initialize(root:)
|
7
|
+
super(nil)
|
8
|
+
@root = root
|
9
|
+
end
|
10
|
+
|
11
|
+
# CUSTOM USE CASES
|
12
|
+
def add
|
13
|
+
self["use_group"] ||= Eco::API::UseCases::UseGroup.new
|
14
|
+
new_group = Eco::API::UseCases::UseGroup.new
|
15
|
+
|
16
|
+
yield(new_group, self)
|
17
|
+
|
18
|
+
group = self["use_group"]
|
19
|
+
group = group ? group.merge(new_group) : group
|
20
|
+
self["use_group"] = group
|
21
|
+
end
|
22
|
+
|
23
|
+
def use_group
|
24
|
+
self["use_group"]
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module UseCases
|
4
|
+
end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
#require_relative 'usecases/case_data'
|
9
|
+
require_relative 'usecases/base_case'
|
10
|
+
require_relative 'usecases/use_case'
|
11
|
+
require_relative 'usecases/use_group'
|
12
|
+
require_relative 'usecases/default_cases'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module UseCases
|
4
|
+
class DefaultCases < UseGroup
|
5
|
+
|
6
|
+
def initialize(*args)
|
7
|
+
super(*args)
|
8
|
+
define_defaults
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def define_defaults
|
14
|
+
ResetLandingPageCase.new(self).process
|
15
|
+
ToCsvCase.new(self).process
|
16
|
+
EmailAsIdCase.new(self).process
|
17
|
+
NewIdCase.new(self).process
|
18
|
+
NewEmailCase.new(self).process
|
19
|
+
SetSupervisorCase.new(self).process
|
20
|
+
UpdateDetailsCase.new(self).process
|
21
|
+
CreateDetailsCase.new(self).process
|
22
|
+
CreateDetailsWithSupervisorCase.new(self).process
|
23
|
+
ReinviteCase.new(self).process
|
24
|
+
DeleteCase.new(self).process
|
25
|
+
RemoveAccountCase.new(self).process
|
26
|
+
RefreshPresets.new(self).process
|
27
|
+
ChangeEMailCase.new(self).process
|
28
|
+
SetDefaultTagCase.new(self).process
|
29
|
+
UpsertAccountCase.new(self).process
|
30
|
+
HrisCase.new(self).process
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
require_relative 'default_cases/reset_landing_page_case'
|
38
|
+
require_relative 'default_cases/to_csv_case'
|
39
|
+
require_relative 'default_cases/email_as_id_case'
|
40
|
+
require_relative 'default_cases/new_id_case'
|
41
|
+
require_relative 'default_cases/new_email_case'
|
42
|
+
require_relative 'default_cases/set_supervisor_case'
|
43
|
+
require_relative 'default_cases/update_details_case'
|
44
|
+
require_relative 'default_cases/create_details_case'
|
45
|
+
require_relative 'default_cases/create_details_with_supervisor_case'
|
46
|
+
require_relative 'default_cases/reinvite_case'
|
47
|
+
require_relative 'default_cases/delete_case'
|
48
|
+
require_relative 'default_cases/remove_account_case'
|
49
|
+
require_relative 'default_cases/refresh_presets'
|
50
|
+
require_relative 'default_cases/change_email_case'
|
51
|
+
require_relative 'default_cases/set_default_tag_case'
|
52
|
+
require_relative 'default_cases/upsert_account_case'
|
53
|
+
require_relative 'default_cases/hris_case'
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module UseCases
|
4
|
+
class DefaultCases
|
5
|
+
class ChangeEMailCase < BaseCase
|
6
|
+
|
7
|
+
def process
|
8
|
+
@cases.define("change-email", type: :sync) do |entries, people, session|
|
9
|
+
remove = session.job_group("main").new("remove account", type: :update, sets: :account)
|
10
|
+
change = session.job_group("main").new("change email", type: :update, sets: :core)
|
11
|
+
add_account = session.job_group("post").new("add account", type: :update, sets: :account)
|
12
|
+
|
13
|
+
entries.each.with_index do |entry, i|
|
14
|
+
person = people.find(entry)
|
15
|
+
|
16
|
+
if !person
|
17
|
+
session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
|
18
|
+
else
|
19
|
+
unless entry.email.downcase == person.email
|
20
|
+
account = person.account
|
21
|
+
person.account = nil
|
22
|
+
remove.add(person)
|
23
|
+
|
24
|
+
new_email = entry.email
|
25
|
+
change.add(person) do |person|
|
26
|
+
person.sync
|
27
|
+
person.email = new_email
|
28
|
+
person
|
29
|
+
end
|
30
|
+
|
31
|
+
add_account.add(person) do |person|
|
32
|
+
person.sync
|
33
|
+
person.account = account
|
34
|
+
person
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module UseCases
|
4
|
+
class DefaultCases
|
5
|
+
class CreateDetailsCase < UseCases::BaseCase
|
6
|
+
|
7
|
+
def process
|
8
|
+
@cases.define("create-details", type: :sync) do |entries, people, session, options|
|
9
|
+
creation = session.job_group("main").new("create", type: :create, sets: [:core, :details])
|
10
|
+
|
11
|
+
entries.each.with_index do |entry, i|
|
12
|
+
if person = people.find(entry)
|
13
|
+
session.logger.error("Entry(#{i}) - this person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}")
|
14
|
+
else
|
15
|
+
person = session.new_person
|
16
|
+
entry.set_core(person, exclude: "supervisor_id")
|
17
|
+
entry.set_details(person)
|
18
|
+
|
19
|
+
creation.add(person)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module UseCases
|
4
|
+
class DefaultCases
|
5
|
+
class CreateDetailsWithSupervisorCase < UseCases::BaseCase
|
6
|
+
|
7
|
+
def process
|
8
|
+
# good candidate to do @cases.case("create-details").use.chain(@cases.case("set-supervisor").use)
|
9
|
+
@cases.define("create-details-with-supervisor", type: :sync) do |entries, people, session|
|
10
|
+
creation = session.job_group("main").new("create", type: :create, sets: [:core, :details])
|
11
|
+
supers = session.job_group("post").new("supers", type: :update, sets: :core)
|
12
|
+
|
13
|
+
entries.each.with_index do |entry, i|
|
14
|
+
if person = people.find(entry)
|
15
|
+
session.logger.error("Entry(#{i}) - this person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}")
|
16
|
+
else
|
17
|
+
person = session.new_person
|
18
|
+
entry.set_core(person, exclude: "supervisor_id")
|
19
|
+
entry.set_details(person)
|
20
|
+
|
21
|
+
creation.add(person)
|
22
|
+
|
23
|
+
# set supervisor
|
24
|
+
if !(sup_id = entry.supervisor_id)
|
25
|
+
person.supervisor_id = nil
|
26
|
+
else
|
27
|
+
if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
|
28
|
+
person.supervisor_id = supervisor.id
|
29
|
+
else
|
30
|
+
# delay setting supervisor if does not exit
|
31
|
+
supers.add(person) do |person|
|
32
|
+
#person = session.new_person(person: person.doc)
|
33
|
+
person.sync
|
34
|
+
person.supervisor_id = sup_id
|
35
|
+
person
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module UseCases
|
4
|
+
class DefaultCases
|
5
|
+
class DeleteCase < BaseCase
|
6
|
+
|
7
|
+
def process
|
8
|
+
@cases.define("delete", type: :transform) do |people, session|
|
9
|
+
delete = session.job_group("main").new("delete", type: :delete, sets: [:core, :details, :account])
|
10
|
+
people.map do |person|
|
11
|
+
delete.add(person)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module UseCases
|
4
|
+
class DefaultCases
|
5
|
+
class EmailAsIdCase < BaseCase
|
6
|
+
|
7
|
+
def process
|
8
|
+
@cases.define("email-as-id", type: :transform) do |people, session|
|
9
|
+
job = session.job_group("main").new("update", type: :update, sets: :core)
|
10
|
+
|
11
|
+
people.each do |person|
|
12
|
+
person.external_id = person.email
|
13
|
+
job.add(person)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|