-
Notifications
You must be signed in to change notification settings - Fork 61
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
Fix missing odata type for externalTenants configuration #264
Conversation
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
There was a problem hiding this 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?
msgraph/models.go
Outdated
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) |
There was a problem hiding this comment.
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?
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") | |
} | |
} |
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) | ||
} | ||
} |
There was a problem hiding this comment.
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?
…per function to test package
There was a problem hiding this 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 Thanks, I like the changes you made! |
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