Exemplo n.º 1
0
def test_get_solution():
    response = SolutionService().get_solution(solution_name=TEST_SOLN_NAME)
    global solution_id
    print(response)
    assert response
    assert response['solution_id']
    solution_id = response['solution_id']
Exemplo n.º 2
0
def get_nifi_link(solution_id):
    context = tracer.get_context(request_id=str(uuid4()), log_level="INFO")
    context.start_span(component=__name__)
    try:
        solution = SolutionService().get_solution(solution_id=solution_id)
        if solution:
            solution_name = solution['solution_name']
            deploy_mode = os.environ['DEPLOY_MODE'] if 'DEPLOY_MODE' in os.environ else ''
            domain_name = os.environ['DOMAIN_NAME'] if 'DOMAIN_NAME' in os.environ else 'dev.xpms.ai'
            if deploy_mode == 'RANCHER':
                if 'STACK_NAME' in os.environ:
                    solution_name = os.environ['STACK_NAME'] + '-' + solution_name
                return "web." + str(solution_name) + ".pl." + domain_name+":8080"
            resp = find_service(REF_PIPELINE, fetch_all=True)
            if resp["status"]["success"]:
                try:
                    ref = ':' + solution_name + '-' + REF_PIPELINE + ':'
                    for service in resp["services_list"]:
                        if ref in service['service_id']:
                            return service["host"] + ":" + str(service["port"])
                except Exception as e:
                    context.log(message=str(e), obj={"tb": traceback.format_exc()})
            else:
                return ""
    # TODO raise specific exception
    except Exception as e:
        context.log(message=str(e), obj={"tb": traceback.format_exc()})
    finally:
        context.end_span()
    return ""
Exemplo n.º 3
0
def auth_user_info(request):
    try:
        from xc.keycloak_service import KeycloakService
        user_info = KeycloakService.get_logged_in_user_info(request)
        user = User.objects.get_by_natural_key(username=user_info["username"])

        if user:
            solution_user = None

            json_extra = {
                "user": {
                    "_id": user.pk,
                    "email": user.email,
                    "first_name": user.first_name,
                    "last_name": user.last_name,
                    "solutions": SolutionService().get_solutions()
                },
                "role": user_info["role"]
            }
            if solution_user:
                json_extra["user"]["role"] = solution_user.user_type
                request.session['username'] = user_info["username"]
                request.session['user_id'] = user.pk
            else:
                json_extra["user"]["role"] = "sa"
            return get_success("user login successful", json_extra)

        else:
            return {"msg": "Invalid session Details", "status": "failure"}
    except Exception as e:
        return {"msg": "Session error " + str(e), "status": "failure"}
Exemplo n.º 4
0
def test_create_solution():
    response = SolutionService().create_solution(TEST_SOLN)
    print(response)
    try:
        assert response["status"] == "success"
    except AssertionError:
        assert "solution name already exists" in response["msg"]
Exemplo n.º 5
0
def get_default_solution(context):
    try:
        solution = SolutionService().get_solution(
            solution_name=DEFAULT_SOLN_NAME)
        if solution:
            return {
                "id": solution['solution_id'],
                "name": solution['solution_name']
            }
    except Exception as e:
        context.log(message=str(e), obj={"tb": traceback.format_exc()})
Exemplo n.º 6
0
 def process_user_solutions(self, request):
     """
     :param request: Http request
     :return: list of solutions as response
     """
     sol_resp = []
     logged_in_user = request.session.get('user', None)
     if logged_in_user:
         self.auth_header += ' ' + request.META['HTTP_AUTHORIZATION']
         user_solutions_from_session = logged_in_user.get('solutions', [])
         for user_solution in user_solutions_from_session:
             sol = SolutionService.get_solution(
                 solution_name=user_solution.get('name'))
             if sol:
                 sol_resp.append({
                     "solution_id": sol['solution_id'],
                     "solution_name": sol['solution_name'],
                     "solution_type": sol['solution_type'],
                     "description": sol['description'],
                     "timestamp": sol['updated_ts']
                 })
     return sol_resp
Exemplo n.º 7
0
def create_soln(context):
    try:
        SolutionService().create_solution(solution_payload)
    except Exception as e:
        context.log(message=str(e), obj={"tb": traceback.format_exc()})
Exemplo n.º 8
0
def test_delete_solution():
    response = SolutionService().delete_solution({"solution_id": solution_id})
    assert response["status"] == 'success'
Exemplo n.º 9
0
def test_get_solutions():
    response = SolutionService().get_solutions()
    global solution_id
    assert response
    assert response['status'] == 'success'