예제 #1
0
func (c *client) Perm(u *model.User, owner, repo string) (*model.Perm, error) {
	// TODO need to fetch real permissions here
	perms := new(model.Perm)
	perms.Pull = true
	perms.Admin = true
	perms.Push = true
	return perms, nil
}
예제 #2
0
파일: client.go 프로젝트: sis-tools/drone
func (c *Client) FindRepoPerms(owner string, repo string) (*model.Perm, error) {
	perms := new(model.Perm)
	// If you don't have access return none right away
	_, err := c.FindRepo(owner, repo)
	if err != nil {
		return perms, err
	}
	// Must have admin to be able to list hooks. If have access the enable perms
	_, err = c.client.Get(fmt.Sprintf(pathHook, c.base, owner, repo, hookName))
	if err == nil {
		perms.Push = true
		perms.Admin = true
	}
	perms.Pull = true
	return perms, nil
}
예제 #3
0
func (c *client) Perm(u *model.User, owner, repo string) (*model.Perm, error) {
	client := NewClientWithToken(&c.Consumer, u.Token)
	perms := new(model.Perm)

	// If you don't have access return none right away
	_, err := c.FindRepo(client, owner, repo)
	if err != nil {
		return perms, err
	}

	// Must have admin to be able to list hooks. If have access the enable perms
	_, err = client.Get(fmt.Sprintf("%s/rest/api/1.0/projects/%s/repos/%s/settings/hooks/%s", c.URL, owner, repo, "com.atlassian.stash.plugin.stash-web-post-receive-hooks-plugin:postReceiveHook"))
	if err == nil {
		perms.Push = true
		perms.Admin = true
	}
	perms.Pull = true
	return perms, nil
}
예제 #4
0
// Perm fetches the named repository permissions from
// the remote system for the specified user.
func (bb *Bitbucket) Perm(u *model.User, owner, name string) (*model.Perm, error) {
	token := oauth2.Token{AccessToken: u.Token, RefreshToken: u.Secret}
	client := NewClientToken(bb.Client, bb.Secret, &token)

	perms := new(model.Perm)
	_, err := client.FindRepo(owner, name)
	if err != nil {
		return perms, err
	}

	// if we've gotten this far we know that the user at
	// least has read access to the repository.
	perms.Pull = true

	// if the user has access to the repository hooks we
	// can deduce that the user has push and admin access.
	_, err = client.ListHooks(owner, name, &ListOpts{})
	if err == nil {
		perms.Push = true
		perms.Admin = true
	}

	return perms, nil
}