def test_create(self): cn = 'testuser' create_result = GitHubUser.create('testuser', sn='testsn') user = GitHubUser.first(cn) assert create_result == True assert isinstance(user, User) assert isinstance(user.token, str)
def paypal_event(): LOG.info(f"Incoming PayPal Event: {request.get_json()}") event = PayPalEvent(**request.get_json(force=True)) LOG.debug(event) user = GitHubUser.find(email=event.email) if user: user.balance += event.amount if GitHubUser.update(user): # if GitHubUser.update(user, balance=user.balance + event.amount): LOG.debug("Paypal update succeeded") return {"message": "OK"}, 200 return '{"message": "unknown error"}', 500
def render_github_url(path): LOG.debug("REQUEST /github: {path}") # BUG: don't want to require owner to load first. or do you? org, project, branch, *tail = path.split('/') path = join(*tail) path = path[:len(path)-4] token = None repo = GitHubRepo.first_repo(org, project) if repo and repo.has_owner: if repo.requires_token and \ repo.token is not None and \ repo.token != request.args.get('token'): return '{"message": "Unauthorized. Provide repo `token` param"}', 401 owner = GitHubUser.first(repo.owner) token = owner.git_token try: LOG.debug(f"fetching {org}, {project}, {path}") body = GitContent(token).get(org, project, path) return render(body) except GithubException as err: LOG.error(err) return "Not Found.", 404
def get_me(): """ returns User object""" token = request.cookies.get(PT_SESSION_TOKEN) if token is not None: user = GitHubUser.find(token=token) if user: return user[0]
def get_creds(org, project): """ returns a user object fully hydrated, or from passed token or from default config """ token = request.args.get('token') creds = User(git_token=[token], name='RequestToken') if token is None: creds = User(git_token=[GITHUB_TOKEN], name='GITHUB_TOKEN') if using_ldap(): repo = GitHubRepo.first(org, project) if is_allowed(repo, token): log.debug(f"Authenticated as {repo.owner}") owner = GitHubUser.first(repo.owner) creds = owner return creds
def render_url(path): LOG.debug("REQUEST /root: {path}") org, project, branch, *tail = path.split('/') path = '/'.join(tail) path = path[:len(path) - 4] token = None repo = GitHubRepo.first_repo(org, project) if repo and repo.has_owner: if repo.requires_token and \ repo.token is not None and \ repo.token != request.args.get('token'): return '{"message": "Unauthorized. Provide repo `token` param"}', 401 owner = GitHubUser.first(repo.owner) token = owner.git_token try: body = GitContent(token).get(org, project, path) return render(body) except GithubException as err: LOG.error(err) return "Not Found.", 404
def test_create_on_user(self): user = GitHubUser.create('bob', sn='bob') results = GitHubRepo.create('bob', 'private5', base_dn='cn=bob') assert results == True
def credit(user, amt): user.pays(amt) GitHubUser(user).pays()
from base64 import b64decode from github import Github from config import ( GITHUB_CLIENT_ID, GITHUB_SECRET, LDAP_HOST, DEFAULT_USER, DEFAULT_TOKEN ) from point.models import GitHubUser # TODO token could be passed by config if LDAP_HOST is not None: DEFAULT_USER = GitHubUser.first(DEFAULT_USER) if DEFAULT_USER: DEFAULT_TOKEN = DEFAULT_USER.git_token class GitContent: def __init__(self, creds=None): if hasattr(creds, 'git_token'): creds = creds.git_token elif DEFAULT_TOKEN: creds = DEFAULT_TOKEN self.github = Github(login_or_token=creds, client_id=GITHUB_CLIENT_ID, client_secret=GITHUB_SECRET) def get(self, owner, repo, branch, path): repo = self.github.get_repo(f'{owner}/{repo}', lazy=False) return b64decode(repo.get_contents(path, ref=branch).content).decode('utf-8') def owner(self, owner, repo):
def test_delete(self): testuser = GitHubUser.first('testuser') assert GitHubUser.delete(testuser)
def test_first(self): results = GitHubUser.first('trevorgrayson') assert results.name == 'trevorgrayson'