mirror of
https://github.com/LukeHagar/plexterraform.git
synced 2025-12-06 12:37:47 +00:00
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
|
|
package validators
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
|
|
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
|
)
|
|
|
|
var _ validator.String = RFC3339TimeValidator{}
|
|
|
|
type RFC3339TimeValidator struct{}
|
|
|
|
func (validator RFC3339TimeValidator) Description(ctx context.Context) string {
|
|
return "value must be a string in RFC3339 format"
|
|
}
|
|
|
|
func (validator RFC3339TimeValidator) MarkdownDescription(ctx context.Context) string {
|
|
return validator.Description(ctx)
|
|
}
|
|
|
|
func (validator RFC3339TimeValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) {
|
|
// Only validate the attribute configuration value if it is known.
|
|
if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() {
|
|
return
|
|
}
|
|
|
|
if _, err := time.Parse(time.RFC3339Nano, req.ConfigValue.ValueString()); err != nil {
|
|
resp.Diagnostics.Append(validatordiag.InvalidAttributeTypeDiagnostic(
|
|
req.Path,
|
|
validator.MarkdownDescription(ctx),
|
|
req.ConfigValue.ValueString(),
|
|
))
|
|
return
|
|
}
|
|
}
|
|
|
|
// IsRFC3339 returns an AttributeValidator which ensures that any configured
|
|
// attribute value:
|
|
//
|
|
// - Is a String.
|
|
// - Is in RFC3339Nano Format.
|
|
//
|
|
// Null (unconfigured) and unknown (known after apply) values are skipped.
|
|
func IsRFC3339() validator.String {
|
|
return RFC3339TimeValidator{}
|
|
}
|