示例#1
0
 def _get_settings_data(self, setting_type):
     setting_types = ['all',
                      'authentication',
                      'azuread-oauth2',
                      'changed', 'github',
                      'github-org',
                      'github-team',
                      'google-oauth2',
                      'jobs',
                      'ldap',
                      'logging',
                      'named-url',
                      'radius',
                      'saml',
                      'system',
                      'tacacsplus',
                      'ui']
     if not setting_type.lower() in setting_types:
         raise InvalidValue(('{value} is invalid. The following setting types are allowed:'
                             '{setting_types}').format(value=setting_type, setting_types=setting_types))
     url = '{api}/settings/{type_}/'.format(api=self._tower.api, type_=setting_type)
     response = self._tower.session.get(url)
     if not response.ok:
         LOGGER.error('Error getting setting type "%s", response was: "%s"', setting_type, response.text)
     return response.json() if response.ok else {}
示例#2
0
 def name(self, value):
     """Update the name of the template."""
     max_characters = 512
     conditions = [validate_max_length(value, max_characters)]
     if all(conditions):
         self._update_values('name', value)
     else:
         raise InvalidValue(
             f'{value} is invalid. Condition max_characters must be less than or equal to '
             f'{max_characters}')
示例#3
0
    def injectors(self, value):
        """Update the injectors of the credential type.

        Returns:
            None:

        """
        if isinstance(value, dict):
            self._update_values('injectors', value)
        else:
            raise InvalidValue('Value is not valid dictionary received: {value}'.format(value=value))
示例#4
0
    def variables(self, value):
        """Update the variables of the team.

        Returns:
            None:

        """
        if validate_json(value):
            self._update_values('variables', value)
        else:
            raise InvalidValue(f'Value is not valid json received: {value}')
示例#5
0
    def inputs(self, value):
        """Update the inputs of the credential.

        Returns:
            None:

        """
        if isinstance(value, dict):
            self._update_values('inputs', value)
        else:
            raise InvalidValue(f'Value is not valid json received: {value}')
示例#6
0
    def variables(self, value):
        """Update the variables on the host.

        Returns:
            None:

        """
        conditions = [validate_json(value)]
        if all(conditions):
            self._update_values('variables', value)
        else:
            raise InvalidValue(f'{value} is not valid json.')
示例#7
0
文件: group.py 项目: ttavi21/towerlib
    def variables(self, value):
        """Update the variables of the group.

        Returns:
            None:

        """
        conditions = [validate_json(value)]
        if all(conditions):
            self._update_values('variables', value)
        else:
            raise InvalidValue(
                '{value} is not valid json.'.format(value=value))
示例#8
0
    def last_name(self, value):
        """Update the last name of the user.

        Returns:
            None:

        """
        max_characters = 30
        conditions = [validate_max_length(value, max_characters)]
        if all(conditions):
            self._update_values('last_name', value)
        else:
            raise InvalidValue(value)
示例#9
0
    def name(self, value):
        """Update the name of the credential type.

        Returns:
            None:

        """
        max_characters = 512
        conditions = [validate_max_length(value, max_characters)]
        if all(conditions):
            self._update_values('name', value)
        else:
            raise InvalidValue('{value} is invalid. Condition max_characters must be less or equal '
                               '{max_characters}'.format(value=value, max_characters=max_characters))
示例#10
0
    def instance_id(self, value):
        """Update the instance_id of the host.

        Returns:
            None:

        """
        max_characters = 1024
        conditions = [validate_max_length(value, max_characters)]
        if all(conditions):
            self._update_values('instance_id', value)
        else:
            raise InvalidValue('{value} is invalid. Condition max_characters must be less than or equal to '
                               '{max_characters}'.format(value=value, max_characters=max_characters))
示例#11
0
    def custom_virtualenv(self, value):
        """Update the custom_virtualenv of the group.

        Returns:
            None:

        """
        max_characters = 100
        conditions = [validate_max_length(value, max_characters)]
        if all(conditions):
            self._update_values('custom_virtualenv', value)
        else:
            raise InvalidValue(f'{value} is invalid. Condition max_characters must be less than or equal to '
                               f'{max_characters}')
示例#12
0
    def scm_branch(self, value):
        """Update the scm_branch project.

        Returns:
            None:

        """
        max_characters = 256
        conditions = [validate_max_length(value, max_characters)]
        if all(conditions):
            self._update_values('scm_branch', value)
        else:
            raise InvalidValue('{value} is invalid. Condition max_characters must be less than or equal to '
                               '{max_characters}'.format(value=value, max_characters=max_characters))
示例#13
0
    def script(self, value):
        """Update the script of the inventory script.

        Returns:
            None:

        """
        pattern = '(#!/(usr|bin)/(sh|bash|bin)(/)?(make|env)?)'
        conditions = re.match(pattern, value)
        if conditions:
            self._update_values('script', value)
        else:
            raise InvalidValue(
                'Script content is invalid, it should start with a shebang.')
示例#14
0
    def name(self, value):
        """Update the name of the inventory script.

        Returns:
            None:

        """
        max_characters = 512
        conditions = [validate_max_length(value, max_characters)]
        if all(conditions):
            self._update_values('name', value)
        else:
            raise InvalidValue(
                f'{value} is invalid. Condition max_characters must be less or equal to '
                f'{max_characters}')
示例#15
0
    def first_name(self, value):
        """Update the first name of the user.

        Returns:
            None:

        """
        max_characters = 30
        conditions = [validate_max_length(value, max_characters)]
        if all(conditions):
            self._update_values('first_name', value)
        else:
            raise InvalidValue(
                f'{value} is invalid. Condition max_characters must be less or equal to '
                f'{max_characters}')
示例#16
0
    def scm_update_cache_timeout(self, value):
        """Update the scm_update_cache_timeout of the project.

        Returns:
            None:

        """
        minimum = 0
        maximum = 2147483647
        conditions = [validate_range(value, minimum, maximum)]
        if all(conditions):
            self._update_values('scm_update_cache_timeout', value)
        else:
            raise InvalidValue(
                f'{value} is invalid, must be between {minimum} and {maximum}')
示例#17
0
    def scm_url(self, value):
        """Update the scm_url project.

        Returns:
            None:

        """
        max_characters = 1024
        conditions = [validate_max_length(value, max_characters)]
        if all(conditions):
            self._update_values('scm_url', value)
        else:
            raise InvalidValue(
                f'{value} is invalid. Condition max_characters must be less than or equal to '
                f'{max_characters}')
示例#18
0
    def email(self, value):
        """Update the email address of the user.

        Returns:
            None:

        """
        max_characters = 254
        conditions = [validate_max_length(value, max_characters)]
        if all(conditions):
            self._update_values('email', value)
        else:
            raise InvalidValue(
                f'{value} is invalid. Condition max_characters must be less or equal to '
                f'{max_characters}')
示例#19
0
    def timeout(self, value):
        """Update the timeout of the project.

        Returns:
            None:

        """
        minimum = -2147483648
        maximum = 2147483647
        conditions = [validate_range(value, minimum, maximum)]
        if all(conditions):
            self._update_values('timeout', value)
        else:
            raise InvalidValue('{value} is invalid, must be between {minimum} and {maximum}'.format(value=value,
                                                                                                    minimum=minimum,
                                                                                                    maximum=maximum))
示例#20
0
    def username(self, value):
        """Update the username of the user.

        Returns:
            None:

        """
        max_characters = 150
        valid_metacharacters = '@.+-_'
        conditions = [
            validate_max_length(value, max_characters),
            validate_characters(value, extra_chars=valid_metacharacters)
        ]
        if all(conditions):
            self._update_values('username', value)
        else:
            raise InvalidValue(
                f'{value} is invalid. Condition max_characters must be less or equal to '
                f'{max_characters} and valid character are only alphanums and {valid_metacharacters}'
            )