diff --git a/README.md b/README.md index d9407b7c..3ebb8d30 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ func main() { return } for _, user := range *users { - fmt.Printf("%s: %s <%s>\n", *user.ID, *user.DisplayName, *user.UserPrincipalName) + fmt.Printf("%s: %s <%s>\n", *user.ID(), *user.DisplayName, *user.UserPrincipalName) } } ``` diff --git a/example/example.go b/example/example.go index 6855139b..1d5bc2e9 100644 --- a/example/example.go +++ b/example/example.go @@ -49,6 +49,6 @@ func main() { return } for _, user := range *users { - fmt.Printf("%s: %s <%s>\n", *user.ID, *user.DisplayName, *user.UserPrincipalName) + fmt.Printf("%s: %s <%s>\n", *user.ID(), *user.DisplayName, *user.UserPrincipalName) } } diff --git a/internal/cmd/test-cleanup/applications.go b/internal/cmd/test-cleanup/applications.go index d50c2c4c..f40874bb 100644 --- a/internal/cmd/test-cleanup/applications.go +++ b/internal/cmd/test-cleanup/applications.go @@ -22,21 +22,21 @@ func cleanupApplications() { return } for _, app := range *apps { - if app.ID == nil || app.AppId == nil || app.DisplayName == nil { + if app.ID() == nil || app.AppId == nil || app.DisplayName == nil { log.Println("App returned with nil ID, AppId or DisplayName") continue } - log.Printf("Deleting application %q (AppID: %q, DisplayName: %q)\n", *app.ID, *app.AppId, *app.DisplayName) - _, err := appsClient.Delete(ctx, *app.ID) + log.Printf("Deleting application %q (AppID: %q, DisplayName: %q)\n", *app.ID(), *app.AppId, *app.DisplayName) + _, err := appsClient.Delete(ctx, *app.ID()) if err != nil { - log.Printf("Error when deleting application %q: %v\n", *app.ID, err) + log.Printf("Error when deleting application %q: %v\n", *app.ID(), err) } - log.Printf("Permanently deleting application %q (AppID: %q, DisplayName: %q)\n", *app.ID, *app.AppId, *app.DisplayName) - _, err = appsClient.DeletePermanently(ctx, *app.ID) + log.Printf("Permanently deleting application %q (AppID: %q, DisplayName: %q)\n", *app.ID(), *app.AppId, *app.DisplayName) + _, err = appsClient.DeletePermanently(ctx, *app.ID()) if err != nil { - log.Printf("Error when permanently deleting application %q: %v\n", *app.ID, err) + log.Printf("Error when permanently deleting application %q: %v\n", *app.ID(), err) } } } diff --git a/internal/cmd/test-cleanup/groups.go b/internal/cmd/test-cleanup/groups.go index d2392808..79c77c88 100644 --- a/internal/cmd/test-cleanup/groups.go +++ b/internal/cmd/test-cleanup/groups.go @@ -22,22 +22,22 @@ func cleanupGroups() { return } for _, group := range *groups { - if group.ID == nil || group.DisplayName == nil { + if group.ID() == nil || group.DisplayName == nil { log.Println("Group returned with nil ID or DisplayName") continue } - log.Printf("Deleting group %q (DisplayName: %q)\n", *group.ID, *group.DisplayName) - _, err := groupsClient.Delete(ctx, *group.ID) + log.Printf("Deleting group %q (DisplayName: %q)\n", *group.ID(), *group.DisplayName) + _, err := groupsClient.Delete(ctx, *group.ID()) if err != nil { - log.Printf("Error when deleting group %q: %v\n", *group.ID, err) + log.Printf("Error when deleting group %q: %v\n", *group.ID(), err) } if group.HasTypes([]msgraph.GroupType{msgraph.GroupTypeUnified}) { - log.Printf("Permanently deleting group %q (DisplayName: %q)\n", *group.ID, *group.DisplayName) - _, err = groupsClient.DeletePermanently(ctx, *group.ID) + log.Printf("Permanently deleting group %q (DisplayName: %q)\n", *group.ID(), *group.DisplayName) + _, err = groupsClient.DeletePermanently(ctx, *group.ID()) if err != nil { - log.Printf("Error when permanently deleting group %q: %v\n", *group.ID, err) + log.Printf("Error when permanently deleting group %q: %v\n", *group.ID(), err) } } } diff --git a/internal/cmd/test-cleanup/serviceprincipals.go b/internal/cmd/test-cleanup/serviceprincipals.go index 7e7ae8e0..1f6a9ee7 100644 --- a/internal/cmd/test-cleanup/serviceprincipals.go +++ b/internal/cmd/test-cleanup/serviceprincipals.go @@ -22,15 +22,15 @@ func cleanupServicePrincipals() { return } for _, servicePrincipal := range *servicePrincipals { - if servicePrincipal.ID == nil || servicePrincipal.DisplayName == nil { + if servicePrincipal.ID() == nil || servicePrincipal.DisplayName == nil { log.Println("Service Principal returned with nil ID or DisplayName") continue } - log.Printf("Deleting service principal %q (DisplayName: %q)\n", *servicePrincipal.ID, *servicePrincipal.DisplayName) - _, err := servicePrincipalsClient.Delete(ctx, *servicePrincipal.ID) + log.Printf("Deleting service principal %q (DisplayName: %q)\n", *servicePrincipal.ID(), *servicePrincipal.DisplayName) + _, err := servicePrincipalsClient.Delete(ctx, *servicePrincipal.ID()) if err != nil { - log.Printf("Error when deleting service principal %q: %v\n", *servicePrincipal.ID, err) + log.Printf("Error when deleting service principal %q: %v\n", *servicePrincipal.ID(), err) } } } diff --git a/internal/cmd/test-cleanup/users.go b/internal/cmd/test-cleanup/users.go index 591a68a1..56b2fce9 100644 --- a/internal/cmd/test-cleanup/users.go +++ b/internal/cmd/test-cleanup/users.go @@ -22,21 +22,21 @@ func cleanupUsers() { return } for _, user := range *users { - if user.ID == nil || user.DisplayName == nil { + if user.ID() == nil || user.DisplayName == nil { log.Println("User returned with nil ID or DisplayName") continue } - log.Printf("Deleting user %q (DisplayName: %q)\n", *user.ID, *user.DisplayName) - _, err := usersClient.Delete(ctx, *user.ID) + log.Printf("Deleting user %q (DisplayName: %q)\n", *user.ID(), *user.DisplayName) + _, err := usersClient.Delete(ctx, *user.ID()) if err != nil { - log.Printf("Error when deleting user %q: %v\n", *user.ID, err) + log.Printf("Error when deleting user %q: %v\n", *user.ID(), err) } - log.Printf("Permanently deleting user %q (DisplayName: %q)\n", *user.ID, *user.DisplayName) - _, err = usersClient.DeletePermanently(ctx, *user.ID) + log.Printf("Permanently deleting user %q (DisplayName: %q)\n", *user.ID(), *user.DisplayName) + _, err = usersClient.DeletePermanently(ctx, *user.ID()) if err != nil { - log.Printf("Error when permanently deleting user %q: %v\n", *user.ID, err) + log.Printf("Error when permanently deleting user %q: %v\n", *user.ID(), err) } } } diff --git a/msgraph/accesspackageresourcerequest_test.go b/msgraph/accesspackageresourcerequest_test.go index d81bbf6a..01853d01 100644 --- a/msgraph/accesspackageresourcerequest_test.go +++ b/msgraph/accesspackageresourcerequest_test.go @@ -37,7 +37,7 @@ func TestAccessPackageResourceRequestClient(t *testing.T) { CatalogId: accessPackage.Catalog.ID, RequestType: utils.StringPtr("AdminAdd"), AccessPackageResource: &msgraph.AccessPackageResource{ - OriginId: aadGroup.ID, + OriginId: aadGroup.ID(), OriginSystem: msgraph.AccessPackageResourceOriginSystemAadGroup, }, }, true) @@ -180,7 +180,7 @@ func testAccessPackageResourceRequestGroup_Create(t *testing.T, c *test.Test, ow } func testAccessPackageResourceRequestGroup_Delete(t *testing.T, c *test.Test, group *msgraph.Group) { - _, err := c.GroupsClient.Delete(c.Context, *group.ID) + _, err := c.GroupsClient.Delete(c.Context, *group.ID()) if err != nil { t.Fatalf("GroupsClient.Delete() - Could not delete test group: %v", err) } diff --git a/msgraph/accesspackageresourcerolescope_test.go b/msgraph/accesspackageresourcerolescope_test.go index 86bf6d75..a09e4879 100644 --- a/msgraph/accesspackageresourcerolescope_test.go +++ b/msgraph/accesspackageresourcerolescope_test.go @@ -37,7 +37,7 @@ func TestAccessPackageResourceRoleScopeClient(t *testing.T) { CatalogId: accessPackage.Catalog.ID, RequestType: utils.StringPtr("AdminAdd"), AccessPackageResource: &msgraph.AccessPackageResource{ - OriginId: aadGroup.ID, + OriginId: aadGroup.ID(), OriginSystem: msgraph.AccessPackageResourceOriginSystemAadGroup, //ResourceType: utils.StringPtr("Security Group") // This is not mandatory for groups but is seen in sharepoint emails }, @@ -245,7 +245,7 @@ func testAccessPackageResourceRoleScopeGroup_Create(t *testing.T, c *test.Test, } func testAccessPackageResourceRoleScopeGroup_Delete(t *testing.T, c *test.Test, group *msgraph.Group) { - _, err := c.GroupsClient.Delete(c.Context, *group.ID) + _, err := c.GroupsClient.Delete(c.Context, *group.ID()) if err != nil { t.Fatalf("GroupsClient.Delete() - Could not delete test group: %v", err) } diff --git a/msgraph/administrative_units_test.go b/msgraph/administrative_units_test.go index 190a85e4..9898e453 100644 --- a/msgraph/administrative_units_test.go +++ b/msgraph/administrative_units_test.go @@ -38,8 +38,8 @@ func TestAdministrativeUnitsClient(t *testing.T) { testAdministrativeUnitsClient_AddMembers(t, c, *administrativeUnit.ID, &msgraph.Members{user.DirectoryObject}) testAdministrativeUnitsClient_ListMembers(t, c, *administrativeUnit.ID) - testAdministrativeUnitsClient_GetMember(t, c, *administrativeUnit.ID, *user.ID) - testAdministrativeUnitsClient_RemoveMembers(t, c, *administrativeUnit.ID, &([]string{*user.ID})) + testAdministrativeUnitsClient_GetMember(t, c, *administrativeUnit.ID, *user.ID()) + testAdministrativeUnitsClient_RemoveMembers(t, c, *administrativeUnit.ID, &([]string{*user.ID()})) directoryRoleTemplates := testDirectoryRoleTemplatesClient_List(t, c) var helpdeskAdministratorRoleId string @@ -52,8 +52,8 @@ func TestAdministrativeUnitsClient(t *testing.T) { directoryRole := testDirectoryRolesClient_GetByTemplateId(t, c, helpdeskAdministratorRoleId) membership := testAdministrativeUnitsClient_AddScopedRoleMember(t, c, *administrativeUnit.ID, msgraph.ScopedRoleMembership{ - RoleId: directoryRole.ID, - RoleMemberInfo: &msgraph.Identity{Id: user.ID}, + RoleId: directoryRole.ID(), + RoleMemberInfo: &msgraph.Identity{Id: user.ID()}, }) testAdministrativeUnitsClient_ListScopedRoleMembers(t, c, *administrativeUnit.ID) testAdministrativeUnitsClient_GetRoleScopedMember(t, c, *administrativeUnit.ID, *membership.Id) @@ -61,7 +61,7 @@ func TestAdministrativeUnitsClient(t *testing.T) { testAdministrativeUnitsClient_List(t, c) testAdministrativeUnitsClient_Delete(t, c, *administrativeUnit.ID) - testUsersClient_Delete(t, c, *user.ID) + testUsersClient_Delete(t, c, *user.ID()) } func testAdministrativeUnitsClient_Create(t *testing.T, c *test.Test, g msgraph.AdministrativeUnit) (administrativeUnit *msgraph.AdministrativeUnit) { diff --git a/msgraph/app_role_assignments_test.go b/msgraph/app_role_assignments_test.go index 62e82cbc..20f3a6f1 100644 --- a/msgraph/app_role_assignments_test.go +++ b/msgraph/app_role_assignments_test.go @@ -80,38 +80,38 @@ func TestAppRoleAssignedToClient(t *testing.T) { // assign app role to group groupAssignment := testAppRoleAssignedToClient_Assign(t, c, msgraph.AppRoleAssignment{ AppRoleId: (*resourceApp.AppRoles)[0].ID, - PrincipalId: group.ID, - ResourceId: resourceServicePrincipal.ID, + PrincipalId: group.ID(), + ResourceId: resourceServicePrincipal.ID(), }) // assign app role to user userAssignment := testAppRoleAssignedToClient_Assign(t, c, msgraph.AppRoleAssignment{ AppRoleId: (*resourceApp.AppRoles)[0].ID, - PrincipalId: user.ID, - ResourceId: resourceServicePrincipal.ID, + PrincipalId: user.ID(), + ResourceId: resourceServicePrincipal.ID(), }) // assign app role to service principal servicePrincipalAssignment := testAppRoleAssignedToClient_Assign(t, c, msgraph.AppRoleAssignment{ AppRoleId: (*resourceApp.AppRoles)[0].ID, - PrincipalId: servicePrincipal.ID, - ResourceId: resourceServicePrincipal.ID, + PrincipalId: servicePrincipal.ID(), + ResourceId: resourceServicePrincipal.ID(), }) // list app roles assigned to resource service principal - testAppRoleAssignedToClient_List(t, c, *resourceServicePrincipal.ID) + testAppRoleAssignedToClient_List(t, c, *resourceServicePrincipal.ID()) // remove the assigned app roles - testAppRoleAssignedToClient_Remove(t, c, *resourceServicePrincipal.ID, *groupAssignment.Id) - testAppRoleAssignedToClient_Remove(t, c, *resourceServicePrincipal.ID, *userAssignment.Id) - testAppRoleAssignedToClient_Remove(t, c, *resourceServicePrincipal.ID, *servicePrincipalAssignment.Id) + testAppRoleAssignedToClient_Remove(t, c, *resourceServicePrincipal.ID(), *groupAssignment.Id) + testAppRoleAssignedToClient_Remove(t, c, *resourceServicePrincipal.ID(), *userAssignment.Id) + testAppRoleAssignedToClient_Remove(t, c, *resourceServicePrincipal.ID(), *servicePrincipalAssignment.Id) // clean up - testGroupsClient_Delete(t, c, *group.ID) - testUsersClient_Delete(t, c, *user.ID) - testServicePrincipalsClient_Delete(t, c, *servicePrincipal.ID) - testServicePrincipalsClient_Delete(t, c, *resourceServicePrincipal.ID) - testApplicationsClient_Delete(t, c, *resourceApp.ID) + testGroupsClient_Delete(t, c, *group.ID()) + testUsersClient_Delete(t, c, *user.ID()) + testServicePrincipalsClient_Delete(t, c, *servicePrincipal.ID()) + testServicePrincipalsClient_Delete(t, c, *resourceServicePrincipal.ID()) + testApplicationsClient_Delete(t, c, *resourceApp.ID()) } func TestGroupsAppRoleAssignmentsClient(t *testing.T) { @@ -156,21 +156,21 @@ func TestGroupsAppRoleAssignmentsClient(t *testing.T) { }) // assign resourceApp role to the test group - appRoleAssignment := testGroupsAppRoleAssignmentsClient_Assign(t, c, *group.ID, *resourceServicePrincipal.ID, testResourceAppRoleId) + appRoleAssignment := testGroupsAppRoleAssignmentsClient_Assign(t, c, *group.ID(), *resourceServicePrincipal.ID(), testResourceAppRoleId) // list resourceApp role assignments for a test group - appRoleAssignments := testGroupsAppRoleAssignmentsClient_List(t, c, *group.ID) + appRoleAssignments := testGroupsAppRoleAssignmentsClient_List(t, c, *group.ID()) if len(*appRoleAssignments) == 0 { t.Fatal("expected at least one resourceApp role assignment assigned to the test group") } // removes resourceApp role assignment previously set to the test group - testGroupsAppRoleAssignmentsClient_Remove(t, c, *group.ID, *appRoleAssignment.Id) + testGroupsAppRoleAssignmentsClient_Remove(t, c, *group.ID(), *appRoleAssignment.Id) // remove all test resources to clean up - testGroupsClient_Delete(t, c, *group.ID) - testServicePrincipalsClient_Delete(t, c, *resourceServicePrincipal.ID) - testApplicationsClient_Delete(t, c, *resourceApp.ID) + testGroupsClient_Delete(t, c, *group.ID()) + testServicePrincipalsClient_Delete(t, c, *resourceServicePrincipal.ID()) + testApplicationsClient_Delete(t, c, *resourceApp.ID()) } func TestUsersAppRoleAssignmentsClient(t *testing.T) { @@ -218,21 +218,21 @@ func TestUsersAppRoleAssignmentsClient(t *testing.T) { }) // assign resourceApp role to the test user - appRoleAssignment := testUsersAppRoleAssignmentsClient_Assign(t, c, *user.ID, *resourceServicePrincipal.ID, testResourceAppRoleId) + appRoleAssignment := testUsersAppRoleAssignmentsClient_Assign(t, c, *user.ID(), *resourceServicePrincipal.ID(), testResourceAppRoleId) // list resourceApp role assignments for a test user - appRoleAssignments := testUsersAppRoleAssignmentsClient_List(t, c, *user.ID) + appRoleAssignments := testUsersAppRoleAssignmentsClient_List(t, c, *user.ID()) if len(*appRoleAssignments) == 0 { t.Fatal("expected at least one resourceApp role assignment assigned to the test user") } // removes resourceApp role assignment previously set to the test user - testUsersAppRoleAssignmentsClient_Remove(t, c, *user.ID, *appRoleAssignment.Id) + testUsersAppRoleAssignmentsClient_Remove(t, c, *user.ID(), *appRoleAssignment.Id) // remove all test resources to clean up - testUsersClient_Delete(t, c, *user.ID) - testServicePrincipalsClient_Delete(t, c, *resourceServicePrincipal.ID) - testApplicationsClient_Delete(t, c, *resourceApp.ID) + testUsersClient_Delete(t, c, *user.ID()) + testServicePrincipalsClient_Delete(t, c, *resourceServicePrincipal.ID()) + testApplicationsClient_Delete(t, c, *resourceApp.ID()) } func TestServicePrincipalsAppRoleAssignmentsClient(t *testing.T) { @@ -293,21 +293,21 @@ func TestServicePrincipalsAppRoleAssignmentsClient(t *testing.T) { }) // assign resourceApp role to the test client service principal - appRoleAssignment := testServicePrincipalsAppRoleAssignmentsClient_Assign(t, c, *clientServicePrincipal.ID, *resourceServicePrincipal.ID, testResourceAppRoleId) + appRoleAssignment := testServicePrincipalsAppRoleAssignmentsClient_Assign(t, c, *clientServicePrincipal.ID(), *resourceServicePrincipal.ID(), testResourceAppRoleId) // list resourceApp role assignments for a test client service principal - appRoleAssignments := testServicePrincipalsAppRoleAssignmentsClient_List(t, c, *clientServicePrincipal.ID) + appRoleAssignments := testServicePrincipalsAppRoleAssignmentsClient_List(t, c, *clientServicePrincipal.ID()) if len(*appRoleAssignments) == 0 { t.Fatal("expected at least one resourceApp role assignment assigned to the test client service principal") } // removes resourceApp role assignment previously set to the test client service principal - testServicePrincipalsAppRoleAssignmentsClient_Remove(t, c, *clientServicePrincipal.ID, *appRoleAssignment.Id) + testServicePrincipalsAppRoleAssignmentsClient_Remove(t, c, *clientServicePrincipal.ID(), *appRoleAssignment.Id) // remove all test resources to clean up - testServicePrincipalsClient_Delete(t, c, *clientServicePrincipal.ID) - testServicePrincipalsClient_Delete(t, c, *resourceServicePrincipal.ID) - testApplicationsClient_Delete(t, c, *resourceApp.ID) + testServicePrincipalsClient_Delete(t, c, *clientServicePrincipal.ID()) + testServicePrincipalsClient_Delete(t, c, *resourceServicePrincipal.ID()) + testApplicationsClient_Delete(t, c, *resourceApp.ID()) } func testGroupsAppRoleAssignmentsClient_List(t *testing.T, c *test.Test, id string) (appRoleAssignments *[]msgraph.AppRoleAssignment) { diff --git a/msgraph/application_templates_test.go b/msgraph/application_templates_test.go index 9f4499ac..950a7f7a 100644 --- a/msgraph/application_templates_test.go +++ b/msgraph/application_templates_test.go @@ -24,10 +24,10 @@ func TestApplicationTemplatesClient(t *testing.T) { DisplayName: utils.StringPtr(fmt.Sprintf("test-applicationTemplate-%s", c.RandomString)), }) - testServicePrincipalsClient_Delete(t, c, *app.ServicePrincipal.ID) + testServicePrincipalsClient_Delete(t, c, *app.ServicePrincipal.ID()) - testApplicationsClient_Delete(t, c, *app.Application.ID) - testApplicationsClient_DeletePermanently(t, c, *app.Application.ID) + testApplicationsClient_Delete(t, c, *app.Application.ID()) + testApplicationsClient_DeletePermanently(t, c, *app.Application.ID()) } func testApplicationTemplatesClient_List(t *testing.T, c *test.Test, o odata.Query) (applicationTemplates []msgraph.ApplicationTemplate) { diff --git a/msgraph/applications.go b/msgraph/applications.go index a0b20ba5..4c3e8426 100644 --- a/msgraph/applications.go +++ b/msgraph/applications.go @@ -155,7 +155,7 @@ func (c *ApplicationsClient) GetDeleted(ctx context.Context, id string, query od func (c *ApplicationsClient) Update(ctx context.Context, application Application) (int, error) { var status int - if application.ID == nil { + if application.ID() == nil { return status, errors.New("ApplicationsClient.Update(): cannot update application with nil ID") } @@ -182,7 +182,7 @@ func (c *ApplicationsClient) Update(ctx context.Context, application Application ConsistencyFailureFunc: checkApplicationConsistency, ValidStatusCodes: []int{http.StatusNoContent}, Uri: Uri{ - Entity: fmt.Sprintf("/applications/%s", *application.ID), + Entity: fmt.Sprintf("/applications/%s", *application.ID()), HasTenantId: true, }, }) @@ -378,10 +378,7 @@ func (c *ApplicationsClient) ListOwners(ctx context.Context, id string) (*[]stri } var data struct { - Owners []struct { - Type string `json:"@odata.type"` - Id string `json:"id"` - } `json:"value"` + Owners []DirectoryObject `json:"value"` } if err := json.Unmarshal(respBody, &data); err != nil { return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) @@ -389,7 +386,9 @@ func (c *ApplicationsClient) ListOwners(ctx context.Context, id string) (*[]stri ret := make([]string, len(data.Owners)) for i, v := range data.Owners { - ret[i] = v.Id + if d := v.ID(); d != nil { + ret[i] = *d + } } return &ret, status, nil @@ -438,7 +437,7 @@ func (c *ApplicationsClient) GetOwner(ctx context.Context, applicationId, ownerI func (c *ApplicationsClient) AddOwners(ctx context.Context, application *Application) (int, error) { var status int - if application.ID == nil { + if application.ID() == nil { return status, errors.New("cannot update application with nil ID") } if application.Owners == nil { @@ -465,7 +464,7 @@ func (c *ApplicationsClient) AddOwners(ctx context.Context, application *Applica ValidStatusCodes: []int{http.StatusNoContent}, ValidStatusFunc: checkOwnerAlreadyExists, Uri: Uri{ - Entity: fmt.Sprintf("/applications/%s/owners/$ref", *application.ID), + Entity: fmt.Sprintf("/applications/%s/owners/$ref", *application.ID()), HasTenantId: true, }, }) diff --git a/msgraph/applications_test.go b/msgraph/applications_test.go index d3c2e657..638942b8 100644 --- a/msgraph/applications_test.go +++ b/msgraph/applications_test.go @@ -39,7 +39,7 @@ func TestApplicationsClient(t *testing.T) { Owners: &msgraph.Owners{*self}, }) - testApplicationsClient_Get(t, c, *app.ID) + testApplicationsClient_Get(t, c, *app.ID()) app.DisplayName = utils.StringPtr(fmt.Sprintf("test-app-updated-%s", c.RandomString)) targetObject := []msgraph.ApplicationExtensionTargetObject{ @@ -50,15 +50,15 @@ func TestApplicationsClient(t *testing.T) { Name: utils.StringPtr("extName"), TargetObjects: &targetObject, } - extensionId := testApplicationsClient_CreateExtension(t, c, newExtension, *app.ID) - testApplicationsClient_ListExtension(t, c, *app.ID) - testApplicationsClient_DeleteExtension(t, c, extensionId, *app.ID) + extensionId := testApplicationsClient_CreateExtension(t, c, newExtension, *app.ID()) + testApplicationsClient_ListExtension(t, c, *app.ID()) + testApplicationsClient_DeleteExtension(t, c, extensionId, *app.ID()) testApplicationsClient_Update(t, c, *app) - owners := testApplicationsClient_ListOwners(t, c, *app.ID) - testApplicationsClient_GetOwner(t, c, *app.ID, (*owners)[0]) - testApplicationsClient_RemoveOwners(t, c, *app.ID, owners) + owners := testApplicationsClient_ListOwners(t, c, *app.ID()) + testApplicationsClient_GetOwner(t, c, *app.ID(), (*owners)[0]) + testApplicationsClient_RemoveOwners(t, c, *app.ID(), owners) app.Owners = &msgraph.Owners{user.DirectoryObject} testApplicationsClient_AddOwners(t, c, app) @@ -67,27 +67,27 @@ func TestApplicationsClient(t *testing.T) { testApplicationsClient_UploadLogo(t, c, app) - credential := testApplicationsClient_CreateFederatedIdentityCredential(t, c, *app.ID, msgraph.FederatedIdentityCredential{ + credential := testApplicationsClient_CreateFederatedIdentityCredential(t, c, *app.ID(), msgraph.FederatedIdentityCredential{ Audiences: &[]string{"api://AzureADTokenExchange"}, Description: msgraph.NullableString("such testing many pull request"), Issuer: utils.StringPtr("https://token.actions.githubusercontent.com"), Name: utils.StringPtr(fmt.Sprintf("test-credential-%s", c.RandomString)), Subject: utils.StringPtr("repo:manicminer-test/gha-test:pull-request"), }) - testApplicationsClient_GetFederatedIdentityCredential(t, c, *app.ID, *credential.ID) + testApplicationsClient_GetFederatedIdentityCredential(t, c, *app.ID(), *credential.ID) credential.Description = msgraph.NullableString("") - testApplicationsClient_UpdateFederatedIdentityCredential(t, c, *app.ID, *credential) - testApplicationsClient_ListFederatedIdentityCredentials(t, c, *app.ID) - testApplicationsClient_DeleteFederatedIdentityCredential(t, c, *app.ID, *credential.ID) + testApplicationsClient_UpdateFederatedIdentityCredential(t, c, *app.ID(), *credential) + testApplicationsClient_ListFederatedIdentityCredentials(t, c, *app.ID()) + testApplicationsClient_DeleteFederatedIdentityCredential(t, c, *app.ID(), *credential.ID) testApplicationsClient_List(t, c) - testApplicationsClient_Delete(t, c, *app.ID) - testApplicationsClient_ListDeleted(t, c, *app.ID) - testApplicationsClient_GetDeleted(t, c, *app.ID) - testApplicationsClient_RestoreDeleted(t, c, *app.ID) - testApplicationsClient_Delete(t, c, *app.ID) - testApplicationsClient_DeletePermanently(t, c, *app.ID) + testApplicationsClient_Delete(t, c, *app.ID()) + testApplicationsClient_ListDeleted(t, c, *app.ID()) + testApplicationsClient_GetDeleted(t, c, *app.ID()) + testApplicationsClient_RestoreDeleted(t, c, *app.ID()) + testApplicationsClient_Delete(t, c, *app.ID()) + testApplicationsClient_DeletePermanently(t, c, *app.ID()) } func TestApplicationsClient_groupMembershipClaims(t *testing.T) { @@ -98,7 +98,7 @@ func TestApplicationsClient_groupMembershipClaims(t *testing.T) { DisplayName: utils.StringPtr(fmt.Sprintf("test-application-%s", c.RandomString)), GroupMembershipClaims: &[]msgraph.GroupMembershipClaim{"SecurityGroup", "ApplicationGroup"}, }) - testApplicationsClient_Delete(t, c, *app.ID) + testApplicationsClient_Delete(t, c, *app.ID()) } func testApplicationsClient_Create(t *testing.T, c *test.Test, a msgraph.Application) (application *msgraph.Application) { @@ -112,7 +112,7 @@ func testApplicationsClient_Create(t *testing.T, c *test.Test, a msgraph.Applica if application == nil { t.Fatal("ApplicationsClient.Create(): application was nil") } - if application.ID == nil { + if application.ID() == nil { t.Fatal("ApplicationsClient.Create(): application.ID was nil") } return @@ -238,10 +238,10 @@ func testApplicationsClient_RestoreDeleted(t *testing.T, c *test.Test, id string if application == nil { t.Fatal("ApplicationsClient.RestoreDeleted(): application was nil") } - if application.ID == nil { + if application.ID() == nil { t.Fatal("ApplicationsClient.RestoreDeleted(): application.ID was nil") } - if *application.ID != id { + if *application.ID() != id { t.Fatal("ApplicationsClient.RestoreDeleted(): application ids do not match") } } @@ -303,7 +303,7 @@ func testApplicationsClient_AddPassword(t *testing.T, c *test.Test, a *msgraph.A DisplayName: utils.StringPtr("test password"), EndDateTime: &expiry, } - newPwd, status, err := c.ApplicationsClient.AddPassword(c.Context, *a.ID, pwd) + newPwd, status, err := c.ApplicationsClient.AddPassword(c.Context, *a.ID(), pwd) if err != nil { t.Fatalf("ApplicationsClient.AddPassword(): %v", err) } @@ -320,7 +320,7 @@ func testApplicationsClient_AddPassword(t *testing.T, c *test.Test, a *msgraph.A } func testApplicationsClient_RemovePassword(t *testing.T, c *test.Test, a *msgraph.Application, p *msgraph.PasswordCredential) { - status, err := c.ApplicationsClient.RemovePassword(c.Context, *a.ID, *p.KeyId) + status, err := c.ApplicationsClient.RemovePassword(c.Context, *a.ID(), *p.KeyId) if err != nil { t.Fatalf("ApplicationsClient.RemovePassword(): %v", err) } @@ -348,7 +348,7 @@ func testApplicationsClient_ListDeleted(t *testing.T, c *test.Test, expectedId s } found := false for _, app := range *deletedApps { - if app.ID != nil && *app.ID == expectedId { + if id := app.ID(); id != nil && *id == expectedId { found = true break } @@ -364,7 +364,7 @@ func testApplicationsClient_UploadLogo(t *testing.T, c *test.Test, a *msgraph.Ap if err != nil { t.Fatalf("reading testlogo.png: %v", err) } - status, err := c.ApplicationsClient.UploadLogo(c.Context, *a.ID, "image/png", b) + status, err := c.ApplicationsClient.UploadLogo(c.Context, *a.ID(), "image/png", b) if err != nil { t.Fatalf("ApplicationsClient.UploadLogo(): %v", err) } diff --git a/msgraph/authentication_methods_test.go b/msgraph/authentication_methods_test.go index 2276db74..ae287598 100644 --- a/msgraph/authentication_methods_test.go +++ b/msgraph/authentication_methods_test.go @@ -25,30 +25,30 @@ func TestAuthenticationMethodsClient(t *testing.T) { }, }) - _ = testAuthMethods_List(t, c, *user.ID) - _ = testAuthMethods_ListFido2Methods(t, c, *user.ID) - _ = testAuthMethods_ListMicrosoftAuthenticatorMethods(t, c, *user.ID) - _ = testAuthMethods_ListWindowsHelloMethods(t, c, *user.ID) - tempAccessPass := testAuthMethods_CreateTemporaryAccessPassMethod(t, c, *user.ID) - _ = testAuthMethods_GetTemporaryAccessPassMethod(t, c, *user.ID, *tempAccessPass.ID) - _ = testAuthMethods_ListTemporaryAccessPassMethods(t, c, *user.ID) - testAuthMethods_DeleteTemporaryAccessPassMethod(t, c, *user.ID, *tempAccessPass.ID) - phoneAuthMethod := testAuthMethods_CreatePhoneMethod(t, c, *user.ID) - _ = testAuthMethods_GetPhoneMethod(t, c, *user.ID, *phoneAuthMethod.ID) - _ = testAuthMethods_ListPhoneMethods(t, c, *user.ID) + _ = testAuthMethods_List(t, c, *user.ID()) + _ = testAuthMethods_ListFido2Methods(t, c, *user.ID()) + _ = testAuthMethods_ListMicrosoftAuthenticatorMethods(t, c, *user.ID()) + _ = testAuthMethods_ListWindowsHelloMethods(t, c, *user.ID()) + tempAccessPass := testAuthMethods_CreateTemporaryAccessPassMethod(t, c, *user.ID()) + _ = testAuthMethods_GetTemporaryAccessPassMethod(t, c, *user.ID(), *tempAccessPass.ID) + _ = testAuthMethods_ListTemporaryAccessPassMethods(t, c, *user.ID()) + testAuthMethods_DeleteTemporaryAccessPassMethod(t, c, *user.ID(), *tempAccessPass.ID) + phoneAuthMethod := testAuthMethods_CreatePhoneMethod(t, c, *user.ID()) + _ = testAuthMethods_GetPhoneMethod(t, c, *user.ID(), *phoneAuthMethod.ID) + _ = testAuthMethods_ListPhoneMethods(t, c, *user.ID()) phoneAuthMethod.PhoneNumber = utils.StringPtr("+44 07777777778") - testAuthMethods_UpdatePhoneMethod(t, c, *user.ID, *phoneAuthMethod) - testAuthMethods_EnablePhoneSMS(t, c, *user.ID, *phoneAuthMethod.ID) - testAuthMethods_DisablePhoneSMS(t, c, *user.ID, *phoneAuthMethod.ID) - testAuthMethods_DeletePhoneMethod(t, c, *user.ID, *phoneAuthMethod.ID) - emailAuthMethod := testAuthMethods_CreateEmailMethod(t, c, *user.ID) - _ = testAuthMethods_GetEmailMethod(t, c, *user.ID, *emailAuthMethod.ID) - _ = testAuthMethods_ListEmailMethods(t, c, *user.ID) + testAuthMethods_UpdatePhoneMethod(t, c, *user.ID(), *phoneAuthMethod) + testAuthMethods_EnablePhoneSMS(t, c, *user.ID(), *phoneAuthMethod.ID) + testAuthMethods_DisablePhoneSMS(t, c, *user.ID(), *phoneAuthMethod.ID) + testAuthMethods_DeletePhoneMethod(t, c, *user.ID(), *phoneAuthMethod.ID) + emailAuthMethod := testAuthMethods_CreateEmailMethod(t, c, *user.ID()) + _ = testAuthMethods_GetEmailMethod(t, c, *user.ID(), *emailAuthMethod.ID) + _ = testAuthMethods_ListEmailMethods(t, c, *user.ID()) emailAuthMethod.EmailAddress = utils.StringPtr("test-user-authenticationmethods@contoso.com") - testAuthMethods_UpdateEmailMethod(t, c, *user.ID, *emailAuthMethod) - testAuthMethods_DeleteEmailMethod(t, c, *user.ID, *emailAuthMethod.ID) - _ = testAuthMethods_ListPasswordMethods(t, c, *user.ID) - testUsersClient_Delete(t, c, *user.ID) + testAuthMethods_UpdateEmailMethod(t, c, *user.ID(), *emailAuthMethod) + testAuthMethods_DeleteEmailMethod(t, c, *user.ID(), *emailAuthMethod.ID) + _ = testAuthMethods_ListPasswordMethods(t, c, *user.ID()) + testUsersClient_Delete(t, c, *user.ID()) } func testAuthMethods_List(t *testing.T, c *test.Test, userID string) (authMethods *[]msgraph.AuthenticationMethod) { diff --git a/msgraph/claims_mapping_policy.go b/msgraph/claims_mapping_policy.go index 08e14b1c..6adf9aa8 100644 --- a/msgraph/claims_mapping_policy.go +++ b/msgraph/claims_mapping_policy.go @@ -125,12 +125,13 @@ func (c *ClaimsMappingPolicyClient) Get(ctx context.Context, id string, query od func (c *ClaimsMappingPolicyClient) Update(ctx context.Context, claimsMappingPolicy ClaimsMappingPolicy) (int, error) { var status int - if claimsMappingPolicy.ID == nil { + if claimsMappingPolicy.ID() == nil { return status, fmt.Errorf("cannot update ClaimsMappingPolicy with nil ID") } - claimsMappingPolicyId := *claimsMappingPolicy.ID - claimsMappingPolicy.ID = nil + claimsMappingPolicyId := *claimsMappingPolicy.ID() + claimsMappingPolicy.Id = nil + claimsMappingPolicy.ObjectId = nil body, err := json.Marshal(claimsMappingPolicy) if err != nil { diff --git a/msgraph/claims_mapping_policy_test.go b/msgraph/claims_mapping_policy_test.go index 487ed4bb..ebe5454e 100644 --- a/msgraph/claims_mapping_policy_test.go +++ b/msgraph/claims_mapping_policy_test.go @@ -22,10 +22,10 @@ func TestClaimsMappingPolicyClient(t *testing.T) { ), }) testClaimsMappingPolicyClient_List(t, c) - testClaimsMappingPolicyClient_Get(t, c, *policy.ID) + testClaimsMappingPolicyClient_Get(t, c, *policy.ID()) policy.DisplayName = utils.StringPtr(fmt.Sprintf("test-claims-mapping-policy-%s", c.RandomString)) testClaimsMappingPolicyClient_Update(t, c, *policy) - testClaimsMappingPolicyClient_Delete(t, c, *policy.ID) + testClaimsMappingPolicyClient_Delete(t, c, *policy.ID()) } func testClaimsMappingPolicyClient_Create(t *testing.T, c *test.Test, p msgraph.ClaimsMappingPolicy) (policy *msgraph.ClaimsMappingPolicy) { @@ -39,7 +39,7 @@ func testClaimsMappingPolicyClient_Create(t *testing.T, c *test.Test, p msgraph. if policy == nil { t.Fatal("ClaimsMappingPolicyClient.Create(): policy was nil") } - if policy.ID == nil { + if policy.ID() == nil { t.Fatal("ClaimsMappingPolicyClient.Create(): policy.ID was nil") } return diff --git a/msgraph/conditionalaccesspolicy_test.go b/msgraph/conditionalaccesspolicy_test.go index 247f209d..c26f867e 100644 --- a/msgraph/conditionalaccesspolicy_test.go +++ b/msgraph/conditionalaccesspolicy_test.go @@ -30,9 +30,9 @@ func TestConditionalAccessPolicyClient(t *testing.T) { }, Users: &msgraph.ConditionalAccessUsers{ IncludeUsers: &[]string{"All"}, - ExcludeUsers: &[]string{*testUser.ID, "GuestsOrExternalUsers"}, - IncludeGroups: &[]string{*testIncGroup.ID}, - ExcludeGroups: &[]string{*testExcGroup.ID}, + ExcludeUsers: &[]string{*testUser.ID(), "GuestsOrExternalUsers"}, + IncludeGroups: &[]string{*testIncGroup.ID()}, + ExcludeGroups: &[]string{*testExcGroup.ID()}, }, Locations: &msgraph.ConditionalAccessLocations{ IncludeLocations: &[]string{"All"}, @@ -137,7 +137,7 @@ func testGroup_Create(t *testing.T, c *test.Test, prefix string) (group *msgraph } func testGroup_Delete(t *testing.T, c *test.Test, group *msgraph.Group) { - _, err := c.GroupsClient.Delete(c.Context, *group.ID) + _, err := c.GroupsClient.Delete(c.Context, *group.ID()) if err != nil { t.Fatalf("GroupsClient.Delete() - Could not delete test group: %v", err) } @@ -161,7 +161,7 @@ func testUser_Create(t *testing.T, c *test.Test) (user *msgraph.User) { } func testUser_Delete(t *testing.T, c *test.Test, user *msgraph.User) { - _, err := c.UsersClient.Delete(c.Context, *user.ID) + _, err := c.UsersClient.Delete(c.Context, *user.ID()) if err != nil { t.Fatalf("UsersClient.Delete() - Could not delete test user: %v", err) } diff --git a/msgraph/connectedorganization_test.go b/msgraph/connectedorganization_test.go index 485e58a7..b12fa413 100644 --- a/msgraph/connectedorganization_test.go +++ b/msgraph/connectedorganization_test.go @@ -136,12 +136,12 @@ func testConnectedOrganizationClient_Sponsors(t *testing.T, c *test.Test, connec t.Fatalf("GroupsClient.Create() - Could not create test groups: %v", err) } - err = c.ConnectedOrganizationClient.AddExternalSponsorGroup(c.Context, *connectedOrganization.ID, *extGroup.ID) + err = c.ConnectedOrganizationClient.AddExternalSponsorGroup(c.Context, *connectedOrganization.ID, *extGroup.ID()) if err != nil { t.Fatalf("ConnectedOrganizationClient.AddExternalSponsorGroup(): %v", err) } - err = c.ConnectedOrganizationClient.AddInternalSponsorGroup(c.Context, *connectedOrganization.ID, *intGroup.ID) + err = c.ConnectedOrganizationClient.AddInternalSponsorGroup(c.Context, *connectedOrganization.ID, *intGroup.ID()) if err != nil { t.Fatalf("ConnectedOrganizationClient.AddInternalSponsorGroup(): %v", err) } @@ -159,19 +159,19 @@ func testConnectedOrganizationClient_Sponsors(t *testing.T, c *test.Test, connec } // Now remove the sponsors - err = c.ConnectedOrganizationClient.DeleteExternalSponsor(c.Context, *connectedOrganization.ID, *extGroup.ID) + err = c.ConnectedOrganizationClient.DeleteExternalSponsor(c.Context, *connectedOrganization.ID, *extGroup.ID()) if err != nil { t.Fatalf("ConnectedOrganizationClient.DeleteExternalSponsor(): %v", err) } - err = c.ConnectedOrganizationClient.DeleteInternalSponsor(c.Context, *connectedOrganization.ID, *intGroup.ID) + err = c.ConnectedOrganizationClient.DeleteInternalSponsor(c.Context, *connectedOrganization.ID, *intGroup.ID()) if err != nil { t.Fatalf("ConnectedOrganizationClient.DeleteInternalSponsor(): %v", err) } // Remove the test groups. - testGroupsClient_Delete(t, c, *extGroup.ID) - testGroupsClient_Delete(t, c, *intGroup.ID) + testGroupsClient_Delete(t, c, *extGroup.ID()) + testGroupsClient_Delete(t, c, *intGroup.ID()) } func createGroupsForSponsors(c *test.Test) (extGroup *msgraph.Group, intGroup *msgraph.Group, err error) { diff --git a/msgraph/delegated_permission_grants_client_test.go b/msgraph/delegated_permission_grants_client_test.go index 978c616a..05a39f89 100644 --- a/msgraph/delegated_permission_grants_client_test.go +++ b/msgraph/delegated_permission_grants_client_test.go @@ -41,10 +41,10 @@ func TestDelegatedPermissionGrantsClient(t *testing.T) { }) grant := testDelegatedPermissionGrantsClient_Create(t, c, msgraph.DelegatedPermissionGrant{ - ClientId: sp.ID, + ClientId: sp.ID(), ConsentType: utils.StringPtr(msgraph.DelegatedPermissionGrantConsentTypePrincipal), - PrincipalId: user.ID, - ResourceId: (*result)[0].ID, + PrincipalId: user.ID(), + ResourceId: (*result)[0].ID(), Scopes: &[]string{"openid", "User.Read"}, }) @@ -53,12 +53,12 @@ func TestDelegatedPermissionGrantsClient(t *testing.T) { testDelegatedPermissionGrantsClient_Update(t, c, *grant) testDelegatedPermissionGrantsClient_List(t, c, odata.Query{}) - testDelegatedPermissionGrantsClient_List(t, c, odata.Query{Filter: fmt.Sprintf("clientId eq '%s'", *sp.ID)}) + testDelegatedPermissionGrantsClient_List(t, c, odata.Query{Filter: fmt.Sprintf("clientId eq '%s'", *sp.ID())}) testDelegatedPermissionGrantsClient_Delete(t, c, *grant.Id) - testUsersClient_Delete(t, c, *user.ID) - testServicePrincipalsClient_Delete(t, c, *sp.ID) - testApplicationsClient_Delete(t, c, *app.ID) + testUsersClient_Delete(t, c, *user.ID()) + testServicePrincipalsClient_Delete(t, c, *sp.ID()) + testApplicationsClient_Delete(t, c, *app.ID()) } func testDelegatedPermissionGrantsClient_Create(t *testing.T, c *test.Test, sp msgraph.DelegatedPermissionGrant) (delegatedPermissionGrant *msgraph.DelegatedPermissionGrant) { diff --git a/msgraph/directory_objects.go b/msgraph/directory_objects.go index 689fe1ee..1e0103c1 100644 --- a/msgraph/directory_objects.go +++ b/msgraph/directory_objects.go @@ -46,13 +46,11 @@ func (c *DirectoryObjectsClient) Get(ctx context.Context, id string, query odata return nil, status, fmt.Errorf("io.ReadAll(): %v", err) } - var data map[string]interface{} - if err := json.Unmarshal(respBody, &data); err != nil { + directoryObject := DirectoryObject{} + if err = directoryObject.UnmarshalJSONWithAdditionalData(respBody); err != nil { return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) } - directoryObject := c.translateResultToDirectoryObject(data) - return &directoryObject, status, nil } @@ -91,7 +89,7 @@ func (c *DirectoryObjectsClient) GetByIds(ctx context.Context, ids []string, typ } var rawData struct { - Objects []map[string]interface{} `json:"value"` + Objects []json.RawMessage `json:"value"` } if err := json.Unmarshal(respBody, &rawData); err != nil { return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) @@ -101,8 +99,12 @@ func (c *DirectoryObjectsClient) GetByIds(ctx context.Context, ids []string, typ Objects []DirectoryObject `json:"value"` } - for _, row := range rawData.Objects { - data.Objects = append(data.Objects, c.translateResultToDirectoryObject(row)) + for _, rawObj := range rawData.Objects { + directoryObject := DirectoryObject{} + if err = directoryObject.UnmarshalJSONWithAdditionalData(rawObj); err != nil { + return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) + } + data.Objects = append(data.Objects, directoryObject) } return &data.Objects, status, nil @@ -167,7 +169,7 @@ func (c *DirectoryObjectsClient) GetMemberGroups(ctx context.Context, id string, result := make([]DirectoryObject, len(data.IDs)) for i, id := range data.IDs { - result[i].ID = utils.StringPtr(id) + result[i].Id = utils.StringPtr(id) } return &result, status, nil @@ -215,43 +217,8 @@ func (c *DirectoryObjectsClient) GetMemberObjects(ctx context.Context, id string result := make([]DirectoryObject, len(data.IDs)) for i, id := range data.IDs { - result[i].ID = utils.StringPtr(id) + result[i].Id = utils.StringPtr(id) } return &result, status, nil } - -// translateResultToDirectoryObject translates directory object data into DirectoryObject -func (c *DirectoryObjectsClient) translateResultToDirectoryObject(data map[string]interface{}) DirectoryObject { - object := DirectoryObject{ - AdditionalData: data, - } - - if val, exists := data["@odata.id"]; exists { - if v, ok := val.(string); ok { - odataId := odata.Id(v) - object.ODataId = &odataId - } - } - - if val, exists := data["@odata.type"]; exists { - if v, ok := val.(string); ok { - odataType := odata.Type(v) - object.ODataType = &odataType - } - } - - if val, exists := data["id"]; exists { - if v, ok := val.(string); ok { - object.ID = &v - } - } - - if val, exists := data["displayName"]; exists { - if v, ok := val.(string); ok { - object.DisplayName = &v - } - } - - return object -} diff --git a/msgraph/directory_objects_test.go b/msgraph/directory_objects_test.go index 126a9ce0..d8ebe2be 100644 --- a/msgraph/directory_objects_test.go +++ b/msgraph/directory_objects_test.go @@ -45,12 +45,12 @@ func TestDirectoryObjectsClient(t *testing.T) { } group2 := testGroupsClient_Create(t, c, newGroup2) - testDirectoryObjectsClient_Get(t, c, *user.ID) - testDirectoryObjectsClient_Get(t, c, *group1.ID) - testDirectoryObjectsClient_GetMemberGroups(t, c, *user.ID, true, []string{*group1.ID, *group2.ID}) - testDirectoryObjectsClient_GetMemberObjects(t, c, *group1.ID, true, []string{*group2.ID}) - testDirectoryObjectsClient_GetByIds(t, c, []string{*group1.ID, *group2.ID, *user.ID}, []string{odata.ShortTypeGroup}) - testDirectoryObjectsClient_Delete(t, c, *group1.ID) + testDirectoryObjectsClient_Get(t, c, *user.ID()) + testDirectoryObjectsClient_Get(t, c, *group1.ID()) + testDirectoryObjectsClient_GetMemberGroups(t, c, *user.ID(), true, []string{*group1.ID(), *group2.ID()}) + testDirectoryObjectsClient_GetMemberObjects(t, c, *group1.ID(), true, []string{*group2.ID()}) + testDirectoryObjectsClient_GetByIds(t, c, []string{*group1.ID(), *group2.ID(), *user.ID()}, []string{odata.ShortTypeGroup}) + testDirectoryObjectsClient_Delete(t, c, *group1.ID()) } func testDirectoryObjectsClient_Get(t *testing.T, c *test.Test, id string) (directoryObject *msgraph.DirectoryObject) { @@ -64,7 +64,7 @@ func testDirectoryObjectsClient_Get(t *testing.T, c *test.Test, id string) (dire if directoryObject == nil { t.Fatal("DirectoryObjectsClient.Get(): directoryObject was nil") } - if directoryObject.ID == nil { + if directoryObject.ID() == nil { t.Fatal("DirectoryObjectsClient.Get(): directoryObject ID was nil") } return @@ -109,7 +109,7 @@ func testDirectoryObjectsClient_GetMemberGroups(t *testing.T, c *test.Test, id s var actualCount int for _, e := range expected { for _, o := range *directoryObjects { - if o.ID != nil && e == *o.ID { + if o.ID() != nil && e == *o.ID() { actualCount++ } } @@ -142,7 +142,7 @@ func testDirectoryObjectsClient_GetMemberObjects(t *testing.T, c *test.Test, id var actualCount int for _, e := range expected { for _, o := range *directoryObjects { - if o.ID != nil && e == *o.ID { + if o.ID() != nil && e == *o.ID() { actualCount++ } } diff --git a/msgraph/directory_roles.go b/msgraph/directory_roles.go index 35b546b2..7dd17ad4 100644 --- a/msgraph/directory_roles.go +++ b/msgraph/directory_roles.go @@ -152,7 +152,7 @@ func (c *DirectoryRolesClient) ListMembers(ctx context.Context, id string) (*[]s func (c *DirectoryRolesClient) AddMembers(ctx context.Context, directoryRole *DirectoryRole) (int, error) { var status int - if directoryRole.ID == nil { + if directoryRole.ID() == nil { return status, errors.New("cannot update directory role with nil ID") } if directoryRole.Members == nil { @@ -178,7 +178,7 @@ func (c *DirectoryRolesClient) AddMembers(ctx context.Context, directoryRole *Di ValidStatusCodes: []int{http.StatusNoContent}, ValidStatusFunc: checkMemberAlreadyExists, Uri: Uri{ - Entity: fmt.Sprintf("/directoryRoles/%s/members/$ref", *directoryRole.ID), + Entity: fmt.Sprintf("/directoryRoles/%s/members/$ref", *directoryRole.ID()), HasTenantId: true, }, }) diff --git a/msgraph/directory_roles_test.go b/msgraph/directory_roles_test.go index 299042fc..e3895615 100644 --- a/msgraph/directory_roles_test.go +++ b/msgraph/directory_roles_test.go @@ -16,7 +16,7 @@ func TestDirectoryRolesClient(t *testing.T) { // list directory roles; usually at least few directory roles are activated within a tenant directoryRoles := testDirectoryRolesClient_List(t, c) directoryRole := (*directoryRoles)[0] - testDirectoryRolesClient_Get(t, c, *directoryRole.ID) + testDirectoryRolesClient_Get(t, c, *directoryRole.ID()) testDirectoryRolesClient_GetByTemplateId(t, c, *directoryRole.RoleTemplateId) // create a new test group which can be later assigned as a member of the previously listed directory role @@ -36,12 +36,12 @@ func TestDirectoryRolesClient(t *testing.T) { testDirectoryRolesClient_AddMembers(t, c, &directoryRole) // list members of the directory role; then remove the added group member to clean up - testDirectoryRolesClient_ListMembers(t, c, *directoryRole.ID) - testDirectoryRolesClient_GetMember(t, c, *directoryRole.ID, *group.ID) - testDirectoryRolesClient_RemoveMembers(t, c, *directoryRole.ID, &[]string{*group.ID}) + testDirectoryRolesClient_ListMembers(t, c, *directoryRole.ID()) + testDirectoryRolesClient_GetMember(t, c, *directoryRole.ID(), *group.ID()) + testDirectoryRolesClient_RemoveMembers(t, c, *directoryRole.ID(), &[]string{*group.ID()}) // remove the test group to clean up - testGroupsClient_Delete(t, c, *group.ID) + testGroupsClient_Delete(t, c, *group.ID()) } func testDirectoryRolesClient_List(t *testing.T, c *test.Test) (directoryRoles *[]msgraph.DirectoryRole) { diff --git a/msgraph/groups.go b/msgraph/groups.go index 85b6e08b..e1a8faae 100644 --- a/msgraph/groups.go +++ b/msgraph/groups.go @@ -206,12 +206,13 @@ func (c *GroupsClient) GetDeleted(ctx context.Context, id string, query odata.Qu func (c *GroupsClient) Update(ctx context.Context, group Group) (int, error) { var status int - if group.ID == nil { + if group.ID() == nil { return status, fmt.Errorf("cannot update group with nil ID") } - groupId := *group.ID - group.ID = nil + groupId := *group.ID() + group.Id = nil + group.ObjectId = nil body, err := json.Marshal(group) if err != nil { @@ -477,7 +478,7 @@ func (c *GroupsClient) AddMembers(ctx context.Context, group *Group) (int, error ValidStatusCodes: []int{http.StatusNoContent}, ValidStatusFunc: checkMemberAlreadyExists, Uri: Uri{ - Entity: fmt.Sprintf("/groups/%s/members/$ref", *group.ID), + Entity: fmt.Sprintf("/groups/%s/members/$ref", *group.ID()), HasTenantId: true, }, }) @@ -643,7 +644,7 @@ func (c *GroupsClient) AddOwners(ctx context.Context, group *Group) (int, error) ValidStatusCodes: []int{http.StatusNoContent}, ValidStatusFunc: checkOwnerAlreadyExists, Uri: Uri{ - Entity: fmt.Sprintf("/groups/%s/owners/$ref", *group.ID), + Entity: fmt.Sprintf("/groups/%s/owners/$ref", *group.ID()), HasTenantId: true, }, }) diff --git a/msgraph/groups_test.go b/msgraph/groups_test.go index 369bdcd7..25031f47 100644 --- a/msgraph/groups_test.go +++ b/msgraph/groups_test.go @@ -25,15 +25,15 @@ func TestGroupsClient(t *testing.T) { Members: &msgraph.Members{*self}, } group := testGroupsClient_Create(t, c, newGroup) - testGroupsClient_Get(t, c, *group.ID) + testGroupsClient_Get(t, c, *group.ID()) - owners := testGroupsClient_ListOwners(t, c, *group.ID) - testGroupsClient_GetOwner(t, c, *group.ID, (*owners)[0]) + owners := testGroupsClient_ListOwners(t, c, *group.ID()) + testGroupsClient_GetOwner(t, c, *group.ID(), (*owners)[0]) - members := testGroupsClient_ListMembers(t, c, *group.ID) - transitiveMembers := testGroupsClient_ListTransitiveMembers(t, c, *group.ID) - testGroupsClient_GetMember(t, c, *group.ID, (*members)[0]) - testGroupsClient_GetMember(t, c, *group.ID, (*transitiveMembers)[0]) + members := testGroupsClient_ListMembers(t, c, *group.ID()) + transitiveMembers := testGroupsClient_ListTransitiveMembers(t, c, *group.ID()) + testGroupsClient_GetMember(t, c, *group.ID(), (*members)[0]) + testGroupsClient_GetMember(t, c, *group.ID(), (*transitiveMembers)[0]) group.DisplayName = utils.StringPtr(fmt.Sprintf("test-updated-group-%s", c.RandomString)) testGroupsClient_Update(t, c, *group) @@ -50,15 +50,15 @@ func TestGroupsClient(t *testing.T) { group.Owners = &msgraph.Owners{user.DirectoryObject} testGroupsClient_AddOwners(t, c, group) - testGroupsClient_RemoveOwners(t, c, *group.ID, &([]string{c.Claims.ObjectId})) + testGroupsClient_RemoveOwners(t, c, *group.ID(), &([]string{c.Claims.ObjectId})) group.Members = &msgraph.Members{user.DirectoryObject} testGroupsClient_AddMembers(t, c, group) - testGroupsClient_RemoveMembers(t, c, *group.ID, &([]string{c.Claims.ObjectId})) + testGroupsClient_RemoveMembers(t, c, *group.ID(), &([]string{c.Claims.ObjectId})) testGroupsClient_List(t, c) - testGroupsClient_Delete(t, c, *group.ID) - testUsersClient_Delete(t, c, *user.ID) + testGroupsClient_Delete(t, c, *group.ID()) + testUsersClient_Delete(t, c, *user.ID()) newGroup365 := msgraph.Group{ DisplayName: utils.StringPtr("test-group-365"), @@ -68,12 +68,12 @@ func TestGroupsClient(t *testing.T) { SecurityEnabled: utils.BoolPtr(true), } group365 := testGroupsClient_Create(t, c, newGroup365) - testGroupsClient_Delete(t, c, *group365.ID) - testGroupsClient_GetDeleted(t, c, *group365.ID) - testGroupsClient_RestoreDeleted(t, c, *group365.ID) - testGroupsClient_Delete(t, c, *group365.ID) - testGroupsClient_ListDeleted(t, c, *group365.ID) - testGroupsClient_DeletePermanently(t, c, *group365.ID) + testGroupsClient_Delete(t, c, *group365.ID()) + testGroupsClient_GetDeleted(t, c, *group365.ID()) + testGroupsClient_RestoreDeleted(t, c, *group365.ID()) + testGroupsClient_Delete(t, c, *group365.ID()) + testGroupsClient_ListDeleted(t, c, *group365.ID()) + testGroupsClient_DeletePermanently(t, c, *group365.ID()) } func testGroupsClient_Create(t *testing.T, c *test.Test, g msgraph.Group) (group *msgraph.Group) { @@ -87,7 +87,7 @@ func testGroupsClient_Create(t *testing.T, c *test.Test, g msgraph.Group) (group if group == nil { t.Fatal("GroupsClient.Create(): group was nil") } - if group.ID == nil { + if group.ID() == nil { t.Fatal("GroupsClient.Create(): group.ID was nil") } return @@ -300,7 +300,7 @@ func testGroupsClient_ListDeleted(t *testing.T, c *test.Test, expectedId string) } found := false for _, group := range *deletedGroups { - if group.ID != nil && *group.ID == expectedId { + if id := group.ID(); id != nil && *id == expectedId { found = true break } @@ -322,10 +322,10 @@ func testGroupsClient_RestoreDeleted(t *testing.T, c *test.Test, id string) { if group == nil { t.Fatal("GroupsClient.RestoreDeleted(): group was nil") } - if group.ID == nil { + if group.ID() == nil { t.Fatal("GroupsClient.RestoreDeleted(): group.ID was nil") } - if *group.ID != id { + if *group.ID() != id { t.Fatal("GroupsClient.RestoreDeleted(): group IDs do not match") } } diff --git a/msgraph/models.go b/msgraph/models.go index 3de02e43..c3db193a 100644 --- a/msgraph/models.go +++ b/msgraph/models.go @@ -761,16 +761,38 @@ type DirectoryAudit struct { type DirectoryObject struct { ODataId *odata.Id `json:"@odata.id,omitempty"` ODataType *odata.Type `json:"@odata.type,omitempty"` - ID *string `json:"id,omitempty"` + Id *string `json:"id,omitempty"` + ObjectId *string `json:"objectId,omitempty"` DisplayName *string `json:"displayName,omitempty"` AdditionalData map[string]interface{} `json:"-"` } +func (o *DirectoryObject) ID() (id *string) { + if o.Id != nil { + id = o.Id + } else if o.ObjectId != nil { + id = o.ObjectId + } + return +} + +func (o *DirectoryObject) UnmarshalJSONWithAdditionalData(data []byte) error { + type directoryObject DirectoryObject + obj := (*directoryObject)(o) + if err := json.Unmarshal(data, &obj); err != nil { + return err + } + if err := json.Unmarshal(data, &obj.AdditionalData); err != nil { + return err + } + return nil +} + func (o *DirectoryObject) Uri(endpoint environments.ApiEndpoint, apiVersion ApiVersion) string { - if o.ID == nil { + if o.Id == nil { return "" } - return fmt.Sprintf("%s/%s/directoryObjects/%s", endpoint, apiVersion, *o.ID) + return fmt.Sprintf("%s/%s/directoryObjects/%s", endpoint, apiVersion, *o.Id) } type DirectoryRole struct { diff --git a/msgraph/role_assignments_test.go b/msgraph/role_assignments_test.go index 4e7d9dfa..0f085839 100644 --- a/msgraph/role_assignments_test.go +++ b/msgraph/role_assignments_test.go @@ -40,16 +40,16 @@ func TestRoleAssignmentsClient(t *testing.T) { roleAssignment := testRoleAssignmentsClient_Create(t, c, msgraph.UnifiedRoleAssignment{ DirectoryScopeId: utils.StringPtr("/"), - PrincipalId: user.ID, - RoleDefinitionId: roleDefinition.ID, + PrincipalId: user.ID(), + RoleDefinitionId: roleDefinition.ID(), }) - testRoleAssignmentsClient_Get(t, c, *roleAssignment.ID) - testRoleAssignmentsClient_List(t, c, odata.Query{Filter: fmt.Sprintf("roleDefinitionId eq '%s'", *roleDefinition.ID)}) - testRoleAssignmentsClient_Delete(t, c, *roleAssignment.ID) - testRoleDefinitionsClient_Delete(t, c, *roleDefinition.ID) - testUsersClient_Delete(t, c, *user.ID) - testUsersClient_DeletePermanently(t, c, *user.ID) + testRoleAssignmentsClient_Get(t, c, *roleAssignment.ID()) + testRoleAssignmentsClient_List(t, c, odata.Query{Filter: fmt.Sprintf("roleDefinitionId eq '%s'", *roleDefinition.ID())}) + testRoleAssignmentsClient_Delete(t, c, *roleAssignment.ID()) + testRoleDefinitionsClient_Delete(t, c, *roleDefinition.ID()) + testUsersClient_Delete(t, c, *user.ID()) + testUsersClient_DeletePermanently(t, c, *user.ID()) } func testRoleAssignmentsClient_Create(t *testing.T, c *test.Test, r msgraph.UnifiedRoleAssignment) (roleAssignment *msgraph.UnifiedRoleAssignment) { @@ -63,7 +63,7 @@ func testRoleAssignmentsClient_Create(t *testing.T, c *test.Test, r msgraph.Unif if roleAssignment == nil { t.Fatal("RoleAssignmentsClient.Create(): roleAssignment was nil") } - if roleAssignment.ID == nil { + if roleAssignment.ID() == nil { t.Fatal("RoleAssignmentsClient.Create(): roleAssignment.ID was nil") } return diff --git a/msgraph/role_definitions.go b/msgraph/role_definitions.go index eb95201d..a0fb5ab3 100644 --- a/msgraph/role_definitions.go +++ b/msgraph/role_definitions.go @@ -129,7 +129,7 @@ func (c *RoleDefinitionsClient) Update(ctx context.Context, roleDefinition Unifi ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, ValidStatusCodes: []int{http.StatusNoContent}, Uri: Uri{ - Entity: fmt.Sprintf("/roleManagement/directory/roleDefinitions/%s", *roleDefinition.ID), + Entity: fmt.Sprintf("/roleManagement/directory/roleDefinitions/%s", *roleDefinition.ID()), HasTenantId: true, }, }) diff --git a/msgraph/role_definitions_test.go b/msgraph/role_definitions_test.go index c965799e..8821480a 100644 --- a/msgraph/role_definitions_test.go +++ b/msgraph/role_definitions_test.go @@ -32,13 +32,13 @@ func TestRoleDefinitionsClient(t *testing.T) { roleDefinition.Description = msgraph.NullableString("for the tests") testRoleDefinitionsClient_Update(t, c, *roleDefinition) - testRoleDefinitionsClient_Get(t, c, *roleDefinition.ID) + testRoleDefinitionsClient_Get(t, c, *roleDefinition.ID()) roleDefinitions := testRoleDefinitionsClient_List(t, c) role := (*roleDefinitions)[0] - testRoleDefinitionsClient_Get(t, c, *role.ID) + testRoleDefinitionsClient_Get(t, c, *role.ID()) - testRoleDefinitionsClient_Delete(t, c, *roleDefinition.ID) + testRoleDefinitionsClient_Delete(t, c, *roleDefinition.ID()) } func testRoleDefinitionsClient_Create(t *testing.T, c *test.Test, r msgraph.UnifiedRoleDefinition) (roleDefinition *msgraph.UnifiedRoleDefinition) { @@ -52,7 +52,7 @@ func testRoleDefinitionsClient_Create(t *testing.T, c *test.Test, r msgraph.Unif if roleDefinition == nil { t.Fatal("RoleDefinitionsClient.Create(): roleDefinition was nil") } - if roleDefinition.ID == nil { + if roleDefinition.ID() == nil { t.Fatal("RoleDefinitionsClient.Create(): roleDefinition.ID was nil") } return diff --git a/msgraph/schema_extensions_test.go b/msgraph/schema_extensions_test.go index 48687d2d..5fb8c3e3 100644 --- a/msgraph/schema_extensions_test.go +++ b/msgraph/schema_extensions_test.go @@ -88,7 +88,7 @@ func testSchemaExtensionsGroup(t *testing.T, c *test.Test, schema *msgraph.Schem }) // Then retrieve the group and populate using msgraph.SchemaExtensionGraph - group = testSchemaExtensionsGroup_Get(t, c, *group.ID, []msgraph.SchemaExtensionData{ + group = testSchemaExtensionsGroup_Get(t, c, *group.ID(), []msgraph.SchemaExtensionData{ { ID: *schema.ID, Properties: &msgraph.SchemaExtensionMap{}, @@ -116,7 +116,7 @@ func testSchemaExtensionsGroup(t *testing.T, c *test.Test, schema *msgraph.Schem testGroupsClient_Update(t, c, *group) // Finally retrieve the group and populate using MyExtensionProperties - group = testSchemaExtensionsGroup_Get(t, c, *group.ID, []msgraph.SchemaExtensionData{ + group = testSchemaExtensionsGroup_Get(t, c, *group.ID(), []msgraph.SchemaExtensionData{ { ID: *schema.ID, Properties: &MyExtensionProperties{}, @@ -130,7 +130,7 @@ func testSchemaExtensionsGroup(t *testing.T, c *test.Test, schema *msgraph.Schem t.Fatalf("Unexpected value for Property2 returned: %+v", val) } - testGroupsClient_Delete(t, c, *group.ID) + testGroupsClient_Delete(t, c, *group.ID()) } func testSchemaExtensionsGroup_Get(t *testing.T, c *test.Test, id string, schemaExtensions []msgraph.SchemaExtensionData) (group *msgraph.Group) { @@ -179,7 +179,7 @@ func testSchemaExtensionsUser(t *testing.T, c *test.Test, schema *msgraph.Schema }) // Then retrieve the user and populate using msgraph.SchemaExtensionGraph - user = testSchemaExtensionsUser_Get(t, c, *user.ID, []msgraph.SchemaExtensionData{ + user = testSchemaExtensionsUser_Get(t, c, *user.ID(), []msgraph.SchemaExtensionData{ { ID: *schema.ID, Properties: &msgraph.SchemaExtensionMap{}, @@ -207,7 +207,7 @@ func testSchemaExtensionsUser(t *testing.T, c *test.Test, schema *msgraph.Schema testUsersClient_Update(t, c, *user) // Finally retrieve the user and populate using MyExtensionProperties - user = testSchemaExtensionsUser_Get(t, c, *user.ID, []msgraph.SchemaExtensionData{ + user = testSchemaExtensionsUser_Get(t, c, *user.ID(), []msgraph.SchemaExtensionData{ { ID: *schema.ID, Properties: &MyExtensionProperties{}, @@ -221,7 +221,7 @@ func testSchemaExtensionsUser(t *testing.T, c *test.Test, schema *msgraph.Schema t.Fatalf("Unexpected value for Property2 returned: %+v", val) } - testUsersClient_Delete(t, c, *user.ID) + testUsersClient_Delete(t, c, *user.ID()) } func testSchemaExtensionsUser_Get(t *testing.T, c *test.Test, id string, schemaExtensions []msgraph.SchemaExtensionData) (user *msgraph.User) { diff --git a/msgraph/serviceprincipals.go b/msgraph/serviceprincipals.go index 698523bf..89eeed4e 100644 --- a/msgraph/serviceprincipals.go +++ b/msgraph/serviceprincipals.go @@ -138,7 +138,7 @@ func (c *ServicePrincipalsClient) Get(ctx context.Context, id string, query odat func (c *ServicePrincipalsClient) Update(ctx context.Context, servicePrincipal ServicePrincipal) (int, error) { var status int - if servicePrincipal.ID == nil { + if servicePrincipal.ID() == nil { return status, errors.New("cannot update service principal with nil ID") } @@ -152,7 +152,7 @@ func (c *ServicePrincipalsClient) Update(ctx context.Context, servicePrincipal S ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, ValidStatusCodes: []int{http.StatusNoContent}, Uri: Uri{ - Entity: fmt.Sprintf("/servicePrincipals/%s", *servicePrincipal.ID), + Entity: fmt.Sprintf("/servicePrincipals/%s", *servicePrincipal.ID()), HasTenantId: true, }, }) @@ -265,7 +265,7 @@ func (c *ServicePrincipalsClient) GetOwner(ctx context.Context, servicePrincipal func (c *ServicePrincipalsClient) AddOwners(ctx context.Context, servicePrincipal *ServicePrincipal) (int, error) { var status int - if servicePrincipal.ID == nil { + if servicePrincipal.ID() == nil { return status, errors.New("cannot update service principal with nil ID") } if servicePrincipal.Owners == nil { @@ -292,7 +292,7 @@ func (c *ServicePrincipalsClient) AddOwners(ctx context.Context, servicePrincipa ValidStatusCodes: []int{http.StatusNoContent}, ValidStatusFunc: checkOwnerAlreadyExists, Uri: Uri{ - Entity: fmt.Sprintf("/servicePrincipals/%s/owners/$ref", *servicePrincipal.ID), + Entity: fmt.Sprintf("/servicePrincipals/%s/owners/$ref", *servicePrincipal.ID()), HasTenantId: true, }, }) @@ -352,7 +352,7 @@ func (c *ServicePrincipalsClient) RemoveOwners(ctx context.Context, servicePrinc func (c *ServicePrincipalsClient) AssignClaimsMappingPolicy(ctx context.Context, servicePrincipal *ServicePrincipal) (int, error) { var status int - if servicePrincipal.ID == nil { + if servicePrincipal.ID() == nil { return status, errors.New("cannot update service principal with nil ID") } if servicePrincipal.ClaimsMappingPolicies == nil { @@ -379,7 +379,7 @@ func (c *ServicePrincipalsClient) AssignClaimsMappingPolicy(ctx context.Context, ValidStatusCodes: []int{http.StatusNoContent}, ValidStatusFunc: checkPolicyAlreadyExists, Uri: Uri{ - Entity: fmt.Sprintf("/servicePrincipals/%s/claimsMappingPolicies/$ref", *servicePrincipal.ID), + Entity: fmt.Sprintf("/servicePrincipals/%s/claimsMappingPolicies/$ref", *servicePrincipal.ID()), HasTenantId: false, }, }) @@ -431,7 +431,7 @@ func (c *ServicePrincipalsClient) RemoveClaimsMappingPolicy(ctx context.Context, return status, errors.New("cannot remove, nil policyIds") } - assignedPolicies, _, err := c.ListClaimsMappingPolicy(ctx, *servicePrincipal.ID) + assignedPolicies, _, err := c.ListClaimsMappingPolicy(ctx, *servicePrincipal.ID()) if err != nil { return status, fmt.Errorf("ServicePrincipalsClient.BaseClient.ListClaimsMappingPolicy(): %v", err) } @@ -442,7 +442,7 @@ func (c *ServicePrincipalsClient) RemoveClaimsMappingPolicy(ctx context.Context, mapClaimsMappingPolicy := map[string]ClaimsMappingPolicy{} for _, v := range *assignedPolicies { - mapClaimsMappingPolicy[*v.ID] = v + mapClaimsMappingPolicy[*v.ID()] = v } for _, policyId := range *policyIds { @@ -465,7 +465,7 @@ func (c *ServicePrincipalsClient) RemoveClaimsMappingPolicy(ctx context.Context, ValidStatusCodes: []int{http.StatusNoContent}, ValidStatusFunc: checkPolicyStatus, Uri: Uri{ - Entity: fmt.Sprintf("/servicePrincipals/%s/claimsMappingPolicies/%s/$ref", *servicePrincipal.ID, policyId), + Entity: fmt.Sprintf("/servicePrincipals/%s/claimsMappingPolicies/%s/$ref", *servicePrincipal.ID(), policyId), HasTenantId: false, }, }) diff --git a/msgraph/serviceprincipals_test.go b/msgraph/serviceprincipals_test.go index b9ab327f..a927066b 100644 --- a/msgraph/serviceprincipals_test.go +++ b/msgraph/serviceprincipals_test.go @@ -38,9 +38,9 @@ func TestServicePrincipalsClient(t *testing.T) { spChild.Owners = &msgraph.Owners{sp.DirectoryObject} testServicePrincipalsClient_AddOwners(t, c, spChild) - testServicePrincipalsClient_ListOwners(t, c, *spChild.ID, []string{*sp.ID}) - testServicePrincipalsClient_GetOwner(t, c, *spChild.ID, *sp.ID) - testServicePrincipalsClient_Get(t, c, *sp.ID) + testServicePrincipalsClient_ListOwners(t, c, *spChild.ID(), []string{*sp.ID()}) + testServicePrincipalsClient_GetOwner(t, c, *spChild.ID(), *sp.ID()) + testServicePrincipalsClient_Get(t, c, *sp.ID()) sp.Tags = &([]string{"TestTag"}) testServicePrincipalsClient_Update(t, c, *sp) pwd := testServicePrincipalsClient_AddPassword(t, c, sp) @@ -64,10 +64,10 @@ func TestServicePrincipalsClient(t *testing.T) { testServicePrincipalsClient_AssignClaimsMappingPolicy(t, c, sp) // ListClaimsMappingPolicy is called within RemoveClaimsMappingPolicy - testServicePrincipalsClient_RemoveClaimsMappingPolicy(t, c, sp, []string{*claimsMappingPolicy.ID}) + testServicePrincipalsClient_RemoveClaimsMappingPolicy(t, c, sp, []string{*claimsMappingPolicy.ID()}) // A Second call tests that a remove call on an empty assignment list returns ok - testServicePrincipalsClient_RemoveClaimsMappingPolicy(t, c, sp, []string{*claimsMappingPolicy.ID}) - testClaimsMappingPolicyClient_Delete(t, c, *claimsMappingPolicy.ID) + testServicePrincipalsClient_RemoveClaimsMappingPolicy(t, c, sp, []string{*claimsMappingPolicy.ID()}) + testClaimsMappingPolicyClient_Delete(t, c, *claimsMappingPolicy.ID()) newGroupParent := msgraph.Group{ DisplayName: utils.StringPtr("test-group-servicePrincipal-parent"), @@ -89,18 +89,18 @@ func TestServicePrincipalsClient(t *testing.T) { groupChild.Members = &msgraph.Members{sp.DirectoryObject} testGroupsClient_AddMembers(t, c, groupChild) - testServicePrincipalsClient_ListGroupMemberships(t, c, *sp.ID) - testServicePrincipalsClient_ListOwnedObjects(t, c, *sp.ID) + testServicePrincipalsClient_ListGroupMemberships(t, c, *sp.ID()) + testServicePrincipalsClient_ListOwnedObjects(t, c, *sp.ID()) - testServicePrincipalsClient_RemoveOwners(t, c, *spChild.ID, []string{*sp.ID}) - testGroupsClient_Delete(t, c, *groupParent.ID) - testGroupsClient_Delete(t, c, *groupChild.ID) + testServicePrincipalsClient_RemoveOwners(t, c, *spChild.ID(), []string{*sp.ID()}) + testGroupsClient_Delete(t, c, *groupParent.ID()) + testGroupsClient_Delete(t, c, *groupChild.ID()) - testServicePrincipalsClient_Delete(t, c, *sp.ID) - testServicePrincipalsClient_Delete(t, c, *spChild.ID) + testServicePrincipalsClient_Delete(t, c, *sp.ID()) + testServicePrincipalsClient_Delete(t, c, *spChild.ID()) - testApplicationsClient_Delete(t, c, *app.ID) - testApplicationsClient_Delete(t, c, *appChild.ID) + testApplicationsClient_Delete(t, c, *app.ID()) + testApplicationsClient_Delete(t, c, *appChild.ID()) } func TestServicePrincipalsClient_AppRoleAssignments(t *testing.T) { @@ -132,7 +132,7 @@ func TestServicePrincipalsClient_AppRoleAssignments(t *testing.T) { AppId: app.AppId, DisplayName: app.DisplayName, }) - testServicePrincipalsClient_Get(t, c, *sp.ID) + testServicePrincipalsClient_Get(t, c, *sp.ID()) sp.Tags = &([]string{"TestTag"}) testServicePrincipalsClient_Update(t, c, *sp) testServicePrincipalsClient_List(t, c, odata.Query{}) @@ -157,23 +157,23 @@ func TestServicePrincipalsClient_AppRoleAssignments(t *testing.T) { groupChild.Members = &msgraph.Members{sp.DirectoryObject} testGroupsClient_AddMembers(t, c, groupChild) - testServicePrincipalsClient_ListGroupMemberships(t, c, *sp.ID) + testServicePrincipalsClient_ListGroupMemberships(t, c, *sp.ID()) // App Role Assignments - appRoleAssignment := testServicePrincipalsClient_AssignAppRole(t, c, *groupParent.ID, *sp.ID, testResourceAppRoleId) + appRoleAssignment := testServicePrincipalsClient_AssignAppRole(t, c, *groupParent.ID(), *sp.ID(), testResourceAppRoleId) // list resourceApp role assignments for a test group - appRoleAssignments := testServicePrincipalsClient_ListAppRoleAssignments(t, c, *sp.ID) + appRoleAssignments := testServicePrincipalsClient_ListAppRoleAssignments(t, c, *sp.ID()) if len(*appRoleAssignments) == 0 { t.Fatal("expected at least one app role assignment assigned to the test group") } // removes app role assignment previously set to the test group - testServicePrincipalsClient_RemoveAppRoleAssignment(t, c, *sp.ID, *appRoleAssignment.Id) + testServicePrincipalsClient_RemoveAppRoleAssignment(t, c, *sp.ID(), *appRoleAssignment.Id) // remove all test resources - testGroupsClient_Delete(t, c, *groupParent.ID) - testGroupsClient_Delete(t, c, *groupChild.ID) - testServicePrincipalsClient_Delete(t, c, *sp.ID) - testApplicationsClient_Delete(t, c, *app.ID) + testGroupsClient_Delete(t, c, *groupParent.ID()) + testGroupsClient_Delete(t, c, *groupChild.ID()) + testServicePrincipalsClient_Delete(t, c, *sp.ID()) + testApplicationsClient_Delete(t, c, *app.ID()) } @@ -188,7 +188,7 @@ func testServicePrincipalsClient_Create(t *testing.T, c *test.Test, sp msgraph.S if servicePrincipal == nil { t.Fatal("ServicePrincipalsClient.Create(): servicePrincipal was nil") } - if servicePrincipal.ID == nil { + if servicePrincipal.ID() == nil { t.Fatal("ServicePrincipalsClient.Create(): servicePrincipal.ID was nil") } return @@ -264,7 +264,7 @@ func testServicePrincipalsClient_AddPassword(t *testing.T, c *test.Test, a *msgr DisplayName: utils.StringPtr("test password"), EndDateTime: &expiry, } - newPwd, status, err := c.ServicePrincipalsClient.AddPassword(c.Context, *a.ID, pwd) + newPwd, status, err := c.ServicePrincipalsClient.AddPassword(c.Context, *a.ID(), pwd) if err != nil { t.Fatalf("ServicePrincipalsClient.AddPassword(): %v", err) } @@ -283,7 +283,7 @@ func testServicePrincipalsClient_AddTokenSigningCertificate(t *testing.T, c *tes DisplayName: utils.StringPtr("cn=test cert"), EndDateTime: &expiry, } - newKey, status, err := c.ServicePrincipalsClient.AddTokenSigningCertificate(c.Context, *a.ID, tsc) + newKey, status, err := c.ServicePrincipalsClient.AddTokenSigningCertificate(c.Context, *a.ID(), tsc) if err != nil { t.Fatalf("ServicePrincipalsClient.AddTokenSigningCertificate(): %v", err) } @@ -300,7 +300,7 @@ func testServicePrincipalsClient_AddTokenSigningCertificate(t *testing.T, c *tes func testServicePrincipalsClient_SetPreferredTokenSigningKeyThumbprint(t *testing.T, c *test.Test, a *msgraph.ServicePrincipal, thumbprint string) { - status, err := c.ServicePrincipalsClient.SetPreferredTokenSigningKeyThumbprint(c.Context, *a.ID, thumbprint) + status, err := c.ServicePrincipalsClient.SetPreferredTokenSigningKeyThumbprint(c.Context, *a.ID(), thumbprint) if err != nil { t.Fatalf("ServicePrincipalsClient.AddTokenSigningCertificate(): %v", err) } @@ -310,7 +310,7 @@ func testServicePrincipalsClient_SetPreferredTokenSigningKeyThumbprint(t *testin } func testServicePrincipalsClient_RemovePassword(t *testing.T, c *test.Test, a *msgraph.ServicePrincipal, p *msgraph.PasswordCredential) { - status, err := c.ServicePrincipalsClient.RemovePassword(c.Context, *a.ID, *p.KeyId) + status, err := c.ServicePrincipalsClient.RemovePassword(c.Context, *a.ID(), *p.KeyId) if err != nil { t.Fatalf("ServicePrincipalsClient.RemovePassword(): %v", err) } diff --git a/msgraph/synchronization_test.go b/msgraph/synchronization_test.go index bce1c682..9dc2c6d3 100644 --- a/msgraph/synchronization_test.go +++ b/msgraph/synchronization_test.go @@ -31,28 +31,28 @@ func TestSynchronizationClient(t *testing.T) { Value: utils.StringPtr("dummy-token"), }, }, - }, *app.ServicePrincipal.ID) - testSynchronizationJobClient_GetSecrets(t, c, *app.ServicePrincipal.ID) + }, *app.ServicePrincipal.ID()) + testSynchronizationJobClient_GetSecrets(t, c, *app.ServicePrincipal.ID()) job := testSynchronizationJobClient_Create(t, c, msgraph.SynchronizationJob{ Schedule: &msgraph.SynchronizationSchedule{ State: utils.StringPtr("Disabled"), }, TemplateId: utils.StringPtr("dataBricks"), - }, *app.ServicePrincipal.ID) + }, *app.ServicePrincipal.ID()) - testSynchronizationJobClient_Get(t, c, *job.ID, *app.ServicePrincipal.ID) - testSynchronizationJobClient_Start(t, c, *job.ID, *app.ServicePrincipal.ID) - testSynchronizationJobClient_List(t, c, *app.ServicePrincipal.ID) - testSynchronizationJobClient_Pause(t, c, *job.ID, *app.ServicePrincipal.ID) - testSynchronizationJobClient_Restart(t, c, *job.ID, msgraph.SynchronizationJobRestartCriteria{}, *app.ServicePrincipal.ID) - testSynchronizationJobClient_Delete(t, c, *job.ID, *app.ServicePrincipal.ID) + testSynchronizationJobClient_Get(t, c, *job.ID, *app.ServicePrincipal.ID()) + testSynchronizationJobClient_Start(t, c, *job.ID, *app.ServicePrincipal.ID()) + testSynchronizationJobClient_List(t, c, *app.ServicePrincipal.ID()) + testSynchronizationJobClient_Pause(t, c, *job.ID, *app.ServicePrincipal.ID()) + testSynchronizationJobClient_Restart(t, c, *job.ID, msgraph.SynchronizationJobRestartCriteria{}, *app.ServicePrincipal.ID()) + testSynchronizationJobClient_Delete(t, c, *job.ID, *app.ServicePrincipal.ID()) // We don't test validateCredentials as this requires provisioning a valid enterprise application - testServicePrincipalsClient_Delete(t, c, *app.ServicePrincipal.ID) + testServicePrincipalsClient_Delete(t, c, *app.ServicePrincipal.ID()) - testApplicationsClient_Delete(t, c, *app.Application.ID) - testApplicationsClient_DeletePermanently(t, c, *app.Application.ID) + testApplicationsClient_Delete(t, c, *app.Application.ID()) + testApplicationsClient_DeletePermanently(t, c, *app.Application.ID()) } func testSynchronizationJobClient_GetSecrets(t *testing.T, c *test.Test, servicePrincipalId string) (synchronizationSecret *msgraph.SynchronizationSecret) { diff --git a/msgraph/users.go b/msgraph/users.go index 45be4567..e503ecc4 100644 --- a/msgraph/users.go +++ b/msgraph/users.go @@ -216,7 +216,7 @@ func (c *UsersClient) Update(ctx context.Context, user User) (int, error) { ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, ValidStatusCodes: []int{http.StatusNoContent}, Uri: Uri{ - Entity: fmt.Sprintf("/users/%s", *user.ID), + Entity: fmt.Sprintf("/users/%s", *user.ID()), HasTenantId: true, }, }) diff --git a/msgraph/users_test.go b/msgraph/users_test.go index a65de2ce..fc7527c7 100644 --- a/msgraph/users_test.go +++ b/msgraph/users_test.go @@ -23,7 +23,7 @@ func TestUsersClient(t *testing.T) { Password: utils.StringPtr(fmt.Sprintf("IrPa55w0rd%s", c.RandomString)), }, }) - testUsersClient_Get(t, c, *user.ID) + testUsersClient_Get(t, c, *user.ID()) user.DisplayName = utils.StringPtr(fmt.Sprintf("test-updated-user-%s", c.RandomString)) testUsersClient_Update(t, c, *user) testUsersClient_List(t, c) @@ -37,7 +37,7 @@ func TestUsersClient(t *testing.T) { Password: utils.StringPtr(fmt.Sprintf("IrPa55w0rd%s", c.RandomString)), }, }) - testUsersClient_Get(t, c, *manager.ID) + testUsersClient_Get(t, c, *manager.ID()) groupParent := testGroupsClient_Create(t, c, msgraph.Group{ DisplayName: utils.StringPtr("test-group-parent-users"), @@ -57,21 +57,21 @@ func TestUsersClient(t *testing.T) { groupChild.Members = &msgraph.Members{user.DirectoryObject} testGroupsClient_AddMembers(t, c, groupChild) - testUsersClient_ListGroupMemberships(t, c, *user.ID) - testGroupsClient_Delete(t, c, *groupParent.ID) - testGroupsClient_Delete(t, c, *groupChild.ID) + testUsersClient_ListGroupMemberships(t, c, *user.ID()) + testGroupsClient_Delete(t, c, *groupParent.ID()) + testGroupsClient_Delete(t, c, *groupChild.ID()) - testUsersClient_AssignManager(t, c, *user.ID, *manager) - testUsersClient_GetManager(t, c, *user.ID) - testUsersClient_DeleteManager(t, c, *user.ID) - testUsersClient_Delete(t, c, *manager.ID) + testUsersClient_AssignManager(t, c, *user.ID(), *manager) + testUsersClient_GetManager(t, c, *user.ID()) + testUsersClient_DeleteManager(t, c, *user.ID()) + testUsersClient_Delete(t, c, *manager.ID()) - testUsersClient_Delete(t, c, *user.ID) - testUsersClient_ListDeleted(t, c, *user.ID) - testUsersClient_GetDeleted(t, c, *user.ID) - testUsersClient_RestoreDeleted(t, c, *user.ID) - testUsersClient_Delete(t, c, *user.ID) - testUsersClient_DeletePermanently(t, c, *user.ID) + testUsersClient_Delete(t, c, *user.ID()) + testUsersClient_ListDeleted(t, c, *user.ID()) + testUsersClient_GetDeleted(t, c, *user.ID()) + testUsersClient_RestoreDeleted(t, c, *user.ID()) + testUsersClient_Delete(t, c, *user.ID()) + testUsersClient_DeletePermanently(t, c, *user.ID()) } func testUsersClient_Create(t *testing.T, c *test.Test, u msgraph.User) (user *msgraph.User) { @@ -85,7 +85,7 @@ func testUsersClient_Create(t *testing.T, c *test.Test, u msgraph.User) (user *m if user == nil { t.Fatal("UsersClient.Create(): user was nil") } - if user.ID == nil { + if user.ID() == nil { t.Fatal("UsersClient.Create(): user.ID was nil") } return @@ -196,7 +196,7 @@ func testUsersClient_ListDeleted(t *testing.T, c *test.Test, expectedId string) } found := false for _, user := range *deletedUsers { - if user.ID != nil && *user.ID == expectedId { + if id := user.ID(); id != nil && *id == expectedId { found = true break } @@ -218,10 +218,10 @@ func testUsersClient_RestoreDeleted(t *testing.T, c *test.Test, id string) { if user == nil { t.Fatal("UsersClient.RestoreDeleted(): user was nil") } - if user.ID == nil { + if user.ID() == nil { t.Fatal("UsersClient.RestoreDeleted(): user.ID was nil") } - if *user.ID != id { + if *user.ID() != id { t.Fatal("UsersClient.RestoreDeleted(): user ids do not match") } }