informant-sinatra 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 02f27a46d2c36eb6ddc7b96a0cf1562877ffbf2b287bce94c3e4472417281f04
4
+ data.tar.gz: d2e4052d06c13b35016fec533114cc4061cf917766274d2d2ea07291dafab28f
5
+ SHA512:
6
+ metadata.gz: 4df3eff5e97481b98e355b12047f3faae1c97e9ba9aa858bb93b00c0f181ac7e28fc3a46e4a01f321245237c81595338ee7c49243b404302200ae239ba5348d5
7
+ data.tar.gz: 5fb9ac00ca156dfcb81c45dc60cef3289fe46fe0565578bd2e550be1854ac9ae93bdaff2614356da2aa36b9771caad0184e52d19c7ccbd669c5f5d15abbd8067
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ MIT License
2
+ Copyright (c) 2016 Informant, LLC
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,115 @@
1
+ # Overview
2
+
3
+ ## [![Homepage](https://s3.amazonaws.com/assets.heroku.com/addons.heroku.com/icons/1347/original.png)](https://www.informantapp.com) InformantSinatra
4
+
5
+ The `informant-sinatra` gem provides Sinatra hooks for The Informant.
6
+
7
+ ## Compatibility
8
+
9
+ The informant-sinatra gem officially supports Ruby 2.5+.
10
+
11
+ It will work automatically with Sinatra 2+ and automatically activate
12
+ validation tracking for ActiveRecord and Mongoid models.
13
+
14
+ [![pipeline status](https://gitlab.com/informantapp/informant-sinatra/badges/master/pipeline.svg)](https://gitlab.com/informantapp/informant-sinatra/-/commits/master)
15
+
16
+ ## Installation
17
+
18
+ 1. Sign up for an account on https://www.informantapp.com or through one of our
19
+ parters, [Heroku](https://dashboard.heroku.com) or
20
+ [Manifold](https://manifold.co).
21
+ 2. Add the `informant-sinatra` gem to your `Gemfile`.
22
+
23
+ ```
24
+ gem 'informant-sinatra', group: :production
25
+ ```
26
+
27
+ 3. Verify the `INFORMANT_API_KEY` is set in your app's environment.
28
+ 4. Bootstrap the Informant in your app's setup.
29
+
30
+ ```
31
+ class MySinatraApp < Sinatra::Base
32
+ register InformantSinatra::Bootstrap
33
+ ```
34
+
35
+ 5. Deploy with the gem installed.
36
+ 6. Submit a form and you'll see it appear in [our web interface](https://console.informantapp.com).
37
+
38
+ ## Troubleshooting
39
+
40
+ The Informant gem includes a rake task to diagnose connectivity problems. From
41
+ your server environment execute `rake informant:diagnostic` and it will print
42
+ helpful information to the terminal.
43
+
44
+ Note: Sinatra doesn't load rake tasks from gems by default so you'll need to
45
+ have code in your Rakefile to do it.
46
+
47
+ ## Usage
48
+
49
+ By default, any request that causes an ActiveRecord or Mongoid model to be
50
+ validated will be tracked by the Informant once the gem is added to your
51
+ project.
52
+
53
+ ### Custom Tracking
54
+
55
+ If you have other objects that conform to the ActiveModel interface, you can
56
+ include validation tracking in your class and it will just work.
57
+
58
+ ```
59
+ class VeryActiveModel
60
+ include ActiveModel::Model
61
+ include InformantSinatra::ValidationTracking
62
+ end
63
+ ```
64
+
65
+ ## Configuration
66
+
67
+ Configuration options are specified in the `InformantSinatra::Config` module.
68
+ Reasonable defaults are provided but you can override them as necessary by
69
+ creating an initializer and passing a block to `configure`.
70
+
71
+ ```
72
+ InformantSinatra::Config.configure do |config|
73
+ config.api_token = ENV['INFORMANT_API_KEY']
74
+ config.exclude_models = %w(UntrackedModel)
75
+ config.filter_parameters.push *%w(password password_confirmation)
76
+ config.value_tracking = true
77
+ end
78
+ ```
79
+
80
+ ### api_token
81
+
82
+ Default Value: `ENV['INFORMANT_API_KEY']`
83
+
84
+ Example Value: `dff67d9e61eaa8cf110b3d3f3238a671`
85
+
86
+ This should be set to the API key assigned to you when you provisioned your application. Heroku will automatically add this to your environment when you provision the addon. Otherwise, you can get this from the Informant web application.
87
+
88
+ ### exclude_models
89
+
90
+ Default Value: `[]`
91
+
92
+ Example Value: `['Person', 'Employee']`
93
+
94
+ This allows you to exclude certain models from tracking. If you don't want them
95
+ included in your metrics list their class names as strings here.
96
+
97
+ ### filter_parameters
98
+
99
+ Default Value: `['password', 'token']`
100
+
101
+ Example Value: `['password', 'token']`
102
+
103
+ Any field values with names matching the strings in this array will be excluded
104
+ from tracking. Sensitive information you wouldn't want to include in your
105
+ server log should be listed here as well.
106
+
107
+ ### value_tracking
108
+
109
+ Default Value: `true`
110
+
111
+ Example Value: `false`
112
+
113
+ This will enable and disable tracking of values globally. If you turn this off,
114
+ no field value information will be tracked at all. This is useful if you have
115
+ compliance or security concerns about the nature of your data.
@@ -0,0 +1,9 @@
1
+ if !ENV['APPRAISAL_INITIALIZED']
2
+ require 'appraisal/task'
3
+ Appraisal::Task.new
4
+ task default: :appraisal
5
+ else
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new
8
+ task default: :spec
9
+ end
@@ -0,0 +1,10 @@
1
+ require 'informant-common'
2
+
3
+ module InformantSinatra
4
+ autoload :Bootstrap, 'informant-sinatra/bootstrap'
5
+ autoload :Config, 'informant-sinatra/config'
6
+ autoload :Diagnostic, 'informant-sinatra/diagnostic'
7
+ autoload :Middleware, 'informant-sinatra/middleware'
8
+ autoload :ValidationTracking, 'informant-sinatra/validation_tracking'
9
+ autoload :VERSION, 'informant-sinatra/version'
10
+ end
@@ -0,0 +1,38 @@
1
+ module InformantSinatra
2
+ module Bootstrap
3
+ def self.registered(app)
4
+ return unless InformantCommon::Config.enabled?
5
+
6
+ transmit_agent_info
7
+
8
+ InformantSinatra::Config.filter_parameters = %w[password token] if InformantSinatra::Config.filter_parameters.empty?
9
+
10
+ app.use InformantSinatra::Middleware
11
+
12
+ register_validation_trackers
13
+ rescue StandardError => e
14
+ puts "Unable to bootstrap informant: #{e.message}"
15
+ end
16
+
17
+ def self.transmit_agent_info
18
+ InformantCommon::Client.transmit(
19
+ InformantCommon::Event::AgentInfo.new(
20
+ agent_identifier: "informant-sinatra-#{InformantSinatra::VERSION}",
21
+ framework_version: "sinatra-#{Sinatra::VERSION}"
22
+ )
23
+ )
24
+ end
25
+
26
+ def self.register_validation_trackers
27
+ return unless defined?(ActiveSupport)
28
+
29
+ ActiveSupport.on_load(:active_record) do
30
+ include InformantSinatra::ValidationTracking
31
+ end
32
+
33
+ ActiveSupport.on_load(:mongoid) do
34
+ include InformantSinatra::ValidationTracking
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,35 @@
1
+ module InformantSinatra
2
+ module Config
3
+ def self.api_token
4
+ InformantCommon::Config.api_token
5
+ end
6
+
7
+ def self.api_token=(api_token)
8
+ InformantCommon::Config.api_token = api_token
9
+ end
10
+
11
+ def self.exclude_models
12
+ InformantCommon::Config.exclude_models
13
+ end
14
+
15
+ def self.exclude_models=(exclude_models)
16
+ InformantCommon::Config.exclude_models = exclude_models
17
+ end
18
+
19
+ def self.filter_parameters
20
+ InformantCommon::Config.filter_parameters
21
+ end
22
+
23
+ def self.filter_parameters=(filter_parameters)
24
+ InformantCommon::Config.filter_parameters = filter_parameters
25
+ end
26
+
27
+ def self.value_tracking?
28
+ InformantCommon::Config.value_tracking?
29
+ end
30
+
31
+ def self.value_tracking=(value_tracking)
32
+ InformantCommon::Config.value_tracking = value_tracking
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,61 @@
1
+ module InformantSinatra
2
+ class Diagnostic
3
+ def self.run
4
+ new.run
5
+ end
6
+
7
+ def run
8
+ if Config.api_token.nil? || Config.api_token == ''
9
+ puts missing_api_token_message
10
+ else
11
+ response = InformantCommon::Client.transmit(test_form_submission).join.value
12
+ display_response_message(response)
13
+ end
14
+
15
+ puts assistance_message
16
+ end
17
+
18
+ private
19
+
20
+ def missing_api_token_message
21
+ %(
22
+ Your API token could not be found in the configuration. You can retrieve it from your Informantapp.com dashboard.
23
+
24
+ Then add it to your server's environment as `INFORMANT_API_KEY`
25
+
26
+ OR
27
+
28
+ Set it manually in your application setup
29
+
30
+ InformantSinatra::Config.api_token = 'your token'
31
+ )
32
+ end
33
+
34
+ def bad_response_message(server_message)
35
+ "Seems like we have a problem. \"#{server_message}\" in this case."
36
+ end
37
+
38
+ def success_message
39
+ 'Everything looks good. You should see a test request on your dashboard.'
40
+ end
41
+
42
+ def assistance_message
43
+ "If you need assistance or have any questions, send an email to support@informantapp.com or tweet @informantapp and we'll help you out!"
44
+ end
45
+
46
+ def test_form_submission
47
+ InformantCommon::Event::FormSubmission.new.tap do |form_submission|
48
+ form_submission.handler = 'Connectivity#test'
49
+ form_submission.process_model(InformantCommon::Model::ActiveModel.new(TestClass.new.tap(&:valid?)))
50
+ end
51
+ end
52
+
53
+ def display_response_message(response)
54
+ if response.code == '204'
55
+ puts success_message
56
+ else
57
+ puts bad_response_message(response.body)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,15 @@
1
+ module InformantSinatra
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ InformantCommon::Client.start_transaction!(env['REQUEST_METHOD'])
9
+ response = @app.call(env)
10
+ InformantCommon::Client.current_transaction.handler = env['sinatra.route']
11
+ InformantCommon::Client.process
12
+ response
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module InformantSinatra
2
+ module ValidationTracking
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include InformantCommon::ValidationTracking
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module InformantSinatra
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'informant-sinatra'
2
+
3
+ namespace :informant do
4
+ desc 'Verify connectivity from your app to Informant'
5
+ task :diagnostic do
6
+ InformantSinatra::Diagnostic.run
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: informant-sinatra
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Informant, LLC
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: informant-common
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 3.0.0
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.0.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: 3.0.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: appraisal
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: webmock
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ description: The Informant tracks what users do wrong in your forms so you can make
104
+ them better.
105
+ email:
106
+ - support@informantapp.com
107
+ executables: []
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - LICENSE
112
+ - README.md
113
+ - Rakefile
114
+ - lib/informant-sinatra.rb
115
+ - lib/informant-sinatra/bootstrap.rb
116
+ - lib/informant-sinatra/config.rb
117
+ - lib/informant-sinatra/diagnostic.rb
118
+ - lib/informant-sinatra/middleware.rb
119
+ - lib/informant-sinatra/validation_tracking.rb
120
+ - lib/informant-sinatra/version.rb
121
+ - lib/tasks/diagnostic.rake
122
+ homepage: https://www.informantapp.com
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubygems_version: 3.0.3
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: The Informant tracks server-side validation errors and gives you metrics
145
+ you never dreamed of.
146
+ test_files: []