Skip to content

Commit 2b9610f

Browse files
author
Guido Zoli
committed
- add field AllowedRuleSet to SaveChangesRules
- change field `Action` field of `SaveChangesRules` to `Actions`
1 parent 76f39d0 commit 2b9610f

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- add field `AllowedRuleSet` to `SaveChangesRules`
13+
- change field `Action` field of `SaveChangesRules` to `Actions`
14+
1015
## [v0.18.0] - 2025-06-03
1116

1217
### Changed

internal/cmd/company/rules/client_test.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,21 @@ func TestClientListTenantRules(t *testing.T) {
3838
"roleIds": ["maintainer"],
3939
"disallowedRuleSet": [
4040
{"jsonPath": "$.services.*.description"},
41-
{"jsonPath": "$.services", "processingOptions": {"action": "create"}}
41+
{"jsonPath": "$.services", "processingOptions": {"actions": ["create"]}}
4242
]
4343
},
4444
{
4545
"roleIds": ["developer"],
4646
"disallowedRuleSet": [
4747
{"ruleId": "endpoint.security.edit"}
4848
]
49+
},
50+
{
51+
"roleIds": ["some-role"],
52+
"allowedRuleSet": [
53+
{ "jsonPath": "$.endpoints.*.public" },
54+
{ "jsonPath": "$.secrets", "processingOptions": { "actions": ["create"], "primaryKey": "clientType" }}
55+
]
4956
}
5057
]
5158
}
@@ -101,7 +108,7 @@ func TestClientListTenantRules(t *testing.T) {
101108
RoleIDs: []string{"maintainer"},
102109
DisallowedRuleSet: []rulesentities.RuleSet{
103110
{JSONPath: "$.services.*.description"},
104-
{JSONPath: "$.services", Options: &rulesentities.RuleOptions{Action: "create"}},
111+
{JSONPath: "$.services", Options: &rulesentities.RuleOptions{Actions: []string{"create"}}},
105112
},
106113
},
107114
{
@@ -110,6 +117,13 @@ func TestClientListTenantRules(t *testing.T) {
110117
{RuleID: "endpoint.security.edit"},
111118
},
112119
},
120+
{
121+
RoleIDs: []string{"some-role"},
122+
AllowedRuleSet: []rulesentities.RuleSet{
123+
{JSONPath: "$.endpoints.*.public"},
124+
{JSONPath: "$.secrets", Options: &rulesentities.RuleOptions{Actions: []string{"create"}, PrimaryKey: "clientType"}},
125+
},
126+
},
113127
}, data)
114128
}
115129
})
@@ -126,7 +140,7 @@ func TestClientListProjectRules(t *testing.T) {
126140
"roleIds": ["maintainer"],
127141
"disallowedRuleSet": [
128142
{"jsonPath": "$.services.*.description"},
129-
{"jsonPath": "$.services", "processingOptions": {"action": "create"}}
143+
{"jsonPath": "$.services", "processingOptions": {"actions":[ "create"]}}
130144
]
131145
},
132146
{
@@ -135,6 +149,13 @@ func TestClientListProjectRules(t *testing.T) {
135149
{"ruleId": "endpoint.security.edit"}
136150
],
137151
"isInheritedFromTenant": true
152+
},
153+
{
154+
"roleIds": ["some-role"],
155+
"allowedRuleSet": [
156+
{ "jsonPath": "$.endpoints.*.public" },
157+
{ "jsonPath": "$.secrets", "processingOptions": { "actions": ["create"], "primaryKey": "clientType" }}
158+
]
138159
}
139160
]
140161
}
@@ -190,7 +211,7 @@ func TestClientListProjectRules(t *testing.T) {
190211
RoleIDs: []string{"maintainer"},
191212
DisallowedRuleSet: []rulesentities.RuleSet{
192213
{JSONPath: "$.services.*.description"},
193-
{JSONPath: "$.services", Options: &rulesentities.RuleOptions{Action: "create"}},
214+
{JSONPath: "$.services", Options: &rulesentities.RuleOptions{Actions: []string{"create"}}},
194215
},
195216
},
196217
{
@@ -200,6 +221,13 @@ func TestClientListProjectRules(t *testing.T) {
200221
},
201222
IsInheritedFromTenant: true,
202223
},
224+
{
225+
RoleIDs: []string{"some-role"},
226+
AllowedRuleSet: []rulesentities.RuleSet{
227+
{JSONPath: "$.endpoints.*.public"},
228+
{JSONPath: "$.secrets", Options: &rulesentities.RuleOptions{Actions: []string{"create"}, PrimaryKey: "clientType"}},
229+
},
230+
},
203231
}, data)
204232
}
205233
})

internal/resources/rules/rules.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ package rules
1818
type SaveChangesRules struct {
1919
RoleIDs []string `yaml:"roleIds,omitempty" json:"roleIds,omitempty"` //nolint:tagliatelle
2020
DisallowedRuleSet []RuleSet `yaml:"disallowedRuleSet,omitempty" json:"disallowedRuleSet,omitempty"`
21+
AllowedRuleSet []RuleSet `yaml:"allowedRuleSet,omitempty" json:"allowedRuleSet,omitempty"`
2122
}
2223

2324
type ProjectSaveChangesRules struct {
2425
RoleIDs []string `yaml:"roleIds,omitempty" json:"roleIds,omitempty"` //nolint:tagliatelle
2526
DisallowedRuleSet []RuleSet `yaml:"disallowedRuleSet,omitempty" json:"disallowedRuleSet,omitempty"`
27+
AllowedRuleSet []RuleSet `yaml:"allowedRuleSet,omitempty" json:"allowedRuleSet,omitempty"`
2628
IsInheritedFromTenant bool `yaml:"isInheritedFromTenant,omitempty" json:"isInheritedFromTenant,omitempty"`
2729
}
2830

@@ -33,6 +35,6 @@ type RuleSet struct {
3335
}
3436

3537
type RuleOptions struct {
36-
Action string `yaml:"action,omitempty" json:"action,omitempty"`
37-
PrimaryKey string `yaml:"primaryKey,omitempty" json:"primaryKey,omitempty"`
38+
Actions []string `yaml:"actions,omitempty" json:"actions,omitempty"`
39+
PrimaryKey string `yaml:"primaryKey,omitempty" json:"primaryKey,omitempty"`
3840
}

0 commit comments

Comments
 (0)