Documentation
¶
Index ¶
- Constants
- func ConvertToOpenAPISchema(schemaData any) (*openapi3.Schema, error)
- func ExtractSensitiveFieldPaths(schema map[string]any, prefix string) []string
- func GetSchema(ctx context.Context, ucpClient *v20231001preview.ClientFactory, ...) (map[string]any, error)
- func GetSecretsBlock(schema map[string]any) ([]string, bool)
- func GetSensitiveFieldPaths(ctx context.Context, ucpClient *v20231001preview.ClientFactory, ...) ([]string, error)
- func HasSecretsBlock(schema map[string]any) bool
- func RedactFields(data map[string]any, paths []string)
- func ValidateResourceAgainstSchema(ctx context.Context, resourceData map[string]any, schemaData any) error
- func ValidateSecretsBlock(schema map[string]any) error
- type ErrorType
- type FieldPathSegment
- type SegmentType
- type ValidationError
- type ValidationErrors
- type Validator
Constants ¶
const ( // SecretsBlockPropertyName is the name of the top-level object property in a resource type // schema that declares a resource's recipe secrets. Its sub-properties are the reserved secret // reference (see SecretNameReferenceKey) plus one entry per secret key produced by the recipe // (for example `connectionString`). SecretsBlockPropertyName = "secrets" // SecretNameReferenceKey is the reserved sub-property of the `secrets` block that Radius populates // at runtime with the name of the managed Radius.Security/secrets resource backing the resource's // declared secrets. Consumers bind to it by name (for example via `properties.secrets.name`). It is // a reserved reference, not a materializable secret data key. SecretNameReferenceKey = "name" )
Variables ¶
This section is empty.
Functions ¶
func ConvertToOpenAPISchema ¶
ConvertToOpenAPISchema converts the schema any to OpenAPI schema
func ExtractSensitiveFieldPaths ¶ added in v0.55.0
ExtractSensitiveFieldPaths recursively walks the schema and returns paths to fields marked with x-radius-sensitive. The prefix parameter builds up the path as we traverse nested objects. Supports object properties, array items, and additionalProperties (maps). If a field is marked sensitive, its nested properties are not checked since the entire field is considered sensitive.
func GetSchema ¶ added in v0.55.0
func GetSchema(ctx context.Context, ucpClient *v20231001preview.ClientFactory, resourceID string, resourceType string, apiVersion string) (map[string]any, error)
GetSchema fetches the OpenAPI schema for a resource type and api version. Returns nil if the schema is not found or the client is nil.
func GetSecretsBlock ¶
GetSecretsBlock inspects a resource type OpenAPI schema and returns the names of the recipe secret output keys declared under the top-level `secrets` object property. The second return value reports whether a `secrets` block is present at all. The returned keys are sorted for deterministic ordering.
A resource type declares its recipe secret outputs like this:
properties:
secrets:
type: object
properties:
name:
type: string
readOnly: true
connectionString:
type: string
readOnly: true
For the schema above GetSecretsBlock returns (["connectionString"], true): the reserved `name` reference is excluded, and only readOnly sub-properties are returned (they are recipe secret outputs to materialize). Writable sub-properties are reserved for future secret inputs and are not returned here. The `secrets` block itself is intentionally not required to be readOnly.
func GetSensitiveFieldPaths ¶ added in v0.55.0
func GetSensitiveFieldPaths(ctx context.Context, ucpClient *v20231001preview.ClientFactory, resourceID string, resourceType string, apiVersion string) ([]string, error)
GetSensitiveFieldPaths fetches the schema for a resource and returns paths to fields marked with x-radius-sensitive. Paths are in dot notation, e.g., "credentials.password" or "config.apiKey".
Parameters:
- ctx: The request context
- ucpClient: UCP client factory for fetching the schema
- resourceID: The full resource ID (e.g., "/planes/radius/local/resourceGroups/test/providers/Foo.Bar/myResources/test")
- resourceType: The resource type (e.g., "Foo.Bar/myResources")
- apiVersion: The API version to fetch the schema for
Returns:
- []string: Paths to sensitive fields, or empty slice if none found
- error: Any error encountered while fetching the schema
func HasSecretsBlock ¶
HasSecretsBlock reports whether the given resource type schema declares a `secrets` block.
func RedactFields ¶ added in v0.55.0
RedactFields sets the values at the given field paths to nil in the data map. Paths support dot notation, wildcards [*], and array indices [N]. Missing fields and invalid paths are silently skipped.
func ValidateResourceAgainstSchema ¶ added in v0.50.0
func ValidateResourceAgainstSchema(ctx context.Context, resourceData map[string]any, schemaData any) error
ValidateResourceAgainstSchema validates resource data against an OpenAPI 3.0 schema. It converts the schema data to OpenAPI format, creates a minimal OpenAPI document for validation, and then validates the resource data against the schema using OpenAPI's built-in validation.
func ValidateSecretsBlock ¶
ValidateSecretsBlock validates the shape of the `secrets` block in a resource type schema, if present. The block must be an object. Every declared sub-property must be a string. The reserved `name` reference sub-property, if present, must be readOnly. The block itself is intentionally not required to be readOnly, and data sub-properties are not required to be readOnly, so the block can hold both recipe secret outputs (readOnly) and, in future, writable secret inputs. It returns nil when no `secrets` block is declared.
Types ¶
type ErrorType ¶
type ErrorType string
ErrorType represents the type of validation error
const ( // ErrorTypeSchema indicates a schema structure validation error ErrorTypeSchema ErrorType = "SchemaError" // ErrorTypeConstraint indicates a Radius constraint violation ErrorTypeConstraint ErrorType = "ConstraintError" // ErrorTypeFormat indicates a format validation error ErrorTypeFormat ErrorType = "FormatError" )
type FieldPathSegment ¶ added in v0.55.0
type FieldPathSegment struct {
Type SegmentType
Value string // field name or index value (empty for wildcards)
}
FieldPathSegment represents a single segment in a field path. A field path can contain field names, wildcards, and array indices.
func ParseFieldPath ¶ added in v0.55.0
func ParseFieldPath(path string) []FieldPathSegment
ParseFieldPath parses a field path string into segments. Supports dot notation, wildcards [*], and array indices [N].
Examples:
- "credentials.password" -> [field:credentials, field:password]
- "secrets[*].value" -> [field:secrets, wildcard, field:value]
- "config[*]" -> [field:config, wildcard]
- "items[0].name" -> [field:items, index:0, field:name]
Returns nil if the path is invalid (e.g., unterminated bracket).
func (FieldPathSegment) IsField ¶ added in v0.55.0
func (s FieldPathSegment) IsField() bool
IsField returns true if the segment is a named field.
func (FieldPathSegment) IsIndex ¶ added in v0.55.0
func (s FieldPathSegment) IsIndex() bool
IsIndex returns true if the segment is an array index.
func (FieldPathSegment) IsWildcard ¶ added in v0.55.0
func (s FieldPathSegment) IsWildcard() bool
IsWildcard returns true if the segment is a wildcard.
type SegmentType ¶ added in v0.55.0
type SegmentType int
SegmentType represents the type of a field path segment.
const ( // SegmentTypeField represents a named field (e.g., "password" in "credentials.password") SegmentTypeField SegmentType = iota // SegmentTypeWildcard represents a wildcard segment (e.g., [*] in "secrets[*].value") SegmentTypeWildcard // SegmentTypeIndex represents an array index (e.g., [0] in "items[0].name") SegmentTypeIndex )
type ValidationError ¶
ValidationError represents a schema validation error
func NewConstraintError ¶
func NewConstraintError(field, message string) *ValidationError
NewConstraintError creates a Radius constraint validation error
func NewFormatError ¶
func NewFormatError(field, format, message string) *ValidationError
NewFormatError creates a new format validation error
func NewSchemaError ¶
func NewSchemaError(field, message string) *ValidationError
NewSchemaError creates a schema validation error
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface
type ValidationErrors ¶
type ValidationErrors struct {
Errors []*ValidationError
}
ValidationErrors represents a collection of validation errors
func (*ValidationErrors) Add ¶
func (ve *ValidationErrors) Add(err *ValidationError)
Add adds a validation error to the collection
func (*ValidationErrors) Error ¶
func (ve *ValidationErrors) Error() string
Error implements the error interface
func (*ValidationErrors) HasErrors ¶
func (ve *ValidationErrors) HasErrors() bool
HasErrors returns true if there are any validation errors
Directories
¶
| Path | Synopsis |
|---|---|
|
Package baseresource declares the "Radius-aware" properties (application, environment, connections, codeReference) that every resource type schema inherits, and merges them into per-type schemas.
|
Package baseresource declares the "Radius-aware" properties (application, environment, connections, codeReference) that every resource type schema inherits, and merges them into per-type schemas. |