Module: Yus

Defined in:
lib/yus/privilege.rb,
lib/yus/entity.rb,
lib/yus/server.rb,
lib/yus/helpers.rb,
lib/yus/session.rb,
lib/yus/version.rb,
lib/yus/persistence/og.rb,
lib/yus/persistence/odba.rb

Overview

Privilege – yus – 31.05.2006 – [email protected]

Defined Under Namespace

Modules: Persistence Classes: AuthenticationError, AutoSession, CircularAffiliationError, DuplicateNameError, Entity, EntitySession, NotPrivilegedError, Privilege, RootSession, Server, Session, TokenSession, UnknownEntityError, YusError

Constant Summary collapse

VERSION =
'1.0.7'

Class Method Summary collapse

Class Method Details

.default_optsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/yus/helpers.rb', line 9

def self.default_opts
  opts = []
  GetoptLong.new(
    ['--help', '-h', GetoptLong::NO_ARGUMENT],
    ['--config', '-c', GetoptLong::OPTIONAL_ARGUMENT],
    ['--root_name', '-r', GetoptLong::OPTIONAL_ARGUMENT],
    ['--server_url', '-u', GetoptLong::OPTIONAL_ARGUMENT],
    ['--yus_dir', '-d', GetoptLong::OPTIONAL_ARGUMENT]
  ).each { |key, pair|
    opts.push("#{key}=#{pair}")
  }
  opts
end

.get_password(prompt = 'Password: ') ⇒ Object



70
71
72
# File 'lib/yus/helpers.rb', line 70

def self.get_password(prompt='Password: ')
  ask(prompt) { |q| q.echo = false}
end

.session(opts = self.default_opts) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/yus/helpers.rb', line 23

def self.session(opts = self.default_opts)
  if /--help=/.match(opts[0])
          puts "\#{File.basename(__FILE__)} ...\n\n-h, --help:\n show help\n\n-c -config\n config directory of yus.yml\n\n-r --root_name\n Root name to use for reading yus\n\n-s --config\n path to YAML-config of Yus\n    EOF\n    exit\n  end\n  default_dir = '/etc/yus'\n  default_config_files = [\n    File.join(default_dir, 'yus.yml'),\n  ]\n   defaults = {\n    'config'            => default_config_files,\n    'root_name'         => 'admin',\n    'server_url'        => 'drbssl://localhost:9997',\n    'yus_dir'           => default_config_files,\n  }\n\n  opts.each{|opt|opt.sub!(/^--/, '') } # Remove leading '--' from the GetOptLong\n  config = RCLConf::RCLConf.new(opts, defaults)\n  config.load(config.config)\n\n  server = DRb::DRbObject.new(nil, config.server_url)\n  server.ping\n\n  session = nil\n  begin\n    pass = Yus.get_password(\"Password for \#{config.root_name}: \")\n    session = server.login(config.root_name, pass.to_s, 'commandline')\n  rescue Yus::YusError => e\n    puts e.message\n    retry\n  end\n  return session\nend\n"