moesif_rack 1.4.7 → 1.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -21
- data/lib/moesif_rack/client_ip.rb +2 -4
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c83ae80cf118c921a212121b0be6af3720b5cd9b0d0e83c6665828f4e542f10
|
4
|
+
data.tar.gz: 0a709decc75d43649da2e1305cd6370e44cbf8cb78b5c931e7df3afb894845c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 703794d208c4cceb7bcefa28e43fa7ae3c2e624569dbf6d8bf6697e70d3235d89e073f9b0c568967d0b7640b6b60650ba9d9bb2f3fa3277affae6ef75a6193b2
|
7
|
+
data.tar.gz: f95e69f49e07f89312c3e7d1c25347e35fd621f064cdf604fbd50f1159b73d3ade37098cfd13e2fead7d8110ebb3d74c11400701b66a0df6ce18e2f8fa058b6f
|
data/README.md
CHANGED
@@ -7,33 +7,37 @@
|
|
7
7
|
[![Source Code][ico-source]][link-source]
|
8
8
|
|
9
9
|
Rack Middleware that logs API calls and sends
|
10
|
-
to [Moesif](https://www.moesif.com) for API analytics and
|
10
|
+
to [Moesif](https://www.moesif.com) for API analytics and monitoring.
|
11
11
|
|
12
|
-
Supports Ruby on Rails
|
12
|
+
Supports Ruby on Rails, Grape, and other Ruby frameworks built on Rack.
|
13
13
|
|
14
14
|
[Source Code on GitHub](https://github.com/moesif/moesif-rack)
|
15
15
|
|
16
16
|
## How to install
|
17
17
|
|
18
|
+
Install the Moesif gem.
|
19
|
+
|
18
20
|
```bash
|
19
21
|
gem install moesif_rack
|
20
22
|
```
|
21
23
|
|
22
|
-
|
24
|
+
If you're using Bundler, add the gem to your `Gemfile`.
|
23
25
|
|
24
|
-
```
|
26
|
+
```ruby
|
25
27
|
gem 'moesif_rack'
|
26
|
-
|
27
28
|
```
|
28
29
|
|
30
|
+
Then, run `bundle install`
|
31
|
+
|
29
32
|
## How to use
|
30
33
|
|
31
|
-
###
|
34
|
+
### 1. Enter Moesif Application Id
|
35
|
+
|
36
|
+
Create an options hash containing application_id and any other options.
|
32
37
|
|
33
38
|
```ruby
|
34
39
|
moesif_options = {
|
35
|
-
'application_id' => 'Your Moesif Application Id'
|
36
|
-
'log_body' => true,
|
40
|
+
'application_id' => 'Your Moesif Application Id'
|
37
41
|
}
|
38
42
|
```
|
39
43
|
|
@@ -44,43 +48,67 @@ You can always find your Moesif Application Id at any time by logging
|
|
44
48
|
into the [_Moesif Portal_](https://www.moesif.com/), click on the top right menu,
|
45
49
|
and then clicking _Installation_.
|
46
50
|
|
47
|
-
### Add
|
51
|
+
### 2. Add the middleware
|
52
|
+
|
53
|
+
#### For Rails 5.0 or newer:
|
48
54
|
|
49
55
|
Using strings or symbols for middleware class names is deprecated for newer frameworks like Ruby 5.0,
|
50
56
|
so you should pass the class directly.
|
51
57
|
|
52
|
-
#### For Rails 5.0 or newer:
|
53
|
-
|
54
58
|
```ruby
|
55
59
|
class Application < Rails::Application
|
56
|
-
|
60
|
+
moesif_options = {
|
61
|
+
'application_id' => 'Your Moesif Application Id'
|
62
|
+
}
|
57
63
|
|
58
64
|
config.middleware.use MoesifRack::MoesifMiddleware, moesif_options
|
59
|
-
|
60
|
-
# snip
|
61
65
|
end
|
62
66
|
```
|
63
67
|
|
64
|
-
#### For other frameworks:
|
68
|
+
#### For Rails 4.0 and other frameworks:
|
69
|
+
|
70
|
+
For most rack-based frameworks including Rails 4.x or older, add the middleware `MoesifRack::MoesifMiddleware`.
|
65
71
|
|
66
72
|
within `config/application.rb`
|
67
73
|
|
68
74
|
```ruby
|
69
75
|
class Application < Rails::Application
|
70
|
-
|
76
|
+
moesif_options = {
|
77
|
+
'application_id' => 'Your Moesif Application Id'
|
78
|
+
}
|
71
79
|
|
72
80
|
config.middleware.use "MoesifRack::MoesifMiddleware", moesif_options
|
81
|
+
end
|
82
|
+
```
|
73
83
|
|
74
|
-
|
84
|
+
#### For Grape API:
|
85
|
+
|
86
|
+
For [Grape APIs](https://github.com/ruby-grape/grape), we can add the middleware after any custom parsers or formatters.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
module Acme
|
90
|
+
class Ping < Grape::API
|
91
|
+
format :json
|
92
|
+
|
93
|
+
moesif_options = {
|
94
|
+
'application_id' => 'Your Moesif Application Id'
|
95
|
+
}
|
96
|
+
|
97
|
+
insert_after Grape::Middleware::Formatter, MoesifRack::MoesifMiddleware, moesif_options
|
98
|
+
|
99
|
+
get '/ping' do
|
100
|
+
{ ping: 'pong' }
|
101
|
+
end
|
75
102
|
end
|
103
|
+
end
|
76
104
|
```
|
77
105
|
|
78
106
|
#### Order of Middleware Matters
|
79
107
|
|
80
|
-
Since Moesif Rack is a logging middleware, the ordering of middleware matters
|
81
|
-
|
108
|
+
Since Moesif Rack is a logging middleware, the ordering of middleware matters.
|
109
|
+
The best place for "MoesifRack::MoesifMidleware" is near the top (so it captures the data closest to the wire), but after
|
110
|
+
any body parsers or authentication middleware.
|
82
111
|
|
83
|
-
The best place for "MoesifRack::MoesifMidleware" is on top (so it captures the data closest to the wire).
|
84
112
|
Typically, right above the default logger of Rails apps, "Rails::Rack::Logger" is a good spot.
|
85
113
|
Or if you want to be as close as wire as possible, put it before "ActionDispatch::Static"
|
86
114
|
|
@@ -107,7 +135,7 @@ To see your current list of middleware:
|
|
107
135
|
|
108
136
|
## Configuration options
|
109
137
|
|
110
|
-
|
138
|
+
Options is a hash with these possible key/value pairs.
|
111
139
|
|
112
140
|
#### __`application_id`__
|
113
141
|
|
@@ -2,10 +2,8 @@
|
|
2
2
|
def is_ip?(value)
|
3
3
|
ipv4 = /^(?:(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/
|
4
4
|
ipv6 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|
6
|
-
|
7
|
-
!!(value =~ ipv4 or value=~ ipv6)
|
8
|
-
end
|
5
|
+
# We use !! to convert the return value to a boolean
|
6
|
+
!!(value =~ ipv4 or value=~ ipv6)
|
9
7
|
end
|
10
8
|
|
11
9
|
def get_client_ip_from_x_forwarded_for(value)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moesif_rack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moesif, Inc
|
@@ -9,10 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name: test-unit
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
17
|
- - "~>"
|
@@ -21,8 +20,9 @@ dependencies:
|
|
21
20
|
- - ">="
|
22
21
|
- !ruby/object:Gem::Version
|
23
22
|
version: 3.1.5
|
24
|
-
|
23
|
+
name: test-unit
|
25
24
|
prerelease: false
|
25
|
+
type: :development
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
28
|
- - "~>"
|
@@ -32,7 +32,6 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 3.1.5
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
|
-
name: moesif_api
|
36
35
|
requirement: !ruby/object:Gem::Requirement
|
37
36
|
requirements:
|
38
37
|
- - "~>"
|
@@ -41,8 +40,9 @@ dependencies:
|
|
41
40
|
- - ">="
|
42
41
|
- !ruby/object:Gem::Version
|
43
42
|
version: 1.2.12
|
44
|
-
|
43
|
+
name: moesif_api
|
45
44
|
prerelease: false
|
45
|
+
type: :runtime
|
46
46
|
version_requirements: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
48
|
- - "~>"
|
@@ -96,7 +96,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
requirements: []
|
99
|
-
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.7.10
|
100
101
|
signing_key:
|
101
102
|
specification_version: 4
|
102
103
|
summary: moesif_rack
|