diff --git a/.circleci/config.yml b/.circleci/config.yml index cfac0f6..c912f31 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2 jobs: build: docker: - - image: circleci/ruby:2.5.1-node-browsers + - image: circleci/ruby:2.7.3-node-browsers - image: circleci/postgres:9.6.2-alpine environment: POSTGRES_USER: postgres diff --git a/.rubocop.yml b/.rubocop.yml index e816ce0..3a365d2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,7 +8,7 @@ Layout/CaseIndentation: Layout/EndAlignment: Enabled: false -Lint/HandleExceptions: +Lint/SuppressedException: Enabled: false Metrics/AbcSize: diff --git a/Gemfile.lock b/Gemfile.lock index fe5a6da..6f9d6f7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,51 +1,58 @@ PATH remote: . specs: - grantinee (0.3.3) + grantinee (0.4.0) GEM remote: https://rubygems.org/ specs: - ast (2.4.0) - byebug (10.0.2) - diff-lcs (1.3) - method_source (0.9.0) - mysql2 (0.5.1) - parallel (1.12.1) - parser (2.5.1.0) - ast (~> 2.4.0) - pg (1.0.0) - powerpack (0.1.1) - rainbow (3.0.0) + ast (2.4.2) + byebug (11.1.3) + diff-lcs (1.5.0) + json (2.6.2) + method_source (1.0.0) + mysql2 (0.5.4) + parallel (1.22.1) + parser (3.1.2.1) + ast (~> 2.4.1) + pg (1.4.4) + rainbow (3.1.1) rake (10.5.0) - rspec (3.7.0) - rspec-core (~> 3.7.0) - rspec-expectations (~> 3.7.0) - rspec-mocks (~> 3.7.0) - rspec-core (3.7.1) - rspec-support (~> 3.7.0) - rspec-expectations (3.7.0) + regexp_parser (2.6.0) + rexml (3.2.5) + rspec (3.11.0) + rspec-core (~> 3.11.0) + rspec-expectations (~> 3.11.0) + rspec-mocks (~> 3.11.0) + rspec-core (3.11.0) + rspec-support (~> 3.11.0) + rspec-expectations (3.11.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-mocks (3.7.0) + rspec-support (~> 3.11.0) + rspec-mocks (3.11.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-support (3.7.1) - rubocop (0.56.0) + rspec-support (~> 3.11.0) + rspec-support (3.11.1) + rubocop (1.37.1) + json (~> 2.3) parallel (~> 1.10) - parser (>= 2.5) - powerpack (~> 0.1) + parser (>= 3.1.2.1) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.23.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.9.0) - unicode-display_width (1.4.0) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.23.0) + parser (>= 3.1.1.0) + ruby-progressbar (1.11.0) + unicode-display_width (2.3.0) PLATFORMS - ruby + arm64-darwin-21 DEPENDENCIES - bundler (~> 1.16) + bundler (>= 1.3.0) byebug grantinee! method_source @@ -56,4 +63,4 @@ DEPENDENCIES rubocop BUNDLED WITH - 1.16.2 + 2.3.24 diff --git a/grantinee.gemspec b/grantinee.gemspec index 09fa831..5bb4807 100644 --- a/grantinee.gemspec +++ b/grantinee.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_development_dependency "bundler", "~> 1.16" + spec.add_development_dependency "bundler", ">= 1.3.0" spec.add_development_dependency "byebug" spec.add_development_dependency "method_source" spec.add_development_dependency "rake", "~> 10.0" diff --git a/lib/grantinee/cli.rb b/lib/grantinee/cli.rb index 63796ee..2cca628 100644 --- a/lib/grantinee/cli.rb +++ b/lib/grantinee/cli.rb @@ -2,9 +2,7 @@ module Grantinee class CLI - attr_accessor :options - attr_accessor :dsl - attr_accessor :engine + attr_accessor :options, :dsl, :engine def initialize(args = ARGV, logger = ::Logger.new($stderr)) @args = args @@ -118,8 +116,8 @@ def process_database_param end require options[:config] - rescue StandardError, LoadError => error - puts error + rescue StandardError, LoadError => e + puts e exit end @@ -131,6 +129,7 @@ def process_grantinee_param # Explicit verbose mode, overrides configuration value def process_verbosity_param return unless @options[:verbose] + log_levels = %w[debug info warn error fatal unknown] @logger.level = log_levels.index(@options[:verbose]) end diff --git a/lib/grantinee/configuration.rb b/lib/grantinee/configuration.rb index f05879a..a05a855 100644 --- a/lib/grantinee/configuration.rb +++ b/lib/grantinee/configuration.rb @@ -7,14 +7,10 @@ class Configuration # Which engine is used by the library? attr_accessor :engine - attr_accessor :logger + attr_accessor :logger, :password, :hostname, :port, :database # Connection parameters attr_accessor :username - attr_accessor :password - attr_accessor :hostname - attr_accessor :port - attr_accessor :database attr_reader :url # Allow verbose mode diff --git a/lib/grantinee/dsl.rb b/lib/grantinee/dsl.rb index a015390..f79577a 100644 --- a/lib/grantinee/dsl.rb +++ b/lib/grantinee/dsl.rb @@ -49,8 +49,8 @@ def user(user, &block) logger.debug "Got table: #{table}, fields: #{fields}" @permissions << @data.merge( - kind: kind, - table: table, + kind: kind, + table: table, fields: fields ) end diff --git a/lib/grantinee/engine/mysql.rb b/lib/grantinee/engine/mysql.rb index 9362a36..6807aba 100644 --- a/lib/grantinee/engine/mysql.rb +++ b/lib/grantinee/engine/mysql.rb @@ -12,8 +12,8 @@ def initialize @connection = Mysql2::Client.new( username: configuration.username, password: configuration.password, - host: configuration.hostname, - port: configuration.port, + host: configuration.hostname, + port: configuration.port, database: configuration.database ) end diff --git a/lib/grantinee/engine/postgresql.rb b/lib/grantinee/engine/postgresql.rb index 71ae787..e0003fd 100644 --- a/lib/grantinee/engine/postgresql.rb +++ b/lib/grantinee/engine/postgresql.rb @@ -10,11 +10,11 @@ def initialize configuration = Grantinee.configuration @connection = PG::Connection.open( - user: configuration.username, + user: configuration.username, password: configuration.password, - host: configuration.hostname, - port: configuration.port, - dbname: configuration.database + host: configuration.hostname, + port: configuration.port, + dbname: configuration.database ) end diff --git a/spec/lib/grantinee/engine/mysql_spec.rb b/spec/lib/grantinee/engine/mysql_spec.rb index 971c0c8..36386ad 100644 --- a/spec/lib/grantinee/engine/mysql_spec.rb +++ b/spec/lib/grantinee/engine/mysql_spec.rb @@ -23,8 +23,8 @@ module Engine { username: "privileged_person", password: "secret", - host: "172.0.0.1", - port: 5432, + host: "172.0.0.1", + port: 5432, database: "grantinee_test" } end diff --git a/spec/lib/grantinee/engine/postgresql_spec.rb b/spec/lib/grantinee/engine/postgresql_spec.rb index 5c0d07f..04c4112 100644 --- a/spec/lib/grantinee/engine/postgresql_spec.rb +++ b/spec/lib/grantinee/engine/postgresql_spec.rb @@ -22,8 +22,8 @@ module Engine { user: "privileged_person", password: "secret", - host: "172.0.0.1", - port: 5432, + host: "172.0.0.1", + port: 5432, dbname: "grantinee_test" } end diff --git a/spec/support/mysql_helpers.rb b/spec/support/mysql_helpers.rb index f10fc48..dc0f224 100644 --- a/spec/support/mysql_helpers.rb +++ b/spec/support/mysql_helpers.rb @@ -1,4 +1,3 @@ - # frozen_string_literal: true require "yaml" @@ -11,16 +10,16 @@ def initialize(user: nil, password: nil, database: nil) @client = Mysql2::Client.new( username: user, password: password, - host: Grantinee.configuration.hostname, - port: Grantinee.configuration.port, + host: Grantinee.configuration.hostname, + port: Grantinee.configuration.port, database: database ) end def create_database(database) @client.query "CREATE DATABASE #{database};" - rescue Mysql2::Error => error - puts error + rescue Mysql2::Error => e + puts e end def drop_database(database) @@ -70,8 +69,8 @@ def drop_table(name) def create_user_records @client.query "INSERT INTO users (id, anonymized) VALUES ('1234', false);" - rescue StandardError => error - puts error + rescue StandardError => e + puts e end def close diff --git a/spec/support/postgresql_helpers.rb b/spec/support/postgresql_helpers.rb index 68731db..0d26072 100644 --- a/spec/support/postgresql_helpers.rb +++ b/spec/support/postgresql_helpers.rb @@ -1,4 +1,3 @@ - # frozen_string_literal: true require "yaml" @@ -9,11 +8,11 @@ def initialize(user: nil, password: nil, database: nil) load "./spec/fixtures/config_postgresql.rb" @client = PG::Connection.open( - user: user, + user: user, password: password, - host: Grantinee.configuration.hostname, - port: Grantinee.configuration.port, - dbname: database + host: Grantinee.configuration.hostname, + port: Grantinee.configuration.port, + dbname: database ) end diff --git a/spec/support/shared_contexts/mysql_database.rb b/spec/support/shared_contexts/mysql_database.rb index 137c168..d46aea4 100644 --- a/spec/support/shared_contexts/mysql_database.rb +++ b/spec/support/shared_contexts/mysql_database.rb @@ -14,8 +14,8 @@ Mysql2::Client.new( username: (defined?(user) ? user : users.first), password: "secret", - host: Grantinee.configuration.hostname, - port: Grantinee.configuration.port, + host: Grantinee.configuration.hostname, + port: Grantinee.configuration.port, database: Grantinee.configuration.database ) end diff --git a/spec/support/shared_contexts/postgresql_database.rb b/spec/support/shared_contexts/postgresql_database.rb index ac1c678..8aec45b 100644 --- a/spec/support/shared_contexts/postgresql_database.rb +++ b/spec/support/shared_contexts/postgresql_database.rb @@ -12,11 +12,11 @@ load "./spec/fixtures/config_postgresql.rb" PG::Connection.open( - user: (defined?(user) ? user : users.first), + user: (defined?(user) ? user : users.first), password: "fake_password", - host: Grantinee.configuration.hostname, - port: Grantinee.configuration.port, - dbname: Grantinee.configuration.database + host: Grantinee.configuration.hostname, + port: Grantinee.configuration.port, + dbname: Grantinee.configuration.database ) end