-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from kbaseapps/dev-fix_build_and_upgrade
Fix build and upgrade to 5.2.0
- Loading branch information
Showing
12 changed files
with
200 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
test_local | ||
sdk.cfg | ||
/.project | ||
/.pydevproject | ||
/.settings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
|
||
# TODO may want to make the image an env var or argument | ||
|
||
# See https://github.com/kbaseapps/kb_sdk_actions/blob/master/bin/kb-sdk for source | ||
|
||
# Cache the group for the docker file | ||
if [ ! -e $HOME/.kbsdk.cache ] ; then | ||
docker run -i -v /var/run/docker.sock:/var/run/docker.sock --entrypoint ls ghcr.io/kbase/kb_sdk_patch-develop:br-0.0.4 -l /var/run/docker.sock|awk '{print $4}' > $HOME/.kbsdk.cache | ||
fi | ||
|
||
exec docker run -i --rm -v $HOME:$HOME -w $(pwd) -v /var/run/docker.sock:/var/run/docker.sock -e DSHELL=$SHELL --group-add $(cat $HOME/.kbsdk.cache) ghcr.io/kbase/kb_sdk_patch-develop:br-0.0.4 $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
# TODO may want to make the image an env var or argument | ||
|
||
# See https://github.com/kbaseapps/kb_sdk_actions/blob/master/bin/make_testdir for source | ||
|
||
# Disable the default `return 1` when creating `test_local` | ||
set +e | ||
|
||
# Cache the group for the docker file | ||
if [ ! -e $HOME/.kbsdk.cache ] ; then | ||
docker run -i -v /var/run/docker.sock:/var/run/docker.sock --entrypoint ls ghcr.io/kbase/kb_sdk_patch-develop:br-0.0.4 -l /var/run/docker.sock|awk '{print $4}' > $HOME/.kbsdk.cache | ||
fi | ||
|
||
exec docker run -i --rm -v $HOME:$HOME -u $(id -u) -w $(pwd) -v /var/run/docker.sock:/var/run/docker.sock -e DUSER=$USER -e DSHELL=$SHELL --group-add $(cat $HOME/.kbsdk.cache) ghcr.io/kbase/kb_sdk_patch-develop:br-0.0.4 test | ||
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ service-language: | |
python | ||
|
||
module-version: | ||
1.0.0 | ||
1.1.0 | ||
|
||
owners: | ||
[gaprice] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
''' | ||
Created on Aug 1, 2016 | ||
A very basic KBase auth client for the Python server. | ||
@author: [email protected] | ||
''' | ||
import time as _time | ||
import requests as _requests | ||
import threading as _threading | ||
import hashlib | ||
|
||
|
||
class TokenCache(object): | ||
''' A basic cache for tokens. ''' | ||
|
||
_MAX_TIME_SEC = 5 * 60 # 5 min | ||
|
||
_lock = _threading.RLock() | ||
|
||
def __init__(self, maxsize=2000): | ||
self._cache = {} | ||
self._maxsize = maxsize | ||
self._halfmax = maxsize / 2 # int division to round down | ||
|
||
def get_user(self, token): | ||
token = hashlib.sha256(token.encode('utf-8')).hexdigest() | ||
with self._lock: | ||
usertime = self._cache.get(token) | ||
if not usertime: | ||
return None | ||
|
||
user, intime = usertime | ||
if _time.time() - intime > self._MAX_TIME_SEC: | ||
return None | ||
return user | ||
|
||
def add_valid_token(self, token, user): | ||
if not token: | ||
raise ValueError('Must supply token') | ||
if not user: | ||
raise ValueError('Must supply user') | ||
token = hashlib.sha256(token.encode('utf-8')).hexdigest() | ||
with self._lock: | ||
self._cache[token] = [user, _time.time()] | ||
if len(self._cache) > self._maxsize: | ||
sorted_items = sorted( | ||
list(self._cache.items()), | ||
key=(lambda v: v[1][1]) | ||
) | ||
for i, (t, _) in enumerate(sorted_items): | ||
if i <= self._halfmax: | ||
del self._cache[t] | ||
else: | ||
break | ||
|
||
|
||
class KBaseAuth(object): | ||
''' | ||
A very basic KBase auth client for the Python server. | ||
''' | ||
|
||
_LOGIN_URL = 'https://kbase.us/services/auth/api/legacy/KBase/Sessions/Login' | ||
|
||
def __init__(self, auth_url=None): | ||
''' | ||
Constructor | ||
''' | ||
self._authurl = auth_url | ||
if not self._authurl: | ||
self._authurl = self._LOGIN_URL | ||
self._cache = TokenCache() | ||
|
||
def get_user(self, token): | ||
if not token: | ||
raise ValueError('Must supply token') | ||
user = self._cache.get_user(token) | ||
if user: | ||
return user | ||
|
||
d = {'token': token, 'fields': 'user_id'} | ||
ret = _requests.post(self._authurl, data=d) | ||
if not ret.ok: | ||
try: | ||
err = ret.json() | ||
except Exception as e: | ||
ret.raise_for_status() | ||
raise ValueError('Error connecting to auth service: {} {}\n{}' | ||
.format(ret.status_code, ret.reason, | ||
err['error']['message'])) | ||
|
||
user = ret.json()['user_id'] | ||
self._cache.add_valid_token(token, user) | ||
return user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.