def create(sourceControlDetails):
    """
    This function creates a new sourceControl in the sourceControl list
    based on the passed in sourceControl data

    :param sourceControl:  sourceControl to create in sourceControl structure
    :return:        201 on success, 406 on sourceControl exists
    """
    key = sourceControlDetails.get("key", None)
    value = sourceControlDetails.get("value", None)

    # Does the sourceControl exist already?
    existing_sourceControl = (SourceControl.query.filter(
        SourceControl.key == key).one_or_none())

    if existing_sourceControl is None:
        schema = SourceControlSchema()
        new_sourceControl = schema.load(sourceControlDetails,
                                        session=db.session)
        db.session.add(new_sourceControl)
        db.session.commit()

        # Serialize and return the newly created deployment
        # in the response
        data = schema.dump(new_sourceControl)

        return data, 201

    # Otherwise, it already exists, that's an error
    else:
        abort(406, f"SourceControl already exists")
예제 #2
0
def update(id, sourceControlDetails):
    """
    This function updates an existing sourceControl in the sourceControl list

    :param id:    id of the sourceControl to update in the sourceControl list
    :param sourceControl:   sourceControl to update
    :return:       updated sourceControl
    """
    app.logger.debug(pformat(sourceControlDetails))

    if sourceControlDetails["id"] != id:
        abort(400, "Key mismatch in path and body")

    # Does the sourceControl exist in sourceControl list?
    existing_sourceControl = (db.session.query(SourceControl).filter(
        SourceControl.id == id).one_or_none())

    # Does sourceControl exist?

    if existing_sourceControl is not None:
        schema = SourceControlSchema()
        update_sourceControl = schema.load(sourceControlDetails,
                                           session=db.session)
        update_sourceControl.id = sourceControlDetails["id"]

        db.session.merge(update_sourceControl)
        db.session.commit()

        # return the updted sourceControl in the response
        data = schema.dump(update_sourceControl)
        return data, 200

    # otherwise, nope, deployment doesn't exist, so that's an error
    else:
        abort(404, "SourceControl not found")
예제 #3
0
def create(sourceControlDetails):
    """
    This function creates a new sourceControl in the sourceControl list
    based on the passed in sourceControl data

    :param sourceControl:  sourceControl to create in sourceControl structure
    :return:        201 on success, 406 on sourceControl exists
    """
    # Remove id as it's created automatically
    if "id" in sourceControlDetails:
        del sourceControlDetails["id"]
    # Does the sourceControl exist already?
    existing_sourceControl = (db.session.query(SourceControl).filter(
        SourceControl.value == sourceControlDetails["value"]).one_or_none())

    if existing_sourceControl is None:
        schema = SourceControlSchema()
        new_sourceControl = schema.load(sourceControlDetails,
                                        session=db.session)
        db.session.add(new_sourceControl)
        db.session.commit()

        # Serialize and return the newly created deployment
        # in the response
        data = schema.dump(new_sourceControl)

        return data, 201

    # Otherwise, it already exists, that's an error
    else:
        abort(406, "SourceControl already exists")
예제 #4
0
def update(key, sourceControl):
    """
    This function updates an existing sourceControl in the sourceControl list

    :param key:    key of the sourceControl to update in the sourceControl list
    :param sourceControl:   sourceControl to update
    :return:       updated sourceControl
    """

    app.logger.debug(pformat(sourceControl))

    if sourceControl["key"] != key:
        abort(400, f"Key mismatch in path and body")

    # Does the sourceControl exist in sourceControl list?
    existing_sourceControl = SourceControl.query.filter(
        SourceControl.key == key).one_or_none()

    # Does sourceControl exist?

    if existing_sourceControl is not None:
        schema = SourceControlSchema()
        update_sourceControl = schema.load(sourceControl, session=db.session)
        update_sourceControl.key = sourceControl['key']

        db.session.merge(update_sourceControl)
        db.session.commit()

        # return the updted sourceControl in the response
        data = schema.dump(update_sourceControl)
        return data, 200

    # otherwise, nope, deployment doesn't exist, so that's an error
    else:
        abort(404, f"SourceControl not found")