Skip to content

Commit

Permalink
internal/fwserver: Prevent ConfigValidators from dropping diagnostics (
Browse files Browse the repository at this point in the history
  • Loading branch information
skirsten authored Jan 13, 2023
1 parent 499f24a commit beaf82a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
16 changes: 8 additions & 8 deletions internal/fwserver/schema_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func SchemaValidate(ctx context.Context, s fwschema.Schema, req ValidateSchemaRe
AttributePathExpression: path.MatchRoot(name),
Config: req.Config,
}
attributeResp := &ValidateAttributeResponse{
Diagnostics: resp.Diagnostics,
}
// Instantiate a new response for each request to prevent validators
// from modifying or removing diagnostics.
attributeResp := &ValidateAttributeResponse{}

AttributeValidate(ctx, attribute, attributeReq, attributeResp)

resp.Diagnostics = attributeResp.Diagnostics
resp.Diagnostics.Append(attributeResp.Diagnostics...)
}

for name, block := range s.GetBlocks() {
Expand All @@ -56,13 +56,13 @@ func SchemaValidate(ctx context.Context, s fwschema.Schema, req ValidateSchemaRe
AttributePathExpression: path.MatchRoot(name),
Config: req.Config,
}
attributeResp := &ValidateAttributeResponse{
Diagnostics: resp.Diagnostics,
}
// Instantiate a new response for each request to prevent validators
// from modifying or removing diagnostics.
attributeResp := &ValidateAttributeResponse{}

BlockValidate(ctx, block, attributeReq, attributeResp)

resp.Diagnostics = attributeResp.Diagnostics
resp.Diagnostics.Append(attributeResp.Diagnostics...)
}

if s.GetDeprecationMessage() != "" {
Expand Down
24 changes: 12 additions & 12 deletions internal/fwserver/server_validatedatasourceconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func (s *Server) ValidateDataSourceConfig(ctx context.Context, req *ValidateData
logging.FrameworkTrace(ctx, "DataSource implements DataSourceWithConfigValidators")

for _, configValidator := range dataSource.ConfigValidators(ctx) {
vdscResp := &datasource.ValidateConfigResponse{
Diagnostics: resp.Diagnostics,
}
// Instantiate a new response for each request to prevent validators
// from modifying or removing diagnostics.
vdscResp := &datasource.ValidateConfigResponse{}

logging.FrameworkDebug(
ctx,
Expand All @@ -75,32 +75,32 @@ func (s *Server) ValidateDataSourceConfig(ctx context.Context, req *ValidateData
},
)

resp.Diagnostics = vdscResp.Diagnostics
resp.Diagnostics.Append(vdscResp.Diagnostics...)
}
}

if dataSource, ok := req.DataSource.(datasource.DataSourceWithValidateConfig); ok {
logging.FrameworkTrace(ctx, "DataSource implements DataSourceWithValidateConfig")

vdscResp := &datasource.ValidateConfigResponse{
Diagnostics: resp.Diagnostics,
}
// Instantiate a new response for each request to prevent validators
// from modifying or removing diagnostics.
vdscResp := &datasource.ValidateConfigResponse{}

logging.FrameworkDebug(ctx, "Calling provider defined DataSource ValidateConfig")
dataSource.ValidateConfig(ctx, vdscReq, vdscResp)
logging.FrameworkDebug(ctx, "Called provider defined DataSource ValidateConfig")

resp.Diagnostics = vdscResp.Diagnostics
resp.Diagnostics.Append(vdscResp.Diagnostics...)
}

validateSchemaReq := ValidateSchemaRequest{
Config: *req.Config,
}
validateSchemaResp := ValidateSchemaResponse{
Diagnostics: resp.Diagnostics,
}
// Instantiate a new response for each request to prevent validators
// from modifying or removing diagnostics.
validateSchemaResp := ValidateSchemaResponse{}

SchemaValidate(ctx, req.Config.Schema, validateSchemaReq, &validateSchemaResp)

resp.Diagnostics = validateSchemaResp.Diagnostics
resp.Diagnostics.Append(validateSchemaResp.Diagnostics...)
}
24 changes: 12 additions & 12 deletions internal/fwserver/server_validateproviderconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func (s *Server) ValidateProviderConfig(ctx context.Context, req *ValidateProvid
logging.FrameworkTrace(ctx, "Provider implements ProviderWithConfigValidators")

for _, configValidator := range providerWithConfigValidators.ConfigValidators(ctx) {
vpcRes := &provider.ValidateConfigResponse{
Diagnostics: resp.Diagnostics,
}
// Instantiate a new response for each request to prevent validators
// from modifying or removing diagnostics.
vpcRes := &provider.ValidateConfigResponse{}

logging.FrameworkDebug(
ctx,
Expand All @@ -56,34 +56,34 @@ func (s *Server) ValidateProviderConfig(ctx context.Context, req *ValidateProvid
},
)

resp.Diagnostics = vpcRes.Diagnostics
resp.Diagnostics.Append(vpcRes.Diagnostics...)
}
}

if providerWithValidateConfig, ok := s.Provider.(provider.ProviderWithValidateConfig); ok {
logging.FrameworkTrace(ctx, "Provider implements ProviderWithValidateConfig")

vpcRes := &provider.ValidateConfigResponse{
Diagnostics: resp.Diagnostics,
}
// Instantiate a new response for each request to prevent validators
// from modifying or removing diagnostics.
vpcRes := &provider.ValidateConfigResponse{}

logging.FrameworkDebug(ctx, "Calling provider defined Provider ValidateConfig")
providerWithValidateConfig.ValidateConfig(ctx, vpcReq, vpcRes)
logging.FrameworkDebug(ctx, "Called provider defined Provider ValidateConfig")

resp.Diagnostics = vpcRes.Diagnostics
resp.Diagnostics.Append(vpcRes.Diagnostics...)
}

validateSchemaReq := ValidateSchemaRequest{
Config: *req.Config,
}
validateSchemaResp := ValidateSchemaResponse{
Diagnostics: resp.Diagnostics,
}
// Instantiate a new response for each request to prevent validators
// from modifying or removing diagnostics.
validateSchemaResp := ValidateSchemaResponse{}

SchemaValidate(ctx, req.Config.Schema, validateSchemaReq, &validateSchemaResp)

resp.Diagnostics = validateSchemaResp.Diagnostics
resp.Diagnostics.Append(validateSchemaResp.Diagnostics...)

// This RPC allows a modified configuration to be returned. This was
// previously used to allow a "required" provider attribute (as defined
Expand Down
24 changes: 12 additions & 12 deletions internal/fwserver/server_validateresourceconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func (s *Server) ValidateResourceConfig(ctx context.Context, req *ValidateResour
logging.FrameworkTrace(ctx, "Resource implements ResourceWithConfigValidators")

for _, configValidator := range resourceWithConfigValidators.ConfigValidators(ctx) {
vdscResp := &resource.ValidateConfigResponse{
Diagnostics: resp.Diagnostics,
}
// Instantiate a new response for each request to prevent validators
// from modifying or removing diagnostics.
vdscResp := &resource.ValidateConfigResponse{}

logging.FrameworkDebug(
ctx,
Expand All @@ -75,32 +75,32 @@ func (s *Server) ValidateResourceConfig(ctx context.Context, req *ValidateResour
},
)

resp.Diagnostics = vdscResp.Diagnostics
resp.Diagnostics.Append(vdscResp.Diagnostics...)
}
}

if resourceWithValidateConfig, ok := req.Resource.(resource.ResourceWithValidateConfig); ok {
logging.FrameworkTrace(ctx, "Resource implements ResourceWithValidateConfig")

vdscResp := &resource.ValidateConfigResponse{
Diagnostics: resp.Diagnostics,
}
// Instantiate a new response for each request to prevent validators
// from modifying or removing diagnostics.
vdscResp := &resource.ValidateConfigResponse{}

logging.FrameworkDebug(ctx, "Calling provider defined Resource ValidateConfig")
resourceWithValidateConfig.ValidateConfig(ctx, vdscReq, vdscResp)
logging.FrameworkDebug(ctx, "Called provider defined Resource ValidateConfig")

resp.Diagnostics = vdscResp.Diagnostics
resp.Diagnostics.Append(vdscResp.Diagnostics...)
}

validateSchemaReq := ValidateSchemaRequest{
Config: *req.Config,
}
validateSchemaResp := ValidateSchemaResponse{
Diagnostics: resp.Diagnostics,
}
// Instantiate a new response for each request to prevent validators
// from modifying or removing diagnostics.
validateSchemaResp := ValidateSchemaResponse{}

SchemaValidate(ctx, req.Config.Schema, validateSchemaReq, &validateSchemaResp)

resp.Diagnostics = validateSchemaResp.Diagnostics
resp.Diagnostics.Append(validateSchemaResp.Diagnostics...)
}

0 comments on commit beaf82a

Please sign in to comment.