Class: CredHubble::Resources::CredentialFactory

Inherits:
RestResource
  • Object
show all
Defined in:
lib/cred_hubble/resources/credential_factory.rb

Class Method Summary collapse

Methods inherited from RestResource

#to_json

Class Method Details

.credential_from_data(credential_data) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cred_hubble/resources/credential_factory.rb', line 19

def self.credential_from_data(credential_data)
  case credential_data['type']
  when Credential::VALUE_TYPE
    ValueCredential.new(credential_data)
  when Credential::JSON_TYPE
    JsonCredential.new(credential_data)
  when Credential::PASSWORD_TYPE
    PasswordCredential.new(credential_data)
  when Credential::USER_TYPE
    UserCredential.new(credential_data)
  when Credential::CERTIFICATE_TYPE
    CertificateCredential.new(credential_data)
  when Credential::RSA_TYPE
    RsaCredential.new(credential_data)
  when Credential::SSH_TYPE
    SshCredential.new(credential_data)
  else
    Credential.new(credential_data)
  end
end

.from_json(raw_json) ⇒ Object



14
15
16
17
# File 'lib/cred_hubble/resources/credential_factory.rb', line 14

def self.from_json(raw_json)
  parsed_json = parse_json(raw_json)
  credential_from_data(parsed_json)
end