• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Twingate / terraform-provider-twingate / 20759866553

06 Jan 2026 07:38PM UTC coverage: 88.615% (-0.07%) from 88.687%
20759866553

push

github

web-flow
Add JIT access support (#805)

883 of 986 new or added lines in 12 files covered. (89.55%)

8 existing lines in 2 files now uncovered.

9628 of 10865 relevant lines covered (88.61%)

2.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.0
/twingate/internal/customvalidator/stringvalidator_duration.go
1
package customvalidator
2

3
import (
4
        "context"
5
        "errors"
6
        "fmt"
7
        "time"
8

9
        "github.com/hashicorp/terraform-plugin-framework/function"
10
        "github.com/hashicorp/terraform-plugin-framework/schema/validator"
11

12
        "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
13
        "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatorfuncerr"
14

15
        "github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/utils"
16
)
17

18
var (
19
        _ validator.String                  = durationValidator{}
20
        _ function.StringParameterValidator = durationValidator{}
21

22
        ErrLessThenMinDuration = errors.New("minimum duration is 1 hour")
23
        ErrExceedsMaxDuration  = errors.New("maximum duration is 365 days")
24
)
25

26
const (
27
        minDuration time.Duration = time.Hour
28
        maxDuration time.Duration = time.Hour * 24 * 365
29
)
30

31
type durationValidator struct{}
32

33
func (validator durationValidator) invalidUsageMessage() string {
2✔
34
        return "string must be a valid duration"
2✔
35
}
2✔
36

37
func (validator durationValidator) Description(_ context.Context) string {
2✔
38
        return validator.invalidUsageMessage()
2✔
39
}
2✔
40

NEW
41
func (validator durationValidator) MarkdownDescription(ctx context.Context) string {
×
NEW
42
        return validator.Description(ctx)
×
NEW
43
}
×
44

45
func (v durationValidator) validate(value string) error {
2✔
46
        duration, err := utils.ParseDurationWithDays(value)
2✔
47
        if err != nil {
2✔
NEW
48
                return fmt.Errorf("failed to parse duration %w", err)
×
NEW
49
        }
×
50

51
        if duration < minDuration {
4✔
52
                return ErrLessThenMinDuration
2✔
53
        }
2✔
54

55
        if duration > maxDuration {
4✔
56
                return ErrExceedsMaxDuration
2✔
57
        }
2✔
58

59
        return nil
2✔
60
}
61

62
func (v durationValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) {
2✔
63
        if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() {
4✔
64
                return
2✔
65
        }
2✔
66

67
        value := request.ConfigValue.ValueString()
2✔
68

2✔
69
        if err := v.validate(value); err != nil {
4✔
70
                response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
2✔
71
                        request.Path,
2✔
72
                        v.Description(ctx),
2✔
73
                        err.Error(),
2✔
74
                ))
2✔
75
        }
2✔
76
}
77

NEW
78
func (v durationValidator) ValidateParameterString(ctx context.Context, request function.StringParameterValidatorRequest, response *function.StringParameterValidatorResponse) {
×
NEW
79
        if request.Value.IsNull() || request.Value.IsUnknown() {
×
NEW
80
                return
×
NEW
81
        }
×
82

NEW
83
        value := request.Value.ValueString()
×
NEW
84

×
NEW
85
        if err := v.validate(value); err != nil {
×
NEW
86
                response.Error = validatorfuncerr.InvalidParameterValueFuncError(
×
NEW
87
                        request.ArgumentPosition,
×
NEW
88
                        v.Description(ctx),
×
NEW
89
                        err.Error(),
×
NEW
90
                )
×
NEW
91
        }
×
92
}
93

94
// Duration returns a validator which ensures that duration string configured correctly.
95
func Duration() durationValidator {
3✔
96
        return durationValidator{}
3✔
97
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc