polyseerio 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +12 -0
  4. data/Gemfile +4 -0
  5. data/HISTORY.md +3 -0
  6. data/LICENSE +21 -0
  7. data/Makefile +43 -0
  8. data/README.md +307 -0
  9. data/lib/agent/agent.rb +35 -0
  10. data/lib/agent/default_config.rb +51 -0
  11. data/lib/agent/enum.rb +35 -0
  12. data/lib/agent/executor.rb +62 -0
  13. data/lib/agent/handler/event.rb +32 -0
  14. data/lib/agent/handler/expectation.rb +10 -0
  15. data/lib/agent/handler/fact.rb +18 -0
  16. data/lib/agent/handler/index.rb +15 -0
  17. data/lib/agent/handler/interface.rb +11 -0
  18. data/lib/agent/handler/metric.rb +23 -0
  19. data/lib/agent/handler/process.rb +10 -0
  20. data/lib/agent/helper.rb +137 -0
  21. data/lib/client.rb +47 -0
  22. data/lib/constant.rb +12 -0
  23. data/lib/enum.rb +82 -0
  24. data/lib/helper.rb +153 -0
  25. data/lib/middleware.rb +51 -0
  26. data/lib/polyseerio.rb +115 -0
  27. data/lib/request.rb +84 -0
  28. data/lib/resource/base.rb +73 -0
  29. data/lib/resource/definition.rb +166 -0
  30. data/lib/resource/factory.rb +149 -0
  31. data/lib/resource/helper.rb +91 -0
  32. data/lib/resource/routine.rb +26 -0
  33. data/lib/response.rb +27 -0
  34. data/lib/sdk/factory.rb +34 -0
  35. data/lib/sdk/helper.rb +50 -0
  36. data/lib/sdk/method/add_fact.rb +14 -0
  37. data/lib/sdk/method/add_gauge.rb +14 -0
  38. data/lib/sdk/method/attach.rb +26 -0
  39. data/lib/sdk/method/check.rb +11 -0
  40. data/lib/sdk/method/detach.rb +11 -0
  41. data/lib/sdk/method/execute.rb +11 -0
  42. data/lib/sdk/method/fact.rb +11 -0
  43. data/lib/sdk/method/gauge.rb +11 -0
  44. data/lib/sdk/method/index.rb +10 -0
  45. data/lib/sdk/method/message.rb +11 -0
  46. data/lib/sdk/method/remove.rb +11 -0
  47. data/lib/sdk/method/save.rb +32 -0
  48. data/lib/sdk/method/to_json.rb +11 -0
  49. data/lib/sdk/method/trigger.rb +17 -0
  50. data/lib/sdk/static/attach.rb +11 -0
  51. data/lib/sdk/static/check.rb +11 -0
  52. data/lib/sdk/static/create.rb +21 -0
  53. data/lib/sdk/static/detach.rb +11 -0
  54. data/lib/sdk/static/execute.rb +11 -0
  55. data/lib/sdk/static/find.rb +20 -0
  56. data/lib/sdk/static/find_by_id.rb +21 -0
  57. data/lib/sdk/static/find_by_name.rb +28 -0
  58. data/lib/sdk/static/index.rb +10 -0
  59. data/lib/sdk/static/message.rb +15 -0
  60. data/lib/sdk/static/remove.rb +21 -0
  61. data/lib/sdk/static/trigger.rb +17 -0
  62. data/lib/sdk/static/update.rb +18 -0
  63. data/lib/url_builder.rb +55 -0
  64. data/polyseerio.gemspec +32 -0
  65. metadata +205 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8358926a5d67bc28c9bc79a638d5095d8c69c33c
4
+ data.tar.gz: d208509a37081b80f9fdd863b87d086f45ee6f16
5
+ SHA512:
6
+ metadata.gz: 34422281004974f2fa7197f75523651cc32483cc042b724ec6d72fdb81c180c8923a8747c27686374b9238b0ede340917bc5df44b708ec1e6d564a27a94176fe
7
+ data.tar.gz: 4980c3839bd68d77c8267ef361e4962c8a1b29938ab385f261fbe18b44d27624ef3869162d50e91d43c5737b15f36017879f9a76d1f26d3474e5304251d2debb
@@ -0,0 +1 @@
1
+ *.gem
@@ -0,0 +1,12 @@
1
+ Style/ExtraSpacing:
2
+ AllowForAlignment: true
3
+ Metrics/ModuleLength:
4
+ Enabled: false
5
+ Metrics/MethodLength:
6
+ Max: 100
7
+ Metrics/AbcSize:
8
+ Max: 50
9
+ Style/AccessModifierIndentation:
10
+ Enabled: false
11
+ Metrics/BlockLength:
12
+ Max: 100
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ gemspec development_group: :dev
@@ -0,0 +1,3 @@
1
+ 0.0.0 / 2016-00-00
2
+ ==================
3
+ * pending initial release
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Kognizant
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,43 @@
1
+ BUILD_ENV?=development
2
+
3
+ all: install test build
4
+
5
+ install:
6
+ bundle install
7
+
8
+ lint:
9
+ ifeq ($(BUILD_ENV),ci)
10
+ rubocop
11
+ else
12
+ rubocop
13
+ endif
14
+
15
+ unit-test:
16
+ ifeq ($(BUILD_ENV),ci)
17
+ rspec ./spec/unit
18
+ else
19
+ rspec ./spec/unit
20
+ endif
21
+
22
+ integration-test:
23
+ ifeq ($(BUILD_ENV),ci)
24
+ rspec ./spec/integration
25
+ else
26
+ rspec ./spec/integration
27
+ endif
28
+
29
+ validation-test:
30
+ ifeq ($(BUILD_ENV),ci)
31
+ rspec ./spec/validation
32
+ else
33
+ rspec ./spec/validation
34
+ endif
35
+
36
+ test: lint unit-test integration-test validation-test
37
+
38
+ build:
39
+ rm -f polyseerio-*.gem
40
+ gem build polyseerio.gemspec
41
+ gem install polyseerio-*.gem
42
+
43
+ .PHONY: install lint unit-test integration-test validation-test build
@@ -0,0 +1,307 @@
1
+ ![Alt text](/asset/polyseerio_sdk_ruby.png?raw=true "Polyseer.io SDK for Ruby.")
2
+
3
+ # Polyseer.io SDK for Ruby
4
+
5
+ The official Polyseer.io SDK for Ruby. Detailed API information can be found at (https://polyseer.io/documentation).
6
+
7
+ ## Requirements
8
+ - Ruby
9
+ - gem
10
+
11
+ ## Installation
12
+
13
+ To install, run:
14
+
15
+ gem install polyseerio
16
+
17
+ To add to your project Gemfile, insert:
18
+
19
+ gem 'polyseerio'
20
+
21
+ ## Example
22
+
23
+ Examples are available in /example
24
+
25
+ ## Environment Variables
26
+
27
+ Certain values can be set in environment variables:
28
+
29
+ * POLYSEERIO_TOKEN access-token used for API calls
30
+ * RAILS_ENV the current environment
31
+
32
+ ## Usage
33
+
34
+ The SDK provides an agent that allows for immediate integration as well as
35
+ direct platform interactions.
36
+
37
+ Example: (Quick start)
38
+
39
+ include 'polyseerio'
40
+
41
+ client = Polyseerio.start
42
+ client.instance.fact('foo', 'bar').execute.value
43
+
44
+ Example: (SDK)
45
+
46
+ include 'polyseerio'
47
+
48
+ client = Polyseerio.make
49
+ client.Event.create(name: 'Testing').execute.value
50
+
51
+ ## Design
52
+
53
+ All Polyseer.io SDK's make use of Promises for async calls. Promises allow for
54
+ delaying and chaining async work.
55
+
56
+ * Provides direct platform calls as well as a Polyseer.io Ruby agent.
57
+ * All client SDK calls return a Concurrent::Promise.
58
+ * Supports functional style programming.
59
+ * Supports object-oriented style programming.
60
+ * ORM style instances. E.g. environment.save(), alert.trigger();
61
+ * A resources environment can be deduced or explicitly passed to SDK calls through the options param.
62
+ * API calls made using the https:// protocol.
63
+
64
+ ## Example
65
+
66
+ Examples are available in /example
67
+
68
+ ## SDK Resources
69
+
70
+ Use of the SDK starts with the creation of a client. To construct a client
71
+ instance, you may call either Polyseerio.start or Polyseerio.make. Once a
72
+ client has been created you may use any of its resources.
73
+
74
+ ### Polyseerio
75
+
76
+ * Polyseerio
77
+ * .`start(options = {}) ⇒ Polyseerio::Client`
78
+ * Create a client and start an Agent.
79
+ * `options (Hash)`
80
+ - `:env` environment variable that holds the current environment
81
+ - `:token` an api token
82
+ - `:token_env` if no token is provided, this environment variable will be checked
83
+ - `:agent` a hash that will be used when starting this client's agent
84
+ - `:upsert_env` if an environment cannot be found it will be created
85
+ - `:version` api version to use
86
+ - `:timeout` integer containing number of ms to wait for server responses
87
+ - `:deduce` if the environment should be deduced when not supplied
88
+ * .`make(options = {}) ⇒ Polyseerio::Client`
89
+ * Create a client.
90
+ * `options (Hash)` see Polyseerio.start options.
91
+ * `::Enum`
92
+ * `::Color (Hash)` platform color values
93
+ * `::Determiner (Hash)` expectation deteriner types
94
+ * `::Direction (Hash)` instance direction types
95
+ * `::Icon (Hash)` platform icon types
96
+ * `::Protocol (Hash)` alert protocol types
97
+ * `::Strategy (Hash)` instance attachment strategies
98
+ * `::Subtype (Hash)` instance subtypes
99
+ * `::Type (Hash)` resource types
100
+
101
+ ### Polyseerio::Client
102
+
103
+ * client
104
+ * `.current_environment ⇒ client.Environment`
105
+ * Resolves the current environment **IF** it has been deduced.
106
+ * `.start_agent(options = {}) ⇒ Polyseerio::Client`
107
+ * Starts the Polyseer.io agent. Will use passed options or config.agent from client construction.
108
+ * `.Alert`
109
+ * `.Channel`
110
+ * `.Environment`
111
+ * `.Event`
112
+ * `.Expectation`
113
+ * `.Instance`
114
+ * `.LogicBlock`
115
+ * `.Member`
116
+ * `.Settings`
117
+ * `.Task`
118
+
119
+ ### Alert
120
+
121
+ * .Alert
122
+ * `.create(attributes = {}, options = {})`
123
+ * `.find(query = {}, options = {})`
124
+ * `.find_by_id(id, options = {})`
125
+ * `.find_by_name(name, options = {})`
126
+ * `.new(attributes = {}) ⇒ client.Alert`
127
+ * `.remove()`
128
+ * `.save()`
129
+ * `.trigger(payload = {})`
130
+ * `.remove(id, options = {})`
131
+ * `.trigger(id, payload, options = {})`
132
+ * `.update(id, updates, options = {})`
133
+
134
+ ### Channel
135
+
136
+ * .Channel
137
+ * `.create(attributes = {}, options = {})`
138
+ * `.find(query = {}, options = {})`
139
+ * `.find_by_id(id, options = {})`
140
+ * `.find_by_name(name, options = {})`
141
+ * `.message(id, content, options = {})`
142
+ * `.new(attributes = {}) ⇒ client.Channel`
143
+ * `.message(content)`
144
+ * `.remove()`
145
+ * `.save()`
146
+ * `.remove(id, options = {})`
147
+ * `.update(id, updates, options = {})`
148
+
149
+ ### Environment
150
+
151
+ * .Environment
152
+ * `.create(attributes = {}, options = {})`
153
+ * `.find(query = {}, options = {})`
154
+ * `.find_by_id(id, options = {})`
155
+ * `.find_by_name(name, options = {})`
156
+ * `.message(id, content, options = {})`
157
+ * `.new(attributes = {}) ⇒ client.Environment`
158
+ * `.message(content)`
159
+ * `.remove()`
160
+ * `.save()`
161
+ * `.remove(id, options = {})`
162
+ * `.update(id, payload = {}, options = {})`
163
+
164
+ ### Event
165
+
166
+ * .Event
167
+ * `.create(attributes = {}, options = {})`
168
+ * `.find(query = {}, options = {})`
169
+ * `.find_by_id(id, options = {})`
170
+ * `.new(attributes = {}) ⇒ client.Event`
171
+ * `.save()`
172
+
173
+ ### Expectation
174
+
175
+ * .Expectation
176
+ * `.check(id, options = {})`
177
+ * `.create(attributes = {}, options = {})`
178
+ * `.find(query = {}, options = {})`
179
+ * `.find_by_id(id, options = {})`
180
+ * `.find_by_name(name, options = {})`
181
+ * `.new(attributes = {}) ⇒ client.Expectation`
182
+ * `.check()`
183
+ * `.remove()`
184
+ * `.save()`
185
+ * `.remove(id, options = {})`
186
+ * `.update(id, updates, options = {})`
187
+
188
+ ### Instance
189
+
190
+ * .Instance
191
+ * `.attach(options = {})`
192
+ * `.create(attributes = {}, options = {})`
193
+ * `.find(query = {}, options = {})`
194
+ * `.find_by_id(id, options = {})`
195
+ * `.find_by_name(name, options = {})`
196
+ * `.new(attributes = {}) ⇒ client.Instance`
197
+ * `.add_fact(key, resolver)`
198
+ * Add a fact to the attach monitoring loop.
199
+ * `key (symbol)`
200
+ * `resolver (string|number|block)`
201
+ * `.add_gauge(key, resolver)`
202
+ * Add a gauge to the attach monitoring loop.
203
+ * `key (symbol)`
204
+ * `resolver (string|number|block)`
205
+ * `.attach()`
206
+ * Start inbound monitoring.
207
+ * `.detach()`
208
+ * Terminate inbound monitoring.
209
+ * `.fact(key, value)`
210
+ * Send a one-off fact.
211
+ * `.gauge(key, value)`
212
+ * Send a one-off gauge metric.
213
+ * `.remove()`
214
+ * `.save()`
215
+ * `.remove(id, options = {})`
216
+ * `.update(id, updates, options = {})`
217
+
218
+ ### Logic Block
219
+
220
+ * .LogicBlock
221
+ * `.create(attributes = {}, options = {})`
222
+ * `.execute(id, options = {})`
223
+ * `.find(query = {}, options = {})`
224
+ * `.find_by_id(id, options = {})`
225
+ * `.find_by_name(name, options = {})`
226
+ * `.new(attributes = {}) ⇒ client.LogicBlock`
227
+ * `.execute()`
228
+ * `.remove()`
229
+ * `.save()`
230
+ * `.remove(id, options = {})`
231
+ * `.update(id, updates, options = {})`
232
+
233
+ ### Member
234
+
235
+ * .Member
236
+ * `.create(attributes = {}, options = {})`
237
+ * `.find(query = {}, options = {})`
238
+ * `.find_by_id(id, options = {})`
239
+ * `.new(attributes = {}) ⇒ client.Member`
240
+ * `.remove()`
241
+ * `.save()`
242
+ * `.remove(id, options = {})`
243
+ * `.update(id, updates, options = {})`
244
+
245
+ ### Settings
246
+
247
+ * .Settings
248
+ * `.retrieve()`
249
+ * `.update(updates, options = {})`
250
+
251
+ ### Task
252
+
253
+ * .Task
254
+ * `.create(attributes = {}, options = {})`
255
+ * `.find(query = {}, options = {})`
256
+ * `.find_by_id(id, options = {})`
257
+ * `.new(attributes = {}) ⇒ client.Task`
258
+ * `.remove()`
259
+ * `.save()`
260
+ * `.remove(id, options = {})`
261
+ * `.update(id, updates = {}, options = {})`
262
+
263
+ ## Building
264
+
265
+ To test, build, and install locally:
266
+
267
+ make
268
+
269
+ To build and install:
270
+
271
+ make build
272
+
273
+ ## Testing
274
+
275
+ Testing requires:
276
+
277
+ - Make
278
+
279
+ Install gems locally by running:
280
+
281
+ make install
282
+
283
+ Then run a command below based on what test suite you need to run.
284
+
285
+ ### Lint
286
+
287
+ make lint
288
+
289
+ ### Unit
290
+
291
+ make unit-test
292
+
293
+ ### Integration
294
+
295
+ make integration-test
296
+
297
+ ### Validation
298
+
299
+ Requires the environment to have a root level access-token defined as:
300
+
301
+ export POLYSEERIO_TOKEN=a-test-root-key
302
+
303
+ make validation-test
304
+
305
+ ### All
306
+
307
+ make test
@@ -0,0 +1,35 @@
1
+ require 'agent/executor'
2
+
3
+ module Polyseerio
4
+ module Agent
5
+ # Polyseer.io Ruby agent.
6
+ class Agent
7
+ attr_accessor :client, :instance
8
+
9
+ def initialize(client)
10
+ @client = client
11
+ end
12
+
13
+ # Starts the agent.
14
+ def start(*args)
15
+ Executor.setup(client, *args)
16
+ .then do |instance|
17
+ @instance = instance
18
+
19
+ client
20
+ end
21
+ end
22
+
23
+ # Stops the agent.
24
+ def stop
25
+ Executor.teardown(client, instance).then do
26
+ @instance = nil
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ attr_writer :client, :instance
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,51 @@
1
+ require 'enum'
2
+
3
+ # Default agent configuration.
4
+ module Polyseerio
5
+ module Agent
6
+ DEFAULT_CONFIG = {
7
+ attach: true,
8
+ attach_strategy: Polyseerio::Enum::Strategy::FALLBACK,
9
+ token: nil,
10
+ name: nil,
11
+ description: 'Created by the Polyseer.io Ruby agent.',
12
+ group: 'agent-created',
13
+ environment: 'development',
14
+ upsert_environment: false,
15
+ env: 'NODE_ENV',
16
+ direction: Polyseerio::Enum::Direction::INBOUND,
17
+ subtype: Polyseerio::Enum::Subtype::LONG_RUNNING,
18
+ heartbeats_till_death: nil,
19
+ heartbeat_ttl: nil,
20
+ on_start: [],
21
+ on_error: [],
22
+ on_exit: [],
23
+ expectation: {
24
+ is_alive: true
25
+ },
26
+ fact: {
27
+ pid: true,
28
+ gid: true
29
+ },
30
+ metric: {
31
+ memory: true,
32
+ cpu: true,
33
+ uptime: true
34
+ },
35
+ event: {
36
+ start: true
37
+ },
38
+ process_event: {
39
+ exit: true,
40
+ warning: true,
41
+ uncaughtException: true,
42
+ unhandledRejection: true
43
+ },
44
+ process_signal: {
45
+ SIGHUP: true,
46
+ SIGINT: true,
47
+ SIGTERM: true
48
+ }
49
+ }.freeze
50
+ end
51
+ end