示例#1
0
def list_commands_app_fields_impact(app_id=None):
    """
    Returns a mapping of the available commands and which App's fields are used:

    >>> from tests.helpers import create_test_app_context; create_test_app_context()
    >>> import json
    >>> config['enable_executescript_command'] = 'true'
    >>> config['blue_green'] = {'enabled': True}

    >>> sorted(json.loads(list_commands_app_fields_impact().data))
    [[u'buildimage', [u'features', u'build_infos']], [u'createinstance', [u'environment_infos']], [u'deploy', [u'modules']], [u'destroyallinstances', []], [u'executescript', []], [u'preparebluegreen', [u'blue_green']], [u'purgebluegreen', [u'blue_green']], [u'recreateinstances', [u'features', u'environment_infos']], [u'redeploy', []], [u'swapbluegreen', [u'blue_green']], [u'updateautoscaling', [u'autoscale', u'environment_infos']], [u'updatelifecyclehooks', [u'lifecycle_hooks']]]

    >>> config['enable_executescript_command'] = 'false'
    >>> sorted(json.loads(list_commands_app_fields_impact().data))
    [[u'buildimage', [u'features', u'build_infos']], [u'createinstance', [u'environment_infos']], [u'deploy', [u'modules']], [u'destroyallinstances', []], [u'preparebluegreen', [u'blue_green']], [u'purgebluegreen', [u'blue_green']], [u'recreateinstances', [u'features', u'environment_infos']], [u'redeploy', []], [u'swapbluegreen', [u'blue_green']], [u'updateautoscaling', [u'autoscale', u'environment_infos']], [u'updatelifecyclehooks', [u'lifecycle_hooks']]]
    """
    app_context = get_app(app_id)
    return jsonify([(name, app_fields) for (name, description, app_fields) in _get_commands(app_context)])
示例#2
0
def list_commands(app_id=None):
    """
    Returns a mapping of the available commands and their descriptions:

    >>> from tests.helpers import create_test_app_context; create_test_app_context()
    >>> import json
    >>> config['enable_executescript_command'] = 'true'
    >>> config['blue_green'] = {'enabled': True}

    >>> sorted(json.loads(list_commands().data))
    [[u'buildimage', u'Build Image'], [u'createinstance', u'Create a new instance'], [u'deploy', u'Deploy module(s)'], [u'destroyallinstances', u'Destroy all instances'], [u'executescript', u'Execute a script/commands on every instance'], [u'preparebluegreen', u'Prepare the Blue/Green env before swap'], [u'purgebluegreen', u'Purge the Blue/Green env'], [u'recreateinstances', u'Recreate all the instances, rolling update possible when using an Autoscale'], [u'redeploy', u'Re-deploy an old module package'], [u'swapbluegreen', u'Swap the Blue/Green env'], [u'updateautoscaling', u'Update the autoscaling group and its LaunchConfiguration'], [u'updatelifecyclehooks', u'Update LifeCycle Hooks scripts']]

    >>> config['enable_executescript_command'] = 'false'
    >>> sorted(json.loads(list_commands().data))
    [[u'buildimage', u'Build Image'], [u'createinstance', u'Create a new instance'], [u'deploy', u'Deploy module(s)'], [u'destroyallinstances', u'Destroy all instances'], [u'preparebluegreen', u'Prepare the Blue/Green env before swap'], [u'purgebluegreen', u'Purge the Blue/Green env'], [u'recreateinstances', u'Recreate all the instances, rolling update possible when using an Autoscale'], [u'redeploy', u'Re-deploy an old module package'], [u'swapbluegreen', u'Swap the Blue/Green env'], [u'updateautoscaling', u'Update the autoscaling group and its LaunchConfiguration'], [u'updatelifecyclehooks', u'Update LifeCycle Hooks scripts']]
    """
    app_context = get_app(app_id)
    return jsonify([(name, description) for (name, description, app_fields) in _get_commands(app_context)])
示例#3
0
    def execute(self, job_id):
        with Connection(Redis(host=REDIS_HOST)):
            self._worker_job = get_current_job()
        # used in worker sub classes, TODO: to cleanup
        self._db = get_fresh_connection()
        self.job = get_job(job_id)
        self.app = get_app(self.job['app_id'])
        self._init_log_file()
        update_job(self.job['_id'], {
            'log_id': self._worker_job.id,
            'started_at': datetime.utcnow(),
        })
        klass_name = self.job['command'].title()
        mod = __import__('commands.' + self.job['command'],
                         fromlist=[klass_name, 'RELATED_APP_FIELDS'])
        command = getattr(mod, klass_name)(self)

        # Execute command and always mark the job as 'failed' in case of an unexpected exception
        try:
            if self.job['status'] == 'init':
                self.update_status("started", "Job processing started")
                command.execute()
                if self.job['status'] == 'done':
                    self._update_app_pending_changes(mod.RELATED_APP_FIELDS)
            else:
                self.update_status(
                    "aborted",
                    "Job was already in '{}' status (not in 'init' status)".
                    format(self.job['status']))
        except:
            message = sys.exc_info()[0]
            log(message, self.log_file)
            traceback.print_exc(file=self.log_file)
            self.update_status("failed", str(message))
            raise
        finally:
            subject, body, slack_msg = format_notif(self.app, self.job)
            self._slack_notification_action(slack_msg)
            self._close_log_file()
            self._mail_log_action(subject, body)
            self._push_log_to_s3()
示例#4
0
    def validate_request(self, conf):
        """
        Check the webhook's request matches webhook's Cloud Deploy configuration.
        """
        # Get app data, useful for some checks
        app = get_app(conf.get('app_id'))

        # Check secret is valid if there's one
        if not self.validate_secret(conf.get('secret_token', None)):
            return False, 'invalid secret'

        # Check event is valid
        if not self.validate_event(conf.get('events', None)):
            return False, 'invalid event'

        # Check rev is valid
        if not self.validate_revision(conf.get('rev', None)):
            return False, 'invalid revision'

        # Check repo url is valid
        if not self.validate_repo_url(app, conf.get('module', None)):
            return False, 'invalid repo url'

        return True, ''