rails_db_guard 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +37 -0
- data/.rubocop.yml +33 -0
- data/.vimrc +4 -0
- data/Gemfile +3 -1
- data/README.md +2 -1
- data/Rakefile +3 -1
- data/lib/rails_db_guard.rb +6 -3
- data/lib/rails_db_guard/adapters/postgresql.rb +6 -6
- data/lib/rails_db_guard/adapters/sqlite3.rb +6 -6
- data/lib/rails_db_guard/railtie.rb +8 -3
- data/lib/rails_db_guard/version.rb +3 -1
- data/rails_db_guard.gemspec +6 -3
- metadata +33 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69c7b5793bccce4da21d45f7ea2d88bda6036da8efb4b5df9eda0a398cd1f246
|
4
|
+
data.tar.gz: f65abc85d8389739a642877f69d9e18365ebdde607aa688dfe386da9c3a0f033
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0e31cd1823b44ea721581fac1d5717c38d26ce5d90d7cde8c371029f14c32ed95a5a7940e57c3fb01b06240858447abbd697a195a025a8abe56effebe719c90
|
7
|
+
data.tar.gz: a5010994c1ca7b67eeeba83761606c7a8720f6bab1b674060ffa2fd6c942fe7c0a06d5dff911155a8de863ded56d15ff2d87d5c466cf6feeea5d68a77d1aa371
|
@@ -0,0 +1,37 @@
|
|
1
|
+
name: Main workflow
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
lint:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- name: Checkout
|
11
|
+
uses: actions/checkout@v1
|
12
|
+
|
13
|
+
- name: Set up Ruby 2.6
|
14
|
+
uses: actions/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: 2.6.2
|
17
|
+
|
18
|
+
- name: Install sqlite3
|
19
|
+
run: sudo apt-get install libsqlite3-dev
|
20
|
+
|
21
|
+
- name: Bundle
|
22
|
+
run: |
|
23
|
+
gem install bundler -v 1.17.3
|
24
|
+
bundle install --jobs 4 --retry 3
|
25
|
+
|
26
|
+
- name: Run rubocop
|
27
|
+
run: bundle exec rubocop
|
28
|
+
|
29
|
+
- name: Prepare test app
|
30
|
+
run: |
|
31
|
+
cd test/rails_app
|
32
|
+
RAILS_ENV=test bundle exec rake db:migrate
|
33
|
+
RAILS_ENV=development bundle exec rake db:migrate
|
34
|
+
RAILS_ENV=production bundle exec rake db:migrate
|
35
|
+
|
36
|
+
- name: Run tests
|
37
|
+
run: bundle exec rake test
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
Exclude:
|
4
|
+
- "bin/console"
|
5
|
+
- "test/rails_app/db/schema.rb"
|
6
|
+
|
7
|
+
Metrics/AbcSize:
|
8
|
+
Exclude:
|
9
|
+
- "test/**/*"
|
10
|
+
|
11
|
+
Metrics/LineLength:
|
12
|
+
AllowHeredoc: true
|
13
|
+
AllowURI: true
|
14
|
+
IgnoreCopDirectives: true
|
15
|
+
Max: 120
|
16
|
+
Exclude:
|
17
|
+
- "authorize_that.gemspec"
|
18
|
+
- "test/**/*"
|
19
|
+
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Exclude:
|
22
|
+
- "test/**/*"
|
23
|
+
|
24
|
+
Style/ClassAndModuleChildren:
|
25
|
+
Exclude:
|
26
|
+
- "test/**/*"
|
27
|
+
|
28
|
+
Style/StringLiterals:
|
29
|
+
EnforcedStyle: double_quotes
|
30
|
+
|
31
|
+
Style/SymbolProc:
|
32
|
+
Exclude:
|
33
|
+
- test/rails_app/db/migrate/20190708175731_create_tables.rb
|
data/.vimrc
ADDED
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source "https://rubygems.org"
|
2
4
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in rails_db_guard.gemspec
|
6
8
|
gemspec
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# RailsDbGuard
|
2
2
|
|
3
|
+
[![Actions Status](https://wdp9fww0r9.execute-api.us-west-2.amazonaws.com/production/badge/betterdoc-org/rails_db_guard)](https://wdp9fww0r9.execute-api.us-west-2.amazonaws.com/production/results/betterdoc-org/rails_db_guard)
|
4
|
+
|
3
5
|
Prevents connecting to protected environments databases from other environments.
|
4
6
|
|
5
7
|
Have you ever used `DATABASE_URL` from production in development? If yes, this is a gem for you. If not, some of your colleague has (or will), so this is a gem for you :)
|
@@ -69,7 +71,6 @@ This also mean you will need to prepare database for each environment.
|
|
69
71
|
* MySQL adapter
|
70
72
|
* CI setup (matrix for multiple database adapter and rails versions combinations)
|
71
73
|
* Setup Rubocop
|
72
|
-
* Add option to skip the check if `DISABLE_DATABASE_ENVIRONMENT_CHECK` environment variable is set
|
73
74
|
|
74
75
|
## Contributing
|
75
76
|
|
data/Rakefile
CHANGED
data/lib/rails_db_guard.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "rails_db_guard/version"
|
4
|
+
require "rails_db_guard/railtie"
|
2
5
|
|
6
|
+
# :nodoc:
|
3
7
|
module RailsDbGuard
|
4
8
|
class Error < StandardError; end
|
5
9
|
|
@@ -14,11 +18,10 @@ module RailsDbGuard
|
|
14
18
|
end
|
15
19
|
|
16
20
|
def guard!(env)
|
17
|
-
return
|
21
|
+
return if ENV.key?("DISABLE_DATABASE_ENVIRONMENT_CHECK")
|
22
|
+
return unless ActiveRecord::Base.protected_environments.include?(env) && Rails.env != env
|
18
23
|
|
19
24
|
raise Error, "You are trying to connect to `#{env}` database from `#{Rails.env}` environment"
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
23
|
-
|
24
|
-
require "rails_db_guard/railtie"
|
@@ -1,8 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.set_callback :checkout, :after do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
raise e unless e.message =~ /relation \"ar_internal_metadata\" does not exist/
|
7
|
-
end
|
4
|
+
env = raw_connection.exec(RailsDbGuard::ENV_NAME_SQL).values.flatten.first
|
5
|
+
RailsDbGuard.guard!(env)
|
6
|
+
rescue PG::UndefinedTable => e
|
7
|
+
raise e unless e.message =~ /relation \"ar_internal_metadata\" does not exist/
|
8
8
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
ActiveRecord::ConnectionAdapters::SQLite3Adapter.set_callback :checkout, :after do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
raise e unless e.message =~ /no such table\: ar_internal_metadata/
|
7
|
-
end
|
4
|
+
env = raw_connection.execute(RailsDbGuard::ENV_NAME_SQL).first["value"]
|
5
|
+
RailsDbGuard.guard!(env)
|
6
|
+
rescue SQLite3::SQLException => e
|
7
|
+
raise e unless e.message =~ /no such table\: ar_internal_metadata/
|
8
8
|
end
|
data/rails_db_guard.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
lib = File.expand_path("
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require "rails_db_guard/version"
|
5
6
|
|
@@ -9,13 +10,13 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.authors = ["BetterDoc GmbH"]
|
10
11
|
spec.email = ["pirates@betterdoc.org"]
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
+
spec.summary = "Prevents connecting to protected environments databases from other environments"
|
13
14
|
spec.homepage = "https://github.com/betterdoc-org/rails_db_guard"
|
14
15
|
spec.license = "MIT"
|
15
16
|
|
16
17
|
# Specify which files should be added to the gem when it is released.
|
17
18
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
-
spec.files = Dir.chdir(File.expand_path(
|
19
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
20
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
21
|
end
|
21
22
|
spec.bindir = "exe"
|
@@ -25,6 +26,8 @@ Gem::Specification.new do |spec|
|
|
25
26
|
spec.add_dependency "rails", ">= 5"
|
26
27
|
|
27
28
|
spec.add_development_dependency "bundler", "~> 1.17"
|
29
|
+
spec.add_development_dependency "climate_control", "~> 0.2.0"
|
28
30
|
spec.add_development_dependency "minitest", "~> 5"
|
29
31
|
spec.add_development_dependency "rake", "~> 10"
|
32
|
+
spec.add_development_dependency "rubocop", "~> 0.74"
|
30
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_db_guard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BetterDoc GmbH
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.17'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: climate_control
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.2.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: minitest
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,20 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.74'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.74'
|
69
97
|
description:
|
70
98
|
email:
|
71
99
|
- pirates@betterdoc.org
|
@@ -73,8 +101,11 @@ executables: []
|
|
73
101
|
extensions: []
|
74
102
|
extra_rdoc_files: []
|
75
103
|
files:
|
104
|
+
- ".github/workflows/main.yml"
|
76
105
|
- ".gitignore"
|
106
|
+
- ".rubocop.yml"
|
77
107
|
- ".travis.yml"
|
108
|
+
- ".vimrc"
|
78
109
|
- CODE_OF_CONDUCT.md
|
79
110
|
- Gemfile
|
80
111
|
- LICENSE.txt
|