def test_gitea_repository(client, auth, app): # test if user is not logged auth.auth_protected("/settings/gitea/repository", data={ "gitea_url": "fff", "gitea_owner": "fff", "gitea_repository": "fff" }, method='post') auth.login() # test that successful gitea configuration were edit response = client.post("/settings/gitea/repository", data={ "gitea_url": "fff", "gitea_owner": "fff", "gitea_repository": "fff" }, follow_redirects=True) assert gettext('Repository configuration saved.').encode( 'utf-8') in response.data with app.app_context(): gitea = get_gitea() assert gitea['url'] == "fff" assert gitea['owner'] == "fff" assert gitea['repository'] == "fff"
def index(): user = get_user(user_id=session.get('user_id')) gitea_user = None error = False if user['gitea_token']: try: gitea_user = GiteaAPI(user['gitea_token']).user_get_current().json() except (requests.exceptions.RequestException, GiteaAPIError, JSONDecodeError) as e: error = True flash(gettext(u'Error something went wrong.'), 'fail') current_app.logger.error(f"{e}") return render_template('settings/index.html', gitea_user=gitea_user, gitea=get_gitea(), api_key=user['api_key'], error=error, isLogged=True)
def index(): if request.method == 'POST': hostname = request.form.get('hostname') module = request.form.get('module') action = request.form.get('action') path = request.form.get('path') error = None if not hostname: error = gettext(u'Hostname is required.') elif not module: error = gettext(u'Module is required.') elif action not in ['save', 'restore']: error = gettext(u'Action is required.') elif not path: error = gettext(u'Path is required.') if error: flash(error, 'fail') return redirect(url_for('tasks.index')) if path[0] == '/': path = path[1:] user = get_user(user_id=session.get('user_id')) gitea = get_gitea() id = create_task(hostname, module, action, path, datetime.now(timezone.utc)) rabbit = RabbitMQ() rabbit.create_task( { 'id': id, 'gitea': { 'token': user['gitea_token'], 'url': gitea['url'], 'owner': gitea['owner'], 'repository': gitea['repository'], }, 'hostname': hostname, 'module': module, 'action': action, 'path': path, }, id) return redirect(url_for('tasks.task', id=id)) else: return render_template('tasks/index.html', isLogged=True)
def index(): ref = request.args.get('ref', 'master') path = request.args.get('path', '') user = get_user(user_id=session.get('user_id')) gitea = get_gitea() repo_contents = None commits = None error = False folder = False try: commits = GiteaAPI(user['gitea_token']).repo_get_commits().json() if not path: req = GiteaAPI(user['gitea_token']).repo_get_contents_list( {'ref': ref}) else: req = GiteaAPI(user['gitea_token']).repo_get_contents( path, {'ref': ref}) except (requests.exceptions.RequestException, GiteaAPIError) as e: flash(gettext(u'Error cannot get configuration files from Gitea.'), 'fail') error = True current_app.logger.error(f"{e}") return redirect(url_for( 'docs.index')) if ref == 'master' and path == '' else redirect( url_for('configuration_files.index')) else: repo_contents = req.json() folder = isinstance(repo_contents, list) if not folder: try: repo_contents['content'] = b64decode( repo_contents['content']).decode('utf-8') except UnicodeDecodeError: flash(gettext(u'Cannot read this type of file.'), 'fail') return redirect(url_for('configuration_files.index')) return render_template('configuration_files/index.html', folder=folder, gitea=gitea, repo_contents=repo_contents, commits=commits, ref=ref, error=error, isLogged=True)
def __init__(self, token=""): gitea = get_gitea() self.url = gitea['url'] self.owner = gitea['owner'] self.repository = gitea['repository'] self.token = token
def post(self): """ Create one task --- tags: - Tasks parameters: - name: task in: body description: The task to create required: true schema: required: - hostname - module - action - path properties: hostname: type: string example: 192.168.0.1 module: type: string example: pfsense action: type: string enum: [save, restore] example: save path: type: string example: /pfsense/backup12.zip responses: 201: description: Task created examples: task_1: { 'id': 1 } task_2: { 'id': 2 } 400: description: Task not created """ args = tasks_parser.parse_args() if not args.hostname or not args.module or args.action not in ['save', 'restore'] or not args.path: return {"message": gettext(u'ERROR: Bad Request')}, 400 else: api_key = request.headers.get("X-Api-Key") if api_key is None: user = get_user(user_id=session.get('user_id')) else: user = get_user(api_key=api_key) if args.path[0] == '/': args.path = args.path[1:] gitea = get_gitea() id = create_task(args.hostname, args.module, args.action, args.path, datetime.now(timezone.utc)) rabbit = RabbitMQ() rabbit.create_task({ 'id': id, 'gitea': { 'token': user['gitea_token'], 'url': gitea['url'], 'owner': gitea['owner'], 'repository': gitea['repository'], }, 'hostname': args.hostname, 'module': args.module, 'action': args.action, 'path': args.path, }, id) return {'id': id}, 201