Object storage misc fixes (#82)
* Fix wrong reference * Fix schema * Fix mapFields not fetching credentials group id * Change expiration timestamp * Fix schema * Remove fields that don't come in the GET response * Add RFC3339SecondsOnly * Change expiration timestamp to not support fractional seconds * Set retry timeout * Harmonize expiration timestamp * Skip import check on credential keys * Add error check * Update docs * Change field description * Add test case, simplify test * Add test case, simplify test * Rename variable * Generate docs --------- Co-authored-by: Henrique Santos <henrique.santos@freiheit.com>
This commit is contained in:
parent
5a5ac6640c
commit
248b9834ff
11 changed files with 229 additions and 73 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"net"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
|
||||
|
|
@ -108,3 +109,31 @@ func MinorVersionNumber() *Validator {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
func RFC3339SecondsOnly() *Validator {
|
||||
description := "value must be in RFC339 format (seconds only)"
|
||||
|
||||
return &Validator{
|
||||
description: description,
|
||||
validate: func(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) {
|
||||
t, err := time.Parse(time.RFC3339, req.ConfigValue.ValueString())
|
||||
if err != nil {
|
||||
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
|
||||
req.Path,
|
||||
description,
|
||||
req.ConfigValue.ValueString(),
|
||||
))
|
||||
return
|
||||
}
|
||||
|
||||
// Check if it failed because it has nanoseconds
|
||||
if t.Nanosecond() != 0 {
|
||||
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
|
||||
req.Path,
|
||||
"value can't have fractional seconds",
|
||||
req.ConfigValue.ValueString(),
|
||||
))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -208,3 +208,57 @@ func TestMinorVersionNumber(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRFC3339SecondsOnly(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
input string
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
"ok",
|
||||
"9999-01-02T03:04:05Z",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"ok_2",
|
||||
"9999-01-02T03:04:05+06:00",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"empty",
|
||||
"",
|
||||
false,
|
||||
},
|
||||
{
|
||||
"not_ok",
|
||||
"foo-bar",
|
||||
false,
|
||||
},
|
||||
{
|
||||
"with_sub_seconds",
|
||||
"9999-01-02T03:04:05.678Z",
|
||||
false,
|
||||
},
|
||||
{
|
||||
"with_sub_seconds_2",
|
||||
"9999-01-02T03:04:05.678+06:00",
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
r := validator.StringResponse{}
|
||||
RFC3339SecondsOnly().ValidateString(context.Background(), validator.StringRequest{
|
||||
ConfigValue: types.StringValue(tt.input),
|
||||
}, &r)
|
||||
|
||||
if !tt.isValid && !r.Diagnostics.HasError() {
|
||||
t.Fatalf("Should have failed")
|
||||
}
|
||||
if tt.isValid && r.Diagnostics.HasError() {
|
||||
t.Fatalf("Should not have failed: %v", r.Diagnostics.Errors())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue