Skip to content

Commit 00c90d7

Browse files
author
Petr Nechvátal
committed
Fix adding graph users
1 parent 8bf534e commit 00c90d7

File tree

1 file changed

+77
-5
lines changed

1 file changed

+77
-5
lines changed

azuredevops/v7/graph/client.go

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ type Client interface {
3232
// [Preview API] Materialize an existing AAD service principal into the ADO account.
3333
CreateServicePrincipal(context.Context, CreateServicePrincipalArgs) (*GraphServicePrincipal, error)
3434
// [Preview API] Materialize an existing AAD or MSA user into the ADO account.
35-
CreateUser(context.Context, CreateUserArgs) (*GraphUser, error)
35+
CreateUserOriginId(ctx context.Context, args CreateUserOriginIdArgs) (*GraphUser, error)
36+
// [Preview API] Materialize an existing AAD or MSA user into the ADO account.
37+
CreateUserMailAddress(ctx context.Context, args CreateUserMailAddressArgs) (*GraphUser, error)
38+
// [Preview API] Materialize an existing AAD or MSA user into the ADO account.
39+
CreateUserUserPrincipalName(ctx context.Context, args CreateUserUserPrincipalNameArgs) (*GraphUser, error)
3640
// [Preview API]
3741
DeleteAvatar(context.Context, DeleteAvatarArgs) error
3842
// [Preview API] Removes an Azure DevOps group from all of its parent groups.
@@ -202,7 +206,57 @@ type CreateServicePrincipalArgs struct {
202206
}
203207

204208
// [Preview API] Materialize an existing AAD or MSA user into the ADO account.
205-
func (client *ClientImpl) CreateUser(ctx context.Context, args CreateUserArgs) (*GraphUser, error) {
209+
func (client *ClientImpl) CreateUserOriginId(ctx context.Context, args CreateUserOriginIdArgs) (*GraphUser, error) {
210+
if args.CreationContext == nil {
211+
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.CreationContext"}
212+
}
213+
queryParams := url.Values{}
214+
if args.GroupDescriptors != nil {
215+
listAsString := strings.Join((*args.GroupDescriptors)[:], ",")
216+
queryParams.Add("groupDescriptors", listAsString)
217+
}
218+
body, marshalErr := json.Marshal(*args.CreationContext)
219+
if marshalErr != nil {
220+
return nil, marshalErr
221+
}
222+
locationId, _ := uuid.Parse("005e26ec-6b77-4e4f-a986-b3827bf241f5")
223+
resp, err := client.Client.Send(ctx, http.MethodPost, locationId, "7.1-preview.1", nil, queryParams, bytes.NewReader(body), "application/json", "application/json", nil)
224+
if err != nil {
225+
return nil, err
226+
}
227+
228+
var responseValue GraphUser
229+
err = client.Client.UnmarshalBody(resp, &responseValue)
230+
return &responseValue, err
231+
}
232+
233+
// [Preview API] Materialize an existing AAD or MSA user into the ADO account.
234+
func (client *ClientImpl) CreateUserUserPrincipalName(ctx context.Context, args CreateUserUserPrincipalNameArgs) (*GraphUser, error) {
235+
if args.CreationContext == nil {
236+
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.CreationContext"}
237+
}
238+
queryParams := url.Values{}
239+
if args.GroupDescriptors != nil {
240+
listAsString := strings.Join((*args.GroupDescriptors)[:], ",")
241+
queryParams.Add("groupDescriptors", listAsString)
242+
}
243+
body, marshalErr := json.Marshal(*args.CreationContext)
244+
if marshalErr != nil {
245+
return nil, marshalErr
246+
}
247+
locationId, _ := uuid.Parse("005e26ec-6b77-4e4f-a986-b3827bf241f5")
248+
resp, err := client.Client.Send(ctx, http.MethodPost, locationId, "7.1-preview.1", nil, queryParams, bytes.NewReader(body), "application/json", "application/json", nil)
249+
if err != nil {
250+
return nil, err
251+
}
252+
253+
var responseValue GraphUser
254+
err = client.Client.UnmarshalBody(resp, &responseValue)
255+
return &responseValue, err
256+
}
257+
258+
// [Preview API] Materialize an existing AAD or MSA user into the ADO account.
259+
func (client *ClientImpl) CreateUserMailAddress(ctx context.Context, args CreateUserMailAddressArgs) (*GraphUser, error) {
206260
if args.CreationContext == nil {
207261
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.CreationContext"}
208262
}
@@ -226,14 +280,32 @@ func (client *ClientImpl) CreateUser(ctx context.Context, args CreateUserArgs) (
226280
return &responseValue, err
227281
}
228282

229-
// Arguments for the CreateUser function
230-
type CreateUserArgs struct {
283+
284+
// Arguments for the CreateUserOriginId function
285+
type CreateUserOriginIdArgs struct {
231286
// (required) The subset of the full graph user used to uniquely find the graph subject in an external provider.
232-
CreationContext *GraphUserCreationContext
287+
CreationContext *GraphUserOriginIdCreationContext
233288
// (optional) A comma separated list of descriptors of groups you want the graph user to join
234289
GroupDescriptors *[]string
235290
}
236291

292+
// Arguments for the CreateUserPrincipalName function
293+
type CreateUserUserPrincipalNameArgs struct {
294+
// (required) The subset of the full graph user used to uniquely find the graph subject in an external provider.
295+
CreationContext *GraphUserPrincipalNameCreationContext
296+
// (optional) A comma separated list of descriptors of groups you want the graph user to join
297+
GroupDescriptors *[]string
298+
}
299+
300+
// Arguments for the CreateUserMailAddress function
301+
type CreateUserMailAddressArgs struct {
302+
// (required) The subset of the full graph user used to uniquely find the graph subject in an external provider.
303+
CreationContext *GraphUserMailAddressCreationContext
304+
// (optional) A comma separated list of descriptors of groups you want the graph user to join
305+
GroupDescriptors *[]string
306+
}
307+
308+
237309
// [Preview API]
238310
func (client *ClientImpl) DeleteAvatar(ctx context.Context, args DeleteAvatarArgs) error {
239311
routeValues := make(map[string]string)

0 commit comments

Comments
 (0)