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

Fix missing odata type for externalTenants configuration #264

Merged

Conversation

agileknight
Copy link
Contributor

Without setting the correct @odata.type for both
possible values all and enumerated, a patch will fail when first enumerating and setting members and then changing to type all because the stored object
is of the wrong type.

References #261

Without setting the correct @odata.type for both
possible values all and enumerated, a patch will fail
when first enumerating and setting members and then
changing to type all because the stored object
is of the wrong type.

References manicminer#261
Copy link
Owner

@manicminer manicminer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agileknight Thanks again for working on this. This mostly LGTM, just a couple of refactoring suggestions below if you can take a look?

Comment on lines 735 to 754
const externalTenantsTypeAll = "#microsoft.graph.conditionalAccessAllExternalTenants"
const externalTenantsTypeEnumerated = "#microsoft.graph.conditionalAccessEnumeratedExternalTenants"
setExternalTenantsObjectType := func(c *conditionalAccessGuestsOrExternalUsers) {
if c == nil {
return
}
if c.ExternalTenants == nil {
return
}
if c.ExternalTenants.MembershipKind == nil {
return
}
switch *c.ExternalTenants.MembershipKind {
case ConditionalAccessExternalTenantsMembershipKindAll:
c.ExternalTenants.ODataType = utils.StringPtr(externalTenantsTypeAll)
case ConditionalAccessExternalTenantsMembershipKindEnumerated:
c.ExternalTenants.ODataType = utils.StringPtr(externalTenantsTypeEnumerated)
}
}
setExternalTenantsObjectType(guestOrExternalUsers.conditionalAccessGuestsOrExternalUsers)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there's no need for reusability here, could we simplify this by forgoing the constant declarations and move the if+switch blocks out into the parent method, dropping the anonymous func? The anonymous struct embeds a pointer to the original struct so this should work?

Suggested change
const externalTenantsTypeAll = "#microsoft.graph.conditionalAccessAllExternalTenants"
const externalTenantsTypeEnumerated = "#microsoft.graph.conditionalAccessEnumeratedExternalTenants"
setExternalTenantsObjectType := func(c *conditionalAccessGuestsOrExternalUsers) {
if c == nil {
return
}
if c.ExternalTenants == nil {
return
}
if c.ExternalTenants.MembershipKind == nil {
return
}
switch *c.ExternalTenants.MembershipKind {
case ConditionalAccessExternalTenantsMembershipKindAll:
c.ExternalTenants.ODataType = utils.StringPtr(externalTenantsTypeAll)
case ConditionalAccessExternalTenantsMembershipKindEnumerated:
c.ExternalTenants.ODataType = utils.StringPtr(externalTenantsTypeEnumerated)
}
}
setExternalTenantsObjectType(guestOrExternalUsers.conditionalAccessGuestsOrExternalUsers)
if c.ExternalTenants != nil && c.ExternalTenants.MembershipKind != nil {
switch *c.ExternalTenants.MembershipKind {
case ConditionalAccessExternalTenantsMembershipKindAll:
c.ExternalTenants.ODataType = utils.StringPtr("#microsoft.graph.conditionalAccessAllExternalTenants")
case ConditionalAccessExternalTenantsMembershipKindEnumerated:
c.ExternalTenants.ODataType = utils.StringPtr("#microsoft.graph.conditionalAccessEnumeratedExternalTenants")
}
}

Comment on lines 203 to 212
func assertJsonMarshalEquals(t *testing.T, value interface{}, expected string) {
bytes, err := json.MarshalIndent(value, "", " ")
if err != nil {
t.Fatalf("Marshalling failed with error %s", err)
}
actual := string(bytes)
if actual != expected {
t.Errorf("Expected marshalled json to equal %s but was %s", expected, actual)
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a useful function to move into the internal/test package?

@manicminer manicminer added bug Something isn't working package/msgraph labels Oct 26, 2023
Copy link
Owner

@manicminer manicminer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agileknight I hope you don't mind, in the interest of getting this in for a release today, I've committed my review suggestions and will tag this shortly. Appreciate the work on this!

@manicminer manicminer added this to the v0.65.0 milestone Oct 26, 2023
@manicminer manicminer merged commit 52e0f56 into manicminer:main Oct 26, 2023
1 of 2 checks passed
@agileknight
Copy link
Contributor Author

@manicminer Thanks, I like the changes you made!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package/msgraph
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants