Skip to content

Commit a6271be

Browse files
authored
Merge pull request #130 from microsoft/users/pnechvatal/GraphGroupFix
Fix graph groups not working
2 parents 938b429 + d1d4569 commit a6271be

File tree

1 file changed

+85
-5
lines changed

1 file changed

+85
-5
lines changed

azuredevops/v7/graph/client.go

+85-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ type Client interface {
2828
// [Preview API] Create a new membership between a container and subject.
2929
AddMembership(context.Context, AddMembershipArgs) (*GraphMembership, error)
3030
// [Preview API] Create a new Azure DevOps group or materialize an existing AAD group.
31-
CreateGroup(context.Context, CreateGroupArgs) (*GraphGroup, error)
31+
CreateGroupOriginId(context.Context, CreateGroupOriginIdArgs) (*GraphGroup, error)
32+
// [Preview API] Create a new Azure DevOps group or materialize an existing AAD group.
33+
CreateGroupMailAddress(context.Context, CreateGroupMailAddressArgs) (*GraphGroup, error)
34+
// [Preview API] Create a new Azure DevOps group or materialize an existing AAD group.
35+
CreateGroupVsts(context.Context, CreateGroupVstsArgs) (*GraphGroup, error)
3236
// [Preview API] Materialize an existing AAD service principal into the ADO account.
3337
CreateServicePrincipal(context.Context, CreateServicePrincipalArgs) (*GraphServicePrincipal, error)
3438
// [Preview API] Materialize an existing AAD or MSA user into the ADO account.
@@ -135,7 +139,63 @@ type AddMembershipArgs struct {
135139
}
136140

137141
// [Preview API] Create a new Azure DevOps group or materialize an existing AAD group.
138-
func (client *ClientImpl) CreateGroup(ctx context.Context, args CreateGroupArgs) (*GraphGroup, error) {
142+
func (client *ClientImpl) CreateGroupOriginId(ctx context.Context, args CreateGroupOriginIdArgs) (*GraphGroup, error) {
143+
if args.CreationContext == nil {
144+
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.CreationContext"}
145+
}
146+
queryParams := url.Values{}
147+
if args.ScopeDescriptor != nil {
148+
queryParams.Add("scopeDescriptor", *args.ScopeDescriptor)
149+
}
150+
if args.GroupDescriptors != nil {
151+
listAsString := strings.Join((*args.GroupDescriptors)[:], ",")
152+
queryParams.Add("groupDescriptors", listAsString)
153+
}
154+
body, marshalErr := json.Marshal(*args.CreationContext)
155+
if marshalErr != nil {
156+
return nil, marshalErr
157+
}
158+
locationId, _ := uuid.Parse("ebbe6af8-0b91-4c13-8cf1-777c14858188")
159+
resp, err := client.Client.Send(ctx, http.MethodPost, locationId, "7.1-preview.1", nil, queryParams, bytes.NewReader(body), "application/json", "application/json", nil)
160+
if err != nil {
161+
return nil, err
162+
}
163+
164+
var responseValue GraphGroup
165+
err = client.Client.UnmarshalBody(resp, &responseValue)
166+
return &responseValue, err
167+
}
168+
169+
// [Preview API] Create a new Azure DevOps group or materialize an existing AAD group.
170+
func (client *ClientImpl) CreateGroupMailAddress(ctx context.Context, args CreateGroupMailAddressArgs) (*GraphGroup, error) {
171+
if args.CreationContext == nil {
172+
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.CreationContext"}
173+
}
174+
queryParams := url.Values{}
175+
if args.ScopeDescriptor != nil {
176+
queryParams.Add("scopeDescriptor", *args.ScopeDescriptor)
177+
}
178+
if args.GroupDescriptors != nil {
179+
listAsString := strings.Join((*args.GroupDescriptors)[:], ",")
180+
queryParams.Add("groupDescriptors", listAsString)
181+
}
182+
body, marshalErr := json.Marshal(*args.CreationContext)
183+
if marshalErr != nil {
184+
return nil, marshalErr
185+
}
186+
locationId, _ := uuid.Parse("ebbe6af8-0b91-4c13-8cf1-777c14858188")
187+
resp, err := client.Client.Send(ctx, http.MethodPost, locationId, "7.1-preview.1", nil, queryParams, bytes.NewReader(body), "application/json", "application/json", nil)
188+
if err != nil {
189+
return nil, err
190+
}
191+
192+
var responseValue GraphGroup
193+
err = client.Client.UnmarshalBody(resp, &responseValue)
194+
return &responseValue, err
195+
}
196+
197+
// [Preview API] Create a new Azure DevOps group or materialize an existing AAD group.
198+
func (client *ClientImpl) CreateGroupVsts(ctx context.Context, args CreateGroupVstsArgs) (*GraphGroup, error) {
139199
if args.CreationContext == nil {
140200
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.CreationContext"}
141201
}
@@ -162,10 +222,30 @@ func (client *ClientImpl) CreateGroup(ctx context.Context, args CreateGroupArgs)
162222
return &responseValue, err
163223
}
164224

165-
// Arguments for the CreateGroup function
166-
type CreateGroupArgs struct {
225+
// Arguments for the CreateGroupOriginId function
226+
type CreateGroupOriginIdArgs struct {
227+
// (required) The subset of the full graph group used to uniquely find the graph subject in an external provider.
228+
CreationContext *GraphGroupOriginIdCreationContext
229+
// (optional) A descriptor referencing the scope (collection, project) in which the group should be created. If omitted, will be created in the scope of the enclosing account or organization. Valid only for VSTS groups.
230+
ScopeDescriptor *string
231+
// (optional) A comma separated list of descriptors referencing groups you want the graph group to join
232+
GroupDescriptors *[]string
233+
}
234+
235+
// Arguments for the CreateGroupMailAddress function
236+
type CreateGroupMailAddressArgs struct {
237+
// (required) The subset of the full graph group used to uniquely find the graph subject in an external provider.
238+
CreationContext *GraphGroupMailAddressCreationContext
239+
// (optional) A descriptor referencing the scope (collection, project) in which the group should be created. If omitted, will be created in the scope of the enclosing account or organization. Valid only for VSTS groups.
240+
ScopeDescriptor *string
241+
// (optional) A comma separated list of descriptors referencing groups you want the graph group to join
242+
GroupDescriptors *[]string
243+
}
244+
245+
// Arguments for the CreateGroupVsts function
246+
type CreateGroupVstsArgs struct {
167247
// (required) The subset of the full graph group used to uniquely find the graph subject in an external provider.
168-
CreationContext *GraphGroupCreationContext
248+
CreationContext *GraphGroupVstsCreationContext
169249
// (optional) A descriptor referencing the scope (collection, project) in which the group should be created. If omitted, will be created in the scope of the enclosing account or organization. Valid only for VSTS groups.
170250
ScopeDescriptor *string
171251
// (optional) A comma separated list of descriptors referencing groups you want the graph group to join

0 commit comments

Comments
 (0)