periscope_rails 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- periscope_rails (0.0.9)
4
+ periscope_rails (0.0.10)
5
5
  activesupport (~> 3.0)
6
6
  rails (~> 3.0)
7
7
 
@@ -4,24 +4,34 @@ class PeriscopeController < ActionController::Base
4
4
 
5
5
  def look
6
6
  if !params[:sql].nil?
7
- render :json => run_sql(params[:sql])
7
+ render :json => merge_on_metadata(run_sql(params[:sql]))
8
8
  else
9
- render :json => {:error => "Command not understood"}
9
+ render :json => merge_on_metadata({:error => "Command not understood"})
10
10
  end
11
11
  end
12
12
 
13
13
  def login
14
- render :json => get_info()
14
+ render :json => merge_on_metadata(get_info())
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  def authenticate
20
20
  unless PeriscopeRails::Config.check_password(params[:password].to_s)
21
- render :json => {:error => "Password invalid."}
21
+ render :json => merge_on_metadata({:error => "Password invalid."})
22
22
  end
23
23
  end
24
24
 
25
+ def merge_on_metadata(hash)
26
+ version = nil
27
+ begin
28
+ version = Gem.loaded_specs["periscope_rails"].version.version
29
+ rescue
30
+ version = "error"
31
+ end
32
+ return hash.merge({ :version => version, :database_type => get_db_type })
33
+ end
34
+
25
35
  def run_sql(sql_command)
26
36
  #TODO: protect based on CFG, not blacklist
27
37
  bad_words = %W{drop delete update into insert index add remove grant revoke create createdb}
@@ -39,13 +49,8 @@ class PeriscopeController < ActionController::Base
39
49
  begin #for whole query
40
50
  active_record = PeriscopeRails::Config.get_active_record()
41
51
  begin #just for costing
42
- begin
43
- is_postgres = ActiveRecord::Base.connection.instance_of? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
44
- rescue Exception => e
45
- is_postgres = false
46
- end
47
52
  active_record.transaction do #costing
48
- if PeriscopeRails::Config.block_expensive_queries? and is_postgres
53
+ if PeriscopeRails::Config.block_expensive_queries? and get_db_type == "postgres"
49
54
  active_record.connection.select_all("explain #{command}")[0]["QUERY PLAN"] =~ /rows=(\d+) width=(\d+)\)$/
50
55
  row_count, width = $1.to_i, $2.to_i
51
56
  if row_count > 0 and width > 0
@@ -87,4 +92,20 @@ class PeriscopeController < ActionController::Base
87
92
  end
88
93
  return {:tables => tables, :error => nil}
89
94
  end
95
+
96
+ def get_db_type
97
+ begin
98
+ return "postgres" if ActiveRecord::Base.connection.instance_of? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
99
+ rescue Exception => e
100
+ begin
101
+ return "mysql" if ActiveRecord::Base.connection.instance_of? ActiveRecord::ConnectionAdapters::MysqlAdapter
102
+ rescue Exception => e
103
+ begin
104
+ return "mysql" if ActiveRecord::Base.connection.instance_of? ActiveRecord::ConnectionAdapters::Mysql2Adapter
105
+ rescue
106
+ return nil
107
+ end
108
+ end
109
+ end
110
+ end
90
111
  end
@@ -10,7 +10,7 @@ module PeriscopeRails
10
10
  @@db_password = nil
11
11
 
12
12
  @@block_expensive_queries = true
13
- @@max_rows = 500
13
+ @@max_rows = 2000
14
14
  @@max_size = @@max_rows * 500
15
15
 
16
16
  def self.set_password(password)
@@ -1,3 +1,3 @@
1
1
  module PeriscopeRails
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.summary = "Rails API for Periscope Database Viewer"
12
12
  s.description = "Periscope allows you to query your production database. The gem provides the API for Periscope to communicate with your Rails app."
13
13
  s.files = Dir["{app,lib,config}/**/*"] + ["MIT-LICENSE", "Rakefile", "Gemfile", "README.rdoc"]
14
- s.version = "0.0.9"
14
+ s.version = PeriscopeRails.const_get(:VERSION)
15
15
 
16
16
  s.add_dependency "activesupport" , "~> 3.0"
17
17
  s.add_dependency "rails" , "~> 3.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: periscope_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-06-23 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &27882840 !ruby/object:Gem::Requirement
17
+ requirement: &28279680 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *27882840
25
+ version_requirements: *28279680
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rails
28
- requirement: &27882528 !ruby/object:Gem::Requirement
28
+ requirement: &28279380 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *27882528
36
+ version_requirements: *28279380
37
37
  description: Periscope allows you to query your production database. The gem provides
38
38
  the API for Periscope to communicate with your Rails app.
39
39
  email: