vectra 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.rock.yml +5 -0
- data/.rspec +2 -0
- data/.travis.yml +1 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +12 -0
- data/Rakefile +17 -0
- data/lib/vectra.rb +27 -0
- data/lib/vectra/api.rb +49 -0
- data/lib/vectra/config.rb +35 -0
- data/lib/vectra/detections.rb +20 -0
- data/lib/vectra/hosts.rb +20 -0
- data/lib/vectra/version.rb +3 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/vectra/vectra_spec.rb +30 -0
- data/vectra.gemspec +34 -0
- metadata +25 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bebaf2ac4a12c7917a69dc288cdca7c3869593e5
|
4
|
+
data.tar.gz: ad4df58d56b6a7f0f74276f40d195691e2f3537f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56d09edeae08914b221242a215d45055714148d92157296cee2facb81f80d9bccdfdfc01a4da97ff6274723719b050dbe7bd83beab05ce5cfbb35c78e8012720
|
7
|
+
data.tar.gz: 0e1cb875c6538be00e85ac4abd533c289900839cdacbf4d1fccec8c69e03af5cbd80c1da2b6392711cd76e99397a4fd9267740921142ecbbb4e893c156f2233e
|
data/.gitignore
ADDED
data/.rock.yml
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
language: ruby
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Mike Mackintosh
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Ruby Vectra
|
2
|
+
A Ruby extension for interfacing with Vectra API.
|
3
|
+
|
4
|
+
[![TravisCI](https://travis-ci.org/mikemackintosh/ruby-vectra.svg)](https://travis-ci.org/mikemackintosh/ruby-vectra)
|
5
|
+
|
6
|
+
# Installation
|
7
|
+
|
8
|
+
Like any other gem:
|
9
|
+
|
10
|
+
```shell
|
11
|
+
gem install vectra
|
12
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
task default: :test
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new do |spec|
|
8
|
+
spec.verbose = false
|
9
|
+
spec.pattern = './spec/{*/**/}*_spec.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
task :test do
|
13
|
+
ENV['RACK_ENV'] = 'test'
|
14
|
+
|
15
|
+
require './spec/spec_helper'
|
16
|
+
Rake::Task['spec'].invoke
|
17
|
+
end
|
data/lib/vectra.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'fattr'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
require 'vectra/config'
|
7
|
+
require 'vectra/api'
|
8
|
+
require 'vectra/hosts'
|
9
|
+
require 'vectra/detections'
|
10
|
+
|
11
|
+
module Vectra
|
12
|
+
|
13
|
+
extend self
|
14
|
+
|
15
|
+
def configure
|
16
|
+
block_given? ? yield(Config) : Config
|
17
|
+
%w(username password endpoint).each do |key|
|
18
|
+
if Vectra::Config.instance_variable_get("@#{key}").nil?
|
19
|
+
raise Vectra::Config::RequiredOptionMissing,
|
20
|
+
"Configuration parameter missing: '#{key}'. " +
|
21
|
+
"Please add it to the Vectra.configure block"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
alias_method :config, :configure
|
26
|
+
|
27
|
+
end
|
data/lib/vectra/api.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Vectra
|
2
|
+
class Api
|
3
|
+
class InvalidResponse < RuntimeError ; end
|
4
|
+
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
def self.send(url, args="", decode)
|
8
|
+
results = []
|
9
|
+
|
10
|
+
# Send the request
|
11
|
+
response = HTTParty.get(
|
12
|
+
"#{url}#{args}",
|
13
|
+
:verify => false, # Vectra doesnt accept real certs yet
|
14
|
+
:basic_auth => {
|
15
|
+
:username => Vectra::Config.username,
|
16
|
+
:password => Vectra::Config.password
|
17
|
+
})
|
18
|
+
|
19
|
+
if !response.code.eql?(200)
|
20
|
+
raise Vectra::Api::InvalidResponse, "Invalid Response Received"
|
21
|
+
end
|
22
|
+
|
23
|
+
# Decode the response
|
24
|
+
response = JSON.parse response.body
|
25
|
+
|
26
|
+
# Check if we should decode this response
|
27
|
+
if decode
|
28
|
+
# Map responses
|
29
|
+
response['results'].map{|r| results.push(r)}
|
30
|
+
else
|
31
|
+
results = response
|
32
|
+
end
|
33
|
+
|
34
|
+
# If there is a next, respect it
|
35
|
+
#unless response['next'].nil?
|
36
|
+
# puts self.send(response['next']).inspect
|
37
|
+
#end
|
38
|
+
|
39
|
+
results
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.request(args="", decode=true)
|
44
|
+
r = self.send("#{Vectra::Config.endpoint}#{self.target}", args, decode)
|
45
|
+
r
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Vectra
|
2
|
+
module Config
|
3
|
+
class RequiredOptionMissing < RuntimeError ; end
|
4
|
+
extend self
|
5
|
+
|
6
|
+
attr_accessor :endpoint, :username, :password
|
7
|
+
|
8
|
+
# Configure vectra from a hash. This is usually called after parsing a
|
9
|
+
# yaml config file such as vectra.yaml.
|
10
|
+
#
|
11
|
+
# @example Configure Vectra.
|
12
|
+
# config.from_hash({})
|
13
|
+
#
|
14
|
+
# @param [ Hash ] options The settings to use.
|
15
|
+
def from_hash(options = {})
|
16
|
+
options.each_pair do |name, value|
|
17
|
+
send("#{name}=", value) if respond_to?("#{name}=")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Load the settings from a compliant vectra.yml file. This can be used for
|
22
|
+
# easy setup with frameworks other than Rails.
|
23
|
+
#
|
24
|
+
# @example Configure Vectra.
|
25
|
+
# Vectra.load!("/path/to/vectra.yml")
|
26
|
+
#
|
27
|
+
# @param [ String ] path The path to the file.
|
28
|
+
def load!(path)
|
29
|
+
settings = YAML.load(ERB.new(File.new(path).read).result)
|
30
|
+
if settings.present?
|
31
|
+
from_hash(settings)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/vectra/hosts.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'vectra')
|
4
|
+
|
5
|
+
# Create the share API context
|
6
|
+
# so we can pass stuff between
|
7
|
+
# the different tests
|
8
|
+
RSpec.shared_context "shared environment", :a => :b do
|
9
|
+
|
10
|
+
before(:all) do
|
11
|
+
|
12
|
+
# Set endpoint details
|
13
|
+
@endpoint_url = 'https://10.200.10.88/api/'
|
14
|
+
@username = "api"
|
15
|
+
@password = "AbpdWjFFKuu3XVdKKXjMZbard3H"
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
# Seems to run tests more than once if we do RSpec.configure more than once
|
22
|
+
#unless RSpec.configuration.color_enabled == true
|
23
|
+
RSpec.configure do |config|
|
24
|
+
config.color = true
|
25
|
+
config.formatter = :documentation
|
26
|
+
end
|
27
|
+
#end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe Vectra::Api, 'Configure' do
|
4
|
+
include_context "shared environment"
|
5
|
+
|
6
|
+
it 'configures correctly' do
|
7
|
+
Vectra.configure do |config|
|
8
|
+
config.endpoint = @endpoint_url
|
9
|
+
config.username = @username
|
10
|
+
config.password = @password
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'gets all hosts' do
|
15
|
+
puts Vectra::Hosts.all
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'gets host by id' do
|
19
|
+
puts Vectra::Hosts.get(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'gets all detections' do
|
23
|
+
puts Vectra::Detections.all
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'gets detection by id' do
|
27
|
+
puts Vectra::Detections.get(95)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/vectra.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Created by hand, like a real man
|
2
|
+
# coding: utf-8
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'vectra/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
|
9
|
+
s.name = 'vectra'
|
10
|
+
s.version = Vectra::VERSION
|
11
|
+
s.date = '2015-02-23'
|
12
|
+
s.summary = "Vectra API Client"
|
13
|
+
s.description = "Easily interface with the Vectra API for consuming detections, threats and events"
|
14
|
+
s.authors = ["Mike Mackintosh"]
|
15
|
+
s.email = 'm@zyp.io'
|
16
|
+
s.homepage =
|
17
|
+
'http://github.com/mikemackintosh/ruby-vectra'
|
18
|
+
|
19
|
+
s.license = 'MIT'
|
20
|
+
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
s.files = `git ls-files -z`.split("\x0")
|
23
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
25
|
+
|
26
|
+
s.add_dependency 'httparty'
|
27
|
+
s.add_dependency 'fattr'
|
28
|
+
|
29
|
+
s.add_development_dependency "bundler"
|
30
|
+
s.add_development_dependency "rake"
|
31
|
+
s.add_development_dependency "rspec"
|
32
|
+
s.add_development_dependency "webmock"
|
33
|
+
|
34
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vectra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Mackintosh
|
@@ -94,13 +94,31 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description: Vectra API
|
97
|
+
description: Easily interface with the Vectra API for consuming detections, threats
|
98
|
+
and events
|
98
99
|
email: m@zyp.io
|
99
100
|
executables: []
|
100
101
|
extensions: []
|
101
102
|
extra_rdoc_files: []
|
102
|
-
files:
|
103
|
-
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rock.yml"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- lib/vectra.rb
|
113
|
+
- lib/vectra/api.rb
|
114
|
+
- lib/vectra/config.rb
|
115
|
+
- lib/vectra/detections.rb
|
116
|
+
- lib/vectra/hosts.rb
|
117
|
+
- lib/vectra/version.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
- spec/vectra/vectra_spec.rb
|
120
|
+
- vectra.gemspec
|
121
|
+
homepage: http://github.com/mikemackintosh/ruby-vectra
|
104
122
|
licenses:
|
105
123
|
- MIT
|
106
124
|
metadata: {}
|
@@ -124,4 +142,6 @@ rubygems_version: 2.2.2
|
|
124
142
|
signing_key:
|
125
143
|
specification_version: 4
|
126
144
|
summary: Vectra API Client
|
127
|
-
test_files:
|
145
|
+
test_files:
|
146
|
+
- spec/spec_helper.rb
|
147
|
+
- spec/vectra/vectra_spec.rb
|