Skip to content

Commit 7abc9ac

Browse files
committed
add groupprivileges
1 parent 813aaad commit 7abc9ac

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Client struct {
4141
Teams teams
4242
Repositories *Repositories
4343
Workspaces *Workspace
44+
GroupPrivileges *GroupPrivileges
4445
Pagelen uint64
4546
MaxDepth uint64
4647
apiBaseURL *url.URL
@@ -155,6 +156,7 @@ func injectClient(a *auth) *Client {
155156
c.User = &User{c: c}
156157
c.Teams = &Teams{c: c}
157158
c.Workspaces = &Workspace{c: c, Repositories: c.Repositories, Permissions: &Permission{c: c}}
159+
c.GroupPrivileges = &GroupPrivileges{c: c}
158160
c.HttpClient = new(http.Client)
159161
return c
160162
}

groupprivileges.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package bitbucket
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/mitchellh/mapstructure"
7+
)
8+
9+
type GroupPrivileges struct {
10+
c *Client
11+
}
12+
13+
type GroupPrivilegesOptions struct {
14+
Owner string
15+
RepoSlug string
16+
Group string
17+
GroupOwner string
18+
Permission string
19+
}
20+
21+
type GroupPrivilege struct {
22+
Repo string `mapstructure:"repo"`
23+
Privilege string `mapstructure:"privilege"`
24+
Group struct {
25+
Owner struct {
26+
DisplayName string `mapstructure:"display_name"`
27+
UUID string `mapstructure:"uuid"`
28+
IsActive bool `mapstructure:"is_active"`
29+
IsTeam bool `mapstructure:"is_team"`
30+
MentionID string `mapstructure:"mention_id"`
31+
Avatar string `mapstructure:"avatar"`
32+
Nickname string `mapstructure:"nickname"`
33+
AccountID string `mapstructure:"account_id"`
34+
} `mapstructure:"owner"`
35+
Name string `mapstructure:"name"`
36+
Members []interface{} `mapstructure:"members"`
37+
Slug string `mapstructure:"slug"`
38+
} `mapstructure:"group"`
39+
Repository struct {
40+
Owner struct {
41+
DisplayName string `mapstructure:"display_name"`
42+
UUID string `mapstructure:"uuid"`
43+
IsActive bool `mapstructure:"is_active"`
44+
IsTeam bool `mapstructure:"is_team"`
45+
MentionID string `mapstructure:"mention_id"`
46+
Avatar string `mapstructure:"avatar"`
47+
Nickname string `mapstructure:"nickname"`
48+
AccountID string `mapstructure:"account_id"`
49+
} `mapstructure:"owner"`
50+
Name string `mapstructure:"name"`
51+
Slug string `mapstructure:"slug"`
52+
} `mapstructure:"repository"`
53+
}
54+
55+
func (g *GroupPrivileges) List(workspace, repoSlug string) ([]GroupPrivilege, error) {
56+
urlStr := fmt.Sprintf("%s/1.0/group-privileges/%s/%s", g.c.GetApiHostnameURL(), workspace, repoSlug)
57+
data, err := g.c.execute("GET", urlStr, "")
58+
if err != nil {
59+
return nil, err
60+
}
61+
62+
return g.decodeGroupPrivileges(data)
63+
}
64+
65+
func (g *GroupPrivileges) Add(gpo GroupPrivilegesOptions) ([]GroupPrivilege, error) {
66+
groupOwner := gpo.GroupOwner
67+
if gpo.GroupOwner == "" {
68+
groupOwner = gpo.Owner
69+
70+
}
71+
urlStr := fmt.Sprintf("%s/1.0/group-privileges/%s/%s/%s/%s/", g.c.GetApiHostnameURL(), gpo.Owner, gpo.RepoSlug, groupOwner, gpo.Group)
72+
data, err := g.c.executeContentType("PUT", urlStr, gpo.Permission, "application/x-www-form-urlencoded")
73+
if err != nil {
74+
return nil, err
75+
}
76+
77+
return g.decodeGroupPrivileges(data)
78+
}
79+
80+
func (g *GroupPrivileges) Get(gpo GroupPrivilegesOptions) ([]GroupPrivilege, error) {
81+
groupOwner := gpo.GroupOwner
82+
if gpo.GroupOwner == "" {
83+
groupOwner = gpo.Owner
84+
85+
}
86+
urlStr := fmt.Sprintf("%s/1.0/group-privileges/%s/%s/%s/%s/", g.c.GetApiHostnameURL(), gpo.Owner, gpo.RepoSlug, groupOwner, gpo.Group)
87+
data, err := g.c.execute("GET", urlStr, "")
88+
if err != nil {
89+
return nil, err
90+
}
91+
92+
return g.decodeGroupPrivileges(data)
93+
}
94+
95+
func (g *GroupPrivileges) Delete(gpo GroupPrivilegesOptions) (interface{}, error) {
96+
groupOwner := gpo.GroupOwner
97+
if gpo.GroupOwner == "" {
98+
groupOwner = gpo.Owner
99+
100+
}
101+
urlStr := fmt.Sprintf("%s/1.0/group-privileges/%s/%s/%s/%s/", g.c.GetApiHostnameURL(), gpo.Owner, gpo.RepoSlug, groupOwner, gpo.Group)
102+
return g.c.execute("DELETE", urlStr, "")
103+
}
104+
105+
func (g *GroupPrivileges) decodeGroupPrivileges(response interface{}) ([]GroupPrivilege, error) {
106+
var gp []GroupPrivilege
107+
err := mapstructure.Decode(response, &gp)
108+
if err != nil {
109+
return nil, err
110+
}
111+
return gp, nil
112+
}

0 commit comments

Comments
 (0)