hakiri 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/hakiri/stack.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  require 'active_support/all'
2
2
 
3
3
  class Hakiri::Stack
4
- attr_accessor :technologies, :default_path
4
+ attr_accessor :technologies, :default_command
5
5
 
6
6
  #
7
7
  # Initializes a stack.
8
8
  #
9
9
  def initialize()
10
- @default_path = ''
10
+ @default_command = ''
11
11
  @technologies = {}
12
12
  @errors = []
13
13
  end
@@ -24,7 +24,7 @@ class Hakiri::Stack
24
24
 
25
25
  #
26
26
  # This method analyzes user input from the Hakiri gem and sets up
27
- # default paths to retrieve versions.
27
+ # default commands to retrieve versions.
28
28
  #
29
29
  # @param [String] server
30
30
  # Rails server selection.
@@ -42,51 +42,51 @@ class Hakiri::Stack
42
42
  # Is Memcached present?
43
43
  #
44
44
  def build_from_input(server, extra_server, db, redis, memcached)
45
- @technologies['ruby'] = { path: @default_path }
46
- @technologies['ruby-on-rails'] = { path: @default_path }
45
+ @technologies['ruby'] = { command: @default_command }
46
+ @technologies['ruby-on-rails'] = { command: @default_command }
47
47
 
48
48
  case server
49
49
  when 1
50
- @technologies['unicorn'] = { path: @default_path }
50
+ @technologies['unicorn'] = { command: @default_command }
51
51
  when 2
52
- @technologies['phusion-passenger'] = { path: @default_path }
52
+ @technologies['phusion-passenger'] = { command: @default_command }
53
53
  when 3
54
- @technologies['thin'] = { path: @default_path }
54
+ @technologies['thin'] = { command: @default_command }
55
55
  when 4
56
- @technologies['trinidad'] = { path: @default_path }
57
- @technologies['java'] = { path: @default_path }
58
- @technologies['apache-tomcat'] = { path: @default_path }
59
- @technologies['jruby'] = { path: @default_path }
56
+ @technologies['trinidad'] = { command: @default_command }
57
+ @technologies['java'] = { command: @default_command }
58
+ @technologies['apache-tomcat'] = { command: @default_command }
59
+ @technologies['jruby'] = { command: @default_command }
60
60
  else
61
61
  nil
62
62
  end
63
63
 
64
64
  case extra_server
65
65
  when 1
66
- @technologies['apache'] = { path: @default_path }
66
+ @technologies['apache'] = { command: @default_command }
67
67
  when 2
68
- @technologies['nginx'] = { path: @default_path }
68
+ @technologies['nginx'] = { command: @default_command }
69
69
  when 3
70
- @technologies['apache'] = { path: @default_path }
71
- @technologies['nginx'] = { path: @default_path }
70
+ @technologies['apache'] = { command: @default_command }
71
+ @technologies['nginx'] = { command: @default_command }
72
72
  else
73
73
  nil
74
74
  end
75
75
 
76
76
  case db
77
77
  when 1
78
- @technologies['mysql'] = { path: @default_path }
78
+ @technologies['mysql'] = { command: @default_command }
79
79
  when 2
80
- @technologies['postgres'] = { path: @default_path }
80
+ @technologies['postgres'] = { command: @default_command }
81
81
  when 3
82
- @technologies['mongodb'] = { path: @default_path }
82
+ @technologies['mongodb'] = { command: @default_command }
83
83
  else
84
84
  nil
85
85
  end
86
86
 
87
- @technologies['redis'] = { path: @default_path } if redis
87
+ @technologies['redis'] = { command: @default_command } if redis
88
88
 
89
- @technologies['memcached'] = { path: @default_path } if memcached
89
+ @technologies['memcached'] = { command: @default_command } if memcached
90
90
  end
91
91
 
92
92
  #
@@ -99,7 +99,7 @@ class Hakiri::Stack
99
99
  @technologies[technology_slug].symbolize_keys!
100
100
 
101
101
  technology_class = Hakiri.const_get(technology_slug.gsub('-', '_').camelcase)
102
- technology_object = technology_class.new(value[:path])
102
+ technology_object = technology_class.new(value[:command])
103
103
 
104
104
  if technology_object.version
105
105
  @technologies[technology_slug][:version] = technology_object.version unless @technologies[technology_slug][:version] and @technologies[technology_slug][:version] != ''
@@ -1,5 +1,5 @@
1
1
  class Hakiri::Apache < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'Apache'
@@ -7,7 +7,7 @@ class Hakiri::Apache < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}httpd -v 2>&1 | awk 'NR == 1 { print ; }'`
10
+ output = (@command.empty?) ? `httpd -v 2>&1 | awk 'NR == 1 { print ; }'` : `#{@command} 2>&1 | awk 'NR == 1 { print ; }'`
11
11
  @default_regexp.match(output)[0]
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,5 +1,5 @@
1
1
  class Hakiri::ApacheTomcat < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'Apache Tomcat'
@@ -7,7 +7,7 @@ class Hakiri::ApacheTomcat < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}trinidad -v 2>&1`
10
+ output = (@command.empty?) ? `trinidad -v 2>&1` : `#{@command} 2>&1`
11
11
  /\d+(\.\d+)?(\.\d+)?\)/.match(output)[0].gsub(/\)/, '')
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,5 +1,5 @@
1
1
  class Hakiri::Java < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'Java'
@@ -7,7 +7,7 @@ class Hakiri::Java < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}java -version 2>&1 | awk 'NR == 2 { print ; }'`
10
+ output = (@command.empty?) ? `java -version 2>&1 | awk 'NR == 2 { print ; }'` : `#{@command} 2>&1 | awk 'NR == 2 { print ; }'`
11
11
  /\d+(\.\d+)?(\.\d+)?(_\d+)?/.match(output)[0].gsub('_', '.')
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,5 +1,5 @@
1
1
  class Hakiri::Jruby < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'JRuby'
@@ -7,7 +7,7 @@ class Hakiri::Jruby < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}jruby -v 2>&1 | awk 'NR == 2 { print ; }'`
10
+ output = (@command.empty?) ? `jruby -v 2>&1 | awk 'NR == 1 { print ; }'` : `#{@command} 2>&1 | awk 'NR == 1 { print ; }'`
11
11
  @default_regexp.match(output)[0]
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,5 +1,5 @@
1
1
  class Hakiri::LinuxKernel < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'Linux Kernel'
@@ -7,7 +7,7 @@ class Hakiri::LinuxKernel < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}uname -r 2>&1`
10
+ output = (@command.empty?) ? `uname -r 2>&1` : `#{@command} 2>&1`
11
11
  @default_regexp.match(output)[0]
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,5 +1,5 @@
1
1
  class Hakiri::Memcached < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'Memcached'
@@ -7,7 +7,7 @@ class Hakiri::Memcached < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}memcached -h 2>&1 | awk 'NR == 1 { print ; }'`
10
+ output = (@command.empty?) ? `memcached -h 2>&1 | awk 'NR == 1 { print ; }'` : `#{@command} 2>&1 | awk 'NR == 1 { print ; }'`
11
11
  @default_regexp.match(output)[0]
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,5 +1,5 @@
1
1
  class Hakiri::Mongodb < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'MongoDB'
@@ -7,7 +7,7 @@ class Hakiri::Mongodb < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `ps -ax | grep mongo 2>&1`
10
+ output = (@command.empty?) ? `ps -ax | grep mongo 2>&1` : `#{@command} 2>&1`
11
11
  @default_regexp.match(output)[0]
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -16,6 +16,6 @@ class Hakiri::Mongodb < Hakiri::Technology
16
16
  end
17
17
 
18
18
  def puts_error(e, output)
19
- puts "Error: couldn't find a running version of MongoDB"
19
+ say '! Can\'t find MongoDB'
20
20
  end
21
21
  end
@@ -1,5 +1,5 @@
1
1
  class Hakiri::Mysql < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'MySQL'
@@ -7,7 +7,7 @@ class Hakiri::Mysql < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}mysql -version 2>&1`
10
+ output = (@command.empty?) ? `mysql -version 2>&1` : `#{@command} 2>&1`
11
11
  @default_regexp.match(output)[0]
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,5 +1,5 @@
1
1
  class Hakiri::Nginx < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'nginx'
@@ -7,7 +7,7 @@ class Hakiri::Nginx < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}nginx -v 2>&1`
10
+ output = (@command.empty?) ? `nginx -v 2>&1` : `#{@command} 2>&1`
11
11
  @default_regexp.match(output)[0]
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,5 +1,5 @@
1
1
  class Hakiri::PhusionPassenger < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'Phusion Passenger'
@@ -7,7 +7,7 @@ class Hakiri::PhusionPassenger < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}passenger -v 2>&1 | awk 'NR == 1 { print ; }'`
10
+ output = (@command.empty?) ? `passenger -v 2>&1 | awk 'NR == 1 { print ; }'` : `#{@command} 2>&1 | awk 'NR == 1 { print ; }'`
11
11
  @default_regexp.match(output)[0]
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,5 +1,5 @@
1
1
  class Hakiri::Postgres < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'Postgres'
@@ -7,7 +7,7 @@ class Hakiri::Postgres < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}postgres -V 2>&1`
10
+ output = (@command.empty?) ? `postgres -V 2>&1` : `#{@command} 2>&1`
11
11
  @default_regexp.match(output)[0]
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,5 +1,5 @@
1
1
  class Hakiri::Redis < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'Redis'
@@ -7,7 +7,7 @@ class Hakiri::Redis < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}redis-server -v 2>&1`
10
+ output = (@command.empty?) ? `redis-server -v 2>&1` : `#{@command} 2>&1`
11
11
  @default_regexp.match(output)[0]
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,5 +1,5 @@
1
1
  class Hakiri::Ruby < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'Ruby'
@@ -7,7 +7,7 @@ class Hakiri::Ruby < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}ruby -v 2>&1`
10
+ output = (@command.empty?) ? `ruby -v 2>&1` : `#{@command} 2>&1`
11
11
  /\d+(\.\d+)(\.\d+)(p\d+)/.match(output)[0].gsub('p', '.')
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,5 +1,5 @@
1
1
  class Hakiri::RubyOnRails < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'Ruby on Rails'
@@ -7,7 +7,7 @@ class Hakiri::RubyOnRails < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}rails -v 2>&1`
10
+ output = (@command.empty?) ? `rails -v 2>&1` : `#{@command} 2>&1`
11
11
  @default_regexp.match(output)[0]
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -3,9 +3,9 @@ class Hakiri::Technology
3
3
  #
4
4
  # Initializes a technology.
5
5
  #
6
- def initialize(path = '')
7
- @default_regexp = /\d+(\.\d+)(\.\d+)/
8
- @path = path
6
+ def initialize(command = '')
7
+ @default_regexp = /\d+\.\d+\.\d+/
8
+ @command = command
9
9
  @name = 'Technology'
10
10
  end
11
11
 
@@ -19,6 +19,6 @@ class Hakiri::Technology
19
19
  # System output from attempted version query.
20
20
  #
21
21
  def puts_error(e, output)
22
- say "! Can't find #{self.class.name.demodulize}: #{output.lines.first}"
22
+ say "! Can't find #{name}: #{output.lines.first}"
23
23
  end
24
24
  end
@@ -1,5 +1,5 @@
1
1
  class Hakiri::Thin < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'Thin'
@@ -7,7 +7,7 @@ class Hakiri::Thin < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}thin -v 2>&1`
10
+ output = (@command.empty?) ? `thin -v 2>&1` : `#{@command} 2>&1`
11
11
  @default_regexp.match(output)[0]
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,5 +1,5 @@
1
1
  class Hakiri::Trinidad < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'Trinidad'
@@ -7,7 +7,7 @@ class Hakiri::Trinidad < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}trinidad -v 2>&1 | awk 'NR == 2 { print ; }'`
10
+ output = (@command.empty?) ? `trinidad -v 2>&1 | awk 'NR == 2 { print ; }'` : `#{@command} 2>&1 | awk 'NR == 2 { print ; }'`
11
11
  puts output
12
12
  @default_regexp.match(output)[0]
13
13
  rescue Exception => e
@@ -1,5 +1,5 @@
1
1
  class Hakiri::Unicorn < Hakiri::Technology
2
- def initialize(path = '')
2
+ def initialize(command = '')
3
3
  super
4
4
 
5
5
  @name = 'Unicorn'
@@ -7,7 +7,7 @@ class Hakiri::Unicorn < Hakiri::Technology
7
7
 
8
8
  def version
9
9
  begin
10
- output = `#{@path}unicorn -v 2>&1`
10
+ output = (@command.empty?) ? `unicorn -v 2>&1` : `#{@command} 2>&1`
11
11
  @default_regexp.match(output)[0]
12
12
  rescue Exception => e
13
13
  puts_error(e, output)
@@ -1,3 +1,3 @@
1
1
  module Hakiri
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hakiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-21 00:00:00.000000000 Z
12
+ date: 2013-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: commander
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -92,7 +108,7 @@ dependencies:
92
108
  - !ruby/object:Gem::Version
93
109
  version: '0'
94
110
  description: Hakiri is a CLI for www.hakiriup.com—a cloud security platform for Ruby
95
- on rails apps.
111
+ on Rails apps.
96
112
  email: vasinov@me.com
97
113
  executables:
98
114
  - hakiri
@@ -102,14 +118,16 @@ files:
102
118
  - .gitignore
103
119
  - Gemfile
104
120
  - Gemfile.lock
121
+ - LICENSE
105
122
  - README.md
123
+ - Rakefile
106
124
  - bin/hakiri
107
125
  - hakiri.gemspec
108
126
  - lib/hakiri.rb
109
127
  - lib/hakiri/cli/cli.rb
110
- - lib/hakiri/cli/system_scan.rb
111
- - lib/hakiri/cli/system_steps.rb
112
- - lib/hakiri/cli/system_sync.rb
128
+ - lib/hakiri/cli/manifest.json
129
+ - lib/hakiri/cli/manifest.rb
130
+ - lib/hakiri/cli/system.rb
113
131
  - lib/hakiri/http_client.rb
114
132
  - lib/hakiri/stack.rb
115
133
  - lib/hakiri/technologies/apache.rb
@@ -131,7 +149,6 @@ files:
131
149
  - lib/hakiri/technologies/trinidad.rb
132
150
  - lib/hakiri/technologies/unicorn.rb
133
151
  - lib/hakiri/version.rb
134
- - technologies.json
135
152
  homepage: http://www.hakiriup.com
136
153
  licenses:
137
154
  - MIT
@@ -156,5 +173,5 @@ rubyforge_project:
156
173
  rubygems_version: 1.8.23
157
174
  signing_key:
158
175
  specification_version: 3
159
- summary: CLI for Hakiri
176
+ summary: Secure Rails with Hakiri
160
177
  test_files: []