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

feat(Context based Restrictions): enforcement mode support #191

Merged
merged 4 commits into from
Jun 23, 2022

Conversation

zhenwan
Copy link
Member

@zhenwan zhenwan commented Jun 7, 2022

PR summary

Context based Restrictions API update to include enforcement mode support

PR Checklist

Please make sure that your PR fulfills the following requirements:

  • The commit message follows the Angular Commit Message Guidelines.
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Current vs new behavior

add enforcement mode to rule

Does this PR introduce a breaking change?

  • Yes
  • [ x] No

Other information

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Member

@soohoowoohoo soohoowoohoo left a 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:

  1. Why are there 3 sets of enforcement mode constants. Can we just have 1 set?
  2. 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 {
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

changed back

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Comment on lines +1218 to +1222
const (
CreateRuleOptionsEnforcementModeDisabledConst = "disabled"
CreateRuleOptionsEnforcementModeEnabledConst = "enabled"
CreateRuleOptionsEnforcementModeReportConst = "report"
)
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

Comment on lines +1896 to +1900
const (
ReplaceRuleOptionsEnforcementModeDisabledConst = "disabled"
ReplaceRuleOptionsEnforcementModeEnabledConst = "enabled"
ReplaceRuleOptionsEnforcementModeReportConst = "report"
)
Copy link
Member

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

Copy link
Member Author

@zhenwan zhenwan Jun 7, 2022

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

Copy link
Member

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???

Copy link
Member

@soohoowoohoo soohoowoohoo Jun 8, 2022

Choose a reason for hiding this comment

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

@padamstx if everything is populated from the swagger it seems that we should check our swagger to make sure we have 1 definition that gets reused then. @zhenwan can you verify whether we have 1 or multiple definitions?

Copy link
Member

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.

Comment on lines +2230 to +2234
const (
RuleEnforcementModeDisabledConst = "disabled"
RuleEnforcementModeEnabledConst = "enabled"
RuleEnforcementModeReportConst = "report"
)
Copy link
Member

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?

Copy link
Member Author

@zhenwan zhenwan Jun 7, 2022

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

Comment on lines 2362 to 2368
func (*ContextBasedRestrictionsV1) NewServiceRefValue(accountID string) (_model *ServiceRefValue, err error) {
_model = &ServiceRefValue{
AccountID: core.StringPtr(accountID),
}
err = core.ValidateStruct(_model, "required parameters")
return
}
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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.

Comment on lines 3612 to 3617
It(`Invoke NewServiceRefValue successfully`, func() {
accountID := "testString"
_model, err := contextBasedRestrictionsService.NewServiceRefValue(accountID)
Expect(_model).ToNot(BeNil())
Expect(err).To(BeNil())
})
Copy link
Member

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.

Copy link
Member Author

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() {
Copy link
Member

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.

Copy link
Member Author

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...")
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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")
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member

@soohoowoohoo soohoowoohoo left a 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.

Copy link
Member

@padamstx padamstx left a 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?

@zhenwan
Copy link
Member Author

zhenwan commented Jun 10, 2022

@padamstx Please merge this PR. thank you!
Yes, we will work on other 3 SDKs too.

@dpopp07 dpopp07 merged commit f049e95 into IBM:main Jun 23, 2022
ibm-devx-sdk pushed a commit that referenced this pull request Jun 23, 2022
# [0.26.0](v0.25.2...v0.26.0) (2022-06-23)

### Features

* **Context based Restrictions:**  enforcement mode support ([#191](#191)) ([f049e95](f049e95))
@ibm-devx-sdk
Copy link

🎉 This PR is included in version 0.26.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants