ats 0.1.7 → 0.1.8
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 +4 -4
- data/lib/ats.rb +1 -0
- data/lib/ats/amp4e/api.rb +8 -28
- data/lib/ats/cli.rb +9 -5
- data/lib/ats/cli/command.rb +46 -0
- data/lib/ats/configuration.rb +14 -5
- data/lib/ats/http_api.rb +3 -2
- data/lib/ats/threat_grid/api.rb +7 -26
- data/lib/ats/version.rb +1 -1
- metadata +2 -4
- data/lib/ats/cli/amp4e/command.rb +0 -26
- data/lib/ats/cli/threat_grid.rb +0 -15
- data/lib/ats/cli/threat_grid/command.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 226e424b41b47a9bed3a8e3e02daa4c8e6747d44cd9c3c0d25e9bbf0f7b977d3
|
4
|
+
data.tar.gz: d67d968d01a44e95a75d1c2541a29319c19d1d7b2d1b05c924c03479ec533c9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e8e7e9a31b025f787681b847fc1d41f08c634ba579facd07d3dd9e468dcaac90a5c0337a7afff9ebadfa7ede6f4d086177ea20400a9879aeb668835c023c840
|
7
|
+
data.tar.gz: 57eababf9c32f5749f6d43a237f7e04ecc3a235e442700449cb36aed4cfea50b4c7764aa1120d4f053fa6658fcdbe804b2858ac23fe111fe834a43e16c8d71bc
|
data/lib/ats.rb
CHANGED
data/lib/ats/amp4e/api.rb
CHANGED
@@ -7,16 +7,16 @@ module ATS
|
|
7
7
|
'User-Agent' => "RubyGems/ATS #{ATS::VERSION}",
|
8
8
|
}.freeze
|
9
9
|
|
10
|
-
attr_reader :http, :
|
10
|
+
attr_reader :http, :port, :host, :scheme, :client_id, :client_secret
|
11
11
|
|
12
|
-
def initialize(
|
13
|
-
|
14
|
-
profile: :default,
|
15
|
-
configuration: ATS.configuration
|
16
|
-
)
|
17
|
-
@http = api
|
18
|
-
@profile = profile.to_sym
|
12
|
+
def initialize(configuration:, debug: false)
|
13
|
+
@http = HttpAPI.new(headers: HEADERS, debug: debug)
|
19
14
|
@configuration = configuration
|
15
|
+
@port = configuration[:port]
|
16
|
+
@scheme = configuration[:scheme]
|
17
|
+
@host = configuration[:host]
|
18
|
+
@client_id = configuration[:client_id]
|
19
|
+
@client_secret = configuration[:client_secret]
|
20
20
|
end
|
21
21
|
|
22
22
|
def computers
|
@@ -47,26 +47,6 @@ module ATS
|
|
47
47
|
URI::Generic.build(host: host, port: port, scheme: scheme, path: "/v#{version}/#{relative_url}")
|
48
48
|
end
|
49
49
|
|
50
|
-
def client_id
|
51
|
-
configuration[profile][:amp4e][:client_id]
|
52
|
-
end
|
53
|
-
|
54
|
-
def client_secret
|
55
|
-
configuration[profile][:amp4e][:client_secret]
|
56
|
-
end
|
57
|
-
|
58
|
-
def host
|
59
|
-
configuration[profile][:amp4e][:host]
|
60
|
-
end
|
61
|
-
|
62
|
-
def scheme
|
63
|
-
configuration[profile][:amp4e][:scheme]
|
64
|
-
end
|
65
|
-
|
66
|
-
def port
|
67
|
-
configuration[profile][:amp4e][:port]
|
68
|
-
end
|
69
|
-
|
70
50
|
def headers
|
71
51
|
{ AUTHORIZATION: "Basic #{Base64.strict_encode64("#{client_id}:#{client_secret}")}" }
|
72
52
|
end
|
data/lib/ats/cli.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'ats'
|
2
|
-
|
3
2
|
require 'thor'
|
4
|
-
require 'ats/cli/
|
5
|
-
require 'ats/cli/
|
3
|
+
require 'ats/cli/command'
|
4
|
+
require 'ats/cli/threat_grid/organizations'
|
5
|
+
require 'ats/cli/threat_grid/samples'
|
6
|
+
require 'ats/cli/threat_grid/search'
|
7
|
+
require 'ats/cli/threat_grid/users'
|
8
|
+
require 'ats/cli/threat_grid/whoami'
|
9
|
+
require 'ats/cli/threat_grid/application'
|
6
10
|
require 'ats/cli/amp4e/computers'
|
7
11
|
require 'ats/cli/amp4e/events'
|
8
12
|
require 'ats/cli/amp4e/groups'
|
@@ -28,7 +32,7 @@ module ATS
|
|
28
32
|
desc 'setup', 'Initialize the .atsrc file.'
|
29
33
|
def setup(configuration = ATS.configuration)
|
30
34
|
say "Current Configuration:", :green
|
31
|
-
say JSON.pretty_generate(configuration.
|
35
|
+
say JSON.pretty_generate(configuration.to_h), :green
|
32
36
|
|
33
37
|
configuration.config_files.each do |file|
|
34
38
|
if File.exist?(file)
|
@@ -49,7 +53,7 @@ module ATS
|
|
49
53
|
port: 443,
|
50
54
|
scheme: 'https',
|
51
55
|
},
|
52
|
-
|
56
|
+
threatgrid: {
|
53
57
|
api_key: '',
|
54
58
|
host: 'panacea.threatgrid.com',
|
55
59
|
port: 443,
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ATS
|
2
|
+
module CLI
|
3
|
+
class Command < Thor
|
4
|
+
class_option :profile, default: :default, required: false
|
5
|
+
class_option :debug, default: false, required: false
|
6
|
+
|
7
|
+
def self.printable_commands(*args)
|
8
|
+
super.map do |x|
|
9
|
+
x[0] = x[0].gsub(/^ats/, "ats #{service_name.downcase}")
|
10
|
+
x
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def api
|
17
|
+
self.class.constant_name.new(
|
18
|
+
configuration: configuration.fetch(profile)[self.class.service_name.downcase.to_sym],
|
19
|
+
debug: configuration.debug,
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def print_json(json)
|
24
|
+
say JSON.pretty_generate(json), :green
|
25
|
+
end
|
26
|
+
|
27
|
+
def configuration
|
28
|
+
ATS.configure do |x|
|
29
|
+
x.debug = options['debug']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def profile
|
34
|
+
options['profile'].to_sym
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.constant_name
|
38
|
+
Kernel.const_get("ATS::#{service_name}::API")
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.service_name
|
42
|
+
name.split("::")[2]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/ats/configuration.rb
CHANGED
@@ -1,26 +1,35 @@
|
|
1
1
|
module ATS
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :logger, :config_files, :
|
3
|
+
attr_accessor :logger, :config_files, :debug
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@logger = Logger.new(STDOUT)
|
7
7
|
@logger.level = Logger::DEBUG
|
8
|
+
@debug = false
|
8
9
|
@config_files = [
|
9
10
|
File.join(Dir.home, ".atsrc"),
|
10
11
|
File.expand_path('.atsrc'),
|
11
12
|
ENV['ATSRC']
|
12
13
|
].compact
|
14
|
+
end
|
15
|
+
|
16
|
+
def fetch(key)
|
17
|
+
hash.fetch(key.to_sym)
|
18
|
+
end
|
13
19
|
|
14
|
-
|
20
|
+
def to_h
|
21
|
+
hash.dup
|
15
22
|
end
|
16
23
|
|
17
|
-
|
18
|
-
|
24
|
+
private
|
25
|
+
|
26
|
+
def hash
|
27
|
+
@hash ||= load_configuration
|
19
28
|
end
|
20
29
|
|
21
30
|
def load_configuration(files = config_files)
|
22
31
|
files.inject({}) do |memo, file|
|
23
|
-
logger.debug("
|
32
|
+
logger.debug("Searching for #{file}...") if debug
|
24
33
|
memo.merge!(YAML.load(IO.read(file))) if File.exist?(file)
|
25
34
|
memo
|
26
35
|
end
|
data/lib/ats/http_api.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module ATS
|
2
2
|
class HttpAPI
|
3
|
-
def initialize(headers: {})
|
3
|
+
def initialize(headers: {}, debug: false)
|
4
4
|
@default_headers = headers
|
5
|
+
@debug = debug
|
5
6
|
end
|
6
7
|
|
7
8
|
def execute(uri, request)
|
@@ -44,7 +45,7 @@ module ATS
|
|
44
45
|
http = Net::HTTP.new(uri.host, uri.port)
|
45
46
|
http.read_timeout = 30
|
46
47
|
http.use_ssl = uri.scheme == "https"
|
47
|
-
http.set_debug_output(ATS.logger)
|
48
|
+
http.set_debug_output(ATS.logger) if @debug
|
48
49
|
http
|
49
50
|
end
|
50
51
|
|
data/lib/ats/threat_grid/api.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'ats/http_api'
|
2
|
-
|
3
1
|
module ATS
|
4
2
|
module ThreatGrid
|
5
3
|
class API
|
@@ -8,16 +6,15 @@ module ATS
|
|
8
6
|
'User-Agent' => "RubyGems/ATS #{ATS::VERSION}",
|
9
7
|
}.freeze
|
10
8
|
|
11
|
-
attr_reader :http, :
|
9
|
+
attr_reader :http, :port, :host, :scheme, :api_key
|
12
10
|
|
13
|
-
def initialize(
|
14
|
-
|
15
|
-
profile: :default,
|
16
|
-
configuration: ATS.configuration
|
17
|
-
)
|
18
|
-
@http = api
|
19
|
-
@profile = profile.to_sym
|
11
|
+
def initialize(configuration:, debug: false)
|
12
|
+
@http = HttpAPI.new(headers: HEADERS, debug: debug)
|
20
13
|
@configuration = configuration
|
14
|
+
@port = configuration[:port]
|
15
|
+
@scheme = configuration[:scheme]
|
16
|
+
@host = configuration[:host]
|
17
|
+
@api_key = configuration[:api_key]
|
21
18
|
end
|
22
19
|
|
23
20
|
def whoami
|
@@ -55,22 +52,6 @@ module ATS
|
|
55
52
|
def build_uri(relative_url, version:)
|
56
53
|
URI::Generic.build(host: host, port: port, scheme: scheme, path: "/api/v#{version}/#{relative_url}")
|
57
54
|
end
|
58
|
-
|
59
|
-
def api_key
|
60
|
-
configuration[profile][:threat_grid][:api_key]
|
61
|
-
end
|
62
|
-
|
63
|
-
def host
|
64
|
-
configuration[profile][:threat_grid][:host]
|
65
|
-
end
|
66
|
-
|
67
|
-
def scheme
|
68
|
-
configuration[profile][:threat_grid][:scheme]
|
69
|
-
end
|
70
|
-
|
71
|
-
def port
|
72
|
-
configuration[profile][:threat_grid][:port]
|
73
|
-
end
|
74
55
|
end
|
75
56
|
end
|
76
57
|
end
|
data/lib/ats/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mokha
|
@@ -88,14 +88,12 @@ files:
|
|
88
88
|
- lib/ats/amp4e/policies.rb
|
89
89
|
- lib/ats/cli.rb
|
90
90
|
- lib/ats/cli/amp4e/application.rb
|
91
|
-
- lib/ats/cli/amp4e/command.rb
|
92
91
|
- lib/ats/cli/amp4e/computers.rb
|
93
92
|
- lib/ats/cli/amp4e/events.rb
|
94
93
|
- lib/ats/cli/amp4e/groups.rb
|
95
94
|
- lib/ats/cli/amp4e/policies.rb
|
96
|
-
- lib/ats/cli/
|
95
|
+
- lib/ats/cli/command.rb
|
97
96
|
- lib/ats/cli/threat_grid/application.rb
|
98
|
-
- lib/ats/cli/threat_grid/command.rb
|
99
97
|
- lib/ats/cli/threat_grid/organizations.rb
|
100
98
|
- lib/ats/cli/threat_grid/samples.rb
|
101
99
|
- lib/ats/cli/threat_grid/search.rb
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module ATS
|
2
|
-
module CLI
|
3
|
-
module AMP4E
|
4
|
-
class Command < Thor
|
5
|
-
class_option :profile, default: :default, required: false
|
6
|
-
|
7
|
-
def self.printable_commands(*args)
|
8
|
-
super.map do |x|
|
9
|
-
x[0] = x[0].gsub(/^ats/, 'ats amp4e')
|
10
|
-
x
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
protected
|
15
|
-
|
16
|
-
def api
|
17
|
-
ATS::AMP4E::API.new(profile: options['profile'])
|
18
|
-
end
|
19
|
-
|
20
|
-
def print_json(json)
|
21
|
-
say JSON.pretty_generate(json), :green
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/ats/cli/threat_grid.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'ats/cli/threat_grid/command'
|
2
|
-
require 'ats/cli/threat_grid/organizations'
|
3
|
-
require 'ats/cli/threat_grid/samples'
|
4
|
-
require 'ats/cli/threat_grid/search'
|
5
|
-
require 'ats/cli/threat_grid/users'
|
6
|
-
require 'ats/cli/threat_grid/whoami'
|
7
|
-
|
8
|
-
require 'ats/cli/threat_grid/application'
|
9
|
-
|
10
|
-
module ATS
|
11
|
-
module CLI
|
12
|
-
module ThreatGrid
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module ATS
|
2
|
-
module CLI
|
3
|
-
module ThreatGrid
|
4
|
-
class Command < Thor
|
5
|
-
class_option :profile, default: :default, required: false
|
6
|
-
|
7
|
-
def self.printable_commands(*args)
|
8
|
-
super.map do |x|
|
9
|
-
x[0] = x[0].gsub(/^ats/, 'ats threatgrid')
|
10
|
-
x
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
protected
|
15
|
-
|
16
|
-
def api
|
17
|
-
ATS::ThreatGrid::API.new(profile: options['profile'])
|
18
|
-
end
|
19
|
-
|
20
|
-
def print_json(json)
|
21
|
-
say JSON.pretty_generate(json), :green
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|