Exemple #1
0
def update(oid, businessUnitDetails):
    """
    Updates an existing businessUnit in the businessUnit list

    :param key:    id of the businessUnit to update in the businessUnit list
    :param businessUnit:   businessUnit to update
    :return:       updated businessUnit.
    """
    if businessUnitDetails["id"] != oid:
        abort(400, "id mismatch in path and body")

    # Does the businessUnit exist in businessUnit list?
    existing_businessUnit = (db.session.query(BusinessUnit).filter(
        BusinessUnit.id == oid).one_or_none())

    # Does businessUnit exist?

    if existing_businessUnit is not None:

        schema = BusinessUnitSchema()
        update_businessUnit = schema.load(businessUnitDetails,
                                          session=db.session)
        update_businessUnit.id = existing_businessUnit.id

        db.session.merge(update_businessUnit)
        db.session.commit()

        # return the updted deployment in the response
        data = schema.dump(update_businessUnit)
        app.logger.debug(data)
        return data, 200

    # otherwise, nope, businessUnit doesn't exist, so that's an error
    else:
        abort(404, f"BusinessUnit with id {oid} not found")
Exemple #2
0
def create(businessUnitDetails):
    """
    Creates a new businessUnit in the businessUnit list
    based on the passed in businessUnit data

    :param businessUnit: businessUnit to create in businessUnit structure
    :return:        201 on success, 406 on businessUnit exists
    """
    # Remove id as it's created automatically
    if "id" in businessUnitDetails:
        del businessUnitDetails["id"]

    # Does the cd exist already?
    existing_businessUnit = (db.session.query(BusinessUnit).filter(
        BusinessUnit.name == businessUnitDetails["name"]).one_or_none())

    if existing_businessUnit is None:
        schema = BusinessUnitSchema()
        new_businessUnit = schema.load(businessUnitDetails, session=db.session)
        db.session.add(new_businessUnit)
        db.session.commit()

        # Serialize and return the newly created deployment
        # in the response
        data = schema.dump(new_businessUnit)
        app.logger.debug(data)
        return data, 201

    # Otherwise, it already exists, that's an error
    else:
        abort(
            406,
            f"BusinessUnit with name {businessUnitDetails['name']} already exists"
        )
def create(businessUnitDetails):
    """
    This function creates a new businessUnit in the businessUnit list
    based on the passed in businessUnit data

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

    # Does the cd exist already?
    existing_businessUnit = (BusinessUnit.query.filter(
        BusinessUnit.key == key).one_or_none())

    if existing_businessUnit is None:
        schema = BusinessUnitSchema()
        new_businessUnit = schema.load(businessUnitDetails, session=db.session)
        db.session.add(new_businessUnit)
        db.session.commit()

        # Serialize and return the newly created deployment
        # in the response
        data = schema.dump(new_businessUnit)
        app.logger.debug(data)
        return data, 201

    # Otherwise, it already exists, that's an error
    else:
        abort(406, f"BusinessUnit already exists")
Exemple #4
0
def update(key, businessUnit):
    """
    This function updates an existing businessUnit in the businessUnit list

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

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

    # Does the businessUnit exist in businessUnit list?
    existing_businessUnit = BusinessUnit.query.filter(
        BusinessUnit.key == key).one_or_none()

    # Does businessUnit exist?

    if existing_businessUnit is not None:

        schema = BusinessUnitSchema()
        update_businessUnit = schema.load(businessUnit, session=db.session)
        update_businessUnit.key = existing_businessUnit.key

        db.session.merge(update_businessUnit)
        db.session.commit()

        # return the updted deployment in the response
        data = schema.dump(update_businessUnit)
        app.logger.debug(data)
        return data, 200

    # otherwise, nope, businessUnit doesn't exist, so that's an error
    else:
        abort(404, f"BusinessUnit not found")
Exemple #5
0
def read_all():
    """
    Responds to a request for /api/businessunit
    with the complete lists of BusinessUnits

    :return:        json string of list of BusinessUnits
    """
    # Create the list of BusinessUnits from our data
    businessUnit = db.session.query(BusinessUnit).order_by(
        BusinessUnit.id).all()
    app.logger.debug(pformat(businessUnit))
    # Serialize the data for the response
    businessUnit_schema = BusinessUnitSchema(many=True)
    data = businessUnit_schema.dump(businessUnit)
    app.logger.debug(data)
    return data, 200
Exemple #6
0
class ExtendedActivatorSchema(Schema):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    id = fields.Int()
    isActive = fields.Boolean()
    lastUpdated = fields.Str()
    isFavourite = fields.Boolean()
    name = fields.Str()
    available = fields.Boolean()
    sensitivity = fields.Str()
    envs = fields.Nested(LZEnvironmentSchema(many=True))
    userCapacity = fields.Int()
    serverCapacity = fields.Int()
    regions = fields.List(fields.Str())
    hosting = fields.List(fields.Str())
    apiManagement = fields.List(fields.Str())
    ciId = fields.Int()
    ci = fields.Nested(CISchema(many=True))
    cdId = fields.Int()
    cd = fields.Nested(CDSchema(many=True))
    sourceControlId = fields.Int()
    sourceControl = fields.Nested(SourceControlSchema(many=False))
    businessUnitId = fields.Int()
    businessUnit = fields.Nested(BusinessUnitSchema(many=False))
    technologyOwner = fields.Str()
    technologyOwnerEmail = fields.Str()
    billing = fields.Str()
    activator = fields.Str()
    status = fields.Str()
    accessRequestedById = fields.Int()
    accessRequestedBy = fields.Nested(ExtendedUserSchema(many=False))
    source = fields.Str()
    gitRepoUrl = fields.Str()
    activatorMetadata = fields.Nested(
        ExtendedActivatorMetadataSchema(many=False))

    @post_load(pass_original=True)
    def deserialize_post_load(self, data, original_data, **kwargs):
        # logger.debug(
        #    "ExtendedActivatorSchema::post_load::serialize_post_load: %s", data
        # )
        if original_data.regions is not None:
            data["regions"] = json.dumps(original_data.regions)
        if original_data.hosting is not None:
            data["hosting"] = json.dumps(original_data.hosting)
        if original_data.apiManagement is not None:
            data["apiManagement"] = json.dumps(original_data.apiManagement)
        return data

    @post_dump(pass_original=True)
    def deserialize_post_dump(self, data, original_data, **kwargs):
        # logger.debug("ExtendedActivatorSchema::post_dump %s", original_data)
        if original_data.regions is not None:
            data["regions"] = json.loads(original_data.regions)
        if original_data.hosting is not None:
            data["hosting"] = json.loads(original_data.hosting)
        if original_data.apiManagement is not None:
            data["apiManagement"] = json.loads(original_data.apiManagement)
        return data
Exemple #7
0
class ExtendedSolutionSchema(Schema):
    __envelope__ = {"single": "solution", "many": "solutions"}

    id = fields.Int()
    isActive = fields.Boolean()
    lastUpdated = fields.Str()
    isFavourite = fields.Boolean()
    name = fields.Str()
    description = fields.Str()
    businessUnitId = fields.Int()
    costCentre = fields.Str()
    ciId = fields.Int()
    ci = fields.Nested(CISchema(many=False))
    cdId = fields.Int()
    cd = fields.Nested(CDSchema(many=False))
    sourceControlId = fields.Int()
    sourceControl = fields.Nested(SourceControlSchema(many=False))
    environments = fields.Nested(LZEnvironmentSchema(many=True))
    favourite = fields.Boolean()
    teamId = fields.Int()
    applications = fields.Nested(ExtendedApplicationSchema(many=True))
    team = fields.Nested(ExtendedTeamSchema(many=False))
    deploymentFolderId = fields.Str()
    businessUnit = fields.Nested(BusinessUnitSchema(many=False))
    deploymentState = fields.Str()
    isSandbox = fields.Boolean()
Exemple #8
0
def read_one(oid):
    """
    Responds to a request for /api/businessunit/{id}
    with one matching businessUnit from BusinessUnits

    :param application:   id of businessUnit to find
    :return:              businessUnit matching id
    """
    businessUnit = (db.session.query(BusinessUnit).filter(
        BusinessUnit.id == oid).one_or_none())

    if businessUnit is not None:
        # Serialize the data for the response
        businessUnit_schema = BusinessUnitSchema()
        data = businessUnit_schema.dump(businessUnit)
        app.logger.debug(data)
        return data, 200
    else:
        abort(404, f"BusinessUnit with id {oid} not found")
def read_one(key):
    """
    This function responds to a request for /api/businessunit/{key}
    with one matching businessUnit from BusinessUnits 

    :param application:   key of businessUnit to find
    :return:              businessUnit matching key
    """

    businessUnit = (BusinessUnit.query.filter(
        BusinessUnit.key == key).one_or_none())

    if businessUnit is not None:
        # Serialize the data for the response
        businessUnit_schema = BusinessUnitSchema()
        data = businessUnit_schema.dump(businessUnit)
        app.logger.debug(data)
        return data
    else:
        abort(404, "BusinessUnit with key {key} not found".format(key=key))
Exemple #10
0
class ExtendedTeamSchema(Schema):
    id = fields.Int()
    name = fields.Str()
    description = fields.Str()
    cloudIdentityGroup = fields.Str()
    businessUnitId = fields.Int()
    isActive = fields.Boolean()
    businessUnit = fields.Nested(BusinessUnitSchema(many=False))
    lastUpdated = fields.Str()
    userCount = fields.Int()
    accessRequestedById = fields.Int()
    accessRequestedBy = fields.Nested(ExtendedUserSchema(many=False))
Exemple #11
0
def read_keyValues():
    """
    Responds to a request for /api/keyValues/businessUnit
    with the complete lists of BusinessUnits
    :return:        json string of list of key value pairs
    """
    # Create the list of BusinessUnits from our data
    businessUnit = db.session.query(BusinessUnit).order_by(
        BusinessUnit.id).all()
    app.logger.debug(pformat(businessUnit))
    # Serialize the data for the response
    businessUnit_schema = BusinessUnitSchema(many=True)
    data = businessUnit_schema.dump(businessUnit)
    app.logger.debug(data)
    keyValues = []
    for d in data:
        keyValuePair = {}
        keyValuePair["key"] = d.get("id")
        keyValuePair["value"] = d.get("name")
        keyValues.append(keyValuePair)
    print(keyValues)
    return keyValues