eco-helpers 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +3 -0
  4. data/README.md +20 -0
  5. data/eco-helpers.gemspec +34 -0
  6. data/lib/eco-helpers.rb +15 -0
  7. data/lib/eco/api.rb +13 -0
  8. data/lib/eco/api/common.rb +10 -0
  9. data/lib/eco/api/common/people.rb +17 -0
  10. data/lib/eco/api/common/people/base_parser.rb +16 -0
  11. data/lib/eco/api/common/people/default_parsers.rb +40 -0
  12. data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +28 -0
  13. data/lib/eco/api/common/people/default_parsers/date_parser.rb +33 -0
  14. data/lib/eco/api/common/people/default_parsers/multi_parser.rb +33 -0
  15. data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +23 -0
  16. data/lib/eco/api/common/people/default_parsers/select_parser.rb +29 -0
  17. data/lib/eco/api/common/people/entries.rb +120 -0
  18. data/lib/eco/api/common/people/person_entry.rb +380 -0
  19. data/lib/eco/api/common/people/person_factory.rb +114 -0
  20. data/lib/eco/api/common/people/person_modifier.rb +62 -0
  21. data/lib/eco/api/common/people/person_parser.rb +140 -0
  22. data/lib/eco/api/common/people/types.rb +47 -0
  23. data/lib/eco/api/common/session.rb +15 -0
  24. data/lib/eco/api/common/session/base_session.rb +46 -0
  25. data/lib/eco/api/common/session/environment.rb +47 -0
  26. data/lib/eco/api/common/session/file_manager.rb +90 -0
  27. data/lib/eco/api/common/session/logger.rb +105 -0
  28. data/lib/eco/api/common/session/mailer.rb +92 -0
  29. data/lib/eco/api/common/session/s3_uploader.rb +110 -0
  30. data/lib/eco/api/common/version_patches.rb +11 -0
  31. data/lib/eco/api/common/version_patches/external_person.rb +11 -0
  32. data/lib/eco/api/eco_faker.rb +59 -0
  33. data/lib/eco/api/organization.rb +13 -0
  34. data/lib/eco/api/organization/account.rb +23 -0
  35. data/lib/eco/api/organization/people.rb +118 -0
  36. data/lib/eco/api/organization/policy_groups.rb +51 -0
  37. data/lib/eco/api/organization/preferences.rb +28 -0
  38. data/lib/eco/api/organization/preferences_reference.json +23 -0
  39. data/lib/eco/api/organization/presets.rb +138 -0
  40. data/lib/eco/api/organization/presets_backup.rb +220 -0
  41. data/lib/eco/api/organization/presets_values.json +10 -0
  42. data/lib/eco/api/organization/tag_tree.rb +134 -0
  43. data/lib/eco/api/organization_old.rb +73 -0
  44. data/lib/eco/api/session.rb +180 -0
  45. data/lib/eco/api/session/batch.rb +132 -0
  46. data/lib/eco/api/session/batch_job.rb +152 -0
  47. data/lib/eco/api/session/batch_jobs.rb +131 -0
  48. data/lib/eco/api/session/batch_status.rb +138 -0
  49. data/lib/eco/api/session/task.rb +92 -0
  50. data/lib/eco/api/session_config.rb +179 -0
  51. data/lib/eco/api/session_config/api.rb +47 -0
  52. data/lib/eco/api/session_config/apis.rb +78 -0
  53. data/lib/eco/api/session_config/files.rb +30 -0
  54. data/lib/eco/api/session_config/logger.rb +54 -0
  55. data/lib/eco/api/session_config/mailer.rb +65 -0
  56. data/lib/eco/api/session_config/people.rb +89 -0
  57. data/lib/eco/api/session_config/s3_bucket.rb +62 -0
  58. data/lib/eco/api/session_config/use_cases.rb +30 -0
  59. data/lib/eco/api/usecases.rb +12 -0
  60. data/lib/eco/api/usecases/base_case.rb +14 -0
  61. data/lib/eco/api/usecases/case_data.rb +13 -0
  62. data/lib/eco/api/usecases/default_cases.rb +53 -0
  63. data/lib/eco/api/usecases/default_cases/change_email_case.rb +47 -0
  64. data/lib/eco/api/usecases/default_cases/create_details_case.rb +29 -0
  65. data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +49 -0
  66. data/lib/eco/api/usecases/default_cases/delete_case.rb +20 -0
  67. data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +24 -0
  68. data/lib/eco/api/usecases/default_cases/hris_case.rb +67 -0
  69. data/lib/eco/api/usecases/default_cases/new_email_case.rb +26 -0
  70. data/lib/eco/api/usecases/default_cases/new_id_case.rb +26 -0
  71. data/lib/eco/api/usecases/default_cases/refresh_presets.rb +25 -0
  72. data/lib/eco/api/usecases/default_cases/reinvite_case.rb +22 -0
  73. data/lib/eco/api/usecases/default_cases/remove_account_case.rb +36 -0
  74. data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +24 -0
  75. data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +44 -0
  76. data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +39 -0
  77. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +36 -0
  78. data/lib/eco/api/usecases/default_cases/update_details_case.rb +30 -0
  79. data/lib/eco/api/usecases/default_cases/upsert_account_case.rb +35 -0
  80. data/lib/eco/api/usecases/use_case.rb +177 -0
  81. data/lib/eco/api/usecases/use_group.rb +104 -0
  82. data/lib/eco/cli.rb +9 -0
  83. data/lib/eco/cli/input.rb +109 -0
  84. data/lib/eco/cli/input_multi.rb +137 -0
  85. data/lib/eco/cli/root.rb +8 -0
  86. data/lib/eco/cli/session.rb +9 -0
  87. data/lib/eco/cli/session/batch.rb +9 -0
  88. data/lib/eco/common.rb +7 -0
  89. data/lib/eco/common/base_cli.rb +116 -0
  90. data/lib/eco/common/language.rb +9 -0
  91. data/lib/eco/data.rb +9 -0
  92. data/lib/eco/data/crypto.rb +7 -0
  93. data/lib/eco/data/crypto/encryption.rb +318 -0
  94. data/lib/eco/data/files.rb +10 -0
  95. data/lib/eco/data/files/directory.rb +93 -0
  96. data/lib/eco/data/files/file_pattern.rb +32 -0
  97. data/lib/eco/data/files/helpers.rb +90 -0
  98. data/lib/eco/data/mapper.rb +54 -0
  99. data/lib/eco/data/random.rb +10 -0
  100. data/lib/eco/data/random/distribution.rb +133 -0
  101. data/lib/eco/data/random/fake.rb +320 -0
  102. data/lib/eco/data/random/values.rb +80 -0
  103. data/lib/eco/language.rb +12 -0
  104. data/lib/eco/language/curry.rb +28 -0
  105. data/lib/eco/language/hash_transform.rb +68 -0
  106. data/lib/eco/language/hash_transform_modifier.rb +114 -0
  107. data/lib/eco/language/match.rb +30 -0
  108. data/lib/eco/language/match_modifier.rb +190 -0
  109. data/lib/eco/language/models.rb +11 -0
  110. data/lib/eco/language/models/attribute_parser.rb +38 -0
  111. data/lib/eco/language/models/collection.rb +181 -0
  112. data/lib/eco/language/models/modifier.rb +68 -0
  113. data/lib/eco/language/models/wrap.rb +114 -0
  114. data/lib/eco/language/values_at.rb +159 -0
  115. data/lib/eco/lexic/dictionary.rb +33 -0
  116. data/lib/eco/lexic/dictionary/dictionary.txt +355484 -0
  117. data/lib/eco/lexic/dictionary/tags.json +38 -0
  118. data/lib/eco/scripting.rb +30 -0
  119. data/lib/eco/scripting/README.md +11 -0
  120. data/lib/eco/scripting/arguments.rb +40 -0
  121. data/lib/eco/tester.rb +97 -0
  122. data/lib/eco/version.rb +3 -0
  123. metadata +325 -0
@@ -0,0 +1,179 @@
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 s3bucket
25
+ self["s3_bucket"] ||= SessionConfig::S3Bucket.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 run_mode=(mode)
71
+ apis.active_api.mode = mode
72
+ end
73
+
74
+ def run_mode_local?
75
+ apis.active_api.local?
76
+ end
77
+
78
+ def run_mode_remote?
79
+ apis.active_api.remote?
80
+ end
81
+
82
+ def apis?
83
+ apis.apis?
84
+ end
85
+
86
+ def add_api(name, **kargs)
87
+ apis.add(name, **kargs)
88
+ self
89
+ end
90
+
91
+ def active_api(name)
92
+ apis.active_name = name
93
+ self
94
+ end
95
+
96
+ def api(logger = ::Logger.new(IO::NULL))
97
+ apis.api(logger)
98
+ end
99
+
100
+ def policy_groups
101
+ policy_groups = api&.policy_groups.to_a.compact
102
+ Eco::API::Organization::PolicyGroups.new(policy_groups)
103
+ end
104
+
105
+ # FILES
106
+ def working_directory=(path)
107
+ files.working_directory = path
108
+ end
109
+
110
+ def file_timestamp_pattern=(pattern)
111
+ files.timestamp_pattern = pattern
112
+ end
113
+
114
+ def file_manager
115
+ Eco::API::Common::Session::FileManager.new(self)
116
+ end
117
+
118
+ def require(file)
119
+ require_relative "#{File.expand_path(file_manager.dir.file(file))}"
120
+ end
121
+
122
+ # ORG
123
+ def tagtree=(file)
124
+ org["tagtree"] = file
125
+ end
126
+
127
+ # PEOPLE
128
+ def discarded_people_file=(value)
129
+ people.discarded_people_file = value
130
+ end
131
+
132
+ def people_cache=(file)
133
+ people.cache = file
134
+ end
135
+
136
+ def requests_backup_folder=(folder)
137
+ people.requests_folder = folder
138
+ end
139
+
140
+ # PERSON FIELDS MAPPER
141
+ def person_fields_mapper=(file)
142
+ people.fields_mapper = file
143
+ end
144
+
145
+ def default_schema=(name)
146
+ people.default_schema = name
147
+ end
148
+
149
+ # ACCOUNT PRESETS
150
+ def presets_custom=(file)
151
+ people.presets_custom = file
152
+ end
153
+
154
+ def presets_map=(file)
155
+ people.presets_map = file
156
+ end
157
+
158
+ # CUSTOM PERSON PARSERS
159
+ def person_parser(format: :csv, &block)
160
+ people.parser(format: format, &block)
161
+ end
162
+
163
+ # CUSTOM USE CASES
164
+ def use_cases(&block)
165
+ usecases.add(&block)
166
+ end
167
+
168
+ end
169
+ end
170
+ end
171
+
172
+ require_relative 'session_config/api'
173
+ require_relative 'session_config/apis'
174
+ require_relative 'session_config/logger'
175
+ require_relative 'session_config/mailer'
176
+ require_relative 'session_config/s3_bucket'
177
+ require_relative 'session_config/files'
178
+ require_relative 'session_config/people'
179
+ require_relative 'session_config/use_cases'
@@ -0,0 +1,47 @@
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
@@ -0,0 +1,78 @@
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
+ self["apis"]
14
+ end
15
+
16
+ def apis?
17
+ apis.keys.length > 0
18
+ end
19
+
20
+ def defined?(name)
21
+ apis.key?(name)
22
+ end
23
+
24
+ def any_defined?(*names)
25
+ [names].flatten.any? do |name|
26
+ self.defined?(name)
27
+ end
28
+ end
29
+
30
+ def add(name, key:, host:, version: :internal, mode: :local)
31
+ apis[name] = SessionConfig::Api.new(
32
+ key: key,
33
+ host: host,
34
+ version: version,
35
+ mode: mode,
36
+ root: self
37
+ )
38
+ self
39
+ end
40
+
41
+ def active_name=(name)
42
+ raise "'#{name}' Api environment not defined" if !apis[name]
43
+ self["active-name"] = name
44
+ self["active-api"] = apis[name]
45
+ self
46
+ end
47
+
48
+ def active_name
49
+ self["active-name"]
50
+ end
51
+
52
+ # you can create multiple apis under same root_name (same org)
53
+ def active_root_name
54
+ active_name.split("-").first
55
+ end
56
+
57
+ def active_api
58
+ self["active-api"]
59
+ end
60
+
61
+ def api(logger = ::Logger.new(IO::NULL))
62
+ key = active_api.key
63
+ host = active_api.host
64
+ mode = active_api.mode
65
+ version = active_api.version
66
+ return @api if @api && key == @key && host == @host && @mode == mode && version == @version
67
+
68
+ api_klass = (version == :external)? Ecoportal::API::External : Ecoportal::API::Internal
69
+
70
+ @api = api_klass.new(key, host: host, logger: logger)
71
+ @key = key; @host = host; @mode = mode; @version = version
72
+ @api
73
+ end
74
+
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,30 @@
1
+ module Eco
2
+ module API
3
+ class SessionConfig
4
+ class Files < Hash
5
+
6
+ def initialize(root:)
7
+ super(nil)
8
+ @root = root
9
+ end
10
+
11
+ def working_directory=(path)
12
+ self["dir"] = path
13
+ end
14
+
15
+ def working_directory
16
+ self["dir"]
17
+ end
18
+
19
+ def timestamp_pattern=(pattern)
20
+ self["timestamp_pattern"] = pattern
21
+ end
22
+
23
+ def timestamp_pattern
24
+ self["timestamp_pattern"]
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,54 @@
1
+ module Eco
2
+ module API
3
+ class SessionConfig
4
+ class Logger < Hash
5
+
6
+ def initialize(root:)
7
+ super(nil)
8
+ @root = root
9
+ end
10
+
11
+ def console_level=(value)
12
+ self["console_level"] = value
13
+ end
14
+
15
+ def console_level
16
+ self["console_level"]
17
+ end
18
+
19
+ def file_level=(value)
20
+ self["file_level"] = value
21
+ end
22
+
23
+ def file_level
24
+ self["file_level"]
25
+ end
26
+
27
+ def file=(file)
28
+ self["file"] = file
29
+ end
30
+
31
+ def file
32
+ self["file"]
33
+ end
34
+
35
+ def timestamp_console=(value)
36
+ self["timestamp_console"] = value
37
+ end
38
+
39
+ def timestamp_console
40
+ self["timestamp_console"]
41
+ end
42
+
43
+ def log_connection=(value)
44
+ self["log_connection"] = value
45
+ end
46
+
47
+ def log_connection?
48
+ !!self["log_connection"]
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,65 @@
1
+ module Eco
2
+ module API
3
+ class SessionConfig
4
+ class Mailer < Hash
5
+
6
+ def initialize(root:)
7
+ super(nil)
8
+ @root = root
9
+ end
10
+
11
+ def from=(value)
12
+ self["from"] = value
13
+ end
14
+
15
+ def from
16
+ self["from"]
17
+ end
18
+
19
+ def access_key_id=(key)
20
+ self["access_key_id"] = key
21
+ end
22
+
23
+ def access_key_id
24
+ self["access_key_id"]
25
+ end
26
+
27
+ def secret_access_key=(key)
28
+ self["secret_access_key"] = key
29
+ end
30
+
31
+ def secret_access_key
32
+ self["secret_access_key"]
33
+ end
34
+
35
+ # AWS::SES::Client
36
+ def region=(region)
37
+ self["region"] = region
38
+ end
39
+
40
+ def region
41
+ self["region"]
42
+ end
43
+
44
+ # AWS::SES::Base
45
+ def server=(domain)
46
+ self["server"] = domain
47
+ end
48
+
49
+ def server
50
+ self["server"]
51
+ end
52
+
53
+ # AWS::SES::Base
54
+ def message_id_domain=(domain)
55
+ self["message_id_domain"] = domain
56
+ end
57
+
58
+ def message_id_domain
59
+ self["message_id_domain"]
60
+ end
61
+
62
+ end
63
+ end
64
+ end
65
+ end