Skip to content

Commit

Permalink
feat(Context-based Restrictions): add enforcement_mode query param
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen SooHoo <[email protected]>
  • Loading branch information
soohoowoohoo authored and padamstx committed Jul 28, 2022
1 parent bbb56e7 commit 6b8440b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
22 changes: 21 additions & 1 deletion contextbasedrestrictionsv1/context_based_restrictions_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

/*
* IBM OpenAPI SDK Code Generator Version: 3.50.0-af9e48c4-20220523-163800
* IBM OpenAPI SDK Code Generator Version: 3.53.0-9710cac3-20220713-193508
*/

// Package contextbasedrestrictionsv1 : Operations and models for the ContextBasedRestrictionsV1 service
Expand Down Expand Up @@ -730,6 +730,9 @@ func (contextBasedRestrictions *ContextBasedRestrictionsV1) ListRulesWithContext
if listRulesOptions.Sort != nil {
builder.AddQuery("sort", fmt.Sprint(*listRulesOptions.Sort))
}
if listRulesOptions.EnforcementMode != nil {
builder.AddQuery("enforcement_mode", fmt.Sprint(*listRulesOptions.EnforcementMode))
}

request, err := builder.Build()
if err != nil {
Expand Down Expand Up @@ -1698,10 +1701,21 @@ type ListRulesOptions struct {
// [Sorting](https://cloud.ibm.com/docs/api-handbook?topic=api-handbook-sorting).
Sort *string `json:"sort,omitempty"`

// The rule's `enforcement_mode` attribute.
EnforcementMode *string `json:"enforcement_mode,omitempty"`

// Allows users to set headers on API requests
Headers map[string]string
}

// Constants associated with the ListRulesOptions.EnforcementMode property.
// The rule's `enforcement_mode` attribute.
const (
ListRulesOptionsEnforcementModeDisabledConst = "disabled"
ListRulesOptionsEnforcementModeEnabledConst = "enabled"
ListRulesOptionsEnforcementModeReportConst = "report"
)

// NewListRulesOptions : Instantiate ListRulesOptions
func (*ContextBasedRestrictionsV1) NewListRulesOptions(accountID string) *ListRulesOptions {
return &ListRulesOptions{
Expand Down Expand Up @@ -1775,6 +1789,12 @@ func (_options *ListRulesOptions) SetSort(sort string) *ListRulesOptions {
return _options
}

// SetEnforcementMode : Allow user to set EnforcementMode
func (_options *ListRulesOptions) SetEnforcementMode(enforcementMode string) *ListRulesOptions {
_options.EnforcementMode = core.StringPtr(enforcementMode)
return _options
}

// SetHeaders : Allow user to set Headers
func (options *ListRulesOptions) SetHeaders(param map[string]string) *ListRulesOptions {
options.Headers = param
Expand Down
10 changes: 10 additions & 0 deletions contextbasedrestrictionsv1/context_based_restrictions_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2012,6 +2012,7 @@ var _ = Describe(`ContextBasedRestrictionsV1`, func() {
Expect(req.URL.Query()["service_type"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["zone_id"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["sort"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["enforcement_mode"]).To(Equal([]string{"enabled"}))
res.Header().Set("Content-type", "application/json")
res.WriteHeader(200)
fmt.Fprint(res, `} this is not valid json {`)
Expand All @@ -2038,6 +2039,7 @@ var _ = Describe(`ContextBasedRestrictionsV1`, func() {
listRulesOptionsModel.ServiceType = core.StringPtr("testString")
listRulesOptionsModel.ZoneID = core.StringPtr("testString")
listRulesOptionsModel.Sort = core.StringPtr("testString")
listRulesOptionsModel.EnforcementMode = core.StringPtr("enabled")
listRulesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}
// Expect response parsing to fail since we are receiving a text/plain response
result, response, operationErr := contextBasedRestrictionsService.ListRules(listRulesOptionsModel)
Expand Down Expand Up @@ -2081,6 +2083,7 @@ var _ = Describe(`ContextBasedRestrictionsV1`, func() {
Expect(req.URL.Query()["service_type"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["zone_id"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["sort"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["enforcement_mode"]).To(Equal([]string{"enabled"}))
// Sleep a short time to support a timeout test
time.Sleep(100 * time.Millisecond)

Expand Down Expand Up @@ -2112,6 +2115,7 @@ var _ = Describe(`ContextBasedRestrictionsV1`, func() {
listRulesOptionsModel.ServiceType = core.StringPtr("testString")
listRulesOptionsModel.ZoneID = core.StringPtr("testString")
listRulesOptionsModel.Sort = core.StringPtr("testString")
listRulesOptionsModel.EnforcementMode = core.StringPtr("enabled")
listRulesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}

// Invoke operation with a Context to test a timeout error
Expand Down Expand Up @@ -2161,6 +2165,7 @@ var _ = Describe(`ContextBasedRestrictionsV1`, func() {
Expect(req.URL.Query()["service_type"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["zone_id"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["sort"]).To(Equal([]string{"testString"}))
Expect(req.URL.Query()["enforcement_mode"]).To(Equal([]string{"enabled"}))
// Set mock response
res.Header().Set("Content-type", "application/json")
res.WriteHeader(200)
Expand Down Expand Up @@ -2194,6 +2199,7 @@ var _ = Describe(`ContextBasedRestrictionsV1`, func() {
listRulesOptionsModel.ServiceType = core.StringPtr("testString")
listRulesOptionsModel.ZoneID = core.StringPtr("testString")
listRulesOptionsModel.Sort = core.StringPtr("testString")
listRulesOptionsModel.EnforcementMode = core.StringPtr("enabled")
listRulesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}

// Invoke operation with valid options model (positive test)
Expand Down Expand Up @@ -2224,6 +2230,7 @@ var _ = Describe(`ContextBasedRestrictionsV1`, func() {
listRulesOptionsModel.ServiceType = core.StringPtr("testString")
listRulesOptionsModel.ZoneID = core.StringPtr("testString")
listRulesOptionsModel.Sort = core.StringPtr("testString")
listRulesOptionsModel.EnforcementMode = core.StringPtr("enabled")
listRulesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}
// Invoke operation with empty URL (negative test)
err := contextBasedRestrictionsService.SetServiceURL("")
Expand Down Expand Up @@ -2275,6 +2282,7 @@ var _ = Describe(`ContextBasedRestrictionsV1`, func() {
listRulesOptionsModel.ServiceType = core.StringPtr("testString")
listRulesOptionsModel.ZoneID = core.StringPtr("testString")
listRulesOptionsModel.Sort = core.StringPtr("testString")
listRulesOptionsModel.EnforcementMode = core.StringPtr("enabled")
listRulesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}

// Invoke operation
Expand Down Expand Up @@ -3455,6 +3463,7 @@ var _ = Describe(`ContextBasedRestrictionsV1`, func() {
listRulesOptionsModel.SetServiceType("testString")
listRulesOptionsModel.SetZoneID("testString")
listRulesOptionsModel.SetSort("testString")
listRulesOptionsModel.SetEnforcementMode("enabled")
listRulesOptionsModel.SetHeaders(map[string]string{"foo": "bar"})
Expect(listRulesOptionsModel).ToNot(BeNil())
Expect(listRulesOptionsModel.AccountID).To(Equal(core.StringPtr("testString")))
Expand All @@ -3468,6 +3477,7 @@ var _ = Describe(`ContextBasedRestrictionsV1`, func() {
Expect(listRulesOptionsModel.ServiceType).To(Equal(core.StringPtr("testString")))
Expect(listRulesOptionsModel.ZoneID).To(Equal(core.StringPtr("testString")))
Expect(listRulesOptionsModel.Sort).To(Equal(core.StringPtr("testString")))
Expect(listRulesOptionsModel.EnforcementMode).To(Equal(core.StringPtr("enabled")))
Expect(listRulesOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"}))
})
It(`Invoke NewListZonesOptions successfully`, func() {
Expand Down

0 comments on commit 6b8440b

Please sign in to comment.