adding file env for download

This commit is contained in:
Cayo Puigdefabregas 2021-03-02 11:42:07 +01:00
parent adb9a8e25a
commit 0d0005b315
3 changed files with 40 additions and 8 deletions

View File

@ -1,7 +1,8 @@
import csv
import datetime
import enum
import uuid
import datetime
import pathlib
from collections import OrderedDict
from io import StringIO
from typing import Callable, Iterable, Tuple
@ -291,10 +292,24 @@ class InternalStatsView(DeviceView):
output.headers['Content-type'] = 'text/csv'
return output
class WbConfDocumentView(DeviceView):
class WbConfDocumentView(View):
def get(self, wbtype: str):
if not wbtype.lower() in ['usodyrate', 'usodywipe']:
return jsonify('')
data = {'token': '111',
'host': 'localhost',
'inventory': 'dbtest'
}
data['erase'] = False if wbtype == 'usodyrate' else True
env = flask.render_template('documents/env', **data)
output = make_response(env)
output.headers['Content-Disposition'] = 'attachment; filename=.env'
output.headers['Content-type'] = 'text/plain'
return output
class DocumentDef(Resource):
__type__ = 'Document'
@ -363,8 +378,8 @@ class DocumentDef(Resource):
actions_view = app.auth.requires_auth(actions_view)
self.add_url_rule('/actions/', defaults=d, view_func=actions_view, methods=get)
wbconf_view = ActionsDocumentView.as_view('WbConfDocumentView',
wbconf_view = WbConfDocumentView.as_view('WbConfDocumentView',
definition=self,
auth=app.auth)
wbconf_view = app.auth.requires_auth(wbconf_view)
self.add_url_rule('/wbconf/', defaults=d, view_func=wbconf_view, methods=get)
self.add_url_rule('/wbconf/<string:wbtype>', view_func=wbconf_view, methods=get)

View File

@ -0,0 +1,14 @@
DH_TOKEN='{{token}}'
DH_HOST='{{host}}'
DH_INVENTORY='{{inventory}}'
DEVICEHUB_URL=https://${DB_HOST}/${DB_INVENTORY}/
WB_BENCHMARK = True
WB_STRESS_TEST = 0
WB_SMART_TEST = 'short'
WB_ERASE = {{erase}}
WB_ERASE_STEPS = 1
WB_ERASE_LEADING_ZEROS = False
WB_DEBUG = True

View File

@ -495,5 +495,8 @@ def test_get_document_internal_stats(user: UserClient, user2: UserClient):
def test_get_wbconf(user: UserClient):
"""Tests for get env file for usb wb."""
csv_str, _ = user.get(res=documents.DocumentDef.t,
item='wbconf/')
env, _ = user.get(res=documents.DocumentDef.t, item='wbconf/usodyrate', accept=ANY)
assert 'WB_ERASE = False' in env
env, _ = user.get(res=documents.DocumentDef.t, item='wbconf/usodywipe', accept=ANY)
assert 'WB_ERASE = True' in env