class DopCommon::Credential
Constants
- VALID_TYPES
Attributes
hash[R]
name[R]
Public Class Methods
new(name, hash)
click to toggle source
# File lib/dop_common/credential.rb, line 14 def initialize(name, hash) @name = name @hash = deep_symbolize_keys(hash) DopCommon.add_log_filter(Proc.new {|msg| filter_secrets(msg)}) end
Public Instance Methods
filter_secrets(msg)
click to toggle source
This method filters the secrets from a message
# File lib/dop_common/credential.rb, line 25 def filter_secrets(msg) case type when :username_password then msg.gsub(password, '****') else msg end end
keytab()
click to toggle source
# File lib/dop_common/credential.rb, line 52 def keytab @keytab ||= keytab_valid? ? load_content(@hash[:keytab]) : nil end
password()
click to toggle source
# File lib/dop_common/credential.rb, line 40 def password @password ||= password_valid? ? load_content(@hash[:password]) : nil end
private_key()
click to toggle source
# File lib/dop_common/credential.rb, line 56 def private_key @private_key ||= private_key_valid? ? load_content(@hash[:private_key]) : nil end
public_key()
click to toggle source
# File lib/dop_common/credential.rb, line 60 def public_key @public_key ||= public_key_valid? ? load_content(@hash[:public_key]) : nil end
realm()
click to toggle source
# File lib/dop_common/credential.rb, line 44 def realm @realm ||= realm_valid? ? @hash[:realm] : nil end
service()
click to toggle source
# File lib/dop_common/credential.rb, line 48 def service @service ||= service_valid? ? @hash[:service] : nil end
type()
click to toggle source
# File lib/dop_common/credential.rb, line 32 def type @type ||= type_valid? ? @hash[:type].to_sym : nil end
username()
click to toggle source
# File lib/dop_common/credential.rb, line 36 def username @username ||= username_valid? ? @hash[:username] : nil end
validate()
click to toggle source
# File lib/dop_common/credential.rb, line 20 def validate log_validation_method('type_valid?') end
Private Instance Methods
credential_load_content_valid?(key)
click to toggle source
# File lib/dop_common/credential.rb, line 130 def credential_load_content_valid?(key) return false if @hash[key].nil? load_content_valid?(@hash[key]) rescue PlanParsingError => e raise PlanParsingError, "Error while parsing the value for #{key} in credential #{@name}: #{e.message}" end
kerberos_valid?()
click to toggle source
# File lib/dop_common/credential.rb, line 89 def kerberos_valid? realm_valid? or raise PlanParsingError, "A realm is missing in the credential #{@name} which is of type #{@hash[:type]}" service_valid? keytab_valid? true end
keytab_valid?()
click to toggle source
# File lib/dop_common/credential.rb, line 118 def keytab_valid? credential_load_content_valid?(:keytab) end
password_valid?()
click to toggle source
# File lib/dop_common/credential.rb, line 114 def password_valid? credential_load_content_valid?(:password) end
private_key_valid?()
click to toggle source
# File lib/dop_common/credential.rb, line 122 def private_key_valid? credential_load_content_valid?(:private_key) end
public_key_valid?()
click to toggle source
# File lib/dop_common/credential.rb, line 126 def public_key_valid? credential_load_content_valid?(:public_key) end
realm_valid?()
click to toggle source
# File lib/dop_common/credential.rb, line 137 def realm_valid? return false if @hash[:realm].nil? @hash[:realm].kind_of?(String) or raise PlanParsingError, "The realm has to be a string in the credential #{@name} which is of type #{@hash[:type]}" true end
service_valid?()
click to toggle source
# File lib/dop_common/credential.rb, line 144 def service_valid? return false if @hash[:service].nil? @hash[:service].kind_of?(String) or raise PlanParsingError, "The service has to be a string in the credential #{@name} which is of type #{@hash[:type]}" true end
ssh_key_valid?()
click to toggle source
# File lib/dop_common/credential.rb, line 97 def ssh_key_valid? username_valid? or raise PlanParsingError, "A username is missing in the credential #{@name} which is of type #{@hash[:type]}" private_key_valid? public_key_valid? true end
type_valid?()
click to toggle source
# File lib/dop_common/credential.rb, line 66 def type_valid? @hash[:type] or raise PlanParsingError, "You need to specify the 'type' of the credental in #{@name} which can be one of #{VALID_TYPES.join(', ')}" case @hash[:type] when :username_password, 'username_password' then username_password_valid? when :kerberos, 'kerberos' then kerberos_valid? when :ssh_key, 'ssh_key' then ssh_key_valid? else raise PlanParsingError, "The 'type' of the credental in #{@name} has to be one of #{VALID_TYPES.join(', ')}" end true end
username_password_valid?()
click to toggle source
This are the type validation methods, they will check if all the mandatory elements are there and if every supported attribute is valid.
# File lib/dop_common/credential.rb, line 81 def username_password_valid? username_valid? or raise PlanParsingError, "A username is missing in the credential #{@name} which is of type #{@hash[:type]}" password_valid? or raise PlanParsingError, "A password is missing in the credential #{@name} which is of type #{@hash[:type]}" true end
username_valid?()
click to toggle source
Attribute verification, will return false if the attribute is not valid, otherwise raise a PlanParsingError
# File lib/dop_common/credential.rb, line 107 def username_valid? return false if @hash[:username].nil? @hash[:username].kind_of?(String) or @hash[:username].kind_of?(Fixnum) or raise PlanParsingError, "The username has to be a string or number in the credential #{@name} which is of type #{@hash[:type]}" true end