#NEWLINE# def validate( self ) : #NEWLINE# #INDENT# def is_alphanumeric( value ) : #NEWLINE# #INDENT# if ( value is None ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# return ( re . compile ( '^[a-zA-Z0-9\\.\\-]+$' ) . match ( value ) is not None ) #NEWLINE# #UNINDENT# def is_valid_username( value ) : #NEWLINE# #INDENT# if ( value is None ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# return ( re . compile ( '^[a-zA-Z0-9\\.\\-\\@]+$' ) . match ( value ) is not None ) #NEWLINE# #UNINDENT# def is_valid_path( value ) : #NEWLINE# #INDENT# if ( value is None ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# return ( re . compile ( '^/(([a-zA-Z0-9\\.\\-_]+)/?)*?$' ) . match ( value ) is not None ) #NEWLINE# #UNINDENT# errors = [ ] #NEWLINE# if ( not is_alphanumeric ( self . id ) ) : #NEWLINE# #INDENT# errors . append ( ( 'id' , 'IDs can only contain letters, digits, dot and dash.' ) ) #NEWLINE# #UNINDENT# if ( not is_alphanumeric ( self . host ) ) : #NEWLINE# #INDENT# errors . append ( ( 'host' , 'Hosts can only contain letters, digits, dot and dash.' ) ) #NEWLINE# #UNINDENT# if ( not is_valid_path ( self . mount_point ) ) : #NEWLINE# #INDENT# errors . append ( ( 'mount_point' , 'Invalid remote mount point.' ) ) #NEWLINE# #UNINDENT# if ( msg . auth_method not in ( self . AUTH_METHOD_PUBLIC_KEY , self . AUTH_METHOD_PASSWORD ) ) : #NEWLINE# #INDENT# errors . append ( ( 'auth_method' , 'Unknown auth type.' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . auth_method == self . AUTH_METHOD_PUBLIC_KEY ) : #NEWLINE# #INDENT# if ( not os . path . exists ( self . ssh_key ) ) : #NEWLINE# #INDENT# errors . append ( ( 'ssh_key' , 'Invalid ssh key path.' ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not is_valid_username ( self . user ) ) : #NEWLINE# #INDENT# errors . append ( ( 'user' , 'Usernames can only contain letters, at signs and digits.' ) ) #NEWLINE# #UNINDENT# if ( not ( self . PORT_RANGE_MIN < self . port <= self . PORT_RANGE_MAX ) ) : #NEWLINE# #INDENT# msg = ( 'Ports need to be numbers between %d and %d.' % ( self . PORT_RANGE_MIN , self . PORT_RANGE_MAX ) ) #NEWLINE# errors . append ( ( 'port' , msg ) ) #NEWLINE# #UNINDENT# if ( not isinstance ( self . mount_opts , list ) ) : #NEWLINE# #INDENT# errors . append ( ( 'mount_opts' , 'Bad options received.' ) ) #NEWLINE# #UNINDENT# if ( ( not isinstance ( self . cmd_before_mount , str ) ) or ( self . cmd_before_mount == '' ) ) : #NEWLINE# #INDENT# errors . append ( ( 'cmd_before_mount' , 'Invalid before mount command.' ) ) #NEWLINE# #UNINDENT# return ( ( len ( errors ) == 0 ) , errors )