예제 #1
0
파일: views.py 프로젝트: Netflix/dispatch
def update_service(*,
                   db_session: Session = Depends(get_db),
                   service_id: PrimaryKey,
                   service_in: ServiceUpdate):
    """Update an existing service."""
    service = get(db_session=db_session, service_id=service_id)
    if not service:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail=[{
                "msg": "A service with this id does not exist."
            }],
        )

    try:
        service = update(db_session=db_session,
                         service=service,
                         service_in=service_in)
    except IntegrityError:
        raise ValidationError(
            [
                ErrorWrapper(ExistsError(
                    msg="A service with this name already exists."),
                             loc="name")
            ],
            model=ServiceUpdate,
        )

    return service
예제 #2
0
파일: views.py 프로젝트: Netflix/dispatch
def update_organization(
    *,
    db_session: Session = Depends(get_db),
    organization_id: PrimaryKey,
    organization_in: OrganizationUpdate,
):
    """Update an organization."""
    organization = get(db_session=db_session, organization_id=organization_id)
    if not organization:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail=[{
                "msg": "An organization with this id does not exist."
            }],
        )
    try:
        organization = update(db_session=db_session,
                              organization=organization,
                              organization_in=organization_in)
    except IntegrityError:
        raise ValidationError(
            [
                ErrorWrapper(ExistsError(
                    msg="An organization with this name already exists."),
                             loc="name")
            ],
            model=OrganizationUpdate,
        )
    return organization
예제 #3
0
파일: views.py 프로젝트: Netflix/dispatch
def create_service(
    *,
    db_session: Session = Depends(get_db),
    service_in: ServiceCreate = Body(
        ...,
        example={
            "name": "myService",
            "type": "pagerduty",
            "is_active": True,
            "external_id": "234234",
        },
    ),
):
    """Create a new service."""
    service = get_by_external_id_and_project_name(
        db_session=db_session,
        external_id=service_in.external_id,
        project_name=service_in.project.name,
    )
    if service:
        raise ValidationError(
            [
                ErrorWrapper(
                    ExistsError(
                        msg="A service with this external_id already exists."),
                    loc="external_id",
                )
            ],
            model=ServiceCreate,
        )
    service = create(db_session=db_session, service_in=service_in)
    return service
예제 #4
0
def create_organization(
        *,
        db_session: Session = Depends(get_db),
        organization_in: OrganizationCreate,
        current_user: DispatchUser = Depends(get_current_user),
):
    """Create a new organization."""
    try:
        organization = create(db_session=db_session,
                              organization_in=organization_in)
    except IntegrityError:
        raise ValidationError(
            [
                ErrorWrapper(ExistsError(
                    msg="An organization with this name already exists."),
                             loc="name")
            ],
            model=OrganizationCreate,
        )

    # add creator as organization owner
    add_user(db_session=db_session,
             organization=organization,
             user=current_user,
             role=UserRoles.owner)

    return organization
예제 #5
0
def update_tag_type(*,
                    db_session: Session = Depends(get_db),
                    tag_type_id: PrimaryKey,
                    tag_type_in: TagTypeUpdate):
    """Update a tag type."""
    tag_type = get(db_session=db_session, tag_type_id=tag_type_id)
    if not tag_type:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail=[{
                "msg": "A tag type with this id does not exist."
            }],
        )

    try:
        tag_type = update(db_session=db_session,
                          tag_type=tag_type,
                          tag_type_in=tag_type_in)
    except IntegrityError:
        raise ValidationError(
            [
                ErrorWrapper(ExistsError(
                    msg="A tag type with this name already exists."),
                             loc="name")
            ],
            model=TagTypeUpdate,
        )
    return tag_type
예제 #6
0
def create_term(*, db_session: Session = Depends(get_db), term_in: TermCreate):
    """Create a new term."""
    term = get_by_text(db_session=db_session, text=term_in.text)
    if term:
        raise ValidationError(
            [
                ErrorWrapper(
                    ExistsError(msg="A term with this name already exists."),
                    loc="name")
            ],
            model=TermCreate,
        )
    term = create(db_session=db_session, term_in=term_in)
    return term
예제 #7
0
def create_search_filter(*,
                         db_session: Session = Depends(get_db),
                         search_filter_in: SearchFilterCreate):
    """Create a new filter."""
    try:
        return create(db_session=db_session, search_filter_in=search_filter_in)
    except IntegrityError:
        raise ValidationError(
            [
                ErrorWrapper(ExistsError(
                    msg="A search filter with this name already exists."),
                             loc="name")
            ],
            model=SearchFilterRead,
        )
예제 #8
0
파일: views.py 프로젝트: Netflix/dispatch
def create_project(*,
                   db_session: Session = Depends(get_db),
                   project_in: ProjectCreate):
    """Create a new project."""
    project = get_by_name(db_session=db_session, name=project_in.name)
    if project:
        raise ValidationError(
            [
                ErrorWrapper(ExistsError(
                    msg="A project with this name already exists."),
                             loc="name")
            ],
            model=ProjectCreate,
        )

    project = create(db_session=db_session, project_in=project_in)
    return project
예제 #9
0
def create_tag_type(*,
                    db_session: Session = Depends(get_db),
                    tag_type_in: TagTypeCreate):
    """Create a new tag type."""
    try:
        tag_type = create(db_session=db_session, tag_type_in=tag_type_in)
    except IntegrityError:
        raise ValidationError(
            [
                ErrorWrapper(ExistsError(
                    msg="A tag type with this name already exists."),
                             loc="name")
            ],
            model=TagTypeCreate,
        )

    return tag_type
예제 #10
0
def create_definition(*,
                      db_session: Session = Depends(get_db),
                      definition_in: DefinitionCreate):
    """Create a new definition."""
    definition = get_by_text(db_session=db_session, text=definition_in.text)
    if definition:
        raise ValidationError(
            [
                ErrorWrapper(ExistsError(
                    msg="A description with this text already exists."),
                             loc="text")
            ],
            model=DefinitionRead,
        )

    definition = create(db_session=db_session, definition_in=definition_in)
    return definition
예제 #11
0
파일: views.py 프로젝트: Netflix/dispatch
def create_team(*,
                db_session: Session = Depends(get_db),
                team_contact_in: TeamContactCreate):
    """Create a new team contact."""
    team = get_by_email(db_session=db_session,
                        email=team_contact_in.email,
                        project_id=team_contact_in.project.id)
    if team:
        raise ValidationError(
            [
                ErrorWrapper(
                    ExistsError(msg="A team with this name already exists."),
                    loc="name")
            ],
            model=TeamContactCreate,
        )
    team = create(db_session=db_session, team_contact_in=team_contact_in)
    return team
예제 #12
0
파일: views.py 프로젝트: Netflix/dispatch
def create_individual(*,
                      db_session: Session = Depends(get_db),
                      individual_contact_in: IndividualContactCreate):
    """Create a new individual contact."""
    individual = get_by_email_and_project(
        db_session=db_session,
        email=individual_contact_in.email,
        project_id=individual_contact_in.project.id,
    )
    if individual:
        raise ValidationError(
            [
                ErrorWrapper(
                    ExistsError(
                        msg="An individual with this email already exists."),
                    loc="email",
                )
            ],
            model=IndividualContactRead,
        )
    individual = create(db_session=db_session,
                        individual_contact_in=individual_contact_in)
    return individual