Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr autoattach #1

Merged
merged 9 commits into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions knowledge_repo/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ def format_date(date):
except:
return date

def append_repo(self,name,uri):
temp = self.repository
self.repository = knowledge_repo.KnowledgeRepository.append_for_uri(name,uri,temp)
self.db_update_index(check_timeouts=False, force=True, reindex=True)
return self.repository

@property
def repository(self):
return getattr(self, '_repository')
Expand Down
10 changes: 6 additions & 4 deletions knowledge_repo/app/auth_providers/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,17 @@ def extract_from_dict(d, key):
if isinstance(key, (list, tuple)):
if len(key) == 1:
key = key[0]
else:
return extract_from_dict(d[key[0]], key[1:])
if isinstance(key, six.string_types):
elif d[key[0]] is None:
return extract_from_dict(d, key[1:])
else:
return extract_from_dict(d, key[0])
if isinstance(key, str):
return d[key]
raise RuntimeError("Invalid key type: {}.".format(key))

response = self.oauth_client.get(self.get_endpoint_url(self.user_info_endpoint), verify=self.verify_ssl_certs)
try:
response_dict = json.loads(response.content)
response_dict = json.loads(request.content.decode('utf-8'))
identifier = extract_from_dict(response_dict, self.user_info_mapping['identifier'])
if identifier is None:
raise ValueError("identifier '{}' not found in authentication response".format(self.user_info_mapping['identifier']))
Expand Down
8 changes: 8 additions & 0 deletions knowledge_repo/app/routes/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def render_index():
return redirect('/feed')


@blueprint.route('/testupload')
@PageView.logged
def test_upload():
global current_repo
repo = current_app.append_repo("3","kr-test")
current_repo = repo
return redirect('/feed')

@blueprint.route('/favorites')
@PageView.logged
@login_required
Expand Down
8 changes: 8 additions & 0 deletions knowledge_repo/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ def for_uris(cls, uri):
krs = {name: cls.for_uri(uri) for name, uri in list(uris.items())}
return MetaKnowledgeRepository(krs)

@classmethod
def append_for_uri(cls,name,uri,meta_repo):
from .repositories.meta import MetaKnowledgeRepository
krs = meta_repo.uri
krs[name] = cls.for_uri(uri)
meta_repo = MetaKnowledgeRepository(krs)
return meta_repo

@classmethod
def from_uri(cls, url, *args, **kwargs):
return cls(url, *args, **kwargs)
Expand Down
9 changes: 8 additions & 1 deletion scripts/knowledge_repo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
from __future__ import print_function
from __future__ import unicode_literals

Expand Down Expand Up @@ -42,6 +42,13 @@ if os.path.exists(os.path.join(contrib_dir, '__init__.py')):
# we finish constructing the entire parser so that the syntax and arguments can change
# from version to version of this script.

# Repeating what the argparse already does
def parse_repo_string(repo_str):
prefix_pattern = re.compile('^(?:\{(?P<name>[a-zA-Z_0-9]*)\})?(?P<uri>.*)$')

prefix = prefix_pattern.match(repo_str)
return prefix.groups()

class ParseRepositories(argparse.Action):

def __init__(self, **kwargs):
Expand Down