def create_filter(self, campaign_id, mechanic_id, condition_id, params):
     add_filter_url = CREATE_FILTER.format(rule_id=campaign_id,
                                           mechanic_id=mechanic_id,
                                           condition_id=condition_id)
     success, status_code, message, data = RestfulHelper.send(
         "POST", add_filter_url, params, self.request, " creating filter")
     return success, data, message
 def create_condition(self, campaign_id, mechanic_id, params):
     add_condition_url = CREATE_CONDITION.format(rule_id=campaign_id,
                                                 mechanic_id=mechanic_id)
     success, status_code, message, data = RestfulHelper.send(
         "POST", add_condition_url, params, self.request,
         " creating condition")
     return success, data, message
Пример #3
0
 def __update_mechanic(self, campaign_id: int, mechanic_id: int,
                       params: dict) -> tuple:
     update_mechanic_url = api_settings.UPDATE_MECHANIC.format(
         rule_id=campaign_id, mechanic_id=mechanic_id)
     is_success, status_code, message, data = RestfulHelper.send(
         'PUT', update_mechanic_url, params, self.request, 'Edit mechanic')
     return is_success, status_code, message
Пример #4
0
    def post(self, request, *args, **kwargs):
        service_id = int(kwargs['id'])
        url = api_settings.EDIT_CHANNEL_SERVICE.format(service_id=service_id)
        form = request.POST
        params = {'name': form['name'], 'location': form['location']}

        if form.get('timeout'):
            params['timeout'] = int(form['timeout'])

        if form.get('max_per_route'):
            params['max_per_route'] = int(form['max_per_route'])

        if form.get('max_total_connection'):
            params['max_total_connection'] = int(form['max_total_connection'])

        is_success, status_code, status_message, data = RestfulHelper.send(
            "PUT", url, params, self.request, "Update Service")

        if is_success:
            messages.add_message(request, messages.SUCCESS,
                                 'Service has been edited')
            return redirect('channel_gateway_service:list')
        else:
            messages.add_message(request, messages.ERROR, status_message)
            return render(request, self.template_name, context={'form': form})
Пример #5
0
 def get_limitation_list(self, campaign_id, mechanic_id, action_id):
     url = api_settings.GET_LIMITION_LIST.format(
         bak_rule_id=campaign_id,
         bak_mechanic_id=mechanic_id,
         bak_action_id=action_id)
     success, status_code, status_message, data = RestfulHelper.send(
         "GET", url, {}, self.request, "getting limitation list", "data")
     return success, data
Пример #6
0
 def get_comparison_list(self, campaign_id, mechanic_id, condition_id):
     url = api_settings.GET_COMPARISON_LIST.format(
         bak_rule_id=campaign_id,
         bak_mechanic_id=mechanic_id,
         bak_condition_id=condition_id)
     success, status_code, status_message, data = RestfulHelper.send(
         "GET", url, {}, self.request, "getting comparison list", "data")
     return success, data
Пример #7
0
 def add_new_trust(self, body):
     url = api_settings.ADD_TRUST
     success, status_code, status_message, data = RestfulHelper.send("POST", url, body, self.request,
                                                                     "creating trust")
     if success:
         return success, data
     else:
         return success, status_message
Пример #8
0
 def delete_scopes(self, url, scopes):
     if not scopes:
         return '', True
     params = {"scopes": scopes}
     success, status_code, status_message, data = RestfulHelper.send(
         "DELETE", url, params, self.request,
         "deleting client api gateway scopes")
     return status_message, success
Пример #9
0
 def insert_scopes(self, url, scopes):
     if not scopes:
         return '', True
     params = {"scopes": scopes}
     success, status_code, status_message, data = RestfulHelper.send(
         "POST", url, params, self.request,
         "adding client api gateway scopes")
     return status_message, success
Пример #10
0
 def get_condition_filter(self, campaign_id, mechanic_id, condition_id):
     url = api_settings.GET_CONDITION_FILTER.format(
         rule_id=campaign_id,
         mechanic_id=mechanic_id,
         condition_id=condition_id)
     success, status_code, status_message, data = RestfulHelper.send(
         "GET", url, {}, self.request, "getting condition filter", "data")
     return success, data
Пример #11
0
 def get_service_detail(self, services_id):
     url = api_settings.GET_CHANNEL_SERVICE
     params = {"id": services_id}
     is_success, status_code, status_message, data = RestfulHelper.send(
         "POST", url, params, self.request, "get service detail")
     if data is None:
         return None
     return data["services"][0]
Пример #12
0
 def get_trust_list(self, body):
     url = api_settings.SEARCH_TRUST
     success, status_code, status_message, data = RestfulHelper.send("POST", url, body, self.request,
                                                                     "searching trust", log_count_field='data.token_information')
     if success:
         return success, data
     else:
         return success, status_message
Пример #13
0
def get_api_list(self, params):
    api_path = api_settings.GET_CHANNEL_API

    success, status_code, status_message, data = RestfulHelper.send("POST", api_path, params, self.request, "get api channel list", "data.apis")
    if data is None:
        data = {}
        data['apis'] = []
    return data
Пример #14
0
    def delete_client_channel_scope(self, params, client_id):
        api_path = api_settings.GET_CLIENT_CHANNEL_GATEWAY_SCOPE_LIST_API.format(
            client_id=client_id)

        success, status_code, status_message, data = RestfulHelper.send(
            "DELETE", api_path, params, self.request,
            "deleting client channel gateway scopes")
        return success
Пример #15
0
def get_service_list(self, params):
    api_path = api_settings.GET_CHANNEL_SERVICE

    success, status_code, status_message, data = RestfulHelper.send("POST", api_path, params, self.request, "get service list", "data.services")
    if success:
        return data['services']
    else:
        return []
Пример #16
0
 def _get_all_scopes_list(self):
     url = api_settings.ALL_SCOPES_LIST_URL
     success, status_code, status_message, data = RestfulHelper.send(
         "GET", url, {}, self.request, "get api gateway list", "data.apis")
     if data is None:
         data = {}
         data['apis'] = []
     return data.get('apis', [])
Пример #17
0
 def _get_client_scopes(self, client_id):
     url = api_settings.CLIENT_SCOPES.format(client_id=client_id)
     success, status_code, status_message, data = RestfulHelper.send(
         "GET", url, {}, self.request, "get client scopes api gateway list",
         "data.scopes")
     if data is None:
         data = {}
         data['scopes'] = []
     return data.get('scopes', [])
Пример #18
0
    def get_services_list(self, params):
        url = SEARCH_SERVICE
        success, status_code, status_message, data = RestfulHelper.send(
            "POST", url, params, self.request, "searching service",
            "data.services")

        if not success:
            messages.add_message(self.request, messages.ERROR, status_message)
        return success, data
Пример #19
0
def get_payment_decimal(request):
    success, status_code, message, data = RestfulHelper.send(
        method='GET',
        url=api_settings.PAYMENT_DECIMAL,
        params={},
        request=request,
        description='getting payment decimal',
    )

    return data
Пример #20
0
 def __delete_action_limit(self, campaign_id: int, mechanic_id: int,
                           action_id: int, action_limit_id: int) -> tuple:
     url = api_settings.DELETE_LIMITATION.format(
         rule_id=campaign_id,
         mechanic_id=mechanic_id,
         action_id=action_id,
         action_limit_id=action_limit_id)
     is_success, status_code, status_message, data = RestfulHelper.send(
         'DELETE', url, {}, self.request, 'Delete action limit')
     return is_success, status_message
Пример #21
0
    def _get_all_channel_gateway_scopes_list(self, client_id):
        api_path = api_settings.GET_CLIENT_CHANNEL_GATEWAY_SCOPE_LIST_API.format(
            client_id=client_id)

        success, status_code, status_message, data = RestfulHelper.send(
            "GET", api_path, {}, self.request,
            "getting client channel gateway scopes", "data.scopes")
        if data is None:
            data = {}
            data['scopes'] = []
        return data['scopes']
Пример #22
0
def get_label_levels(request):
    success, status_code, message, data = RestfulHelper.send(
        method='GET',
        url=api_settings.TIER_LEVELS_LIST,
        params={},
        request=request,
        description='getting label levels list',
        log_count_field='data')
    if success:
        request.session['tier_levels'] = data
        return data
    return {}
Пример #23
0
    def post(self, request, *args, **kwargs):
        api_id = int(kwargs['id'])
        api_path = api_settings.DELETE_CHANNEL_API.format(api_id=api_id)
        success, status_code, status_message, data = RestfulHelper.send(
            "DELETE", api_path, {}, self.request, "delete api")

        if success:
            messages.add_message(request, messages.SUCCESS,
                                 'API has been deleted')
            return redirect('channel_gateway_api:list')
        else:
            messages.add_message(request, messages.ERROR, status_message)
            api = get_api_detail(self, api_id)
            context = {"form": api}
            return render(request, self.template_name, context)
Пример #24
0
def get_currency_by_service_id(request, service_id):
    currency = request.session.get('{}_currency'.format(service_id))
    if currency:
        return currency

    success, status_code, message, data = RestfulHelper.send(
        method='GET',
        url=api_settings.SERVICE_DETAIL_URL.format(service_id),
        params={},
        request=request,
        description='getting service currency',
    )

    currency = data.get('currency') if data else ''
    request.session['{}_currency'.format(service_id)] = currency
    return currency
Пример #25
0
    def post(self, request, *args, **kwargs):
        services_id = int(kwargs['id'])
        api_path = api_settings.DELETE_CHANNEL_SERVICE.format(
            service_id=services_id)
        success, status_code, status_message, data = RestfulHelper.send(
            "DELETE", api_path, {}, self.request, "delete service")

        if success:
            messages.add_message(request, messages.SUCCESS,
                                 'Service has been deleted')
            return redirect('channel_gateway_service:list')
        else:
            messages.add_message(request, messages.ERROR, status_message)
            services = self.get_service_detail(services_id)
            context = {"form": services}
            return render(request, self.template_name, context)
Пример #26
0
    def get_service_group_list(self):
        url = SERVICE_GROUP_LIST_URL
        success, status_code, status_message, data = RestfulHelper.send(
            "GET", url, {}, self.request, "getting service groups", "data")
        is_permission_detail = check_permissions_by_user(
            self.request.user, 'CAN_VIEW_SERVICE_GROUP')
        is_permission_edit = check_permissions_by_user(
            self.request.user, 'CAN_EDIT_SERVICE_GROUP')
        is_permission_delete = check_permissions_by_user(
            self.request.user, 'CAN_DELETE_SERVICE_GROUP')

        if success:
            for i in data:
                i['is_permission_detail'] = is_permission_detail
                i['is_permission_edit'] = is_permission_edit
                i['is_permission_delete'] = is_permission_delete
        return data
Пример #27
0
def get_api_detail(self, api_id):
    url = api_settings.GET_CHANNEL_API
    params = {
        "id": api_id
    }
    is_success, status_code, status_message, data = RestfulHelper.send("POST", url, params, self.request,
                                                                       "get api detail")
    if is_success:
        data = data["apis"][0]
        if 'service' in data:
            data['service_id'] = data['service']['id']
        if 'is_required_access_token' in data:
            if data['is_required_access_token'] == True:
                data['require_access_token'] = "1"
            else:
                data['require_access_token'] = "0"
        return data
    else:
        return {}
Пример #28
0
    def post(self, request, *args, **kwargs):
        context = super(TierLevelEdit, self).get_context_data(**kwargs)
        lvl_id = kwargs.get('level_id')
        form = request.POST

        success, status_code, message, data = RestfulHelper.send(
            method='PUT',
            url=api_settings.TIER_LEVELS_EDIT.format(tier_level_id=lvl_id),
            params={'label': form['label']},
            request=request,
            description='updating label level',
        )

        if success:
            messages.add_message(request, messages.SUCCESS,
                                 'Label successfully updated')
            return redirect('services:tier_label_list')
        else:
            context['form'] = form
            messages.add_message(request, messages.ERROR, message)
            return render(request, self.template_name, context=context)
Пример #29
0
    def post(self, request, *args, **kwargs):
        api_id = int(kwargs['id'])
        url = api_settings.EDIT_CHANNEL_API.format(api_id=api_id)
        form = request.POST
        params = {}

        if form.get('name'):
            params['name'] = form['name']

        if form.get('http_method'):
            params['http_method'] = form['http_method']

        if form.get('pattern'):
            params['pattern'] = form['pattern']

        if form.get('service_id'):
            params['service_id'] = int(form['service_id'])

        if form.get('require_access_token'):
            params['is_required_access_token'] = True if form[
                'require_access_token'] == '1' else False

        success, status_code, status_message, data = RestfulHelper.send(
            "PUT", url, params, self.request, "Update API")

        if success:
            messages.add_message(request, messages.SUCCESS,
                                 'API has been edited')
            return redirect('channel_gateway_api:list')
        else:
            body_res = {'is_deleted': False, 'paging': False}
            service_list = get_service_list(self, body_res)
            messages.add_message(request, messages.ERROR, status_message)
            return render(request,
                          self.template_name,
                          context={
                              'form': form,
                              'service_list': service_list
                          })
Пример #30
0
 def get_mechanic(self, campaign_id, mechanic_id):
     url = api_settings.GET_MECHANIC_DETAIL.format(bak_rule_id=campaign_id,
                                                   mechanic_id=mechanic_id)
     success, status_code, status_message, data = RestfulHelper.send(
         "GET", url, {}, self.request, "getting mechanic detail")
     return success, data