Class: Bundler::Audit::Database
- Inherits:
-
Object
- Object
- Bundler::Audit::Database
- Defined in:
- lib/bundler/audit/database.rb
Overview
Represents the directory of advisories, grouped by gem name and CVE number.
Constant Summary collapse
- URL =
Git URL of the ruby-advisory-db
'https://github.com/rubysec/ruby-advisory-db.git'
- VENDORED_PATH =
Default path to the ruby-advisory-db
File.(File.join(File.dirname(__FILE__),'..','..','..','data','ruby-advisory-db'))
- USER_PATH =
Path to the user's copy of the ruby-advisory-db
File.join(Gem.user_home,'.local','share','ruby-advisory-db')
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
The path to the advisory database.
Class Method Summary collapse
-
.path ⇒ String
The default path for the database.
-
.update! ⇒ Boolean
Updates the ruby-advisory-db.
Instance Method Summary collapse
-
#advisories {|advisory| ... } ⇒ Enumerator
Enumerates over every advisory in the database.
-
#advisories_for(name) {|advisory| ... } ⇒ Enumerator
Enumerates over advisories for the given gem.
-
#check_gem(gem) {|advisory| ... } ⇒ Enumerator
Verifies whether the gem is effected by any advisories.
-
#each_advisory_path {|path| ... } ⇒ Object
protected
Enumerates over every advisory path in the database.
-
#each_advisory_path_for(name) {|path| ... } ⇒ Object
protected
Enumerates over the advisories for the given gem.
-
#initialize(path = self.class.path) ⇒ Database
constructor
Initializes the Advisory Database.
-
#inspect ⇒ String
Inspects the database.
-
#size ⇒ Integer
The number of advisories within the database.
-
#to_s ⇒ String
Converts the database to a String.
Constructor Details
#initialize(path = self.class.path) ⇒ Database
Initializes the Advisory Database.
52 53 54 55 56 57 58 |
# File 'lib/bundler/audit/database.rb', line 52 def initialize(path=self.class.path) unless File.directory?(path) raise(ArgumentError,"#{path.dump} is not a directory") end @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
The path to the advisory database
41 42 43 |
# File 'lib/bundler/audit/database.rb', line 41 def path @path end |
Class Method Details
.path ⇒ String
The default path for the database.
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bundler/audit/database.rb', line 66 def self.path if File.directory?(USER_PATH) t1 = Dir.chdir(USER_PATH) { Time.parse(`git log --pretty="%cd" -1`) } t2 = File.ctime(VENDORED_PATH) if t1 >= t2 then USER_PATH else VENDORED_PATH end else VENDORED_PATH end end |
.update! ⇒ Boolean
Requires network access.
Updates the ruby-advisory-db.
90 91 92 93 94 95 96 97 98 |
# File 'lib/bundler/audit/database.rb', line 90 def self.update! if File.directory?(USER_PATH) Dir.chdir(USER_PATH) do system 'git', 'pull', 'origin', 'master' end else system 'git', 'clone', URL, USER_PATH end end |
Instance Method Details
#advisories {|advisory| ... } ⇒ Enumerator
Enumerates over every advisory in the database.
112 113 114 115 116 117 118 |
# File 'lib/bundler/audit/database.rb', line 112 def advisories(&block) return enum_for(__method__) unless block_given? each_advisory_path do |path| yield Advisory.load(path) end end |
#advisories_for(name) {|advisory| ... } ⇒ Enumerator
Enumerates over advisories for the given gem.
135 136 137 138 139 140 141 |
# File 'lib/bundler/audit/database.rb', line 135 def advisories_for(name) return enum_for(__method__,name) unless block_given? each_advisory_path_for(name) do |path| yield Advisory.load(path) end end |
#check_gem(gem) {|advisory| ... } ⇒ Enumerator
Verifies whether the gem is effected by any advisories.
159 160 161 162 163 164 165 166 167 |
# File 'lib/bundler/audit/database.rb', line 159 def check_gem(gem) return enum_for(__method__,gem) unless block_given? advisories_for(gem.name) do |advisory| if advisory.vulnerable?(gem.version) yield advisory end end end |
#each_advisory_path {|path| ... } ⇒ Object (protected)
Enumerates over every advisory path in the database.
210 211 212 |
# File 'lib/bundler/audit/database.rb', line 210 def each_advisory_path(&block) Dir.glob(File.join(@path,'gems','*','*.yml'),&block) end |
#each_advisory_path_for(name) {|path| ... } ⇒ Object (protected)
Enumerates over the advisories for the given gem.
226 227 228 |
# File 'lib/bundler/audit/database.rb', line 226 def each_advisory_path_for(name,&block) Dir.glob(File.join(@path,'gems',name,'*.yml'),&block) end |
#inspect ⇒ String
Inspects the database.
195 196 197 |
# File 'lib/bundler/audit/database.rb', line 195 def inspect "#<#{self.class}:#{self}>" end |
#size ⇒ Integer
The number of advisories within the database.
175 176 177 |
# File 'lib/bundler/audit/database.rb', line 175 def size each_advisory_path.count end |
#to_s ⇒ String
Converts the database to a String.
185 186 187 |
# File 'lib/bundler/audit/database.rb', line 185 def to_s @path end |