mirror of
https://github.com/ansible/awx.git
synced 2026-03-02 17:28:51 -03:30
Make error message grammar more consistent
This commit is contained in:
@@ -329,12 +329,12 @@ class Credential(PasswordFieldsModel, CommonModelNameNotUnique, ResourceMixin):
|
||||
def clean_ssh_key_unlock(self):
|
||||
if self.has_encrypted_ssh_key_data and not self.ssh_key_unlock:
|
||||
raise ValidationError('SSH key unlock must be set when SSH key '
|
||||
'is encrypted')
|
||||
'is encrypted.')
|
||||
return self.ssh_key_unlock
|
||||
|
||||
def clean(self):
|
||||
if self.deprecated_user and self.deprecated_team:
|
||||
raise ValidationError('Credential cannot be assigned to both a user and team')
|
||||
raise ValidationError('Credential cannot be assigned to both a user and team.')
|
||||
|
||||
def _password_field_allows_ask(self, field):
|
||||
return bool(self.kind == 'ssh' and field != 'ssh_key_data')
|
||||
@@ -394,7 +394,7 @@ def validate_ssh_private_key(data):
|
||||
'cert_bin': '', # Cert data as binary.
|
||||
}
|
||||
data = data.strip()
|
||||
validation_error = ValidationError('Invalid private key')
|
||||
validation_error = ValidationError('Invalid private key.')
|
||||
|
||||
# Sanity check: We may potentially receive a full PEM certificate,
|
||||
# and we want to accept these.
|
||||
|
||||
@@ -994,7 +994,7 @@ class InventorySourceOptions(BaseModel):
|
||||
# an EC2 instance with an IAM Role assigned, boto will use credentials
|
||||
# from the instance metadata instead of those explicitly provided.
|
||||
elif self.source in CLOUD_PROVIDERS and self.source != 'ec2':
|
||||
raise ValidationError('Credential is required for a cloud source')
|
||||
raise ValidationError('Credential is required for a cloud source.')
|
||||
return cred
|
||||
|
||||
def clean_source_regions(self):
|
||||
|
||||
@@ -244,11 +244,11 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, ResourceMixin):
|
||||
|
||||
def clean(self):
|
||||
if self.job_type == 'scan' and (self.inventory is None or self.ask_inventory_on_launch):
|
||||
raise ValidationError('Scan jobs must be assigned a fixed inventory')
|
||||
raise ValidationError({"inventory": ["Scan jobs must be assigned a fixed inventory.",]})
|
||||
if (not self.ask_inventory_on_launch) and self.inventory is None:
|
||||
raise ValidationError('Job Template must either have an inventory or allow prompting for inventory')
|
||||
raise ValidationError({"inventory": ["Job Template must provide 'inventory' or allow prompting for it.",]})
|
||||
if (not self.ask_credential_on_launch) and self.credential is None:
|
||||
raise ValidationError('Job Template must either have a credential or allow prompting for credential')
|
||||
raise ValidationError({"credential": ["Job Template must provide 'credential' or allow prompting for it.",]})
|
||||
return super(JobTemplate, self).clean()
|
||||
|
||||
def create_job(self, **kwargs):
|
||||
@@ -292,9 +292,9 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, ResourceMixin):
|
||||
if not self.survey_enabled:
|
||||
return errors
|
||||
if 'name' not in self.survey_spec:
|
||||
errors.append("'name' missing from survey spec")
|
||||
errors.append("'name' missing from survey spec.")
|
||||
if 'description' not in self.survey_spec:
|
||||
errors.append("'description' missing from survey spec")
|
||||
errors.append("'description' missing from survey spec.")
|
||||
for survey_element in self.survey_spec.get("spec", []):
|
||||
if survey_element['variable'] not in data and \
|
||||
survey_element['required']:
|
||||
@@ -302,50 +302,50 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, ResourceMixin):
|
||||
elif survey_element['type'] in ["textarea", "text", "password"]:
|
||||
if survey_element['variable'] in data:
|
||||
if 'min' in survey_element and survey_element['min'] not in ["", None] and len(data[survey_element['variable']]) < survey_element['min']:
|
||||
errors.append("'%s' value %s is too small (must be at least %s)" %
|
||||
errors.append("'%s' value %s is too small (must be at least %s)." %
|
||||
(survey_element['variable'], data[survey_element['variable']], survey_element['min']))
|
||||
if 'max' in survey_element and survey_element['max'] not in ["", None] and len(data[survey_element['variable']]) > survey_element['max']:
|
||||
errors.append("'%s' value %s is too large (must be no more than %s)" %
|
||||
errors.append("'%s' value %s is too large (must be no more than %s)." %
|
||||
(survey_element['variable'], data[survey_element['variable']], survey_element['max']))
|
||||
elif survey_element['type'] == 'integer':
|
||||
if survey_element['variable'] in data:
|
||||
if 'min' in survey_element and survey_element['min'] not in ["", None] and survey_element['variable'] in data and \
|
||||
data[survey_element['variable']] < survey_element['min']:
|
||||
errors.append("'%s' value %s is too small (must be at least %s)" %
|
||||
errors.append("'%s' value %s is too small (must be at least %s)." %
|
||||
(survey_element['variable'], data[survey_element['variable']], survey_element['min']))
|
||||
if 'max' in survey_element and survey_element['max'] not in ["", None] and survey_element['variable'] in data and \
|
||||
data[survey_element['variable']] > survey_element['max']:
|
||||
errors.append("'%s' value %s is too large (must be no more than %s)" %
|
||||
errors.append("'%s' value %s is too large (must be no more than %s)." %
|
||||
(survey_element['variable'], data[survey_element['variable']], survey_element['max']))
|
||||
if type(data[survey_element['variable']]) != int:
|
||||
errors.append("Value %s for %s expected to be an integer" % (data[survey_element['variable']],
|
||||
survey_element['variable']))
|
||||
errors.append("Value %s for '%s' expected to be an integer." % (data[survey_element['variable']],
|
||||
survey_element['variable']))
|
||||
elif survey_element['type'] == 'float':
|
||||
if survey_element['variable'] in data:
|
||||
if 'min' in survey_element and survey_element['min'] not in ["", None] and data[survey_element['variable']] < survey_element['min']:
|
||||
errors.append("'%s' value %s is too small (must be at least %s)" %
|
||||
errors.append("'%s' value %s is too small (must be at least %s)." %
|
||||
(survey_element['variable'], data[survey_element['variable']], survey_element['min']))
|
||||
if 'max' in survey_element and survey_element['max'] not in ["", None] and data[survey_element['variable']] > survey_element['max']:
|
||||
errors.append("'%s' value %s is too large (must be no more than %s)" %
|
||||
errors.append("'%s' value %s is too large (must be no more than %s)." %
|
||||
(survey_element['variable'], data[survey_element['variable']], survey_element['max']))
|
||||
if type(data[survey_element['variable']]) not in (float, int):
|
||||
errors.append("Value %s for %s expected to be a numeric type" % (data[survey_element['variable']],
|
||||
survey_element['variable']))
|
||||
errors.append("Value %s for '%s' expected to be a numeric type." % (data[survey_element['variable']],
|
||||
survey_element['variable']))
|
||||
elif survey_element['type'] == 'multiselect':
|
||||
if survey_element['variable'] in data:
|
||||
if type(data[survey_element['variable']]) != list:
|
||||
errors.append("'%s' value is expected to be a list" % survey_element['variable'])
|
||||
errors.append("'%s' value is expected to be a list." % survey_element['variable'])
|
||||
else:
|
||||
for val in data[survey_element['variable']]:
|
||||
if val not in survey_element['choices']:
|
||||
errors.append("Value %s for %s expected to be one of %s" % (val, survey_element['variable'],
|
||||
survey_element['choices']))
|
||||
errors.append("Value %s for '%s' expected to be one of %s." % (val, survey_element['variable'],
|
||||
survey_element['choices']))
|
||||
elif survey_element['type'] == 'multiplechoice':
|
||||
if survey_element['variable'] in data:
|
||||
if data[survey_element['variable']] not in survey_element['choices']:
|
||||
errors.append("Value %s for %s expected to be one of %s" % (data[survey_element['variable']],
|
||||
survey_element['variable'],
|
||||
survey_element['choices']))
|
||||
errors.append("Value %s for '%s' expected to be one of %s." % (data[survey_element['variable']],
|
||||
survey_element['variable'],
|
||||
survey_element['choices']))
|
||||
return errors
|
||||
|
||||
def _update_unified_job_kwargs(self, **kwargs):
|
||||
|
||||
@@ -116,10 +116,10 @@ class ProjectOptions(models.Model):
|
||||
scm_url = update_scm_url(self.scm_type, scm_url,
|
||||
check_special_cases=False)
|
||||
except ValueError, e:
|
||||
raise ValidationError((e.args or ('Invalid SCM URL',))[0])
|
||||
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')
|
||||
raise ValidationError('SCM URL is required.')
|
||||
return unicode(self.scm_url or '')
|
||||
|
||||
def clean_credential(self):
|
||||
@@ -128,7 +128,7 @@ class ProjectOptions(models.Model):
|
||||
cred = self.credential
|
||||
if cred:
|
||||
if cred.kind != 'scm':
|
||||
raise ValidationError('Credential kind must be "scm"')
|
||||
raise ValidationError("Credential kind must be 'scm'.")
|
||||
try:
|
||||
scm_url = update_scm_url(self.scm_type, self.scm_url,
|
||||
check_special_cases=False)
|
||||
@@ -143,7 +143,7 @@ class ProjectOptions(models.Model):
|
||||
update_scm_url(self.scm_type, self.scm_url, scm_username,
|
||||
scm_password)
|
||||
except ValueError, e:
|
||||
raise ValidationError((e.args or ('Invalid credential',))[0])
|
||||
raise ValidationError((e.args or ('Invalid credential.',))[0])
|
||||
except ValueError:
|
||||
pass
|
||||
return cred
|
||||
|
||||
Reference in New Issue
Block a user