Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- add field `AllowedRuleSet` to `SaveChangesRules`
- change field `Action` field of `SaveChangesRules` to `Actions`

## [v0.18.0] - 2025-06-03

### Changed
Expand Down
36 changes: 32 additions & 4 deletions internal/cmd/company/rules/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,21 @@ func TestClientListTenantRules(t *testing.T) {
"roleIds": ["maintainer"],
"disallowedRuleSet": [
{"jsonPath": "$.services.*.description"},
{"jsonPath": "$.services", "processingOptions": {"action": "create"}}
{"jsonPath": "$.services", "processingOptions": {"actions": ["create"]}}
]
},
{
"roleIds": ["developer"],
"disallowedRuleSet": [
{"ruleId": "endpoint.security.edit"}
]
},
{
"roleIds": ["some-role"],
"allowedRuleSet": [
{ "jsonPath": "$.endpoints.*.public" },
{ "jsonPath": "$.secrets", "processingOptions": { "actions": ["create"], "primaryKey": "clientType" }}
]
}
]
}
Expand Down Expand Up @@ -101,7 +108,7 @@ func TestClientListTenantRules(t *testing.T) {
RoleIDs: []string{"maintainer"},
DisallowedRuleSet: []rulesentities.RuleSet{
{JSONPath: "$.services.*.description"},
{JSONPath: "$.services", Options: &rulesentities.RuleOptions{Action: "create"}},
{JSONPath: "$.services", Options: &rulesentities.RuleOptions{Actions: []string{"create"}}},
},
},
{
Expand All @@ -110,6 +117,13 @@ func TestClientListTenantRules(t *testing.T) {
{RuleID: "endpoint.security.edit"},
},
},
{
RoleIDs: []string{"some-role"},
AllowedRuleSet: []rulesentities.RuleSet{
{JSONPath: "$.endpoints.*.public"},
{JSONPath: "$.secrets", Options: &rulesentities.RuleOptions{Actions: []string{"create"}, PrimaryKey: "clientType"}},
},
},
}, data)
}
})
Expand All @@ -126,7 +140,7 @@ func TestClientListProjectRules(t *testing.T) {
"roleIds": ["maintainer"],
"disallowedRuleSet": [
{"jsonPath": "$.services.*.description"},
{"jsonPath": "$.services", "processingOptions": {"action": "create"}}
{"jsonPath": "$.services", "processingOptions": {"actions":[ "create"]}}
]
},
{
Expand All @@ -135,6 +149,13 @@ func TestClientListProjectRules(t *testing.T) {
{"ruleId": "endpoint.security.edit"}
],
"isInheritedFromTenant": true
},
{
"roleIds": ["some-role"],
"allowedRuleSet": [
{ "jsonPath": "$.endpoints.*.public" },
{ "jsonPath": "$.secrets", "processingOptions": { "actions": ["create"], "primaryKey": "clientType" }}
]
}
]
}
Expand Down Expand Up @@ -190,7 +211,7 @@ func TestClientListProjectRules(t *testing.T) {
RoleIDs: []string{"maintainer"},
DisallowedRuleSet: []rulesentities.RuleSet{
{JSONPath: "$.services.*.description"},
{JSONPath: "$.services", Options: &rulesentities.RuleOptions{Action: "create"}},
{JSONPath: "$.services", Options: &rulesentities.RuleOptions{Actions: []string{"create"}}},
},
},
{
Expand All @@ -200,6 +221,13 @@ func TestClientListProjectRules(t *testing.T) {
},
IsInheritedFromTenant: true,
},
{
RoleIDs: []string{"some-role"},
AllowedRuleSet: []rulesentities.RuleSet{
{JSONPath: "$.endpoints.*.public"},
{JSONPath: "$.secrets", Options: &rulesentities.RuleOptions{Actions: []string{"create"}, PrimaryKey: "clientType"}},
},
},
}, data)
}
})
Expand Down
6 changes: 4 additions & 2 deletions internal/resources/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ package rules
type SaveChangesRules struct {
RoleIDs []string `yaml:"roleIds,omitempty" json:"roleIds,omitempty"` //nolint:tagliatelle
DisallowedRuleSet []RuleSet `yaml:"disallowedRuleSet,omitempty" json:"disallowedRuleSet,omitempty"`
AllowedRuleSet []RuleSet `yaml:"allowedRuleSet,omitempty" json:"allowedRuleSet,omitempty"`
}

type ProjectSaveChangesRules struct {
RoleIDs []string `yaml:"roleIds,omitempty" json:"roleIds,omitempty"` //nolint:tagliatelle
DisallowedRuleSet []RuleSet `yaml:"disallowedRuleSet,omitempty" json:"disallowedRuleSet,omitempty"`
AllowedRuleSet []RuleSet `yaml:"allowedRuleSet,omitempty" json:"allowedRuleSet,omitempty"`
IsInheritedFromTenant bool `yaml:"isInheritedFromTenant,omitempty" json:"isInheritedFromTenant,omitempty"`
}

Expand All @@ -33,6 +35,6 @@ type RuleSet struct {
}

type RuleOptions struct {
Action string `yaml:"action,omitempty" json:"action,omitempty"`
PrimaryKey string `yaml:"primaryKey,omitempty" json:"primaryKey,omitempty"`
Actions []string `yaml:"actions,omitempty" json:"actions,omitempty"`
PrimaryKey string `yaml:"primaryKey,omitempty" json:"primaryKey,omitempty"`
}