Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update model for DirectoryObject #198

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
14 changes: 7 additions & 7 deletions internal/cmd/test-cleanup/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
14 changes: 7 additions & 7 deletions internal/cmd/test-cleanup/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/test-cleanup/serviceprincipals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
14 changes: 7 additions & 7 deletions internal/cmd/test-cleanup/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
4 changes: 2 additions & 2 deletions msgraph/accesspackageresourcerequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions msgraph/accesspackageresourcerolescope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions msgraph/administrative_units_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,16 +52,16 @@ 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)
testAdministrativeUnitsClient_RemoveScopedRoleMember(t, c, *administrativeUnit.ID, *membership.Id)

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) {
Expand Down
66 changes: 33 additions & 33 deletions msgraph/app_role_assignments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions msgraph/application_templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading