threadfix-cli 0.2.0 → 0.3.0

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: b742e971c8a8526553a028f6977d58f412ea8366279ddb691ec1359b924fb371
4
- data.tar.gz: c08fabb6f96447287c261d5bd102cf6f76141842f3614e6fc0058af3b9067dc6
3
+ metadata.gz: 211f70bf2afa9eeb52ed00045e60efb66d579acdd555216be902f7b3aa63a89e
4
+ data.tar.gz: b225cc93ac012b25ef8125eb9eb77fc373ba0f342676e05d0e8f9d0ab9618888
5
5
  SHA512:
6
- metadata.gz: 7263c301222945d2b3faed28fca1df0100a0b5310b66213b7557d3761dfd735ef3effcca67b7879e4a7b6bef99f93cb7b3b31b3a04facac4568633beefd725ee
7
- data.tar.gz: 44ecd4264b54fc75276fd4ada4e9d2013b0a59faf0baa3c20e08b6bf0248d45c65f7a9688753a9bc0bfa292d5130b6b11e744684b1c697f0783e7f215cf38e2c
6
+ metadata.gz: f813b8519a5fffbb01e9860e8442bbc4593f5bd751f3b51215f9383edf594344220f8bbdfe288fb79a4b82856cc3307f9de33bd9eb9982edc592628fffa97939
7
+ data.tar.gz: 2455dfaae7f91fe92809370180d188d7b8c3664b0e0a9fc9bb54ad7b9cc2a04621eb5e46b005eb50af7a0b82f4b83189538244ce70450e4da141da7ead5780eb
@@ -2,6 +2,27 @@ require "threadfix/client"
2
2
  module Threadfix
3
3
  module Cli
4
4
  class Applications < Thor
5
+ desc "get_id", "gets an application ID from a application name"
6
+ option :host
7
+ option :key, desc: "Authorisation key"
8
+ option :app_name, required: true
9
+ def get_id
10
+ Client.configure do |config|
11
+ config.host = options[:host] if options[:host]
12
+ config.key = options[:key] if options[:key]
13
+ end
14
+
15
+ begin
16
+ response = Client::Applications.get_id(app_name: options[:app_name] )
17
+ if !response.nil?
18
+ puts response
19
+ end
20
+ rescue SocketError => e
21
+ puts "Error: Unable open connection to '#{Client.config.host}'"
22
+ exit 1
23
+ end
24
+ end
25
+
5
26
  desc "lookup", "lookup an application ID"
6
27
  option :host
7
28
  option :key, desc: "Authorisation key"
@@ -15,7 +15,10 @@ module Threadfix
15
15
 
16
16
  begin
17
17
  response = Client::Scans.upload(file_path: options[:file], app_id: options[:app_id] )
18
- puts response['message']
18
+ message = response['message']
19
+ message = message + " (ID: #{response['object']['id']})" if response['object'] && response['object']['id']
20
+
21
+ puts message
19
22
  rescue Errno::ENOENT => e
20
23
  puts "Error: File or directory '#{options[:file]}' doesn't exist."
21
24
  exit 1
@@ -1,5 +1,5 @@
1
1
  module Threadfix
2
2
  module Cli
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -0,0 +1,54 @@
1
+ module Threadfix
2
+ module Client
3
+ module Applications
4
+ class GetId
5
+ # https://denimgroup.atlassian.net/wiki/spaces/TDOC/pages/664567813/List+Applications+-+API
6
+ API_VERSION='2.7.5'
7
+
8
+ attr_reader :app_name
9
+
10
+ def initialize(options={})
11
+ @app_name = options[:app_name]
12
+ end
13
+
14
+ def perform!
15
+ begin
16
+ r = RestClient.get(
17
+ endpoint.to_s,
18
+ { :accept => "application/json", :Authorization => "APIKEY #{apiKey}" }
19
+ )
20
+ body = JSON.parse(r.body)
21
+
22
+ begin
23
+ body.fetch('object')
24
+ .find{ |a| a.fetch('name') == app_name}.fetch('id')
25
+ rescue => e
26
+ puts "App '#{app_name}' was not found."
27
+ nil # return nil if data not found
28
+ end
29
+ rescue RestClient::NotFound => e
30
+ puts "Endpoint not found (using API version: #{API_VERSION})"
31
+ raise e
32
+ rescue RestClient::ExceptionWithResponse => e
33
+ raise e
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def endpoint
40
+ URI("#{host}/rest/#{API_VERSION}/applications")
41
+ end
42
+
43
+ def host
44
+ Client.config.host
45
+ end
46
+
47
+ def apiKey
48
+ Client.config.key
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -1,16 +1,25 @@
1
1
  require "threadfix/client/applications/lookup"
2
+ require "threadfix/client/applications/get_id"
2
3
 
3
4
  module Threadfix
4
5
  module Client
5
6
  module Applications
6
7
  class <<self
7
8
 
8
- # @param file_path
9
+ # @param options[app_name]
10
+ # @param options[team_name]
9
11
  # @return Hash
10
12
  def lookup(options={})
11
13
  action = Lookup.new(options)
12
14
  action.perform!
13
15
  end
16
+
17
+ # @param options[app_name]
18
+ # @return Hash
19
+ def get_id(options={})
20
+ action = GetId.new(options)
21
+ action.perform!
22
+ end
14
23
  end
15
24
  end
16
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: threadfix-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Elliott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-09 00:00:00.000000000 Z
11
+ date: 2022-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -88,14 +88,6 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - ".gitignore"
92
- - ".rspec"
93
- - CHANGE_LOG.md
94
- - Gemfile
95
- - Gemfile.lock
96
- - LICENSE
97
- - README.md
98
- - Rakefile
99
91
  - bin/console
100
92
  - bin/setup
101
93
  - bin/threadfix
@@ -105,10 +97,10 @@ files:
105
97
  - lib/threadfix/cli/version.rb
106
98
  - lib/threadfix/client.rb
107
99
  - lib/threadfix/client/applications.rb
100
+ - lib/threadfix/client/applications/get_id.rb
108
101
  - lib/threadfix/client/applications/lookup.rb
109
102
  - lib/threadfix/client/scans.rb
110
103
  - lib/threadfix/client/scans/upload.rb
111
- - threadfix-cli.gemspec
112
104
  homepage: https://github.com/DDAZZA/threadfix-cli
113
105
  licenses: []
114
106
  metadata:
@@ -130,8 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
122
  - !ruby/object:Gem::Version
131
123
  version: '0'
132
124
  requirements: []
133
- rubyforge_project:
134
- rubygems_version: 2.7.6
125
+ rubygems_version: 3.2.32
135
126
  signing_key:
136
127
  specification_version: 4
137
128
  summary: CLI to upload scan report to ThreadFix
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/CHANGE_LOG.md DELETED
@@ -1,9 +0,0 @@
1
- # v0.1.0
2
-
3
- - Initial release to upload scans
4
-
5
- # v0.2.0
6
-
7
- - Changed $HOST to $THREADFIX_HOST
8
- - Added $ threadfix version
9
- - Added $ threadfix applications lookup
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in threadfix-cli.gemspec
4
- gemspec
5
-
6
- gem 'pry'
data/Gemfile.lock DELETED
@@ -1,59 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- threadfix-cli (0.1.0)
5
- rest-client (= 2.0.2)
6
- thor (= 0.20.3)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- coderay (1.1.2)
12
- diff-lcs (1.3)
13
- domain_name (0.5.20180417)
14
- unf (>= 0.0.5, < 1.0.0)
15
- http-cookie (1.0.3)
16
- domain_name (~> 0.5)
17
- method_source (0.9.2)
18
- mime-types (3.2.2)
19
- mime-types-data (~> 3.2015)
20
- mime-types-data (3.2019.0331)
21
- netrc (0.11.0)
22
- pry (0.12.2)
23
- coderay (~> 1.1.0)
24
- method_source (~> 0.9.0)
25
- rake (10.5.0)
26
- rest-client (2.0.2)
27
- http-cookie (>= 1.0.2, < 2.0)
28
- mime-types (>= 1.16, < 4.0)
29
- netrc (~> 0.8)
30
- rspec (3.8.0)
31
- rspec-core (~> 3.8.0)
32
- rspec-expectations (~> 3.8.0)
33
- rspec-mocks (~> 3.8.0)
34
- rspec-core (3.8.0)
35
- rspec-support (~> 3.8.0)
36
- rspec-expectations (3.8.2)
37
- diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.8.0)
39
- rspec-mocks (3.8.0)
40
- diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.8.0)
42
- rspec-support (3.8.0)
43
- thor (0.20.3)
44
- unf (0.1.4)
45
- unf_ext
46
- unf_ext (0.0.7.5)
47
-
48
- PLATFORMS
49
- ruby
50
-
51
- DEPENDENCIES
52
- bundler (~> 2.0)
53
- pry
54
- rake (~> 10.0)
55
- rspec (~> 3.0)
56
- threadfix-cli!
57
-
58
- BUNDLED WITH
59
- 2.0.1
data/LICENSE DELETED
@@ -1,9 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2019 David Elliott
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,37 +0,0 @@
1
- # Threadfix
2
- Command line tool that wraps the ThreadFix API
3
-
4
- ## Installation
5
-
6
- Install with:
7
-
8
- ```ruby
9
- $ gem install threadfix-cli
10
- ```
11
-
12
- ## Usage
13
-
14
- ```ruby
15
- $ export THREADFIX_TOKEN=<API key>
16
-
17
- $ threadfix applications lookup \
18
- --app-name <Application Name> \
19
- --team-name <Team Name> \
20
- #=> <Application ID>
21
-
22
- $ threadfix scan upload \
23
- --app-id <Application ID> \
24
- --host <Host Name> \
25
- --file ./repo/results.json
26
- #=> <Upload Status>
27
- ```
28
-
29
- ## Development
30
-
31
- 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.
32
-
33
- 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).
34
-
35
- ## Contributing
36
-
37
- Bug reports and pull requests are welcome on GitHub at https://github.com/DDAZZA/threadfix-cli.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,44 +0,0 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "threadfix/cli/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "threadfix-cli"
8
- spec.version = Threadfix::Cli::VERSION
9
- spec.authors = ["Dave Elliott"]
10
- spec.email = ["ddazza@gmail.com"]
11
-
12
- spec.summary = %q{CLI to upload scan report to ThreadFix}
13
- spec.description = %q{Command line tool to upload a static analysis report to ThreadFix}
14
- spec.homepage = "https://github.com/DDAZZA/threadfix-cli"
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"] = "https://github.com/DDAZZA/threadfix-cli"
23
- spec.metadata["changelog_uri"] = "https://github.com/DDAZZA/threadfix-cli/blob/master/CHANGE_LOG.md"
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 = "bin"
35
- spec.executables = "threadfix"
36
- spec.require_paths = ["lib"]
37
-
38
- spec.add_runtime_dependency "thor", '0.20.3'
39
- spec.add_runtime_dependency "rest-client", '2.0.2'
40
-
41
- spec.add_development_dependency "bundler", "~> 2.0"
42
- spec.add_development_dependency "rake", "~> 10.0"
43
- spec.add_development_dependency "rspec", "~> 3.0"
44
- end