Skip to content

Commit

Permalink
Merge pull request #12 from koenrh/add-aws-plugin
Browse files Browse the repository at this point in the history
Add support for AWS credentials
  • Loading branch information
Melvin Lammerts authored Oct 26, 2016
2 parents 6e5731d + 7b9206e commit 7e48e27
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ gem 'require_all'
gem 'tty'
gem 'http'
gem 'nokogiri'

group :test do
gem 'minitest'
gem 'rake'
end

group :development do
gem 'rubocop'
end
20 changes: 19 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ GEM
remote: https://rubygems.org/
specs:
addressable (2.4.0)
ast (2.3.0)
coderay (1.1.1)
domain_name (0.5.20160615)
unf (>= 0.0.5, < 1.0.0)
Expand All @@ -17,19 +18,32 @@ GEM
http_parser.rb (0.6.0)
method_source (0.8.2)
mini_portile2 (2.1.0)
minitest (5.9.1)
necromancer (0.3.0)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
parser (2.3.1.4)
ast (~> 2.2)
pastel (0.6.1)
equatable (~> 0.5.0)
tty-color (~> 0.3.0)
pkg-config (1.1.7)
powerpack (0.1.1)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rainbow (2.1.0)
rake (11.3.0)
require_all (1.3.3)
rubocop (0.43.0)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
slop (3.6.0)
tty (0.5.0)
equatable (~> 0.5.0)
Expand Down Expand Up @@ -75,6 +89,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
unicode-display_width (1.1.1)
unicode_utils (1.4.0)
verse (0.4.0)
unicode_utils (~> 1.4.0)
Expand All @@ -85,10 +100,13 @@ PLATFORMS

DEPENDENCIES
http
minitest
nokogiri
pry
rake
require_all
rubocop
tty

BUNDLED WITH
1.12.5
1.13.6
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true
require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.pattern = 'test/**/*_test.rb'
end

task default: :test
5 changes: 5 additions & 0 deletions lib/plugin_list.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module Vcsmap
class PluginList
PLUGINS = {
aws: {
title: 'AWS access key',
description: 'Extracts AWS credentials from config and credentials files.',
class_name: 'Vcsmap::Plugin::AwsAccessToken'
},
wordpress_config: {
title: 'Wordpress configuration files',
description: 'Extracts database credentials from wp-config.php.',
Expand Down
25 changes: 25 additions & 0 deletions lib/plugins/aws_access_token.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Vcsmap
module Plugin
class AwsAccessToken < Vcsmap::Plugin::BasePlugin
def initialize
@search_string = ['aws_secret_access_key',
'filename:config',
'filename:credentials'].join('+')
@access_key_id_regex = /=\s+(AKIA[0-9A-Z]{16})/
@secret_access_key_regex = %r{=\s+([0-9a-zA-Z\/+]{40})}
end

def credentials(file)
@access_key_id = capture_match(@access_key_id_regex, file)
@secret_access_key = capture_match(@secret_access_key_regex, file)
[@access_key_id, @secret_access_key]
rescue NoMethodError
[]
end

def table_header
['Access Key ID', 'Secret Access Key']
end
end
end
end
25 changes: 25 additions & 0 deletions test/plugins/aws_access_token_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require_relative '../test_helper'

require 'plugins/base_plugin'
require 'plugins/aws_access_token'

describe Vcsmap::Plugin::AwsAccessToken do
let(:plugin) { Vcsmap::Plugin::AwsAccessToken.new }

let(:file) do
<<-eos
[contoso]
aws_access_key_id = AKIAED8B369A90EDAB2A
aws_secret_access_key = EAB37ae33174B8A2B0f0/3798C78ca26EAB37AE3
eos
end

describe '#capture_match' do
it 'must return the matched AWS key pair' do
credentials = plugin.credentials(file)

expected = ['AKIAED8B369A90EDAB2A', 'EAB37ae33174B8A2B0f0/3798C78ca26EAB37AE3']
credentials.must_equal expected
end
end
end
3 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)

require 'minitest/autorun'

0 comments on commit 7e48e27

Please sign in to comment.