yus 1.0.0

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/bin/yus_add_user ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
4
+
5
+ require 'drb'
6
+ require 'drb/ssl'
7
+ require 'password'
8
+ require 'rclconf'
9
+ require 'yus/session'
10
+ require 'getoptlong'
11
+
12
+ opts = []
13
+ GetoptLong.new(
14
+ ['--config', '-c', GetoptLong::OPTIONAL_ARGUMENT],
15
+ ['--root_name', '-r', GetoptLong::OPTIONAL_ARGUMENT],
16
+ ['--server_url', '-u', GetoptLong::OPTIONAL_ARGUMENT],
17
+ ['--yus_dir', '-d', GetoptLong::OPTIONAL_ARGUMENT]
18
+ ).each { |pair|
19
+ opts.push(pair.join('=')[2..-1])
20
+ }
21
+
22
+ name, action, item = ARGV
23
+
24
+ unless(name)
25
+ puts <<-EOS
26
+ Usage: yus_add_user <username> [<action> [<item>]]
27
+ EOS
28
+ exit
29
+ end
30
+
31
+ default_dir = File.join(ENV['HOME'], '.yus')
32
+ default_config_files = [
33
+ File.join(default_dir, 'yus.yml'),
34
+ '/etc/yus/yus.yml',
35
+ ]
36
+ defaults = {
37
+ 'config' => default_config_files,
38
+ 'root_name' => 'admin',
39
+ 'server_url' => 'drbssl://localhost:9997',
40
+ 'yus_dir' => default_dir,
41
+ }
42
+
43
+ config = RCLConf::RCLConf.new(opts, defaults)
44
+ config.load(config.config)
45
+
46
+ server = DRb::DRbObject.new(nil, config.server_url)
47
+ server.ping
48
+
49
+ session = nil
50
+ begin
51
+ pass = Password.get("Password for #{config.root_name}: ")
52
+ session = server.login(config.root_name, pass.to_s, 'commandline')
53
+ rescue Yus::YusError => e
54
+ puts e.message
55
+ retry
56
+ end
57
+
58
+ cont = nil
59
+ callcc { |cont| }
60
+ pass1 = Password.get("New Password for #{name}: ")
61
+ pass2 = Password.get("Repeat Password for #{name}: ")
62
+
63
+ if(pass1 != pass2)
64
+ puts "Passwords did not match"
65
+ cont.call
66
+ end
67
+
68
+ session.create_entity(name)
69
+ session.set_password(name, pass1.to_s)
70
+ if(action)
71
+ session.grant(name, action, item)
72
+ end
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
4
+
5
+ require 'drb'
6
+ require 'drb/ssl'
7
+ require 'password'
8
+ require 'rclconf'
9
+ require 'yus/session'
10
+ require 'getoptlong'
11
+
12
+ opts = []
13
+ GetoptLong.new(
14
+ ['--config', '-c', GetoptLong::OPTIONAL_ARGUMENT],
15
+ ['--root_name', '-r', GetoptLong::OPTIONAL_ARGUMENT],
16
+ ['--server_url', '-u', GetoptLong::OPTIONAL_ARGUMENT],
17
+ ['--yus_dir', '-d', GetoptLong::OPTIONAL_ARGUMENT]
18
+ ).each { |pair|
19
+ opts.push(pair.join('=')[2..-1])
20
+ }
21
+
22
+ name, action, item = ARGV
23
+
24
+ unless(name)
25
+ puts <<-EOS
26
+ Usage: yus_delete_user <username>
27
+ EOS
28
+ exit
29
+ end
30
+
31
+ default_dir = File.join(ENV['HOME'], '.yus')
32
+ default_config_files = [
33
+ File.join(default_dir, 'yus.yml'),
34
+ '/etc/yus/yus.yml',
35
+ ]
36
+ defaults = {
37
+ 'config' => default_config_files,
38
+ 'root_name' => 'admin',
39
+ 'server_url' => 'drbssl://localhost:9997',
40
+ 'yus_dir' => default_dir,
41
+ }
42
+
43
+ config = RCLConf::RCLConf.new(opts, defaults)
44
+ config.load(config.config)
45
+
46
+ server = DRb::DRbObject.new(nil, config.server_url)
47
+ server.ping
48
+
49
+ session = nil
50
+ begin
51
+ pass = Password.get("Password for #{config.root_name}: ")
52
+ session = server.login(config.root_name, pass.to_s, 'commandline')
53
+ rescue Yus::YusError => e
54
+ puts e.message
55
+ retry
56
+ end
57
+
58
+ session.delete_entity(name)
data/bin/yus_grant ADDED
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
4
+
5
+ require 'drb'
6
+ require 'drb/ssl'
7
+ require 'password'
8
+ require 'rclconf'
9
+ require 'yus/session'
10
+ require 'getoptlong'
11
+
12
+ opts = []
13
+ command = :grant
14
+ date = 'until'
15
+ GetoptLong.new(
16
+ ['--config', '-c', GetoptLong::REQUIRED_ARGUMENT],
17
+ ['--root_name', '-r', GetoptLong::REQUIRED_ARGUMENT],
18
+ ['--server_url', '-u', GetoptLong::REQUIRED_ARGUMENT],
19
+ ['--yus_dir', '-d', GetoptLong::REQUIRED_ARGUMENT],
20
+ ['--revoke', '-R', GetoptLong::NO_ARGUMENT]
21
+ ).each { |key, value|
22
+ case key
23
+ when '--revoke'
24
+ command = :revoke
25
+ date = 'from'
26
+ else
27
+ opts.push([key, value].join('=')[2..-1])
28
+ end
29
+ }
30
+
31
+ name, action, item, expires = ARGV
32
+
33
+ unless(action)
34
+ puts <<-EOS
35
+ Usage: yus_grant <username> <action> [<item> [<expiry_time>]]
36
+ EOS
37
+ exit
38
+ end
39
+
40
+ default_dir = File.join(ENV['HOME'], '.yus')
41
+ default_config_files = [
42
+ File.join(default_dir, 'yus.yml'),
43
+ '/etc/yus/yus.yml',
44
+ ]
45
+ defaults = {
46
+ 'config' => default_config_files,
47
+ 'root_name' => 'admin',
48
+ 'server_url' => 'drbssl://localhost:9997',
49
+ 'yus_dir' => default_dir,
50
+ }
51
+
52
+ time = nil
53
+ if expires
54
+ if match = /(\d{1,2})\.(\d{1,2})\.(\d{4})/.match(expires.to_s)
55
+ time = Time.local(match[3].to_i, match[2].to_i, match[1].to_i)
56
+ else
57
+ puts <<-EOS
58
+ expiry_date must be in the Format: mm.dd.YYYY
59
+ EOS
60
+ end
61
+ end
62
+
63
+ config = RCLConf::RCLConf.new(opts, defaults)
64
+ config.load(config.config)
65
+
66
+ server = DRb::DRbObject.new(nil, config.server_url)
67
+ server.ping
68
+
69
+ session = nil
70
+ begin
71
+ pass = Password.get("Password for #{config.root_name}: ")
72
+ session = server.login(config.root_name, pass.to_s, 'commandline')
73
+ rescue Yus::YusError => e
74
+ puts e.message
75
+ retry
76
+ end
77
+
78
+ session.send(command, name, action, item, time)
79
+ puts sprintf("%sed permission to %s %s for %s %s %s",
80
+ command, action, item, name, date, expires)
data/bin/yus_passwd ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
4
+
5
+ require 'drb'
6
+ require 'drb/ssl'
7
+ require 'password'
8
+ require 'rclconf'
9
+ require 'yus/session'
10
+ require 'getoptlong'
11
+
12
+ opts = []
13
+ GetoptLong.new(
14
+ ['--config', '-c', GetoptLong::OPTIONAL_ARGUMENT],
15
+ ['--root_name', '-r', GetoptLong::OPTIONAL_ARGUMENT],
16
+ ['--server_url', '-u', GetoptLong::OPTIONAL_ARGUMENT],
17
+ ['--yus_dir', '-d', GetoptLong::OPTIONAL_ARGUMENT]
18
+ ).each { |pair|
19
+ opts.push(pair.join('=')[2..-1])
20
+ }
21
+
22
+ name = ARGV.first
23
+
24
+ unless(name)
25
+ puts <<-EOS
26
+ Usage: yus_passwd <username>
27
+ EOS
28
+ exit
29
+ end
30
+
31
+ default_dir = File.join(ENV['HOME'], '.yus')
32
+ default_config_files = [
33
+ File.join(default_dir, 'yus.yml'),
34
+ '/etc/yus/yus.yml',
35
+ ]
36
+ defaults = {
37
+ 'config' => default_config_files,
38
+ 'root_name' => 'admin',
39
+ 'server_url' => 'drbssl://localhost:9997',
40
+ 'yus_dir' => default_dir,
41
+ }
42
+
43
+ config = RCLConf::RCLConf.new(opts, defaults)
44
+ config.load(config.config)
45
+
46
+ server = DRb::DRbObject.new(nil, config.server_url)
47
+ server.ping
48
+
49
+ session = nil
50
+ begin
51
+ pass = Password.get("Password for #{config.root_name}: ")
52
+ session = server.login(config.root_name, pass.to_s, 'commandline')
53
+ rescue Yus::YusError => e
54
+ puts e.message
55
+ retry
56
+ end
57
+
58
+ cont = nil
59
+ callcc { |cont| }
60
+ pass1 = Password.get("New Password for #{name}: ")
61
+ pass2 = Password.get("Repeat Password for #{name}: ")
62
+
63
+ if(pass1 != pass2)
64
+ puts "Passwords did not match"
65
+ cont.call
66
+ end
67
+
68
+ session.set_password(name, pass1.to_s)
data/bin/yus_show ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
4
+
5
+ require 'drb'
6
+ require 'drb/ssl'
7
+ require 'password'
8
+ require 'rclconf'
9
+ require 'yus/session'
10
+ require 'getoptlong'
11
+
12
+ opts = []
13
+ recursive = false
14
+ GetoptLong.new(
15
+ ['--config', '-c', GetoptLong::REQUIRED_ARGUMENT],
16
+ ['--root_name', '-r', GetoptLong::REQUIRED_ARGUMENT],
17
+ ['--server_url', '-u', GetoptLong::REQUIRED_ARGUMENT],
18
+ ['--yus_dir', '-d', GetoptLong::REQUIRED_ARGUMENT],
19
+ ['--recursive', '-R', GetoptLong::NO_ARGUMENT]
20
+ ).each { |key, value|
21
+ case key
22
+ when '--recursive'
23
+ recursive = true
24
+ else
25
+ opts.push([key, value].join('=')[2..-1])
26
+ end
27
+ }
28
+
29
+ name = ARGV.first
30
+
31
+ unless(name)
32
+ puts <<-EOS
33
+ Usage: yus_show <username>
34
+ EOS
35
+ exit
36
+ end
37
+
38
+ default_dir = File.join(ENV['HOME'], '.yus')
39
+ default_config_files = [
40
+ File.join(default_dir, 'yus.yml'),
41
+ '/etc/yus/yus.yml',
42
+ ]
43
+ defaults = {
44
+ 'config' => default_config_files,
45
+ 'root_name' => 'admin',
46
+ 'server_url' => 'drbssl://localhost:9997',
47
+ 'yus_dir' => default_dir,
48
+ }
49
+
50
+ config = RCLConf::RCLConf.new(opts, defaults)
51
+ config.load(config.config)
52
+
53
+ server = DRb::DRbObject.new(nil, config.server_url)
54
+ server.ping
55
+
56
+ session = nil
57
+ begin
58
+ pass = Password.get("Password for #{config.root_name}: ")
59
+ session = server.login(config.root_name, pass.to_s, 'commandline')
60
+ rescue Yus::YusError => e
61
+ puts e.message
62
+ retry
63
+ end
64
+
65
+ puts session.show(name, recursive)
data/bin/yusd ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env ruby18
2
+
3
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
4
+
5
+ require 'rclconf'
6
+ require 'logger'
7
+ require 'drb'
8
+ require 'drb/ssl'
9
+ require 'drb/timeridconv'
10
+ require 'digest/sha2'
11
+
12
+ default_dir = File.join(ENV['HOME'], '.yus')
13
+ default_config_files = [
14
+ File.join(default_dir, 'yus.yml'),
15
+ '/etc/yus/yus.yml',
16
+ ]
17
+ defaults = {
18
+ 'cleaning_interval' => 300,
19
+ 'config' => default_config_files,
20
+ 'db_name' => 'yus',
21
+ 'db_user' => 'yus',
22
+ 'db_auth' => 'yus',
23
+ 'db_backend' => :psql,
24
+ 'digest' => Digest::SHA256,
25
+ 'log_file' => STDERR,
26
+ 'log_level' => 'INFO',
27
+ 'persistence' => 'odba',
28
+ 'root_name' => 'admin',
29
+ 'root_pass' => nil,
30
+ 'server_url' => 'drbssl://localhost:9997',
31
+ 'session_timeout' => 300,
32
+ 'ssl_key' => File.expand_path('../data/yus.key',
33
+ File.dirname(__FILE__)),
34
+ 'ssl_cert' => File.expand_path('../data/yus.crt',
35
+ File.dirname(__FILE__)),
36
+ 'token_lifetime' => 30,
37
+ 'yus_dir' => default_dir,
38
+ }
39
+
40
+ config = RCLConf::RCLConf.new(ARGV, defaults)
41
+ config.load(config.config)
42
+
43
+ require File.join('yus', 'persistence', config.persistence)
44
+ persistence = nil
45
+ case config.persistence
46
+ when 'odba'
47
+ require 'odba/connection_pool'
48
+ require 'odba/drbwrapper'
49
+ DRb.install_id_conv ODBA::DRbIdConv.new
50
+ ODBA.storage.dbi = ODBA::ConnectionPool.new("DBI:pg:#{config.db_name}",
51
+ config.db_user, config.db_auth)
52
+ ODBA.cache.setup
53
+ persistence = Yus::Persistence::Odba.new
54
+ when 'og'
55
+ DRb.install_id_conv DRb::TimerIdConv.new
56
+ Og.setup({
57
+ :name => config.db_name,
58
+ :user => config.db_user,
59
+ :password => config.db_auth,
60
+ :store => config.db_backend,
61
+ :evolve_schema => true,
62
+ })
63
+ persistence = Yus::Persistence::Og.new
64
+ end
65
+
66
+ log_file = config.log_file
67
+ if(log_file.is_a?(String))
68
+ FileUtils.mkdir_p(File.dirname(log_file))
69
+ log_file = File.open(log_file, 'a')
70
+ at_exit { log_file.close }
71
+ end
72
+ logger = Logger.new(log_file)
73
+ logger.level = Logger.const_get(config.log_level)
74
+
75
+ begin
76
+ server = Yus::Server.new(persistence, config, logger)
77
+ server.extend(DRbUndumped)
78
+
79
+ url = config.server_url
80
+ drbconf = {}
81
+ case url
82
+ when /drbssl/
83
+ keypath = File.expand_path(config.ssl_key, config.yus_dir)
84
+ certpath = File.expand_path(config.ssl_cert, config.yus_dir)
85
+ drbconf.update({
86
+ :SSLPrivateKey => OpenSSL::PKey::RSA.new(File.read(keypath)),
87
+ :SSLCertificate => OpenSSL::X509::Certificate.new(File.read(certpath)),
88
+ })
89
+ end
90
+ url.untaint
91
+ DRb.start_service(url, server, drbconf)
92
+ $SAFE = 1
93
+ logger.info('start') {
94
+ sprintf("starting yus-server on %s", url) }
95
+ DRb.thread.join
96
+ rescue Exception => error
97
+ logger.error('fatal') { error }
98
+ raise
99
+ end
data/config.save ADDED
@@ -0,0 +1,12 @@
1
+ site-ruby=$prefix/lib/ruby/site_ruby/1.8
2
+ prefix=/usr
3
+ ruby-prog=/usr/bin/ruby18
4
+ ruby-path=/usr/bin/ruby18
5
+ make-prog=make
6
+ site-ruby-common=$prefix/lib/ruby/site_ruby
7
+ rb-dir=$site-ruby
8
+ without-ext=no
9
+ std-ruby=$prefix/lib/ruby/1.8
10
+ bin-dir=$prefix/bin
11
+ data-dir=$prefix/share
12
+ so-dir=$prefix/lib/ruby/site_ruby/1.8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