diff options
| author | mokha <mokha@cisco.com> | 2018-03-19 17:29:31 -0600 |
|---|---|---|
| committer | mokha <mokha@cisco.com> | 2018-03-19 17:29:31 -0600 |
| commit | cb7067f9c620573e97f9887f396302aaa6518aec (patch) | |
| tree | e83d3f3311728fb7fec9d9e895cb22e6ad458f83 /lib | |
| parent | 6d55456c1f59e9ac6135c89816b407f2b2d24e63 (diff) | |
add command to connect to token introspection endpoint.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ats.rb | 2 | ||||
| -rw-r--r-- | lib/ats/cli.rb | 5 | ||||
| -rw-r--r-- | lib/ats/cli/shiro/application.rb | 10 | ||||
| -rw-r--r-- | lib/ats/cli/shiro/tokens.rb | 12 | ||||
| -rw-r--r-- | lib/ats/shiro/api.rb | 42 | ||||
| -rw-r--r-- | lib/ats/shiro/tokens.rb | 15 |
6 files changed, 86 insertions, 0 deletions
@@ -18,6 +18,8 @@ require 'ats/threat_grid/organizations' require 'ats/threat_grid/samples' require 'ats/threat_grid/search' require 'ats/threat_grid/users' +require 'ats/shiro/api' +require 'ats/shiro/tokens' module ATS class << self diff --git a/lib/ats/cli.rb b/lib/ats/cli.rb index cd400fc..2345c6e 100644 --- a/lib/ats/cli.rb +++ b/lib/ats/cli.rb @@ -13,6 +13,8 @@ require 'ats/cli/amp4e/events' require 'ats/cli/amp4e/groups' require 'ats/cli/amp4e/policies' require 'ats/cli/amp4e/application' +require 'ats/cli/shiro/tokens' +require 'ats/cli/shiro/application' module ATS module CLI @@ -25,6 +27,9 @@ module ATS desc 'amp4e SUBCOMMAND ...ARGS', 'interact with the AMP for Endpoints API' subcommand 'amp4e', AMP4E::Application + desc 'shiro SUBCOMMAND ...ARGS', 'interact with the AMP for Endpoints API' + subcommand 'shiro', Shiro::Application + desc 'setup', 'setup' subcommand :setup, ATS::CLI::Setup diff --git a/lib/ats/cli/shiro/application.rb b/lib/ats/cli/shiro/application.rb new file mode 100644 index 0000000..be78dd9 --- /dev/null +++ b/lib/ats/cli/shiro/application.rb @@ -0,0 +1,10 @@ +module ATS + module CLI + module Shiro + class Application < Thor + desc 'tokens SUBCOMMAND ...ARGS', 'interact with the AMP4E API' + subcommand :tokens, ATS::CLI::Shiro::Tokens + end + end + end +end diff --git a/lib/ats/cli/shiro/tokens.rb b/lib/ats/cli/shiro/tokens.rb new file mode 100644 index 0000000..4bca3da --- /dev/null +++ b/lib/ats/cli/shiro/tokens.rb @@ -0,0 +1,12 @@ +module ATS + module CLI + module Shiro + class Tokens < Command + desc 'introspect <TOKEN>', 'introspection endpoint' + def introspect(token) + print_json api.tokens.introspect(token) + end + end + end + end +end diff --git a/lib/ats/shiro/api.rb b/lib/ats/shiro/api.rb new file mode 100644 index 0000000..d5e6f3e --- /dev/null +++ b/lib/ats/shiro/api.rb @@ -0,0 +1,42 @@ +module ATS + module Shiro + class API + HEADERS = { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + 'User-Agent' => "RubyGems/ATS #{ATS::VERSION}", + }.freeze + + attr_reader :http, :port, :host, :scheme, :bearer_token + + def initialize(configuration:, debug: false) + @http = HttpAPI.new(headers: HEADERS, debug: debug) + @configuration = configuration + @port = configuration[:port] + @scheme = configuration[:scheme] + @host = configuration[:host] + @bearer_token = configuration[:bearer_token] + end + + def tokens + ATS::Shiro::Tokens.new(self) + end + + def post(url, params: {}, version: 1) + http.post(build_uri(url, version: version), headers: headers, body: params) do |request, response| + JSON.parse(response.body, symbolize_names: true) + end + end + + private + + def build_uri(relative_url, version:) + URI::Generic.build(host: host, port: port, scheme: scheme, path: "/api/v#{version}/#{relative_url}") + end + + def headers + { AUTHORIZATION: "Bearer #{bearer_token}" } + end + end + end +end diff --git a/lib/ats/shiro/tokens.rb b/lib/ats/shiro/tokens.rb new file mode 100644 index 0000000..08b749f --- /dev/null +++ b/lib/ats/shiro/tokens.rb @@ -0,0 +1,15 @@ +module ATS + module Shiro + class Tokens + attr_reader :api + + def initialize(api) + @api = api + end + + def introspect(token) + api.post("tokens/introspect", params: { token: token }) + end + end + end +end |
