threadfix-cli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a1e54acd08e9bb3fae80fc89232d76d1e2c2d57b3e94d4d640b687c61cace57f
4
+ data.tar.gz: 2269a7fb0d0b9ac1ab02072ce8d507a57383d385a0330655aa73400b9969771a
5
+ SHA512:
6
+ metadata.gz: 7b123e7c57c914c821cf434430c46310bd41cf46e5bce6bcab53c0ee882ae0b1742bcc9ba918aeb68a76f9d14058359b2ad7a0c061a79f6d8b2ae87fb02b0a68
7
+ data.tar.gz: af0c3b4df849907049b148f73c7d7ebacb6856f0e52ed87de12dcb52a911051413e81a5b737a70e38dae108789bda9ee6df02d541a6dd93b3d721674baa55376
data/.gitignore ADDED
@@ -0,0 +1,11 @@
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 ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGE_LOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # v0.1.0
2
+
3
+ - Initial release to upload scans
data/Gemfile ADDED
@@ -0,0 +1,6 @@
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 ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ threadfix (0.1.0)
5
+ rest-client
6
+ thor
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!
57
+
58
+ BUNDLED WITH
59
+ 2.0.1
data/LICENSE ADDED
@@ -0,0 +1,9 @@
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 ADDED
@@ -0,0 +1,26 @@
1
+ # Threadfix
2
+ Command line tool to upload a static analysis report to ThreadFix
3
+
4
+ ## Installation
5
+
6
+ Install it with:
7
+
8
+ ```ruby
9
+ $ gem install threadfix
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```ruby
15
+ $ threadfix scan upload --app-id <APP-ID> --host <Server> --key <Auth Key> --file ./repo/results.json
16
+ ```
17
+
18
+ ## Development
19
+
20
+ 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.
21
+
22
+ 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).
23
+
24
+ ## Contributing
25
+
26
+ Bug reports and pull requests are welcome on GitHub at https://github.com/DDAZZA/threadfix-cli.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "threadfix/cli"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/threadfix ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "threadfix/cli"
3
+
4
+ Threadfix::CLI.start
@@ -0,0 +1,14 @@
1
+ require 'thor'
2
+ require "threadfix/cli/version"
3
+ require "threadfix/cli/scan"
4
+ require "threadfix/client"
5
+
6
+ module Threadfix
7
+ class CLI < Thor
8
+
9
+ class Error < StandardError; end
10
+
11
+ desc "scan <command>", "manage scans"
12
+ subcommand "scan", Cli::Scan
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ require "threadfix/client"
2
+ module Threadfix
3
+ module Cli
4
+ class Scan < Thor
5
+ desc "upload", "Uploads a scan to ThreadFix"
6
+ option :host
7
+ option 'app-id', required: true, type: :numeric
8
+ option :file, required: true, aliases: '-f', desc: "Report to upload"
9
+ option :key, desc: "Authorisation key"
10
+ def upload
11
+ Client.configure do |config|
12
+ config.host = options[:host] if options[:host]
13
+ config.key = options[:key] if options[:key]
14
+ end
15
+
16
+ begin
17
+ response = Client::Scans.upload(file_path: options[:file], app_id: options['app-id'] )
18
+ puts response['message']
19
+ rescue Errno::ENOENT => e
20
+ puts "Error: File or directory '#{options[:file]}' doesn't exist."
21
+ exit 1
22
+ rescue SocketError => e
23
+ puts "Error: Unable open connection to '#{Client.config.host}'"
24
+ exit 1
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module Threadfix
2
+ module Cli
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ require "threadfix/client/scans"
2
+
3
+ module Threadfix
4
+ module Client
5
+ class << self
6
+ attr_accessor :config
7
+ end
8
+
9
+ def self.configure
10
+ self.config ||= Configuration.new
11
+ yield(config)
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :host, :key
16
+
17
+ def initialize
18
+ @host = ENV['HOST']
19
+ @key = ENV['THREADFIX_TOKEN']
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ require "threadfix/client/scans/upload"
2
+
3
+ module Threadfix
4
+ module Client
5
+ module Scans
6
+ class <<self
7
+
8
+ # @param file_path
9
+ # @return Hash
10
+ def upload(options={})
11
+ action = Upload.new(options)
12
+ action.perform!
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,48 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ module Threadfix
5
+ module Client
6
+ module Scans
7
+ class Upload
8
+ API_VERSION='2.5'
9
+ attr_accessor :file_path, :app_id
10
+
11
+ def initialize(options={})
12
+ @file_path = options[:file_path]
13
+ @app_id = options[:app_id]
14
+ end
15
+
16
+ def perform!
17
+ begin
18
+ r = RestClient.post(
19
+ "#{host}/rest/#{API_VERSION}/applications/#{app_id}/upload",
20
+ { file: file },
21
+ { :accept => "application/json", :Authorization => "APIKEY #{apiKey}" }
22
+ )
23
+ JSON.parse(r.body)
24
+ rescue RestClient::NotFound => e
25
+ puts "Endpoint not found (using API version: #{API_VERSION})"
26
+ raise e
27
+ rescue RestClient::ExceptionWithResponse => e
28
+ raise e
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def file
35
+ File.new(file_path, 'rb')
36
+ end
37
+
38
+ def host
39
+ Client.config.host
40
+ end
41
+
42
+ def apiKey
43
+ Client.config.key
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,44 @@
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
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: threadfix-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dave Elliott
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.20.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.20.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Command line tool to upload a static analysis report to ThreadFix
84
+ email:
85
+ - ddazza@gmail.com
86
+ executables:
87
+ - threadfix
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - CHANGE_LOG.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - bin/threadfix
102
+ - lib/threadfix/cli.rb
103
+ - lib/threadfix/cli/scan.rb
104
+ - lib/threadfix/cli/version.rb
105
+ - lib/threadfix/client.rb
106
+ - lib/threadfix/client/scans.rb
107
+ - lib/threadfix/client/scans/upload.rb
108
+ - threadfix-cli.gemspec
109
+ homepage: https://github.com/DDAZZA/threadfix-cli
110
+ licenses: []
111
+ metadata:
112
+ homepage_uri: https://github.com/DDAZZA/threadfix-cli
113
+ source_code_uri: https://github.com/DDAZZA/threadfix-cli
114
+ changelog_uri: https://github.com/DDAZZA/threadfix-cli/blob/master/CHANGE_LOG.md
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.7.6
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: CLI to upload scan report to ThreadFix
135
+ test_files: []