Skip to content

Commit 55b43cc

Browse files
committed
update
1 parent a01d731 commit 55b43cc

File tree

6 files changed

+57
-18
lines changed

6 files changed

+57
-18
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ localconfig.py
2525
.whoosh
2626

2727
docs/code
28+
src/pyff/web
29+
MANIFEST

npm_modules.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@sunet/mdq-browser@1.0.2
2+
@theidentityselector/thiss@1.5.0-dev0

setup.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,33 @@
22
# -*- encoding: utf-8 -*-
33

44
from distutils.core import setup
5+
from distutils.command.sdist import sdist
6+
from distutils.dir_util import copy_tree
57
from pathlib import PurePath
68
from platform import python_implementation
79
from typing import List
8-
10+
from tempfile import TemporaryDirectory
911
from setuptools import find_packages
1012

1113
__author__ = 'Leif Johansson'
12-
__version__ = '2.0.0'
14+
__version__ = '2.1.0dev0'
15+
16+
17+
class NPMSdist(sdist):
18+
def run(self):
19+
import subprocess
20+
21+
npm_modules = load_requirements(here.with_name('npm_modules.txt'))
22+
with TemporaryDirectory() as tmp:
23+
for npm_module in npm_modules:
24+
subprocess.check_call(['npm', 'install', '--production', '--prefix', tmp, npm_module])
25+
for npm_module in npm_modules:
26+
(npm_module_path, _, _) = npm_module.rpartition('@')
27+
copy_tree(
28+
"{}/node_modules/{}/dist".format(tmp, npm_module_path), './src/pyff/web/{}'.format(npm_module_path)
29+
)
30+
31+
super().run()
1332

1433

1534
def load_requirements(path: PurePath) -> List[str]:
@@ -37,6 +56,7 @@ def load_requirements(path: PurePath) -> List[str]:
3756

3857
setup(
3958
name='pyFF',
59+
cmdclass={'sdist': NPMSdist},
4060
version=__version__,
4161
description="Federation Feeder",
4262
long_description=README + '\n\n' + NEWS,
@@ -55,7 +75,7 @@ def load_requirements(path: PurePath) -> List[str]:
5575
packages=find_packages('src'),
5676
package_dir={'': 'src'},
5777
include_package_data=True,
58-
package_data={'pyff': ['xslt/*.xsl', 'schema/*.xsd']},
78+
package_data={'pyff': ['xslt/*.xsl', 'schema/*.xsd', 'web/**/*']},
5979
zip_safe=False,
6080
install_requires=install_requires,
6181
scripts=['scripts/mirror-mdq.sh'],
@@ -64,6 +84,11 @@ def load_requirements(path: PurePath) -> List[str]:
6484
'paste.app_factory': ['pyffapp=pyff.wsgi:app_factory'],
6585
'paste.server_runner': ['pyffs=pyff.wsgi:server_runner'],
6686
},
67-
message_extractors={'src': [('**.py', 'python', None), ('**/templates/**.html', 'mako', None),]},
87+
message_extractors={
88+
'src': [
89+
('**.py', 'python', None),
90+
('**/templates/**.html', 'mako', None),
91+
]
92+
},
6893
python_requires='>=3.7',
6994
)

src/pyff/api.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from pyramid.events import NewRequest
1616
from pyramid.request import Request
1717
from pyramid.response import Response
18-
from pyramid.static import static_view
1918
from six import b
2019
from six.moves.urllib_parse import quote_plus
2120

@@ -26,7 +25,7 @@
2625
from pyff.repo import MDRepository
2726
from pyff.resource import Resource
2827
from pyff.samlmd import entity_display_name
29-
from pyff.utils import b2u, dumptree, hash_id, json_serializer, utc_now, FrontendApp
28+
from pyff.utils import b2u, dumptree, hash_id, json_serializer, utc_now, FrontendApp, resource_filename
3029

3130
log = get_log(__name__)
3231

@@ -64,6 +63,7 @@ def json_response(data) -> Response:
6463
response.headers['Content-Type'] = 'application/json'
6564
return response
6665

66+
6767
def status_handler(request: Request) -> Response:
6868
"""
6969
Implements the /api/status endpoint
@@ -572,17 +572,22 @@ def mkapp(*args: Any, **kwargs: Any) -> Any:
572572
ctx.add_route('call', '/api/call/{entry}', request_method=['POST', 'PUT'])
573573
ctx.add_view(process_handler, route_name='call')
574574

575-
if config.mdq_browser or config.thiss:
575+
if config.mdq_browser is not None or config.thiss is not None:
576576
ctx.add_route_predicate('ext', ExtensionPredicate)
577577

578+
if config.mdq_browser is not None and len(config.mdq_browser) == 0:
579+
config.mdq_browser = resource_filename('web/@sunet/mdq-browser')
580+
578581
if config.mdq_browser:
579-
os.environ['MDQ_URL'] = config.base_url + "/entities/"
580-
FrontendApp.load(config.mdq_browser).add_route(ctx)
582+
log.debug("serving mdq-browser from {}".format(config.mdq_browser))
583+
FrontendApp.load('/', 'mdq_browser', config.mdq_browser).add_route(ctx)
584+
585+
if config.thiss is not None and len(config.thiss) == 0:
586+
config.thiss = resource_filename('web/@theidentityselector/thiss')
581587

582588
if config.thiss:
583-
os.environ['BASE_URL'] = config.base_url
584-
os.environ['STORAGE_DOMAIN'] = config.host # TODO - make this configurable or grab from base_url
585-
FrontendApp.load(config.thiss).add_route(ctx)
589+
log.debug("serving thiss from {}".format(config.thiss))
590+
FrontendApp.load('/thiss/', 'thiss', config.thiss).add_route(ctx)
586591

587592
ctx.add_route('request', '/*path', request_method='GET')
588593
ctx.add_view(request_handler, route_name='request')

src/pyff/resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def local_copy_fn(self):
264264

265265
@property
266266
def post(
267-
self,
267+
self,
268268
) -> Iterable[Callable]: # TODO: move classes to make this work -> List[Union['Lambda', 'PipelineCallback']]:
269269
return self.opts.via
270270

src/pyff/utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
This module contains various utilities.
77
88
"""
9+
from __future__ import annotations
10+
911
import base64
1012
import cgi
1113
import contextlib
@@ -51,6 +53,8 @@
5153
from pyff.logs import get_log
5254

5355
from pydantic import BaseModel
56+
from pyramid.static import static_view
57+
5458

5559
etree.set_default_parser(etree.XMLParser(resolve_entities=False))
5660

@@ -985,14 +989,15 @@ def utc_now() -> datetime:
985989

986990

987991
class FrontendApp(BaseModel):
992+
url_path: str
988993
name: str
989994
directory: str
990995
dirs: List[str] = []
991-
exts: Set[str] = []
996+
exts: Set[str] = set()
992997

993998
@staticmethod
994-
def load(name: str, directory: str) -> FrontendApp:
995-
fa = FrontendApp(name=name, directory=directory)
999+
def load(url_path: str, name: str, directory: str) -> FrontendApp:
1000+
fa = FrontendApp(url_path=url_path, name=name, directory=directory)
9961001
with os.scandir(fa.directory) as it:
9971002
for entry in it:
9981003
if not entry.name.startswith('.'):
@@ -1004,13 +1009,13 @@ def load(name: str, directory: str) -> FrontendApp:
10041009
return fa
10051010

10061011
def add_route(self, ctx):
1007-
for uri_part in ["/"] + [d + "/" for d in self.dirs]:
1012+
for uri_part in [self.url_path] + [self.url_path + d + "/" for d in self.dirs]:
10081013
route = '{}_{}'.format(self.name, uri_part)
10091014
path = '{:s}{{sep:/?}}{{path:.*}}'.format(uri_part)
10101015
ctx.add_route(
10111016
route,
10121017
path,
10131018
request_method='GET',
1014-
ext=['path'] + self.exts,
1019+
ext=['path'] + list(self.exts),
10151020
)
10161021
ctx.add_view(static_view(self.directory, use_subpath=False), route_name=route)

0 commit comments

Comments
 (0)