Ejemplo n.º 1
0
async def put_stack_instance(
    background_tasks: BackgroundTasks,
    stack_instance_update: StackInstanceUpdate,
    document_manager: DocumentManager = Depends(get_document_manager),
    stack_manager: StackManager = Depends(get_stack_manager),
    redis=Depends(get_redis)):
    """
    Updates a stack instance by using a StackInstanceUpdate object
    """
    logger.info("[StackInstances PUT] Received PUT request")
    to_be_deleted = stack_manager.check_delete_services(stack_instance_update)
    (stack_instance, return_result) = stack_manager.process_stack_request(
        stack_instance_update, "update")
    if stack_instance is None:
        return HTTPException(422, return_result)

    # Perform invocations
    if not stack_instance_update.disable_invocation:
        for service in to_be_deleted:
            background_tasks.add_task(create_job_per_service, service,
                                      document_manager, "delete", redis,
                                      stack_instance, to_be_deleted)
        copy_stack_instance = stack_instance.copy(deep=True)
        delete_services(to_be_deleted, copy_stack_instance)
        background_tasks.add_task(create_job_for_agent, copy_stack_instance,
                                  "update", redis)

    document_manager.write_stack_instance(stack_instance)

    return return_result
Ejemplo n.º 2
0
def put_stack_application_template(
    sat: StackApplicationTemplate,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Create the document with a specific type and an optional name given in the payload"""
    document_manager.write_stack_application_template(sat)

    return sat
def get_infrastructure_base_by_type_and_name(
    infrastructure_base_type: str,
    infrastructure_base_name: str,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Returns a specific infrastructure_base document with a type and name"""
    logger.info(f"GET request for type '{infrastructure_base_type}' and \
          document '{infrastructure_base_name}'")
    if infrastructure_base_type == "environment":
        infrastructure_document = document_manager.get_environment(
            infrastructure_base_name)
    elif infrastructure_base_type == "location":
        infrastructure_document = document_manager.get_location(
            infrastructure_base_name)
    elif infrastructure_base_type == "zone":
        infrastructure_document = document_manager.get_zone(
            infrastructure_base_name)
    else:
        raise HTTPException(
            status_code=400,
            detail="type has to be environment, location or zone")

    if not infrastructure_document:
        raise HTTPException(status_code=404, detail="Document not found")

    return infrastructure_document
def delete_functional_requirement(
    name: str,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Delete a functional requirement by name"""
    logger.info(f"API Delete request for document '{name}'")
    document_manager.delete_functional_requirement(name)
    return {"result": f"deleted functional requirement {name}"}
def post_functional_requirement(
    document: FunctionalRequirement,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Create the document with a specific type and an optional name given in the payload"""
    logger.info(f"[PostDocument] Receiver POST request with data: {document}")
    document_manager.write_functional_requirement(document)
    return document
Ejemplo n.º 6
0
def post_service(
    service: Service,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Create the document with a specific type and an optional name given in the payload"""
    logger.info(f"[PostDocument] Receiver POST request with data: {service}")

    document_manager.write_service(service)
    return service
def post_stack_infrastructure_template(
        sit: StackInfrastructureTemplate,
        document_manager: DocumentManager = Depends(get_document_manager)):
    """Create the document with a specific type and an optional name given in the payload"""
    logger.info(f"[PostDocument] Receiver POST request with data: {sit}")

    document_manager.write_stack_infrastructure_template(sit)
    return sit
Ejemplo n.º 8
0
def delete_policy_template(
    name: str,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """
    Deletes a policy template by name
    """
    document_manager.delete_policy_template(name)
    return {"result": "deleted policy template"}
Ejemplo n.º 9
0
def add_outputs(
    outputs_update: OutputsUpdate,
    document_manager: DocumentManager = Depends(get_document_manager),
    stack_manager: StackManager = Depends(get_stack_manager)):
    """
    Function used to add outputs to a stack instance
    Returns the updated stack_instance
    """
    stack_instance = stack_manager.add_outputs(outputs_update)
    document_manager.write_stack_instance(stack_instance)
    return stack_instance
def delete_infrastructure_base(
    infrastructure_base_type: str,
    infrastructure_base_name: str,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """
    Delete an infrastructure base document by name and type
    Type is environment, location or zone
    """
    document_manager.delete_base_document(infrastructure_base_type,
                                          infrastructure_base_name)

    return {
        "result":
        f"deleted {infrastructure_base_type} {infrastructure_base_name}"
    }
def get_stack_infrastructure_templates(
        document_manager: DocumentManager = Depends(get_document_manager)):
    """Returns all functional requirements with a specific type"""
    logger.info(
        "COLLECT request with type_name 'stack_infrastructrure_templates'"
    )
    return document_manager.get_stack_infrastructure_templates()
Ejemplo n.º 12
0
async def post_stack_instance(
    background_tasks: BackgroundTasks,
    stack_instance_invocation: StackInstanceInvocation,
    document_manager: DocumentManager = Depends(get_document_manager),
    stack_manager: StackManager = Depends(get_stack_manager),
    redis=Depends(get_redis)):
    """Creates a stack instance with a specific name"""
    logger.info("[StackInstances POST] Received POST request")
    (stack_instance, return_result) = stack_manager.process_stack_request(
        stack_instance_invocation, "create")
    if stack_instance is None:
        return HTTPException(422, return_result)

    document_manager.write_stack_instance(stack_instance)
    # Perform invocations
    background_tasks.add_task(create_job_for_agent, stack_instance, "create",
                              redis)
    return return_result
Ejemplo n.º 13
0
def get_stack_instances(
    name: str = "",
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Returns all stack instances that contain optional name"""
    logger.info(
        f"[StackInstancesAll GET] Returning all stack instances that contain optional name '{name}'"
    )
    stack_instances = document_manager.get_stack_instances()
    return stack_instances
def get_infrastructure_base_by_type(
    infrastructure_base_type: str,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Returns a specific infrastructure_base document with a type and name"""
    logger.info(
        f"API COLLECT request with type_name '{infrastructure_base_type}'")
    if infrastructure_base_type == "environment":
        infrastructure_documents = document_manager.get_environments()
    elif infrastructure_base_type == "location":
        infrastructure_documents = document_manager.get_locations()
    elif infrastructure_base_type == "zone":
        infrastructure_documents = document_manager.get_zones()
    else:
        raise HTTPException(
            status_code=400,
            detail="type has to be environment, location or zone")

    return infrastructure_documents
Ejemplo n.º 15
0
def put_policy_template(
    policy: PolicyTemplate,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """
    Updates a policy template
    """
    logger.info(
        f"[PutDocument] API PUT request with policy_template: {policy}")
    policy_template = document_manager.write_policy_template(policy)
    return policy_template
def get_functional_requirement_by_name(
    name: str,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Returns a functional requirement"""
    logger.info(
        f"API GET request for type 'policy_template' and document '{name}'")
    functional_requirement = document_manager.get_functional_requirement(name)
    if not functional_requirement:
        raise HTTPException(status_code=404, detail="FR not found")
    return functional_requirement
Ejemplo n.º 17
0
def get_stack_instance(
    name: str,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Returns a stack instance with a specific name"""
    logger.info(
        f"[StackInstancesName GET] Getting document for stack instance '{name}'"
    )
    stack_instance = document_manager.get_stack_instance(name)
    if not stack_instance:
        raise HTTPException(status_code=404, detail="Stack instance not found")
    return stack_instance
Ejemplo n.º 18
0
def get_service_by_name(
    name: str,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Returns a functional requirement"""
    logger.info(
        f"[DocumentByTypeAndName GET] API GET request for type 'service' and document '{name}'"
    )
    service = document_manager.get_service(name)
    if not service:
        raise HTTPException(status_code=404, detail="Service not found")
    return service
Ejemplo n.º 19
0
def get_stack_application_template_by_name(
    name: str,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Returns a functional requirement"""
    logger.info(
        f"GET request for type 'stack_application_template' and document '{name}'"
    )
    sat = document_manager.get_stack_application_template(name)
    if not sat:
        raise HTTPException(status_code=404, detail="SAT not found")
    return sat
def put_infrastructure_base(
    infrastructure_base_document: InfrastructureBaseDocument,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """
    Updates the infrastructure_base document with a specific type
    and an optional name given in the payload
    """
    infrastructure_document = document_manager.write_base_document(
        infrastructure_base_document)

    return infrastructure_document
Ejemplo n.º 21
0
def get_policy_template_by_name(
    policy_name: str,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Returns a policy template"""
    logger.info(
        f"GET request for type 'policy_template' and document '{policy_name}'")
    policy_template = document_manager.get_policy_template(policy_name)
    if not policy_template:
        raise HTTPException(status_code=404,
                            detail="Policy template not found")
    return policy_template
def post_infrastructure_base(
    infrastructure_base_document: InfrastructureBaseDocument,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """
    Create the infrastructure_base document with a specific type and an
    optional name given in the payload
    """
    logger.info(f"POST request with data: {infrastructure_base_document}")

    infrastructure_document = document_manager.write_base_document(
        infrastructure_base_document)

    return infrastructure_document
Ejemplo n.º 23
0
async def put_stack_instance(
    background_tasks: BackgroundTasks,
    stack_instance_update: StackInstanceUpdate,
    document_manager: DocumentManager = Depends(get_document_manager),
    stack_manager: StackManager = Depends(get_stack_manager),
    redis=Depends(get_redis)):
    """
    Updates a stack instance by using a StackInstanceUpdate object
    """
    logger.info("[StackInstances PUT] Received PUT request")

    (stack_instance, return_result) = stack_manager.process_stack_request(
        stack_instance_update, "update")
    if stack_instance is None:
        return HTTPException(422, return_result)

    document_manager.write_stack_instance(stack_instance)

    # Perform invocations
    if not stack_instance_update.disable_invocation:
        background_tasks.add_task(create_job_for_agent, stack_instance,
                                  "update", document_manager, redis)

    return return_result
Ejemplo n.º 24
0
def delete_stack_instance(
    name: str,
    background_tasks: BackgroundTasks,
    force: bool = False,
    document_manager: DocumentManager = Depends(get_document_manager),
    redis=Depends(get_redis)):
    """Delete a stack instance with a specific name"""
    stack_instance = document_manager.get_stack_instance(name)
    background_tasks.add_task(create_job_for_agent,
                              stack_instance,
                              "delete",
                              document_manager,
                              redis,
                              force_delete=force)

    return {"result": f"Deleting stack instance {name}"}
Ejemplo n.º 25
0
def delete_stack_instance(
    name: str,
    background_tasks: BackgroundTasks,
    force: bool = False,
    document_manager: DocumentManager = Depends(get_document_manager),
    redis=Depends(get_redis)):
    """Delete a stack instance with a specific name"""
    stack_instance = document_manager.get_stack_instance(name)
    if stack_instance is None:
        return {
            "result":
            f"Stack instance {name} can't be deleted because it does not exist"
        }
    else:
        background_tasks.add_task(create_job_for_agent,
                                  stack_instance,
                                  "delete",
                                  redis,
                                  force_delete=force)
        return {"result": f"Stack instance {name} is being deleted"}
Ejemplo n.º 26
0
def get_stack_application_templates(
        document_manager: DocumentManager = Depends(get_document_manager)):
    """Returns all functional requirements with a specific type"""
    logger.info("GET request with type_name 'stack_application_templates'")
    sats = document_manager.get_stack_application_templates()
    return sats
Ejemplo n.º 27
0
def delete_service(
    name: str,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Delete a service document by name"""
    document_manager.delete_service(name)
    return {"result": "deleted service"}
def get_functional_requirements(
        document_manager: DocumentManager = Depends(get_document_manager)):
    """Returns all functional requirements with a specific type"""
    logger.info("API COLLECT request with type_name 'policy_template'")
    return document_manager.get_functional_requirements()
Ejemplo n.º 29
0
def delete_stack_application_template(
    name: str,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Delete a stack application template by name"""
    document_manager.delete_stack_application_template(name)
    return {"result": "Deleted SAT"}
def put_functional_requirement(
    document: FunctionalRequirement,
    document_manager: DocumentManager = Depends(get_document_manager)):
    """Create the document with a specific type and an optional name given in the payload"""
    document_manager.write_functional_requirement(document)
    return document