-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
decoder: Enable validators to deal with unknown schema
- Loading branch information
1 parent
9697577
commit ce29849
Showing
5 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package schemahelper | ||
|
||
import "context" | ||
|
||
type unknownSchemaCtxKey struct{} | ||
|
||
// WithUnknownSchema attaches a flag indicating that the schema being passed | ||
// is not wholly known. | ||
func WithUnknownSchema(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, unknownSchemaCtxKey{}, true) | ||
} | ||
|
||
// HasUnknownSchema returns true if the schema being passed | ||
// is not wholly known. This allows each validator to decide | ||
// whether and how to validate the AST. | ||
func HasUnknownSchema(ctx context.Context) bool { | ||
value := ctx.Value(unknownSchemaCtxKey{}) | ||
uSchema, ok := value.(bool) | ||
if !ok { | ||
return false | ||
} | ||
return uSchema | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters