Beispiel #1
0
def create_user_for_soa(request):
    if request.method == 'POST':
        result, data = login_soa(request)
        if result.get("success"):
            token = request.session.get("passToken")
            auth_url = data.get("auth_url")
            user_list = data.get("user")

            response_data = {}
            for user in user_list:
                data = {
                    "user": {
                        "default_project_id": user.get("default_project_id"),
                        "name": user.get("name"),
                        "password": user.get("password"),
                        "email": user.get("email"),
                        "domain_id": request.session.get("domain_id"),
                        "enabled": True,
                        "description": u"SOA 관리포털에서 생성"
                    }
                }

                keystone = KeystoneRestAPI(auth_url, token)
                result = keystone.create_user(data)
                if result.get("success"):
                    created_user = result["success"].get("user")

                    params = (auth_url, created_user.get("default_project_id"),
                              created_user.get("id"), created_user.get("name"))

                    try:
                        soa_conn = SOAControlDBConnector.getInstance()
                        soa_conn.insert(INSERT_SOAC_USER, params)
                    except Exception as e:
                        logger.debug("soac 사용자 생성 실패(" +
                                     created_user.get("name") + ")" + str(e))
                        result = {
                            "error": {
                                "title": e.message,
                                "message": "soac db insert user error",
                                "code": 500
                            }
                        }
                        # end except
                    # end if
                response_data[user.get("name")] = result
                # end for
            result = response_data
            # end if
        return JsonResponse(result)
Beispiel #2
0
def create_user(request):
    if request.is_ajax() and request.method == 'POST':
        token = request.session.get('passToken')
        auth_url = request.session.get('auth_url')
        keystone = KeystoneRestAPI(auth_url, token)
        user = json.loads(request.POST.get("user"))
        data = {
            "user": {
                k: v
                for k, v in user.items()
                if v is not None and k not in ["role_id", "domain_name"]
            }
        }
        result = keystone.create_user(data)
        if result.get("success") and user.get("default_project_id"):
            created_user = result["success"].get("user")
            a_result = keystone.assign_role_to_user_on_projects(user.get("default_project_id"), created_user.get("id"), user.get("role_id"))
            if a_result.get("error"):
                result["error"] = a_result["error"]
        return JsonResponse(result)