ats 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f2fe2728729b93415b0a3207e83702f05b99d6bdd4171881cd92b3c7e135549
4
- data.tar.gz: a078e537c475aca4ecb294278f862aba09964e5067793e84b4747b057f1e0666
3
+ metadata.gz: 7eb27ec01faf12a9d4ccf0ca36588f91b72305ce29c6dc6034fe9089f546bc53
4
+ data.tar.gz: 941b422bf5a5e71ca0004dc6ad9b2d516a54b83db255fcb24e292844fe130322
5
5
  SHA512:
6
- metadata.gz: 36443b75271928b0cc6adc098a064b39b554b4d53b677b91b7569e7330ef010ecfacf8e641e8234eb5e59eac97c4ffbf0592ce2fd526faccf01462b18b58ac75
7
- data.tar.gz: 3f0657e29f705f3076acef287c6984edf1a11d7a9618bc4b82feb9cd3a9ec6c15a4e38984aad34aba0029e89b0af0bde4aae40b7fa117baa2e4e052c0cd07889
6
+ metadata.gz: 165b94fb99a63af982466640a85abddcef4e32a2a23369e88371e09f19f8be124249b7891e542228f408ed292b09bf3acd11f3614f72aa3bf5695228a9e958da
7
+ data.tar.gz: 78d3cfecdebf5b0e0ec64aac27319c2670e3fb98d46f6b6e4ed770d64b6e67d0dfa957e22988c0a1e918e670ac918af42fe288b81d981bf0a00b7ddbdbd1c416
data/ats-cli.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.bindir = "exe"
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
+ spec.required_ruby_version = '>= 2.5.0'
25
26
 
26
27
  spec.add_dependency 'thor', '~> 0.20'
27
28
  spec.add_development_dependency "bundler", "~> 1.16"
data/lib/ats.rb CHANGED
@@ -18,6 +18,8 @@ require 'ats/threat_grid/organizations'
18
18
  require 'ats/threat_grid/samples'
19
19
  require 'ats/threat_grid/search'
20
20
  require 'ats/threat_grid/users'
21
+ require 'ats/shiro/api'
22
+ require 'ats/shiro/tokens'
21
23
 
22
24
  module ATS
23
25
  class << self
data/lib/ats/cli.rb CHANGED
@@ -13,6 +13,9 @@ require 'ats/cli/amp4e/events'
13
13
  require 'ats/cli/amp4e/groups'
14
14
  require 'ats/cli/amp4e/policies'
15
15
  require 'ats/cli/amp4e/application'
16
+ require 'ats/cli/shiro/tokens'
17
+ require 'ats/cli/shiro/versions'
18
+ require 'ats/cli/shiro/application'
16
19
 
17
20
  module ATS
18
21
  module CLI
@@ -25,6 +28,9 @@ module ATS
25
28
  desc 'amp4e SUBCOMMAND ...ARGS', 'interact with the AMP for Endpoints API'
26
29
  subcommand 'amp4e', AMP4E::Application
27
30
 
31
+ desc 'shiro SUBCOMMAND ...ARGS', 'interact with the AMP for Endpoints API'
32
+ subcommand 'shiro', Shiro::Application
33
+
28
34
  desc 'setup', 'setup'
29
35
  subcommand :setup, ATS::CLI::Setup
30
36
 
data/lib/ats/cli/setup.rb CHANGED
@@ -5,6 +5,10 @@ module ATS
5
5
 
6
6
  desc 'setup', 'Initialize the .atsrc file.'
7
7
  def setup
8
+ say "Default Configuration:", :green
9
+ yaml = YAML.dump(default_settings)
10
+ say yaml, :yellow
11
+
8
12
  say "Current Configuration:", :green
9
13
  say JSON.pretty_generate(configuration.to_h), :green
10
14
 
@@ -18,9 +22,8 @@ module ATS
18
22
  say "Configuration file not found."
19
23
  new_file = configuration.config_files.first
20
24
  say "New file created at #{new_file}."
21
- yaml = YAML.dump(default_settings)
22
- say yaml, :yellow
23
25
  IO.write(new_file, yaml)
26
+ File.chmod(0600, new_file)
24
27
  end
25
28
 
26
29
  private
@@ -41,6 +44,12 @@ module ATS
41
44
  port: 443,
42
45
  scheme: 'https',
43
46
  },
47
+ shiro: {
48
+ bearer_token: '',
49
+ host: 'auth.amp.cisco.com',
50
+ port: 443,
51
+ scheme: 'https',
52
+ },
44
53
  }
45
54
  }
46
55
  end
@@ -0,0 +1,13 @@
1
+ module ATS
2
+ module CLI
3
+ module Shiro
4
+ class Application < Thor
5
+ desc 'tokens SUBCOMMAND ...ARGS', 'interact with the Auth API'
6
+ subcommand :tokens, ATS::CLI::Shiro::Tokens
7
+
8
+ desc 'version SUBCOMMAND ...ARGS', 'interact with the Auth API'
9
+ subcommand :version, ATS::CLI::Shiro::Versions
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module ATS
2
+ module CLI
3
+ module Shiro
4
+ class Tokens < Command
5
+ desc 'introspect <TOKEN>', 'introspection endpoint'
6
+ def introspect(token)
7
+ print_json api.tokens.introspect(token)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module ATS
2
+ module CLI
3
+ module Shiro
4
+ class Versions < Command
5
+ default_command :show
6
+
7
+ desc 'show', ''
8
+ def show
9
+ print_json api.version
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/ats/http_api.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'openssl'
2
+
1
3
  module ATS
2
4
  class HttpAPI
3
5
  def initialize(headers: {}, debug: false)
@@ -45,7 +47,10 @@ module ATS
45
47
  http = Net::HTTP.new(uri.host, uri.port)
46
48
  http.read_timeout = 30
47
49
  http.use_ssl = uri.scheme == "https"
48
- http.set_debug_output(ATS.logger) if @debug
50
+ if debug?
51
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
52
+ http.set_debug_output(ATS.logger)
53
+ end
49
54
  http
50
55
  end
51
56
 
@@ -66,5 +71,9 @@ module ATS
66
71
  x.body = JSON.generate(body)
67
72
  end
68
73
  end
74
+
75
+ def debug?
76
+ @debug
77
+ end
69
78
  end
70
79
  end
@@ -0,0 +1,52 @@
1
+ module ATS
2
+ module Shiro
3
+ class API
4
+ HEADERS = {
5
+ 'Content-Type' => 'application/json',
6
+ 'Accept' => 'application/json',
7
+ 'User-Agent' => "RubyGems/ATS #{ATS::VERSION}",
8
+ }.freeze
9
+
10
+ attr_reader :http, :port, :host, :scheme, :bearer_token
11
+
12
+ def initialize(configuration:, debug: false)
13
+ @http = HttpAPI.new(headers: HEADERS, debug: debug)
14
+ @configuration = configuration
15
+ @port = configuration[:port]
16
+ @scheme = configuration[:scheme]
17
+ @host = configuration[:host]
18
+ @bearer_token = configuration[:bearer_token]
19
+ end
20
+
21
+ def tokens
22
+ ATS::Shiro::Tokens.new(self)
23
+ end
24
+
25
+ def version
26
+ get("version")
27
+ end
28
+
29
+ def get(url, params: {}, version: 1)
30
+ http.get(build_uri(url, version: version), headers: headers, body: params) do |request, response|
31
+ JSON.parse(response.body, symbolize_names: true)
32
+ end
33
+ end
34
+
35
+ def post(url, params: {}, version: 1)
36
+ http.post(build_uri(url, version: version), headers: headers, body: params) do |request, response|
37
+ JSON.parse(response.body, symbolize_names: true)
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def build_uri(relative_url, version:)
44
+ URI::Generic.build(host: host, port: port, scheme: scheme, path: "/api/v#{version}/#{relative_url}")
45
+ end
46
+
47
+ def headers
48
+ { AUTHORIZATION: "Bearer #{bearer_token}" }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,15 @@
1
+ module ATS
2
+ module Shiro
3
+ class Tokens
4
+ attr_reader :api
5
+
6
+ def initialize(api)
7
+ @api = api
8
+ end
9
+
10
+ def introspect(token)
11
+ api.post("tokens/introspect", params: { token: token })
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/ats/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ATS
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - mokha
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-19 00:00:00.000000000 Z
11
+ date: 2018-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -94,6 +94,9 @@ files:
94
94
  - lib/ats/cli/amp4e/policies.rb
95
95
  - lib/ats/cli/command.rb
96
96
  - lib/ats/cli/setup.rb
97
+ - lib/ats/cli/shiro/application.rb
98
+ - lib/ats/cli/shiro/tokens.rb
99
+ - lib/ats/cli/shiro/versions.rb
97
100
  - lib/ats/cli/threat_grid/application.rb
98
101
  - lib/ats/cli/threat_grid/organizations.rb
99
102
  - lib/ats/cli/threat_grid/samples.rb
@@ -102,6 +105,8 @@ files:
102
105
  - lib/ats/cli/threat_grid/whoami.rb
103
106
  - lib/ats/configuration.rb
104
107
  - lib/ats/http_api.rb
108
+ - lib/ats/shiro/api.rb
109
+ - lib/ats/shiro/tokens.rb
105
110
  - lib/ats/threat_grid/api.rb
106
111
  - lib/ats/threat_grid/organizations.rb
107
112
  - lib/ats/threat_grid/samples.rb
@@ -120,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
125
  requirements:
121
126
  - - ">="
122
127
  - !ruby/object:Gem::Version
123
- version: '0'
128
+ version: 2.5.0
124
129
  required_rubygems_version: !ruby/object:Gem::Requirement
125
130
  requirements:
126
131
  - - ">="