Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ linters:
- bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false]
- deadcode # Finds unused code [fast: false, auto-fix: false]
- decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false]
- durationcheck # check for two durations multiplied together [fast: false, auto-fix: false]
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
Expand Down Expand Up @@ -61,6 +60,7 @@ linters:
- whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true]

disable:
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
- dupl # Tool for code clone detection [fast: true, auto-fix: false]
- containedctx # containedctx is a linter that detects struct contained context.Context field [fast: true, auto-fix: false]
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
Expand Down
69 changes: 40 additions & 29 deletions internal/require_if_attribute_is_one_of.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ func (av RequireIfAttributeIsOneOf) Validate(ctx context.Context, req RequireIfA
return
}

expression := req.PathExpression.Merge(av.PathExpression)

// Here attribute configuration is null or unknown, so we need to check if attribute in the path
// is equal to one of the excepted values
paths, diags := req.Config.PathMatches(ctx, av.PathExpression)
paths, diags := req.Config.PathMatches(ctx, expression)
res.Diagnostics.Append(diags...)
if diags.HasError() {
if res.Diagnostics.HasError() {
return
}

Expand Down Expand Up @@ -123,9 +125,10 @@ func (av RequireIfAttributeIsOneOf) Validate(ctx context.Context, req RequireIfA

func (av RequireIfAttributeIsOneOf) ValidateBool(ctx context.Context, req validator.BoolRequest, resp *validator.BoolResponse) {
validateReq := RequireIfAttributeIsOneOfRequest{
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
PathExpression: req.PathExpression,
}
validateResp := &RequireIfAttributeIsOneOfResponse{}

Expand All @@ -136,9 +139,10 @@ func (av RequireIfAttributeIsOneOf) ValidateBool(ctx context.Context, req valida

func (av RequireIfAttributeIsOneOf) ValidateFloat64(ctx context.Context, req validator.Float64Request, resp *validator.Float64Response) {
validateReq := RequireIfAttributeIsOneOfRequest{
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
PathExpression: req.PathExpression,
}
validateResp := &RequireIfAttributeIsOneOfResponse{}

Expand All @@ -149,9 +153,10 @@ func (av RequireIfAttributeIsOneOf) ValidateFloat64(ctx context.Context, req val

func (av RequireIfAttributeIsOneOf) ValidateInt64(ctx context.Context, req validator.Int64Request, resp *validator.Int64Response) {
validateReq := RequireIfAttributeIsOneOfRequest{
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
PathExpression: req.PathExpression,
}
validateResp := &RequireIfAttributeIsOneOfResponse{}

Expand All @@ -162,9 +167,10 @@ func (av RequireIfAttributeIsOneOf) ValidateInt64(ctx context.Context, req valid

func (av RequireIfAttributeIsOneOf) ValidateList(ctx context.Context, req validator.ListRequest, resp *validator.ListResponse) {
validateReq := RequireIfAttributeIsOneOfRequest{
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
PathExpression: req.PathExpression,
}
validateResp := &RequireIfAttributeIsOneOfResponse{}

Expand All @@ -175,9 +181,10 @@ func (av RequireIfAttributeIsOneOf) ValidateList(ctx context.Context, req valida

func (av RequireIfAttributeIsOneOf) ValidateMap(ctx context.Context, req validator.MapRequest, resp *validator.MapResponse) {
validateReq := RequireIfAttributeIsOneOfRequest{
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
PathExpression: req.PathExpression,
}
validateResp := &RequireIfAttributeIsOneOfResponse{}

Expand All @@ -188,9 +195,10 @@ func (av RequireIfAttributeIsOneOf) ValidateMap(ctx context.Context, req validat

func (av RequireIfAttributeIsOneOf) ValidateNumber(ctx context.Context, req validator.NumberRequest, resp *validator.NumberResponse) {
validateReq := RequireIfAttributeIsOneOfRequest{
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
PathExpression: req.PathExpression,
}
validateResp := &RequireIfAttributeIsOneOfResponse{}

Expand All @@ -201,9 +209,10 @@ func (av RequireIfAttributeIsOneOf) ValidateNumber(ctx context.Context, req vali

func (av RequireIfAttributeIsOneOf) ValidateObject(ctx context.Context, req validator.ObjectRequest, resp *validator.ObjectResponse) {
validateReq := RequireIfAttributeIsOneOfRequest{
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
PathExpression: req.PathExpression,
}
validateResp := &RequireIfAttributeIsOneOfResponse{}

Expand All @@ -214,9 +223,10 @@ func (av RequireIfAttributeIsOneOf) ValidateObject(ctx context.Context, req vali

func (av RequireIfAttributeIsOneOf) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) {
validateReq := RequireIfAttributeIsOneOfRequest{
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
PathExpression: req.PathExpression,
}
validateResp := &RequireIfAttributeIsOneOfResponse{}

Expand All @@ -227,9 +237,10 @@ func (av RequireIfAttributeIsOneOf) ValidateSet(ctx context.Context, req validat

func (av RequireIfAttributeIsOneOf) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) {
validateReq := RequireIfAttributeIsOneOfRequest{
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
Config: req.Config,
ConfigValue: req.ConfigValue,
Path: req.Path,
PathExpression: req.PathExpression,
}
validateResp := &RequireIfAttributeIsOneOfResponse{}

Expand Down
4 changes: 0 additions & 4 deletions listvalidator/not_valid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import (
func TestNotValidator(t *testing.T) {
t.Parallel()

type testStruct struct {
foo string
}

type testCase struct {
val []attr.Value
expectError bool
Expand Down
4 changes: 0 additions & 4 deletions mapvalidator/not_valid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import (
func TestNotValidator(t *testing.T) {
t.Parallel()

type testStruct struct {
foo string
}

type testCase struct {
val map[string]attr.Value
expectError bool
Expand Down
4 changes: 0 additions & 4 deletions setvalidator/not_valid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import (
func TestNotValidator(t *testing.T) {
t.Parallel()

type testStruct struct {
foo string
}

type testCase struct {
val []attr.Value
expectError bool
Expand Down