littlebluefox-ruby 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/README.md +84 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/littlebluefox/client.rb +60 -0
- data/lib/littlebluefox/core.rb +4 -0
- data/lib/littlebluefox/event.rb +46 -0
- data/lib/littlebluefox/version.rb +3 -0
- data/littlebluefox-ruby.gemspec +41 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dda88c418c0ef82968640e77c993affc13df97bcca95875d75e6aa2d3ba0c47e
|
4
|
+
data.tar.gz: 65b4c2e42cbdc76a5c34ec9dad2b07407abcb495c3298183c87025803b63a017
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f785cde27a6b713343f56f1688c8d32260b1e61f9058ee9e298a8a994e4abe893b1a7b3b16150b28b1e8d1dcbb6751ce426d97d526687b6912f9d65470f12a4d
|
7
|
+
data.tar.gz: eb0484eb0ba87737a0faa42bf53df3a5a9f1251fe5f0740da49e2683a7692e71056b099e046b4bc9bf52b23c198446b95a7c446bec4ba5e674c8833930b07f53
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
littlebluefox-ruby (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.8.0)
|
12
|
+
rspec-core (~> 3.8.0)
|
13
|
+
rspec-expectations (~> 3.8.0)
|
14
|
+
rspec-mocks (~> 3.8.0)
|
15
|
+
rspec-core (3.8.0)
|
16
|
+
rspec-support (~> 3.8.0)
|
17
|
+
rspec-expectations (3.8.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-mocks (3.8.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-support (3.8.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 2.0)
|
30
|
+
littlebluefox-ruby!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
2.0.1
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# LittleBlueFox Ruby gem
|
2
|
+
|
3
|
+
Push your security events on the littlebleufox.io API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
# Gemfile
|
11
|
+
|
12
|
+
gem 'littlebluefox-ruby'
|
13
|
+
```
|
14
|
+
or
|
15
|
+
|
16
|
+
```bash
|
17
|
+
$ gem install littlebluefox-ruby
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
With a RubyOnRails application:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# config/initializers/littlebluefox.rb
|
26
|
+
|
27
|
+
LittleBlueFoxClient = LittleBlueFox::Client.new("...") # Access Token
|
28
|
+
```
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# app/controllers/sessions_controller.rb
|
32
|
+
|
33
|
+
class SessionsController < ApplicationController
|
34
|
+
# ...
|
35
|
+
|
36
|
+
def create
|
37
|
+
# ...
|
38
|
+
|
39
|
+
event = LittleBlueFox::Event.new(
|
40
|
+
:authentication_success,
|
41
|
+
'42',
|
42
|
+
'demo@demo.com',
|
43
|
+
request.remote_ip,
|
44
|
+
request.headers,
|
45
|
+
)
|
46
|
+
|
47
|
+
if user.authenticate(session_params)
|
48
|
+
event.event_type = :authentication_success
|
49
|
+
push_security_event(event)
|
50
|
+
|
51
|
+
# redirect_to hompage_path
|
52
|
+
else
|
53
|
+
event.event_type = :authentication_failure
|
54
|
+
push_security_event(event)
|
55
|
+
|
56
|
+
# ...
|
57
|
+
# render :new
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def push_security_event(event)
|
64
|
+
begin
|
65
|
+
LittleBlueFoxClient.push(event)
|
66
|
+
rescue => e
|
67
|
+
Rails.logger.info(e)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# ...
|
72
|
+
end
|
73
|
+
|
74
|
+
```
|
75
|
+
|
76
|
+
## Development
|
77
|
+
|
78
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
79
|
+
|
80
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
81
|
+
|
82
|
+
## Contributing
|
83
|
+
|
84
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/LittleBlueFox/littlebluefox-ruby.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "littlebluefox/core"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "net/http"
|
2
|
+
|
3
|
+
module LittleBlueFox
|
4
|
+
DefaultEndpointUrl = "https://events.littlebluefox.io/"
|
5
|
+
ExpectedResponseCode = 202
|
6
|
+
|
7
|
+
class Client
|
8
|
+
attr_reader :endpoint_url
|
9
|
+
|
10
|
+
def initialize(access_token, endpoint_url = DefaultEndpointUrl)
|
11
|
+
@access_token = access_token
|
12
|
+
@endpoint_url = endpoint_url
|
13
|
+
end
|
14
|
+
|
15
|
+
def push(event)
|
16
|
+
http = Net::HTTP.new(endpoint_uri.host, endpoint_uri.port)
|
17
|
+
http.use_ssl = true if endpoint_uri.port == 443
|
18
|
+
|
19
|
+
req = Net::HTTP::Post.new("/")
|
20
|
+
req["Content-Type"] = "application/json"
|
21
|
+
req["Authorization"] = "Bearer: #{@access_token}"
|
22
|
+
|
23
|
+
req.body = event.to_json
|
24
|
+
|
25
|
+
resp = http.request(req)
|
26
|
+
|
27
|
+
if resp.code == ''
|
28
|
+
raise UnexpectedResponseCode.new(ExpectedResponseCode, nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
status_code = resp.code.to_i
|
32
|
+
|
33
|
+
case status_code
|
34
|
+
when 200..299
|
35
|
+
return true
|
36
|
+
else
|
37
|
+
raise UnexpectedResponseCode.new(ExpectedResponseCode, status_code)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def endpoint_uri
|
44
|
+
@endpoint_uri ||= URI.parse(@endpoint_url)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class UnexpectedResponseCode < StandardError
|
49
|
+
attr_reader :expected_code,
|
50
|
+
:received_code
|
51
|
+
|
52
|
+
def initialize(expected_code, received_code)
|
53
|
+
@expected_code, @received_code = expected_code, received_code
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_s
|
57
|
+
"Unexpected response code from LittleBlueFox.io (expected: #{@expected_code}, got: #{@received_code})"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module LittleBlueFox
|
4
|
+
class Event
|
5
|
+
attr_accessor :event_type,
|
6
|
+
:uref,
|
7
|
+
:email,
|
8
|
+
:remote_ip,
|
9
|
+
:http_headers
|
10
|
+
|
11
|
+
def initialize(event_type, uref, email, remote_ip, http_headers)
|
12
|
+
@event_type, @uref, @email, @remote_ip, @http_headers = event_type, uref, email, remote_ip, http_headers
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_json
|
16
|
+
JSON.dump({
|
17
|
+
event_type: event_type,
|
18
|
+
uref: uref,
|
19
|
+
email: email,
|
20
|
+
remote_ip: remote_ip,
|
21
|
+
http_headers: normalized_http_headers,
|
22
|
+
})
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def normalized_http_headers
|
28
|
+
@http_headers.inject({}) do |acc, (k, v)|
|
29
|
+
acc[k] = v if v.kind_of?(String)
|
30
|
+
acc
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
AllowedEventTypes = %w(authentication_request
|
36
|
+
authentication_failure
|
37
|
+
authentication_success
|
38
|
+
password_update_request
|
39
|
+
password_update_failure
|
40
|
+
password_update_success
|
41
|
+
account_creation_success
|
42
|
+
account_creation_failure
|
43
|
+
access_sensitive_data
|
44
|
+
sensitive_data_updated
|
45
|
+
payment_failure)
|
46
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "littlebluefox/core"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "littlebluefox-ruby"
|
8
|
+
spec.version = LittleBlueFox::VERSION
|
9
|
+
spec.authors = ["Sam"]
|
10
|
+
spec.email = ["sam@littlebluefox.io"]
|
11
|
+
|
12
|
+
spec.summary = %q{Offical gem of LittleBlueFox.io API}
|
13
|
+
spec.description = %q{Push your security events on LittleBlueFox API}
|
14
|
+
spec.homepage = "https://github.com/littlebluefox/littlebluefox-ruby"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
|
21
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
22
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
23
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
24
|
+
# else
|
25
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
26
|
+
# "public gem pushes."
|
27
|
+
# end
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = "exe"
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ["lib"]
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
39
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: littlebluefox-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Push your security events on LittleBlueFox API
|
56
|
+
email:
|
57
|
+
- sam@littlebluefox.io
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/littlebluefox/client.rb
|
72
|
+
- lib/littlebluefox/core.rb
|
73
|
+
- lib/littlebluefox/event.rb
|
74
|
+
- lib/littlebluefox/version.rb
|
75
|
+
- littlebluefox-ruby.gemspec
|
76
|
+
homepage: https://github.com/littlebluefox/littlebluefox-ruby
|
77
|
+
licenses: []
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubygems_version: 3.0.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Offical gem of LittleBlueFox.io API
|
98
|
+
test_files: []
|