diff options
author | 2015-12-25 17:16:14 +0100 | |
---|---|---|
committer | 2015-12-25 17:16:14 +0100 | |
commit | f02847608d9dbde44947588286c8c0cc01237a87 (patch) | |
tree | dc066280f8adfc35c9ef06633d1c7bb79efee6d1 | |
parent | Make parsing more resilient to weird advisories (diff) | |
download | security-f02847608d9dbde44947588286c8c0cc01237a87.tar.gz security-f02847608d9dbde44947588286c8c0cc01237a87.tar.bz2 security-f02847608d9dbde44947588286c8c0cc01237a87.zip |
Ruby style settings and fixes
-rw-r--r-- | .rubocop.yml | 20 | ||||
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | anzen.rb | 4 | ||||
-rw-r--r-- | lib/glsa_repository.rb | 7 | ||||
-rw-r--r-- | lib/glsav1.rb | 13 | ||||
-rw-r--r-- | lib/helpers.rb | 17 |
6 files changed, 42 insertions, 21 deletions
diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..d2f9768 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,20 @@ +Style/AsciiComments: + Enabled: false + +Style/FormatString: + Enabled: false + +Style/Documentation: + Enabled: false + +Style/PerlBackrefs: + Enabled: false + +Metrics/LineLength: + Max: 120 + +Metrics/MethodLength: + Max: 20 + +Metrics/ModuleLength: + Max: 200 @@ -5,4 +5,4 @@ gem 'sinatra-partial' gem 'json' gem 'nokogiri' gem 'thin' -gem 'sanitize'
\ No newline at end of file +gem 'sanitize' @@ -52,7 +52,7 @@ get '/glsa/feed.:format' do end get '/glsa/:glsaid.xml' do - if params[:glsaid] =~ /^\d{6}-\d{2}$/ and GLSARepository.instance.has? params[:glsaid] + if params[:glsaid] =~ /^\d{6}-\d{2}$/ && GLSARepository.instance.has?(params[:glsaid]) send_file(File.join(File.dirname(__FILE__), 'data/glsa/glsa-' + params[:glsaid] + '.xml'), type: :xml) else status 404 @@ -98,4 +98,4 @@ end get '/update' do GLSARepository.instance.update! 'ok' -end
\ No newline at end of file +end diff --git a/lib/glsa_repository.rb b/lib/glsa_repository.rb index 9fe571a..ae45369 100644 --- a/lib/glsa_repository.rb +++ b/lib/glsa_repository.rb @@ -44,7 +44,7 @@ class GLSARepository end def latest(n = 10) - @latest[0...n].map {|id| @advisories[id] } + @latest[0...n].map { |id| @advisories[id] } end def[](id) @@ -52,13 +52,14 @@ class GLSARepository end def has?(id) - @advisories.has_key? id + @advisories.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 +end diff --git a/lib/glsav1.rb b/lib/glsav1.rb index 22ec1f1..d2c1692 100644 --- a/lib/glsav1.rb +++ b/lib/glsav1.rb @@ -3,7 +3,7 @@ require 'date' # A version 1 GLSA class GLSAv1 attr_reader :id, :title, :synopsis, :product, :date, :revised, :revision, :bugs, :access, :packages, - :background, :description, :severity, :impact, :workaround, :resolution, :references + :background, :description, :severity, :impact, :workaround, :resolution, :references def parse(xml) @id = xml.root['id'] @@ -15,15 +15,15 @@ class GLSAv1 @revision = xml.xpath('/glsa/revised/text()').first.content.split(': ') @revised = DateTime.parse(@revised) - @bugs = xml.xpath('/glsa/bug/text()').map {|bug_node| bug_node.content.to_i } + @bugs = xml.xpath('/glsa/bug/text()').map { |bug_node| bug_node.content.to_i } @access = xml.xpath('/glsa/access/text()').first.content @packages = {} xml.xpath('/glsa/affected/package').each do |package| @packages[package['name'] + ':' + package['arch']] = { auto: package['auto'] == 'yes', - unaffected: package.xpath('./unaffected').map {|ver| [ver['range'], ver.content] }, - vulnerable: package.xpath('./vulnerable').map {|ver| [ver['range'], ver.content] } + unaffected: package.xpath('./unaffected').map { |ver| [ver['range'], ver.content] }, + vulnerable: package.xpath('./vulnerable').map { |ver| [ver['range'], ver.content] } } end @@ -33,12 +33,13 @@ class GLSAv1 @impact = xml_content xml, '/glsa/impact' @workaround = xml_content xml, '/glsa/workaround' @resolution = xml_content xml, '/glsa/resolution' - @references = xml.xpath('/glsa/references/uri').map {|uri| [uri.content, uri['link']] } + @references = xml.xpath('/glsa/references/uri').map { |uri| [uri.content, uri['link']] } self end private + def xml_content(xml, xpath) xml.xpath(xpath).first.children.to_xml.strip rescue @@ -50,4 +51,4 @@ class GLSAv1 rescue '' end -end
\ No newline at end of file +end diff --git a/lib/helpers.rb b/lib/helpers.rb index 5ad9e82..d19e8f5 100644 --- a/lib/helpers.rb +++ b/lib/helpers.rb @@ -20,7 +20,7 @@ helpers do end def u(text) - ERB::Util::url_encode(text) + ERB::Util.url_encode(text) end def h2(text) @@ -57,21 +57,20 @@ helpers do def feed(type, items) RSS::Maker.make(type) do |maker| - maker.channel.author = "Gentoo Security Team" - maker.channel.about = "https://security.gentoo.org/glsa" - maker.channel.link = "https://security.gentoo.org/glsa" - maker.channel.description = "This feed contains new Gentoo Linux Security Advisories. Contact security@gentoo.org with questions." - maker.channel.title = "Gentoo Linux Security Advisories" + maker.channel.author = 'Gentoo Security Team' + maker.channel.about = 'https://security.gentoo.org/glsa' + maker.channel.link = 'https://security.gentoo.org/glsa' + maker.channel.description = 'This feed contains new Gentoo Linux Security Advisories. Contact security@gentoo.org with questions.' + maker.channel.title = 'Gentoo Linux Security Advisories' maker.channel.updated = items.first.revised.to_s items.each do |input_item| maker.items.new_item do |item| item.link = BASE_URL + 'glsa/' + input_item.id - item.title = "GLSA %s: %s" % [input_item.id, input_item.title] + item.title = 'GLSA %s: %s' % [input_item.id, input_item.title] item.updated = input_item.revised.to_s end end end.to_s end - -end
\ No newline at end of file +end |