How to use awxkit - 10 common examples

To help you get started, we’ve selected a few awxkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ansible / awx / awxkit / awxkit / api / pages / notification_templates.py View on Github external
from . import base
from . import page


job_results = ('any', 'error', 'success')
notification_types = (
    'email',
    'irc',
    'pagerduty',
    'slack',
    'twilio',
    'webhook',
    'mattermost')


class NotificationTemplate(HasCopy, HasCreate, base.Base):

    dependencies = [Organization]

    def test(self):
        """Create test notification"""
        assert 'test' in self.related, \
            "No such related attribute 'test'"

        # trigger test notification
        notification_id = self.related.test.post().notification

        # return notification page
        notifications_pg = self.get_related(
            'notifications', id=notification_id).wait_until_count(1)
        assert notifications_pg.count == 1, \
            "test notification triggered (id:%s) but notification not found in response at %s/notifications/" % \
github ansible / awx / awxkit / awxkit / cli / resource.py View on Github external
auth.add_argument('--conf.client_id', metavar='TEXT')
        auth.add_argument('--conf.client_secret', metavar='TEXT')
        auth.add_argument(
            '--conf.scope', choices=['read', 'write'], default='write'
        )
        if client.help:
            self.print_help(parser)
            raise SystemExit()
        parsed = parser.parse_known_args()[0]
        kwargs = {
            'client_id': getattr(parsed, 'conf.client_id', None),
            'client_secret': getattr(parsed, 'conf.client_secret', None),
            'scope': getattr(parsed, 'conf.scope', None),
        }
        try:
            token = api.Api().get_oauth2_token(**kwargs)
        except Exception as e:
            self.print_help(parser)
            cprint(
                'Error retrieving an OAuth2.0 token ({}).'.format(e.__class__),
                'red'
            )
        else:
            fmt = client.get_config('format')
            if fmt == 'human':
                print('export TOWER_TOKEN={}'.format(token))
            else:
                print(to_str(FORMATTERS[fmt]({'token': token}, '.')).strip())
github ansible / awx / awxkit / awxkit / cli / client.py View on Github external
self.get_config('format') == 'human' and
                _filter == '.' and
                self.resource in UNIQUENESS_RULES
            ):
                _filter = ', '.join(UNIQUENESS_RULES[self.resource])

            formatted = format_response(
                response,
                fmt=self.get_config('format'),
                filter=_filter,
                changed=self.original_action in (
                    'modify', 'create', 'associate', 'disassociate'
                )
            )
            if formatted:
                print(utils.to_str(formatted), file=self.stdout)
        else:
            if six.PY3:
                self.parser.print_help()
            elif six.PY2 and not self.help:
                # Unfortunately, argparse behavior between py2 and py3
                # changed in a notable way when required subparsers
                # have invalid (or missing) arguments specified
                # see: https://github.com/python/cpython/commit/f97c59aaba2d93e48cbc6d25f7ff9f9c87f8d0b2
                print('\nargument resource: invalid choice')
                raise SystemExit(2)
github ansible / awx / awxkit / awxkit / api / pages / credentials.py View on Github external
def payload(self, kind='cloud', **kwargs):
        payload = PseudoNamespace(
            name=kwargs.get('name') or 'CredentialType - {}'.format(
                random_title()),
            description=kwargs.get('description') or random_title(10),
            kind=kind)
        fields = ('inputs', 'injectors')
        update_payload(payload, fields, kwargs)
        return payload
github ansible / awx / awxkit / awxkit / api / pages / notification_templates.py View on Github external
def payload(self, organization, notification_type='slack', **kwargs):
        payload = PseudoNamespace(
            name=kwargs.get('name') or 'NotificationTemplate ({0}) - {1}' .format(
                notification_type,
                random_title()),
            description=kwargs.get('description') or random_title(10),
            organization=organization.id,
            notification_type=notification_type)

        notification_configuration = kwargs.get(
            'notification_configuration', {})
        payload.notification_configuration = notification_configuration

        if payload.notification_configuration == {}:
            services = config.credentials.notification_services

            if notification_type == 'email':
                fields = (
github ansible / awx / awxkit / awxkit / scripts / basic_session.py View on Github external
def main():
    exc = None
    try:
        global akit_args
        akit_args = parse_args()
        config.base_url = akit_args.base_url

        if akit_args.credential_file != utils.not_provided:
            config.credentials = utils.load_credentials(
                akit_args.credential_file)
        else:
            config.credentials = utils.PseudoNamespace({
                'default': {
                    'username': os.getenv('AWXKIT_USER', 'admin'),
                    'password': os.getenv('AWXKIT_USER_PASSWORD', 'password')
                }
            })

        if akit_args.project_file != utils.not_provided:
            config.project_urls = utils.load_projects(
                akit_args.project_file)

        global root
        root = api.Api()
        if uses_sessions(root.connection):
            config.use_sessions = True
            root.load_session().get()
        else:
github ansible / awx / awxkit / awxkit / api / pages / users.py View on Github external
def payload(self, **kwargs):
        payload = PseudoNamespace(
            username=kwargs.get('username') or 'User-{}'.format(
                random_title(
                    non_ascii=False)),
            password=kwargs.get('password') or config.credentials.default.password,
            is_superuser=kwargs.get(
                'is_superuser',
                False),
            is_system_auditor=kwargs.get(
                'is_system_auditor',
                False),
            first_name=kwargs.get(
                'first_name',
                random_title()),
            last_name=kwargs.get(
                'last_name',
                random_title()),
github ansible / awx / awxkit / awxkit / api / pages / job_templates.py View on Github external
def payload(self, job_type='run', playbook='ping.yml', **kwargs):
        name = kwargs.get('name') or 'JobTemplate - {}'.format(random_title())
        description = kwargs.get('description') or random_title(10)
        payload = PseudoNamespace(
            name=name,
            description=description,
            job_type=job_type)

        optional_fields = (
            'ask_scm_branch_on_launch',
            'ask_credential_on_launch',
            'ask_diff_mode_on_launch',
            'ask_inventory_on_launch',
            'ask_job_type_on_launch',
            'ask_limit_on_launch',
            'ask_skip_tags_on_launch',
            'ask_tags_on_launch',
            'ask_variables_on_launch',
            'ask_verbosity_on_launch',
            'allow_simultaneous',
github ansible / awx / awxkit / awxkit / api / pages / credentials.py View on Github external
def payload(
            self,
            credential_type,
            user=None,
            team=None,
            organization=None,
            inputs=None,
            **kwargs):
        if not any((user, team, organization)):
            raise TypeError(
                '{0.__class__.__name__} requires user, team, and/or organization instances.'.format(self))

        if inputs is None:
            inputs = {}

        payload = PseudoNamespace(
            name=kwargs.get('name') or 'Credential - {}'.format(
                random_title()),
            description=kwargs.get('description') or random_title(10),
            credential_type=credential_type.id,
            inputs=inputs)
        if user:
            payload.user = user.id
        if team:
            payload.team = team.id
        if organization:
            payload.organization = organization.id

        kind, config_cred = kind_and_config_cred_from_credential_type(
            credential_type)

        for field in credential_input_fields:
github ansible / awx / awxkit / awxkit / api / pages / credentials.py View on Github external
return kind, PseudoNamespace()
    try:
        if credential_type.kind == 'net':
            config_cred = config.credentials.network
            kind = 'net'
        elif credential_type.kind == 'cloud':
            kind = credential_type_name_to_config_kind_map[credential_type.name.lower(
            )]
            config_kind = kind if kind != 'azure_rm' else 'azure'
            config_cred = config.credentials.cloud[config_kind]
        else:
            kind = credential_type.kind.lower()
            config_cred = config.credentials[kind]
        return kind, config_cred
    except (KeyError, AttributeError):
        return kind, PseudoNamespace()