rokku 0.6.1 → 0.6.2
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/rokku +1 -1
- data/lib/rokku/commands/commands.rb +96 -32
- data/lib/rokku/version.rb +1 -1
- metadata +2 -3
- data/lib/rokku/policy_generator/policy_generator.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ab320b2b11ae398d36a715e8895ffc3e471c2c8b2d02ec930ecdb17c96ca91d
|
4
|
+
data.tar.gz: ff14c12f1609d2d5f9522face2487eb4141547661dc3a068881b21f42827f157
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d189c151d7264efc138a39234b06a2bccd34e46d65576b284768f1d3636e69ea43995fb8916ec3a7560cef661d210b5023366452caa361f9895857d9d80c2c2f
|
7
|
+
data.tar.gz: 15b6d68bae30e7a590aa8db35944e741780f9a47203111a3484a61b405fb8eb925638304d9158c2f6740958a08e57cb4d1baf5ccbdb3eb5e2e6373fc8b77f4a4
|
data/Gemfile.lock
CHANGED
data/bin/rokku
CHANGED
@@ -1,41 +1,105 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
1
|
require 'optparse'
|
3
|
-
|
2
|
+
require 'fileutils'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module Commands
|
5
|
+
def self.run
|
6
|
+
options = {}
|
7
|
+
optparse = OptionParser.new do |opts|
|
8
|
+
opts.banner = "\nHanami authorization policy generator
|
9
|
+
Usage: rokku -n myapp -p user
|
10
|
+
Flags:
|
11
|
+
\n"
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
opts.on("-n", "--app_name APP", "Specify the application name for the policy") do |app_name|
|
14
|
+
options[:app_name] = app_name
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
opts.on("-p", "--policy POLICY", "Specify the policy name") do |policy|
|
18
|
+
options[:policy] = policy
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-h", "--help", "Displays help") do
|
22
|
+
puts opts
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
optparse.parse!
|
29
|
+
puts "Add flag -h or --help to see usage instructions." if options.empty?
|
30
|
+
mandatory = [:app_name, :policy]
|
31
|
+
missing = mandatory.select{ |arg| options[arg].nil? }
|
32
|
+
unless missing.empty?
|
33
|
+
raise OptionParser::MissingArgument.new(missing.join(', '))
|
34
|
+
end
|
35
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
36
|
+
puts $!.to_s
|
37
|
+
puts optparse
|
38
|
+
exit
|
39
|
+
end
|
19
40
|
|
20
|
-
|
21
|
-
|
22
|
-
exit
|
41
|
+
puts "Performing task with options: #{options.inspect}"
|
42
|
+
generate_policy("#{options[:app_name]}", "#{options[:policy]}") if options[:policy]
|
23
43
|
end
|
24
|
-
end
|
25
44
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
45
|
+
private
|
46
|
+
# The generate_policy method creates the policy file for specified
|
47
|
+
# application and controller. By default all actions to check against
|
48
|
+
# are commented out.
|
49
|
+
# Uncomment the needed actions and define appropriate user roles.
|
50
|
+
|
51
|
+
def self.generate_policy(app_name, controller_name)
|
52
|
+
app_name = app_name
|
53
|
+
controller = controller_name.downcase.capitalize
|
54
|
+
policy_txt = <<-TXT
|
55
|
+
class #{controller}Policy
|
56
|
+
def initialize(roles)
|
57
|
+
@user_roles = roles
|
58
|
+
# Uncomment the required roles and add the
|
59
|
+
# appropriate user role to the @authorized_roles* array.
|
60
|
+
# @authorized_roles_for_new = []
|
61
|
+
# @authorized_roles_for_create = []
|
62
|
+
# @authorized_roles_for_show = []
|
63
|
+
# @authorized_roles_for_index = []
|
64
|
+
# @authorized_roles_for_edit = []
|
65
|
+
# @authorized_roles_for_update = []
|
66
|
+
# @authorized_roles_for_destroy = []
|
67
|
+
end
|
68
|
+
|
69
|
+
def new?
|
70
|
+
(@authorized_roles_for_new & @user_roles).any?
|
71
|
+
end
|
72
|
+
|
73
|
+
def create?
|
74
|
+
(@authorized_roles_for_create & @user_roles).any?
|
75
|
+
end
|
76
|
+
|
77
|
+
def show?
|
78
|
+
(@authorized_roles_for_show & @user_roles).any?
|
79
|
+
end
|
80
|
+
|
81
|
+
def index?
|
82
|
+
(@authorized_roles_for_index & @user_roles).any?
|
83
|
+
end
|
84
|
+
|
85
|
+
def edit?
|
86
|
+
(@authorized_roles_for_edit & @user_roles).any?
|
87
|
+
end
|
88
|
+
|
89
|
+
def update?
|
90
|
+
(@authorized_roles_for_update & @user_roles).any?
|
91
|
+
end
|
92
|
+
|
93
|
+
def destroy?
|
94
|
+
(@authorized_roles_for_destroy & @user_roles).any?
|
95
|
+
end
|
96
|
+
end
|
97
|
+
TXT
|
98
|
+
|
99
|
+
FileUtils.mkdir_p "lib/#{app_name}/policies" unless File.directory?("lib/#{app_name}/policies")
|
100
|
+
unless File.file?("lib/#{app_name}/policies/#{controller}Policy.rb")
|
101
|
+
File.open("lib/#{app_name}/policies/#{controller}Policy.rb", 'w') { |file| file.write(policy_txt) }
|
102
|
+
end
|
103
|
+
puts("Generated policy: lib/#{app_name}/policies/#{controller}Policy.rb") if File.file?("lib/#{app_name}/policies/#{controller}Policy.rb")
|
33
104
|
end
|
34
|
-
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
35
|
-
puts $!.to_s
|
36
|
-
puts optparse
|
37
|
-
exit
|
38
105
|
end
|
39
|
-
|
40
|
-
puts "Performing task with options: #{options.inspect}"
|
41
|
-
generate_policy("#{options[:app_name]}", "#{options[:policy]}") if options[:policy]
|
data/lib/rokku/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rokku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastjan Hribar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -145,7 +145,6 @@ files:
|
|
145
145
|
- bin/setup
|
146
146
|
- lib/rokku.rb
|
147
147
|
- lib/rokku/commands/commands.rb
|
148
|
-
- lib/rokku/policy_generator/policy_generator.rb
|
149
148
|
- lib/rokku/version.rb
|
150
149
|
- rokku.gemspec
|
151
150
|
homepage: https://github.com/sebastjan-hribar/rokku
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
require 'hanami/controller'
|
4
|
-
require 'hanami/action/session'
|
5
|
-
|
6
|
-
module Hanami
|
7
|
-
module Rokku
|
8
|
-
private
|
9
|
-
# The generate_policy method creates the policy file for specified
|
10
|
-
# application and controller. By default all actions to check against
|
11
|
-
# are commented out.
|
12
|
-
# Uncomment the needed actions and define appropriate user roles.
|
13
|
-
|
14
|
-
def generate_policy(app_name, controller_name)
|
15
|
-
app_name = app_name
|
16
|
-
controller = controller_name.downcase.capitalize
|
17
|
-
policy_txt = <<-TXT
|
18
|
-
class #{controller}Policy
|
19
|
-
def initialize(roles)
|
20
|
-
@user_roles = roles
|
21
|
-
# Uncomment the required roles and add the
|
22
|
-
# appropriate user role to the @authorized_roles* array.
|
23
|
-
# @authorized_roles_for_new = []
|
24
|
-
# @authorized_roles_for_create = []
|
25
|
-
# @authorized_roles_for_show = []
|
26
|
-
# @authorized_roles_for_index = []
|
27
|
-
# @authorized_roles_for_edit = []
|
28
|
-
# @authorized_roles_for_update = []
|
29
|
-
# @authorized_roles_for_destroy = []
|
30
|
-
end
|
31
|
-
|
32
|
-
def new?
|
33
|
-
(@authorized_roles_for_new & @user_roles).any?
|
34
|
-
end
|
35
|
-
|
36
|
-
def create?
|
37
|
-
(@authorized_roles_for_create & @user_roles).any?
|
38
|
-
end
|
39
|
-
|
40
|
-
def show?
|
41
|
-
(@authorized_roles_for_show & @user_roles).any?
|
42
|
-
end
|
43
|
-
|
44
|
-
def index?
|
45
|
-
(@authorized_roles_for_index & @user_roles).any?
|
46
|
-
end
|
47
|
-
|
48
|
-
def edit?
|
49
|
-
(@authorized_roles_for_edit & @user_roles).any?
|
50
|
-
end
|
51
|
-
|
52
|
-
def update?
|
53
|
-
(@authorized_roles_for_update & @user_roles).any?
|
54
|
-
end
|
55
|
-
|
56
|
-
def destroy?
|
57
|
-
(@authorized_roles_for_destroy & @user_roles).any?
|
58
|
-
end
|
59
|
-
end
|
60
|
-
TXT
|
61
|
-
|
62
|
-
FileUtils.mkdir_p "lib/#{app_name}/policies" unless File.directory?("lib/#{app_name}/policies")
|
63
|
-
unless File.file?("lib/#{app_name}/policies/#{controller}Policy.rb")
|
64
|
-
File.open("lib/#{app_name}/policies/#{controller}Policy.rb", 'w') { |file| file.write(policy_txt) }
|
65
|
-
end
|
66
|
-
puts("Generated policy: lib/#{app_name}/policies/#{controller}Policy.rb") if File.file?("lib/#{app_name}/policies/#{controller}Policy.rb")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|