Class: Oraora::Credentials
- Inherits:
-
Object
- Object
- Oraora::Credentials
- Defined in:
- lib/oraora/credentials.rb
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- @@vault =
[]
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
-
#password ⇒ Object
Returns the value of attribute password.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(c) ⇒ Boolean
- #fill_password_from_vault ⇒ Object
-
#initialize(user = nil, password = nil, database = nil) ⇒ Credentials
constructor
A new instance of Credentials.
- #match?(c) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(user = nil, password = nil, database = nil) ⇒ Credentials
Returns a new instance of Credentials.
8 9 10 11 12 |
# File 'lib/oraora/credentials.rb', line 8 def initialize(user = nil, password = nil, database = nil) @user = user @password = password @database = database end |
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database.
5 6 7 |
# File 'lib/oraora/credentials.rb', line 5 def database @database end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/oraora/credentials.rb', line 5 def password @password end |
#user ⇒ Object
Returns the value of attribute user.
5 6 7 |
# File 'lib/oraora/credentials.rb', line 5 def user @user end |
Class Method Details
.parse(str) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/oraora/credentials.rb', line 29 def self.parse(str) if str match = str.match /^([^\/@]+)?\/?([^\/@]+)?@?([^\/@]+)?$/ raise ParseError, "invalid format (use login/pass@DB)" if !match user, password, database = match[1..3] raise ParseError, "user can only contain alphanumeric characters" if user && !user.match(/^\w+$/) raise ParseError, "database name can only contain alphanumeric characters" if database && !database.match(/^\w+$/) return new(user, password, database) else return new end end |
.read_passfile(filename) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/oraora/credentials.rb', line 14 def self.read_passfile(filename) @@vault = [] ok = true File.open(filename, "r") do |infile| while (line = infile.gets) begin @@vault << parse(line.chomp) rescue ParseError ok = false end end end ok end |
Instance Method Details
#eql?(c) ⇒ Boolean
56 57 58 |
# File 'lib/oraora/credentials.rb', line 56 def eql?(c) user == c.user && password == c.password && database == c.database end |
#fill_password_from_vault ⇒ Object
42 43 44 45 46 |
# File 'lib/oraora/credentials.rb', line 42 def fill_password_from_vault entry = @@vault.detect { |e| match?(e) } @password = entry.password if entry && !@password self end |
#match?(c) ⇒ Boolean
60 61 62 |
# File 'lib/oraora/credentials.rb', line 60 def match?(c) user == c.user && database == c.database end |
#to_s ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/oraora/credentials.rb', line 48 def to_s s = @user || '' s += '/' + @password if @password s = '/' if s == '' s += '@' + @database if @database s end |