<commit_before>from logging import getLogger
from ckan.lib.base import request, BaseController, abort, json

import json
import pylons.config as config

log = getLogger(__name__)

class Resource_fileController(BaseController):

	def create_file(self,file_route,received_data):

		file = open(file_route, "w")
		file.truncate()
		file.write(received_data)    
		file.close()

	def validate_json(self,received_data):

		try:
			json_object = json.loads(received_data)
		except ValueError, e:
			return False
		return True

	def change_persisted_file(self):

		if not request.body:
			abort(405, 'No data POST')

		content_type = request.headers.get('Content-Type', '')

		if not content_type.startswith('application/json'):
			abort(415, 'Content-Type should be "application/json"')

		received_data=request.body;

		file_route = config.get('ckan.storage_file.route_file') 

		json_validate = self.validate_json(received_data)

		if json_validate:
			self.create_file(file_route,received_data)
		else:
			abort(400, 'Wrong Syntax')
		<commit_msg>Security<commit_after>from logging import getLogger
from ckan.lib.base import request, BaseController, abort, json, c
from ckan.plugins import toolkit

import ckan.logic as logic
import ckan.plugins as p
import json
import pylons.config as config
import ckan.model as model
import ckan.logic


log = getLogger(__name__)

class Resource_fileController(BaseController):

	def create_file(self,file_route,received_data):

		file = open(file_route, "w")
		file.truncate()
		file.write(received_data)    
		file.close()

	def validate_json(self,received_data):

		try:
			json_object = json.loads(received_data)
		except ValueError, e:
			return False
		return True

	def change_persisted_file(self):

		if not request.method == 'POST':
			abort(405, 'Method not allowed')

		if not c.userobj:
			abort(401, 'Forbidden, need user login')

		if not c.userobj.sysadmin:
			abort(401, 'Forbidden, need API-Key')

		if not request.body:
			abort(400, 'No body data received')

		content_type = request.headers.get('Content-Type', '')

		if not content_type.startswith('application/json'):
			abort(415, 'Content-Type should be "application/json"')

		received_data=request.body

		file_route = config.get('ckan.storage_file.route_file') 

		json_validate = self.validate_json(received_data)

		if json_validate:
			self.create_file(file_route,received_data)
		else:
			abort(400, 'Wrong Syntax')
{'fraction_non_alphanumeric': 0.1037037037037037, 'fraction_numerical': 0.011111111111111112, 'mean_word_length': 4.829736211031175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6520283', 'n_tokens_mistral': 909, 'n_tokens_neox': 792, 'n_words': 187}