<s> from kmip . core . enums import CredentialType <EOL> from kmip . core . objects import Credential <EOL> class CredentialFactory ( object ) : <EOL> def __init__ ( self ) : <EOL> pass <EOL> def _create_credential ( self , credential_type , credential_value ) : <EOL> credential_type = Credential . CredentialType ( credential_type ) <EOL> return Credential ( credential_type = credential_type , <EOL> credential_value = credential_value ) <EOL> def create_credential ( self , cred_type , value ) : <EOL> if cred_type is CredentialType . USERNAME_AND_PASSWORD : <EOL> value = self . _create_username_password_credential ( value ) <EOL> elif cred_type is CredentialType . DEVICE : <EOL> value = self . _create_device_credential ( value ) <EOL> else : <EOL> msg = '<STR_LIT>' <EOL> raise ValueError ( msg . format ( cred_type ) ) <EOL> return self . _create_credential ( cred_type , value ) <EOL> def _create_username_password_credential ( self , value ) : <EOL> username = value . get ( '<STR_LIT>' ) <EOL> password = value . get ( '<STR_LIT>' ) <EOL> username = Credential . UsernamePasswordCredential . Username ( username ) <EOL> password = Credential . UsernamePasswordCredential . Password ( password ) <EOL> return Credential . UsernamePasswordCredential ( username = username , <EOL> password = password ) <EOL> def _create_device_credential ( self , value ) : <EOL> dsn = value . get ( '<STR_LIT>' ) <EOL> password = value . get ( '<STR_LIT>' ) <EOL> dev_id = value . get ( '<STR_LIT>' ) <EOL> net_id = value . get ( '<STR_LIT>' ) <EOL> mach_id = value . get ( '<STR_LIT>' ) <EOL> med_id = value . get ( '<STR_LIT>' ) <EOL> dsn = Credential . DeviceCredential . DeviceSerialNumber ( dsn ) <EOL> password = Credential . DeviceCredential . Password ( password ) <EOL> dev_id = Credential . DeviceCredential . DeviceIdentifier ( dev_id ) <EOL> net_id = Credential . DeviceCredential . NetworkIdentifier ( net_id ) <EOL> mach_id = Credential . DeviceCredential . MachineIdentifier ( mach_id ) <EOL> med_id = Credential . DeviceCredential . MediaIdentifier ( med_id ) <EOL> return Credential . DeviceCredential ( device_serial_number = dsn , <EOL> password = password , <EOL> device_identifier = dev_id , <EOL> network_identifier = net_id , <EOL> machine_identifier = mach_id , <EOL> media_identifier = med_id ) </s>
