Skip to content

Commit

Permalink
Change signature of rule parameters validation
Browse files Browse the repository at this point in the history
It now takes a map, since that's easier to use.

Signed-off-by: Juan Antonio Osorio <[email protected]>
  • Loading branch information
JAORMX committed Oct 17, 2024
1 parent ec3ab44 commit 270dfa7
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 117 deletions.
2 changes: 1 addition & 1 deletion cmd/dev/app/rule_type/rttst.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func runEvaluationForRules(
}
cmd.Printf("Profile valid according to the JSON schema!\n")

if err := val.ValidateParamsAgainstSchema(frag.GetParams()); err != nil {
if err := val.ValidateParamsAgainstSchema(frag.GetParams().AsMap()); err != nil {
return fmt.Errorf("error validating params against schema: %w", err)
}

Expand Down
15 changes: 2 additions & 13 deletions internal/engine/rtengine/docs.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2024 Stacklok, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2024 The Minder Authors
// SPDX-License-Identifier: Apache-2.0

// Package rtengine contains utilities for the rule type engine.
package rtengine
12 changes: 2 additions & 10 deletions internal/profiles/rule_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"

"github.com/xeipuuv/gojsonschema"
"google.golang.org/protobuf/types/known/structpb"

minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
)
Expand Down Expand Up @@ -64,19 +63,12 @@ func (r *RuleValidator) ValidateRuleDefAgainstSchema(contextualProfile map[strin

// ValidateParamsAgainstSchema validates the given parameters against the
// schema for this rule type
func (r *RuleValidator) ValidateParamsAgainstSchema(params *structpb.Struct) error {
func (r *RuleValidator) ValidateParamsAgainstSchema(params map[string]any) error {
if r.paramSchema == nil {
return nil
}

if params == nil {
return &RuleValidationError{
RuleType: r.ruleTypeName,
Err: "params cannot be nil",
}
}

if err := validateAgainstSchema(r.paramSchema, params.AsMap()); err != nil {
if err := validateAgainstSchema(r.paramSchema, params); err != nil {
return &RuleValidationError{
RuleType: r.ruleTypeName,
Err: err.Error(),
Expand Down
2 changes: 1 addition & 1 deletion internal/profiles/rule_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestExampleRulesAreValidatedCorrectly(t *testing.T) {
err := rval.ValidateRuleDefAgainstSchema(ruleCall.Def.AsMap())
require.NoError(t, err, "failed to validate rule definition for rule type %s", path)

err = rval.ValidateParamsAgainstSchema(ruleCall.GetParams())
err = rval.ValidateParamsAgainstSchema(ruleCall.GetParams().AsMap())
require.NoError(t, err, "failed to validate rule parameters for rule type %s", path)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/profiles/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (_ *Validator) validateRuleParams(
return fmt.Errorf("error validating rule: %w", err)
}

if err := ruleValidator.ValidateParamsAgainstSchema(profileRule.GetParams()); err != nil {
if err := ruleValidator.ValidateParamsAgainstSchema(profileRule.GetParams().AsMap()); err != nil {
return fmt.Errorf("error validating rule params: %w", err)
}

Expand Down
15 changes: 2 additions & 13 deletions pkg/engine/v1/interfaces/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2024 Stacklok, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2024 The Minder Authors
// SPDX-License-Identifier: Apache-2.0

// Package interfaces contains the interfaces for the Minder policy engine.
package interfaces
Expand Down
15 changes: 2 additions & 13 deletions pkg/engine/v1/rtengine/engine_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2024 Stacklok, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2023 The Minder Authors
// SPDX-License-Identifier: Apache-2.0

package rtengine

Expand Down
15 changes: 2 additions & 13 deletions pkg/testkit/v1/testkit.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2024 Stacklok, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2024 The Minder Authors
// SPDX-License-Identifier: Apache-2.0

// Package v1 contains the v1 version of the testkit package. This is meant to
// aid developers in testing out minder rule types and other components.
Expand Down
15 changes: 2 additions & 13 deletions pkg/testkit/v1/testkit_ingest.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2024 Stacklok, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2024 The Minder Authors
// SPDX-License-Identifier: Apache-2.0

package v1

Expand Down
15 changes: 2 additions & 13 deletions pkg/testkit/v1/testkit_provider.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2024 Stacklok, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2024 The Minder Authors
// SPDX-License-Identifier: Apache-2.0

package v1

Expand Down
15 changes: 2 additions & 13 deletions pkg/testkit/v1/testkit_rest.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2024 Stacklok, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2024 The Minder Authors
// SPDX-License-Identifier: Apache-2.0

package v1

Expand Down
15 changes: 2 additions & 13 deletions pkg/testkit/v1/voidresultsink.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2024 Stacklok, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2024 The Minder Authors
// SPDX-License-Identifier: Apache-2.0

package v1

Expand Down

0 comments on commit 270dfa7

Please sign in to comment.