예제 #1
0
 def clean_credential(self):
     if not self.scm_type:
         return None
     cred = self.credential
     if not cred and self.scm_type == 'insights':
         raise ValidationError(_("Insights Credential is required for an Insights Project."))
     elif cred:
         if self.scm_type == 'insights':
             if cred.kind != 'insights':
                 raise ValidationError(_("Credential kind must be 'insights'."))
         elif cred.kind != 'scm':
             raise ValidationError(_("Credential kind must be 'scm'."))
         try:
             if self.scm_type == 'insights':
                 self.scm_url = settings.INSIGHTS_URL_BASE
             scm_url = update_scm_url(self.scm_type, self.scm_url, check_special_cases=False)
             scm_url_parts = urlparse.urlsplit(scm_url)
             # Prefer the username/password in the URL, if provided.
             scm_username = scm_url_parts.username or cred.get_input('username', default='')
             if scm_url_parts.password or cred.has_input('password'):
                 scm_password = '******'
             else:
                 scm_password = ''
             try:
                 update_scm_url(self.scm_type, self.scm_url, scm_username, scm_password)
             except ValueError as e:
                 raise ValidationError((e.args or (_('Invalid credential.'),))[0])
         except ValueError:
             pass
     return cred
예제 #2
0
 def clean_scm_url(self):
     if self.scm_type == 'insights':
         self.scm_url = settings.INSIGHTS_URL_BASE
     scm_url = str(self.scm_url or '')
     if not self.scm_type:
         return ''
     try:
         scm_url = update_scm_url(self.scm_type, scm_url, check_special_cases=False)
     except ValueError as e:
         raise ValidationError((e.args or (_('Invalid SCM URL.'),))[0])
     scm_url_parts = urlparse.urlsplit(scm_url)
     if self.scm_type and not any(scm_url_parts):
         raise ValidationError(_('SCM URL is required.'))
     return str(self.scm_url or '')