add file param

This commit is contained in:
Dmitry Belyaev 2021-09-22 12:46:18 +03:00
parent d289a41e4d
commit d37db9fb86
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -115,10 +115,10 @@ class WebPub1C:
return publication_data(publication)
def add(self, ibname: str, url: Optional[str] = None) -> str:
def add(self, ibname: str, url: Optional[str] = None, file: str = '') -> str:
""" Add new publication """
publication = self._apache_cfg.create_publication(ibname, url)
publication = self._apache_cfg.create_publication(ibname, url, file)
self._apache_cfg.add_publication(publication)
self._log.info(f'publication added: {ibname}')
return publication.url_path
@ -145,9 +145,11 @@ class WebPub1C:
pub_parser = reqparse.RequestParser()
pub_parser.add_argument('name', required=True, type=str, help='name required')
pub_parser.add_argument('url', type=str)
pub_parser.add_argument('file', type=str)
url_parser = reqparse.RequestParser()
url_parser.add_argument('url', type=str)
url_parser.add_argument('file', type=str)
url_req_parser = reqparse.RequestParser()
url_req_parser.add_argument('url', type=str, required=True)
@ -234,7 +236,7 @@ class Publications(Resource):
if args.name in webpub.list():
abort(409, message=f'publication exists: {args.name}')
try:
url = webpub.add(args.name, url)
url = webpub.add(args.name, url, args.file)
except Exception as e:
abort(422, message=f'publication failed: {args.name}', traceback=traceback.format_exc())
return {'message': 'created', 'name': args.name, 'url': url}, 201
@ -257,7 +259,7 @@ class Publication(Resource):
if name in webpub.list():
abort(409, message=f'publication exists: {name}')
try:
url = webpub.add(name, url)
url = webpub.add(name, url, args.file)
except Exception as e:
abort(422, message=f'publication failed: {name}', traceback=traceback.format_exc())
return {'message': 'created', 'name': name, 'url': url}, 201