Beispiel #1
0
    def create_repo(self, **kwargs):
        kwargs.setdefault('url', PROJECT_ROOT)
        kwargs.setdefault('vcs', 'git')

        repo = Repository(**kwargs)
        db.session.add(repo)
        db.session.commit()

        return repo
Beispiel #2
0
    def create_repo(self, **kwargs):
        kwargs.setdefault("url", PROJECT_ROOT)
        kwargs.setdefault("vcs", "git")

        repo = Repository(**kwargs)
        db.session.add(repo)
        db.session.commit()

        return repo
Beispiel #3
0
    def post(self):
        """
        Create a new app.
        """
        args = self.post_parser.parse_args()

        provider_config = parse_provider_config(
            args.provider, args.provider_config or {}
        )

        checks_config = parse_checks_config(args.checks or [])

        notifiers_config = parse_notifiers_config(args.notifiers or [])

        environments_config = parse_environments_config(args.environments or {})

        # TODO(dcramer): this needs to be a get_or_create pattern
        repo = Repository.query.filter(Repository.url == args.repository).first()
        if repo is None:
            repo = Repository(url=args.repository, vcs="git")
            db.session.add(repo)
            db.session.flush()

        app = App(
            name=args.name,
            repository_id=repo.id,
            data={"environments": environments_config},
        )
        db.session.add(app)
        db.session.flush()

        # For backwards compatibility, we assume that we need a deploy TaskConfig
        # on the app at all times.
        deploy_config = TaskConfig(
            app_id=app.id,
            type=TaskConfigType.deploy,
            provider=args.provider,
            data={
                "provider_config": provider_config,
                "notifiers": notifiers_config,
                "checks": checks_config,
            },
        )
        db.session.add(deploy_config)
        db.session.commit()

        return self.respond(serialize(app), status_code=201)
Beispiel #4
0
    def post(self):
        """
        Create a new app.
        """
        args = self.post_parser.parse_args()

        provider_config = parse_provider_config(args.provider,
                                                args.provider_config or {})

        checks_config = parse_checks_config(args.checks or [])

        notifiers_config = parse_notifiers_config(args.notifiers or [])

        environments_config = parse_environments_config(args.environments
                                                        or {})

        # TODO(dcramer): this needs to be a get_or_create pattern
        repo = Repository.query.filter(
            Repository.url == args.repository, ).first()
        if repo is None:
            repo = Repository(url=args.repository, vcs='git')
            db.session.add(repo)
            db.session.flush()

        app = App(
            name=args.name,
            repository_id=repo.id,
            provider=args.provider,
            data={
                'provider_config': provider_config,
                'notifiers': notifiers_config,
                'checks': checks_config,
                'environments': environments_config,
            },
        )
        db.session.add(app)
        db.session.commit()

        return self.respond(serialize(app), status_code=201)
Beispiel #5
0
    def put(self, app):
        """
        Update an app.
        """
        args = self.put_parser.parse_args()

        app = App.query.filter(App.name == app).first()
        if app is None:
            return self.error('Invalid app', name='invalid_resource', status_code=404)

        # For backwards compatibility, we assume that we need a deploy TaskConfig
        # on the app at all times.
        deploy_config = TaskConfig.query.filter(
            TaskConfig.app_id == app.id,
            TaskConfig.type == TaskConfigType.deploy,
        ).first()
        if deploy_config is None:
            deploy_config = TaskConfig(app_id=app.id, type=TaskConfigType.deploy)
            db.session.add(deploy_config)
            db.session.flush()

        if args.provider or args.provider_config:
            if args.provider is not None:
                provider = args.provider
            else:
                provider = deploy_config.provider

            if args.provider_config is not None:
                provider_config = args.provider_config
            else:
                provider_config = deploy_config.provider_config

            deploy_config.provider = provider
            deploy_config.data['provider_config'] = parse_provider_config(
                provider, provider_config
            )

        if args.notifiers is not None:
            deploy_config.data['notifiers'] = parse_notifiers_config(args.notifiers)

        if args.checks is not None:
            deploy_config.data['checks'] = parse_checks_config(args.checks)

        if args.environments is not None:
            app.data['environments'] = parse_environments_config(args.environments)

        if args.name:
            app.name = args.name

        # TODO(dcramer): this needs to be a get_or_create pattern
        if args.repository:
            repo = Repository.query.filter(
                Repository.url == args.repository,
            ).first()
            if repo is None:
                repo = Repository(url=args.repository, vcs='git')
                db.session.add(repo)
                db.session.flush()
            app.repository_id = repo.id

        db.session.add(app)
        db.session.add(deploy_config)
        db.session.commit()

        context = serialize(app)
        context.update({
            'provider': deploy_config.provider,
            'provider_config': deploy_config.provider_config,
            'notifiers': deploy_config.notifiers,
            'checks': deploy_config.checks,
        })

        return self.respond(context)
Beispiel #6
0
    def put(self, app):
        """
        Update an app.
        """
        args = self.put_parser.parse_args()

        app = App.query.filter(App.name == app).first()
        if app is None:
            return self.error('Invalid app',
                              name='invalid_resource',
                              status_code=404)

        if args.provider or args.provider_config:
            if args.provider is not None:
                provider = args.provider
            else:
                provider = app.provider

            if args.provider_config is not None:
                provider_config = args.provider_config
            else:
                provider_config = app.provider_config

            app.provider = provider
            app.data['provider_config'] = parse_provider_config(
                provider, provider_config)

        if args.notifiers is not None:
            app.data['notifiers'] = parse_notifiers_config(args.notifiers)

        if args.checks is not None:
            app.data['checks'] = parse_checks_config(args.checks)

        if args.environments is not None:
            app.data['environments'] = parse_environments_config(
                args.environments)

        if args.name:
            app.name = args.name

        # TODO(dcramer): this needs to be a get_or_create pattern
        if args.repository:
            repo = Repository.query.filter(
                Repository.url == args.repository, ).first()
            if repo is None:
                repo = Repository(url=args.repository, vcs='git')
                db.session.add(repo)
                db.session.flush()
            app.repository_id = repo.id

        db.session.add(app)
        db.session.commit()

        context = serialize(app)
        context.update({
            'provider': app.provider,
            'provider_config': app.provider_config,
            'notifiers': app.notifiers,
            'checks': app.checks,
        })

        return self.respond(context)