Exemplo n.º 1
0
def repo_delete(owner, repo):
    me = get_me()

    repo = GitHubRepo.first_repo(owner, repo)
    if repo.owner == me.name:
        GitHubRepo.delete(repo.dn)  # raises
        return '{"message": "OK"}'
    else:
        return '{"message": "unauthorized"}', 401
Exemplo n.º 2
0
def index():
    me = get_me()
    if me:
        repos = GitHubRepo.of(me.name)
        return fmt(list(map(lambda r: r.as_json, repos)))
    else:
        return fmt({'message': 'unavailable'}), 401
Exemplo n.º 3
0
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
Exemplo n.º 4
0
 def test_repos_of(self):
     results = GitHubRepo.of('trevorgrayson')
     assert results != []
     assert len(results) > 1
     result = results[0]
     assert result.name == 'private'
     assert result.label == 'trevorgrayson/private'
Exemplo n.º 5
0
def create():
    me = get_me()
    repo = request.form.get('repo')
    if repo:
        repo = repo.split('/')
    else:
        raise Exception("github `repo` variable required.")

    base_dn = GitHubRepo.create(*repo, base_dn=f'cn={me.cn}')
    if base_dn:
        return fmt({"message": "OK"})
Exemplo n.º 6
0
def repo_claim():
    """ create repo, under a username """
    me = get_me()
    repo = request.form.get('repo')

    if repo:
        repo = repo.split('/')
    else:
        raise Exception("github `repo` variable required.")

    base_dn = GitHubRepo.create(*repo, base_dn=f'cn={me.cn}')
    response = make_response(redirect('/repos'))
    return response
Exemplo n.º 7
0
def create():
    me = get_me()
    content_client = GitContent(me)
    repo = request.form.get('repo')
    dry_run = request.form.get("dry_run") == "true"
    if repo:
        repo = repo.split('/')
    else:
        raise Exception("github `repo` variable required.")

    owner = content_client.owner(repo[0], repo[1])
    if not owner:
        return fmt({"message": "not found"}), 404

    if not dry_run:
        base_dn = GitHubRepo.create(*repo, base_dn=f'cn={me.cn}')
        if base_dn:
            return fmt({"message": "OK"})
    else:
        return {"owner": owner}, 4
Exemplo n.º 8
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
Exemplo n.º 9
0
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
Exemplo n.º 10
0
    def test_create_on_user(self):
        user = GitHubUser.create('bob', sn='bob')
        results = GitHubRepo.create('bob', 'private5', base_dn='cn=bob')

        assert results == True
Exemplo n.º 11
0
    def test_create(self):
        results = GitHubRepo.create('trevorgrayson', 'private3')

        assert results == True
Exemplo n.º 12
0
 def test_search(self):
     results = GitHubRepo.search('private3')
     print(results)
Exemplo n.º 13
0
 def test_repo_owner(self):
     repo = GitHubRepo.first_repo('trevorgrayson', 'private')
     assert repo.owner == 'trevorgrayson'