summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/glsa_repository.rb')
-rw-r--r--lib/glsa_repository.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/glsa_repository.rb b/lib/glsa_repository.rb
new file mode 100644
index 0000000..90c9899
--- /dev/null
+++ b/lib/glsa_repository.rb
@@ -0,0 +1,55 @@
+require_relative 'glsav1.rb'
+require 'date'
+
+class GLSARepository
+ include Singleton
+
+ CACHE_SECONDS = 3600
+ DATA_PATH = File.join(File.dirname(__FILE__), '../data/glsa/')
+
+ def initialize
+ update!
+ end
+
+ def update!
+ advisories = {}
+
+ Dir.glob(DATA_PATH + '*.xml').each do |glsa_file|
+ f = File.open(glsa_file)
+ glsa = Nokogiri::XML(f)
+ f.close
+
+ if glsa.root.key? 'version'
+ # Future extension: GLSAv2
+ else
+ begin
+ advisories[glsa.root['id']] = GLSAv1.new.parse(glsa)
+ rescue
+ next
+ end
+ end
+ end
+
+ @load_date = DateTime.now
+ @advisories = advisories.freeze
+ end
+
+ def get
+ @advisories
+ end
+
+ def[](id)
+ @advisories[id]
+ end
+
+ def has?(id)
+ @advisories.has_key? id
+ end
+
+ private
+ def update?
+ if ((DateTime.now - @load_date) * 60 * 60 * 24).to_i > CACHE_SECONDS
+ update!
+ end
+ end
+end \ No newline at end of file