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
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
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})
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
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
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
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
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
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
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]
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
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
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
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 []
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', [])
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', [])
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
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
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
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']
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 {}
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)
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
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)
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
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 {}
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)
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 })
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