grantinee 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +68 -0
- data/.circleci/setup-rubygems.sh +3 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +37 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Dockerfile +15 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +59 -0
- data/Grantinee +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +127 -0
- data/Rakefile +14 -0
- data/bin/console +16 -0
- data/bin/setup +10 -0
- data/config/grantinee.rb +29 -0
- data/docker-compose.yml +34 -0
- data/exe/grantinee +15 -0
- data/grantinee.gemspec +33 -0
- data/lib/grantinee.rb +37 -0
- data/lib/grantinee/cli.rb +128 -0
- data/lib/grantinee/configuration.rb +51 -0
- data/lib/grantinee/dsl.rb +63 -0
- data/lib/grantinee/engine.rb +67 -0
- data/lib/grantinee/engine/abstract_engine.rb +48 -0
- data/lib/grantinee/engine/mysql.rb +87 -0
- data/lib/grantinee/engine/postgresql.rb +80 -0
- data/lib/grantinee/executor.rb +34 -0
- data/lib/grantinee/version.rb +5 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bf367e26de633adeffbbcaefc8e9d75b18ddb1ab
|
4
|
+
data.tar.gz: 7554a517aee2e1bd0bd926289b48a06552b51909
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 311aef92e98ecd7121f880d193b2261214311b60c5061996fcb7dc70b0a434bb36dcdf32200a6202ec393f4f6304d9cfcb977f48edc7ca086747aaa57fa920bd
|
7
|
+
data.tar.gz: 4cace4a332ae4d9280b4a3d2953d966670d5beb1ec692bcec8bedc574fc8b7ae5c8a835be8777d5fdfae46cd3e626629675bab1993a99763751719f3256d4653
|
@@ -0,0 +1,68 @@
|
|
1
|
+
version: 2
|
2
|
+
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
docker:
|
6
|
+
- image: circleci/ruby:2.5.1-node-browsers
|
7
|
+
- image: circleci/postgres:9.6.2-alpine
|
8
|
+
environment:
|
9
|
+
POSTGRES_USER: postgres
|
10
|
+
POSTGRES_PASSWORD: postgres
|
11
|
+
POSTGRES_DB: grantinee_test
|
12
|
+
- image: circleci/mysql:5.7
|
13
|
+
environment:
|
14
|
+
MYSQL_DATABASE: grantinee_test
|
15
|
+
MYSQL_ROOT_PASSWORD: mysql
|
16
|
+
steps:
|
17
|
+
- checkout
|
18
|
+
|
19
|
+
- run:
|
20
|
+
name: Wait for postgres DB
|
21
|
+
command: dockerize -wait tcp://localhost:5432 -timeout 1m
|
22
|
+
|
23
|
+
- run:
|
24
|
+
name: Wait for mysql DB
|
25
|
+
command: dockerize -wait tcp://localhost:3306 -timeout 1m
|
26
|
+
|
27
|
+
- run:
|
28
|
+
name: Install dependencies
|
29
|
+
command: bundle install --jobs=4 --retry=3 --path vendor/bundle
|
30
|
+
|
31
|
+
- run:
|
32
|
+
name: Run tests
|
33
|
+
command: bundle exec rake
|
34
|
+
|
35
|
+
deploy:
|
36
|
+
docker:
|
37
|
+
- image: circleci/ruby:2.5.1-node-browsers
|
38
|
+
steps:
|
39
|
+
- checkout
|
40
|
+
|
41
|
+
- run:
|
42
|
+
name: Setup Rubygems
|
43
|
+
command: bash .circleci/setup-rubygems.sh
|
44
|
+
|
45
|
+
- run:
|
46
|
+
name: Publish to Rubygems
|
47
|
+
command: |
|
48
|
+
gem build grantinee.gemspec
|
49
|
+
gem push "grantinee-$(git describe --tags | cut -c2-).gem"
|
50
|
+
|
51
|
+
workflows:
|
52
|
+
version: 2
|
53
|
+
|
54
|
+
build-and-deploy:
|
55
|
+
jobs:
|
56
|
+
- build:
|
57
|
+
filters:
|
58
|
+
tags:
|
59
|
+
only: /.*/
|
60
|
+
|
61
|
+
- deploy:
|
62
|
+
requires:
|
63
|
+
- build
|
64
|
+
filters:
|
65
|
+
tags:
|
66
|
+
only: /^v.*/
|
67
|
+
branches:
|
68
|
+
ignore: /.*/
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
Layout/CaseIndentation:
|
2
|
+
EnforcedStyle: end
|
3
|
+
|
4
|
+
# offense count: 4
|
5
|
+
Layout/EndAlignment:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Lint/HandleExceptions:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Metrics/AbcSize:
|
12
|
+
Max: 17
|
13
|
+
|
14
|
+
Metrics/BlockLength:
|
15
|
+
Exclude:
|
16
|
+
- "grantinee.gemspec"
|
17
|
+
- "spec/**/*"
|
18
|
+
|
19
|
+
Metrics/LineLength:
|
20
|
+
Max: 100
|
21
|
+
Exclude:
|
22
|
+
- grantinee.gemspec
|
23
|
+
|
24
|
+
Metrics/MethodLength:
|
25
|
+
Max: 15
|
26
|
+
|
27
|
+
Security/Eval:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Style/Documentation:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Style/FormatStringToken:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Style/StringLiterals:
|
37
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at pawel@blinkist.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Dockerfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
FROM ruby:2.5
|
2
|
+
|
3
|
+
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
|
4
|
+
|
5
|
+
RUN mkdir /myapp
|
6
|
+
WORKDIR /myapp
|
7
|
+
|
8
|
+
COPY Gemfile /myapp/Gemfile
|
9
|
+
COPY Gemfile.lock /myapp/Gemfile.lock
|
10
|
+
COPY grantinee.gemspec /myapp/grantinee.gemspec
|
11
|
+
COPY lib /myapp/lib
|
12
|
+
|
13
|
+
RUN bundle install
|
14
|
+
|
15
|
+
COPY . /myapp
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
grantinee (0.3.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
byebug (10.0.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
method_source (0.9.0)
|
13
|
+
mysql2 (0.5.1)
|
14
|
+
parallel (1.12.1)
|
15
|
+
parser (2.5.1.0)
|
16
|
+
ast (~> 2.4.0)
|
17
|
+
pg (1.0.0)
|
18
|
+
powerpack (0.1.1)
|
19
|
+
rainbow (3.0.0)
|
20
|
+
rake (10.5.0)
|
21
|
+
rspec (3.7.0)
|
22
|
+
rspec-core (~> 3.7.0)
|
23
|
+
rspec-expectations (~> 3.7.0)
|
24
|
+
rspec-mocks (~> 3.7.0)
|
25
|
+
rspec-core (3.7.1)
|
26
|
+
rspec-support (~> 3.7.0)
|
27
|
+
rspec-expectations (3.7.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.7.0)
|
30
|
+
rspec-mocks (3.7.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.7.0)
|
33
|
+
rspec-support (3.7.1)
|
34
|
+
rubocop (0.56.0)
|
35
|
+
parallel (~> 1.10)
|
36
|
+
parser (>= 2.5)
|
37
|
+
powerpack (~> 0.1)
|
38
|
+
rainbow (>= 2.2.2, < 4.0)
|
39
|
+
ruby-progressbar (~> 1.7)
|
40
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
41
|
+
ruby-progressbar (1.9.0)
|
42
|
+
unicode-display_width (1.4.0)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
bundler (~> 1.16)
|
49
|
+
byebug
|
50
|
+
grantinee!
|
51
|
+
method_source
|
52
|
+
mysql2
|
53
|
+
pg
|
54
|
+
rake (~> 10.0)
|
55
|
+
rspec (~> 3.0)
|
56
|
+
rubocop
|
57
|
+
|
58
|
+
BUNDLED WITH
|
59
|
+
1.16.2
|
data/Grantinee
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Paweł Komarnicki
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# Grantinee
|
2
|
+
|
3
|
+
Grantinee is a library to manage your database permissions. It supports MySQL and Postgres, allowing for granular per-table, and per-column permission setting. Tight and explicit permissions, instead of "allow all access" approach, may enhance the data security in your app, and make the GDPR compliance easier for multi-user databases (like when you have a service-oriented architecture).
|
4
|
+
|
5
|
+
[![CircleCI](https://circleci.com/gh/blinkist/grantinee/tree/master.svg?style=svg&circle-token=be47ddf3e39aa44795797ae40c06bd42144ad888)](https://circleci.com/gh/blinkist/grantinee/tree/master)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'grantinee'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install grantinee
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Before you start using Grantinee you need to configure it.
|
26
|
+
|
27
|
+
### User ActiveRecord connection (Rails)
|
28
|
+
|
29
|
+
As long as you use Grantinee's executable, everything is plug-and-play. Just make sure that you operate in the right environment, and your database user has granting rights (most likely it won't have them for security reasons). Simply run:
|
30
|
+
|
31
|
+
$ RAILS_ENV=production bundle exec grantinee
|
32
|
+
|
33
|
+
If you'd like to use Grantinee programmatically as a library, you will need to create two things:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# Create or pass an existing logger
|
37
|
+
Grantinee.logger = ::Logger.new(STDOUT)
|
38
|
+
|
39
|
+
# (optional) Manually call ActiveRecord detection
|
40
|
+
Grantinee::Engine.detect_active_record_connection!
|
41
|
+
```
|
42
|
+
|
43
|
+
### Custom database connection
|
44
|
+
|
45
|
+
You may create an initializer, providing each information separately:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
Grantinee.configure do |c|
|
49
|
+
c.engine = :mysql
|
50
|
+
|
51
|
+
c.username = 'root'
|
52
|
+
c.password = 'password'
|
53
|
+
c.hostname = 'localhost'
|
54
|
+
c.port = 3306
|
55
|
+
c.database = 'database_name'
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
Alternatively you can use the database URL (looking at you Heroku):
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
Grantinee.configure do |c|
|
63
|
+
c.engine = :mysql
|
64
|
+
c.url = "mysql://root:password@localhost:3306/database_name"
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
In case you do not want to or cannot use an initializer, you can save your configuration in a standalone ruby file, which you pass as an argument in the command line, i.e.:
|
69
|
+
|
70
|
+
$ grantinee -c ./config/grantinee.yml
|
71
|
+
|
72
|
+
### Command line options
|
73
|
+
|
74
|
+
Grantinee provides flexible configuration options through the command line parameters, you can easily review them, by running:
|
75
|
+
|
76
|
+
$ grantinee --help
|
77
|
+
|
78
|
+
```
|
79
|
+
Usage: grantinee [options]
|
80
|
+
-h, --help Displays help
|
81
|
+
-v, --verbosity=LEVEL Set verbosity level to debug, info, warn, error, fatal, or unknown (default: warning)
|
82
|
+
-r, --require=FILE Application boot file path (default: ./config/environment.rb)
|
83
|
+
-f, --file=FILE Permission definitions file path (default: ./Grantinee)
|
84
|
+
-c, --config=FILE Database configuration file path
|
85
|
+
```
|
86
|
+
|
87
|
+
## Permissions definition
|
88
|
+
|
89
|
+
You can use the DSL to quickly set up your permissions:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
on "database_name" do
|
93
|
+
# User on any host
|
94
|
+
user :username do
|
95
|
+
select :users, [ :id, :name ]
|
96
|
+
insert :users, [ :tracking_id ]
|
97
|
+
update :users, [ :tracking_id ]
|
98
|
+
|
99
|
+
all :articles
|
100
|
+
end
|
101
|
+
|
102
|
+
# Or user on a specific host
|
103
|
+
user 'username@example.org' do
|
104
|
+
select :users, [ :id, :name ]
|
105
|
+
insert :users, [ :tracking_id ]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
```
|
110
|
+
|
111
|
+
## Development
|
112
|
+
|
113
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
114
|
+
|
115
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
116
|
+
|
117
|
+
## Contributing
|
118
|
+
|
119
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/blinkist/grantinee. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
120
|
+
|
121
|
+
## License
|
122
|
+
|
123
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
124
|
+
|
125
|
+
## Code of Conduct
|
126
|
+
|
127
|
+
Everyone interacting in the Grantinee project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/grantinee/blob/master/CODE_OF_CONDUCT.md).
|