-
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
feat(Context based Restrictions): enforcement mode support #191
Conversation
|
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.
I think most of the testing changes that were removed can be put back. I left comments on some of the high level samples that need to be duplicated everywhere. I guess the top items for me are:
- Why are there 3 sets of enforcement mode constants. Can we just have 1 set?
- Why was the
NewServiceRefValue
method removed. I didn't see a replacement for this.
// Options : Service options | ||
type Options struct { | ||
// ContextBasedRestrictionsV1Options : Service options | ||
type ContextBasedRestrictionsV1Options struct { |
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.
@zhenwan I think you can change this back to Options
. I think this value is what was originally there and that Alberto might have updated it to just be plain Options
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.
changed back
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.
It's preferable to just leave the generated code as-is, otherwise you'll need to make this change whenever you regenerate the service and your service will be will be inconsistent with other services in the SDK.
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.
@padamstx I agree with this statement. However, it seems the first person to publish already started making changes to the auto-generated names. My concern is that if we allow this longer name to stay that we'll have to do a major version bump since this would be a breaking change to the struct name. If you're ok with this (or have some other strategy to handle this), I'm ok with sticking with the auto-generated name.
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.
Yes, it would be a breaking change to revert back to the auto-generated name, but the platform-services SDKs are technically still pre-release, so breaking changes do not need a major version bump.
const ( | ||
CreateRuleOptionsEnforcementModeDisabledConst = "disabled" | ||
CreateRuleOptionsEnforcementModeEnabledConst = "enabled" | ||
CreateRuleOptionsEnforcementModeReportConst = "report" | ||
) |
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.
@zhenwan I assume these are auto generated?
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.
yes
const ( | ||
ReplaceRuleOptionsEnforcementModeDisabledConst = "disabled" | ||
ReplaceRuleOptionsEnforcementModeEnabledConst = "enabled" | ||
ReplaceRuleOptionsEnforcementModeReportConst = "report" | ||
) |
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.
Another enforcement mode reference if changes need to be made
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.
those are auto-generated, I will delete them
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.
These are generated as a result of the fact that the corresponding schema defines an enum. Why delete the const definitions here???
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.
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.
The duplicates might be generated due to the way in which the options model structs are synthesized. The generator will "explode" body vars which means that when representing a request body within the options model struct, the generator will essentially copy each of the request body's top-level properties (assume the request body is defined as an "object"). This might result in duplicates because the options model struct AND the original request body schema would now both define the "enforcement_mode" property which (I assume) contains the enum definition.
Viewing the duplicates through that lens, it makes sense that we're seeing the duplicate definitions. My suggestion would be to just leave the duplicate const definitions there since any changes to the generated code will need to be applied every time you re-gen the service.
const ( | ||
RuleEnforcementModeDisabledConst = "disabled" | ||
RuleEnforcementModeEnabledConst = "enabled" | ||
RuleEnforcementModeReportConst = "report" | ||
) |
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.
Why do we have a third set of constants?
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.
those are auto-generated , I will delete them
func (*ContextBasedRestrictionsV1) NewServiceRefValue(accountID string) (_model *ServiceRefValue, err error) { | ||
_model = &ServiceRefValue{ | ||
AccountID: core.StringPtr(accountID), | ||
} | ||
err = core.ValidateStruct(_model, "required parameters") | ||
return | ||
} |
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.
What happened to this function?
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.
The code generator deleted it. I will added it back according to your comments below
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.
We should first understand what changed in the API definition that caused this to no longer be generated. We can't just add and delete stuff from the generated service code on a whim.
It(`Invoke NewServiceRefValue successfully`, func() { | ||
accountID := "testString" | ||
_model, err := contextBasedRestrictionsService.NewServiceRefValue(accountID) | ||
Expect(_model).ToNot(BeNil()) | ||
Expect(err).To(BeNil()) | ||
}) |
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.
I think should be kept.
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.
added back
|
||
var _ = Describe(`contextbasedrestrictionsv1.ContextBasedRestrictionsV1 Examples Tests`, func() { |
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.
The package prefix can stay.
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.
The package prefixes are removed by the new code generator.
@@ -63,22 +62,23 @@ var _ = Describe(`contextbasedrestrictionsv1.ContextBasedRestrictionsV1 Examples | |||
|
|||
var shouldSkipTest = func() { | |||
if !configLoaded { | |||
Skip("External configuration is not available, skipping tests...") |
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.
we can probably keep calling these tests instead of examples.
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.
yes, if external configuration file is missing, example and integration tests will be skipped, but not the unit tests.
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 change is due to the new version of the generator.
@@ -132,9 +136,9 @@ var _ = Describe(`contextbasedrestrictionsv1.ContextBasedRestrictionsV1 Examples | |||
} | |||
|
|||
createZoneOptions := contextBasedRestrictionsService.NewCreateZoneOptions() | |||
createZoneOptions.SetName("SDK TEST - an example of zone") |
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.
We probably want to keep the SDK TEST -
prefix for our own testing.
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.
I removed them to use the default one so next time when we run the code generator we will have less thing to update
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.
These values come from the example fields defined in the API definition.
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.
Looks good from my end.
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.
LGTM
@zhenwan Let me know when you're ready for me to merge this PR. I assume you'll be making similar changes to the other 3 SDKs, is that right?
@padamstx Please merge this PR. thank you! |
# [0.26.0](v0.25.2...v0.26.0) (2022-06-23) ### Features * **Context based Restrictions:** enforcement mode support ([#191](#191)) ([f049e95](f049e95))
🎉 This PR is included in version 0.26.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
PR summary
Context based Restrictions API update to include enforcement mode support
PR Checklist
Please make sure that your PR fulfills the following requirements:
Current vs new behavior
add
enforcement mode
to ruleDoes this PR introduce a breaking change?
Other information