qualys 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 82d46fe75c445a67a07782c8ea2b9f92011e7f9e
4
+ data.tar.gz: 79fb99dbdcbf7bb6da466cd91b806662c7979c2f
5
+ SHA512:
6
+ metadata.gz: 90601d93e13d3d24b2779290f5a112a5c8fb2edd84f89f193353364fd9c420390dab5aa7e7e435c9d05725b06b6e70639160618e2797411150715ceff698dc95
7
+ data.tar.gz: d01666b6aefab5de181db30b3ec30df00aac9531e951f07324234001f770f024f413fbbc149e2e39acae006bb16e5ae57ad1723cdeaf78ff934cdb7571db3cc2
@@ -0,0 +1,5 @@
1
+ /.bundle/
2
+ /vendor/
3
+ Gemfile.lock
4
+ *.gem
5
+ /config/qualys.yaml
@@ -0,0 +1,17 @@
1
+ runtime: ruby21
2
+ build_gem: |
3
+ rm -rf *.gem
4
+ gem build qualys.gemspec
5
+
6
+ push_gem: exec gem push *.gem
7
+
8
+ gem: |
9
+ rm -rf *.gem
10
+ gem build qualys.gemspec
11
+ gem push *.gem
12
+
13
+ sublime: |
14
+ rock run bin/test.rb
15
+
16
+ todo: |
17
+ find bin lib spec -type f -exec grep -Hni --color "todo" {} \; > TODO
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Mike Mackintosh
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # Ruby Qualys API v2
2
+ A Ruby extension for interfacing with Qualys v2 API.
3
+
4
+ [![](http://ruby-gem-downloads-badge.herokuapp.com/qualys)](https://rubygems.org/gems/qualys)
5
+
6
+ [![Dependency Status](https://gemnasium.com/mikemackintosh/ruby-qualys.svg)](https://gemnasium.com/mikemackintosh/ruby-qualys)
7
+
8
+ [![Gem Version](https://badge.fury.io/rb/qualys.svg)](https://rubygems.org/gems/qualys)
9
+
10
+ ### Introduction
11
+
12
+ I had the need to pull stats and details from Qualys automatically to collect and alert on metrics. Let's face it, in 2015, email alerts just don't cut it anymore.
13
+
14
+ ## Installation
15
+
16
+ Like any other gem:
17
+
18
+ ```shell
19
+ gem install qualys
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Below you can find details on the configuration and usage of the Qualys API Client.
25
+
26
+ ### Configuration
27
+
28
+ Before utilizing the API, you must configure it. You can configure it with a block like below, or by passing in a `Hash#` or load a yaml file.
29
+ ```ruby
30
+ Qualys.configure do |config|
31
+ config.username = @email
32
+ config.password = @password
33
+ end
34
+ ```
35
+
36
+ or configure using a `yaml` doc:
37
+
38
+ ```ruby
39
+ Qualys::Config.load!("config/qualys.yaml")
40
+ ```
41
+
42
+ ### Getting Scans
43
+
44
+ You can easily get a list of all scans within your Qualys account by accessing the following methods:
45
+
46
+ ```ruby
47
+ scans = Qualys::Scans.all
48
+ ```
49
+
50
+ ## References
51
+
52
+ The API was built using the following documentation: https://www.qualys.com/docs/qualys-api-v2-quick-reference.pdf
@@ -0,0 +1,27 @@
1
+ #encoding: utf-8
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
5
+
6
+ task :default => :test
7
+
8
+ RSpec::Core::RakeTask.new do |spec|
9
+ spec.verbose = false
10
+ spec.pattern = './spec/{*/**/}*_spec.rb'
11
+ end
12
+
13
+ task :test do
14
+ ENV['RACK_ENV'] = 'test'
15
+
16
+ require './spec/spec_helper'
17
+ Rake::Task['spec'].invoke
18
+ end
19
+
20
+ desc 'Run RuboCop on the lib directory'
21
+ RuboCop::RakeTask.new(:rubocop) do |task|
22
+ task.patterns = ['lib/**/*.rb']
23
+ # only show the files with failures
24
+ task.formatters = ['progress']
25
+ # don't abort rake on failure
26
+ task.fail_on_error = false
27
+ end
File without changes
@@ -0,0 +1,30 @@
1
+ require 'httparty'
2
+ require 'json'
3
+ require 'erb'
4
+
5
+ require 'qualys/version'
6
+
7
+ require 'qualys/config'
8
+ require 'qualys/api'
9
+ require 'qualys/auth'
10
+
11
+ require 'qualys/scans'
12
+
13
+
14
+ module Qualys
15
+
16
+ extend self
17
+
18
+ def configure
19
+ block_given? ? yield(Config) : Config
20
+ %w(username password).each do |key|
21
+ if Qualys::Config.instance_variable_get("@#{key}").nil?
22
+ raise Qualys::Config::RequiredOptionMissing,
23
+ "Configuration parameter missing: '#{key}'. " +
24
+ "Please add it to the Qualys.configure block"
25
+ end
26
+ end
27
+ end
28
+ alias_method :config, :configure
29
+
30
+ end
@@ -0,0 +1,66 @@
1
+ module Qualys
2
+ class Api
3
+
4
+ class InvalidResponse < RuntimeError; end
5
+ class AuthorizationRequired < RuntimeError; end
6
+ class UnauthorizedRequest < RuntimeError; end
7
+
8
+ # Set the current production endpoint
9
+ PRODUCTION_ENDPOINT = 'https://qualysapi.qualys.com/api/2.0/fo/'
10
+
11
+ # Set HTTParty defaults
12
+ HTTParty::Basement.default_options.update(base_uri: PRODUCTION_ENDPOINT)
13
+ HTTParty::Basement.default_options.update(headers: {
14
+ "X-Requested-With" => "Qualys Ruby Client v#{Qualys::VERSION}"
15
+ })
16
+
17
+ #
18
+ #
19
+ def self.api_get(url, options={})
20
+
21
+ unless Qualys::Config.session_key.nil?
22
+ HTTParty::Basement.default_cookies.add_cookies(Qualys::Config.session_key)
23
+ end
24
+
25
+ # Send Request
26
+ response = HTTParty.get(url, options)
27
+
28
+ # Check if you need to be authorized
29
+ if response.code.eql?(401)
30
+ raise Qualys::Api::AuthorizationRequired, "Please Login Before Communicating With The API"
31
+ elsif response.code.eql?(403)
32
+ raise Qualys::Api::UnauthorizedRequest, "You either sent an invalid request or do not have access to that add-on"
33
+ elsif !response.code.eql?(200)
34
+ raise Qualys::Api::InvalidResponse, "Invalid Response Received"
35
+ end
36
+
37
+ # return the response
38
+ response
39
+ end
40
+
41
+ #
42
+ #
43
+ def self.api_post(url, options={})
44
+
45
+ unless Qualys::Config.session_key.nil?
46
+ HTTParty::Basement.default_cookies.add_cookies(Qualys::Config.session_key)
47
+ end
48
+
49
+ # Send Request
50
+ response = HTTParty.post(url, options)
51
+
52
+ # Check if you need to be authorized
53
+ if response.code.eql?(401)
54
+ raise Qualys::Api::AuthorizationRequired, "Please Configure A Username and Password Before Communicating With The API"
55
+ elsif response.code.eql?(403)
56
+ raise Qualys::Api::UnauthorizedRequest, "You either sent an invalid request or do not have access to that add-on"
57
+ elsif response.code.eql?(500)
58
+ raise Qualys::Api::InvalidResponse, "Invalid Response Received"
59
+ end
60
+
61
+ # return the response
62
+ response
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,42 @@
1
+ module Qualys
2
+ class Auth < Api
3
+ class InvalidLogin < RuntimeError; end
4
+
5
+ attr_reader :name
6
+
7
+ # Do Login
8
+ def self.login
9
+
10
+ # Request a login
11
+ response = self.api_post('session/', {
12
+ :body => {
13
+ :action => 'login',
14
+ :username => Qualys::Config.username,
15
+ :password => Qualys::Config.password
16
+ }
17
+ })
18
+
19
+ # set the session key
20
+ Qualys::Config.session_key = response.header['Set-Cookie']
21
+ true
22
+
23
+ end
24
+
25
+ # Set Logout
26
+ def self.logout
27
+
28
+ # Request a login
29
+ response = self.api_post('session/', {
30
+ :body => {
31
+ :action => 'logout',
32
+ }
33
+ })
34
+
35
+ # set the session key
36
+ Qualys::Config.session_key = nil
37
+ true
38
+
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,35 @@
1
+ module Qualys
2
+ module Config
3
+ class RequiredOptionMissing < RuntimeError; end
4
+ extend self
5
+
6
+ attr_accessor :username, :password, :session_key
7
+
8
+ # Configure Qualys from a hash. This is usually called after parsing a
9
+ # yaml config file such as qualys.yaml.
10
+ #
11
+ # @example Configure Qualys.
12
+ # config.from_hash({})
13
+ #
14
+ # @param [ Hash ] options The settings to use.
15
+ def from_hash(options = {})
16
+ options.each_pair do |name, value|
17
+ send("#{name}=", value) if respond_to?("#{name}=")
18
+ end
19
+ end
20
+
21
+ # Load the settings from a compliant Qualys.yml file. This can be used for
22
+ # easy setup with frameworks other than Rails.
23
+ #
24
+ # @example Configure Qualys.
25
+ # Qualys.load!("/path/to/qualys.yml")
26
+ #
27
+ # @param [ String ] path The path to the file.
28
+ def load!(path)
29
+ settings = YAML.load(ERB.new(File.new(path).read).result)['api']
30
+ if settings.is_a? Hash
31
+ from_hash(settings)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ module Qualys
2
+ class Scans < Api
3
+
4
+ def self.all
5
+ response = api_get("scan/", { :query => { :action => 'list' }})
6
+ scanlist = response.parsed_response['SCAN_LIST_OUTPUT']['RESPONSE']['SCAN_LIST']
7
+ puts scanlist.inspect
8
+ end
9
+
10
+ def self.each
11
+ @events.each do |event|
12
+ yield event
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ class Scan
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Qualys
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,37 @@
1
+ # Created by hand, like a real man
2
+ # coding: utf-8
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'qualys/version'
6
+
7
+ Gem::Specification.new do |s|
8
+
9
+ s.name = 'qualys'
10
+ s.version = Qualys::VERSION
11
+ s.date = '2015-02-25'
12
+ s.summary = "qualys API Client"
13
+ s.description = "Easily interface with the qualys for consuming events"
14
+ s.authors = ["Mike Mackintosh"]
15
+ s.email = 'm@zyp.io'
16
+ s.homepage =
17
+ 'http://github.com/mikemackintosh/ruby-qualys'
18
+
19
+ s.license = 'MIT'
20
+
21
+ s.require_paths = ["lib"]
22
+ s.files = `git ls-files -z`.split("\x0")
23
+ #s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
+ #s.test_files = s.files.grep(%r{^(test|spec|features)/})
25
+
26
+ s.add_dependency 'json'
27
+ s.add_dependency 'erubis'
28
+ s.add_dependency 'httparty'
29
+
30
+ s.add_development_dependency "bundler"
31
+ s.add_development_dependency "rake"
32
+ s.add_development_dependency "rspec"
33
+ s.add_development_dependency "vcr"
34
+ s.add_development_dependency "webmock"
35
+ s.add_development_dependency "rubocop"
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qualys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Mackintosh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: erubis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Easily interface with the qualys for consuming events
140
+ email: m@zyp.io
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - ".gitignore"
146
+ - ".rock.yml"
147
+ - ".rspec"
148
+ - LICENSE.txt
149
+ - README.md
150
+ - Rakefile
151
+ - config/.gitkeep
152
+ - lib/qualys.rb
153
+ - lib/qualys/api.rb
154
+ - lib/qualys/auth.rb
155
+ - lib/qualys/config.rb
156
+ - lib/qualys/scans.rb
157
+ - lib/qualys/version.rb
158
+ - qualys.gemspec
159
+ homepage: http://github.com/mikemackintosh/ruby-qualys
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.2.2
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: qualys API Client
183
+ test_files: []