-
Notifications
You must be signed in to change notification settings - Fork 289
/
Copy pathvalidate.go
70 lines (65 loc) · 2.02 KB
/
validate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package request
import (
"context"
"github.com/hashicorp/boundary/internal/errors"
)
// Validate the request.State
func (s *State) Validate(ctx context.Context) error {
const op = "request.(State).Validate"
if s == nil {
return errors.New(ctx, errors.InvalidParameter, op, "missing state")
}
if s.TokenRequestId == "" {
return errors.New(ctx, errors.InvalidParameter, op, "missing token request id")
}
if s.CreateTime == nil {
return errors.New(ctx, errors.InvalidParameter, op, "missing create time")
}
if s.ExpirationTime == nil {
return errors.New(ctx, errors.InvalidParameter, op, "missing expiration time")
}
if s.FinalRedirectUrl == "" {
return errors.New(ctx, errors.InvalidParameter, op, "missing final redirect URL")
}
if s.Nonce == "" {
return errors.New(ctx, errors.InvalidParameter, op, "missing nonce")
}
if s.ProviderConfigHash == 0 {
return errors.New(ctx, errors.InvalidParameter, op, "missing provider config hash")
}
return nil
}
// Validate the request.Wrapper
func (w *Wrapper) Validate(ctx context.Context) error {
const op = "request.(Wrapper).Validate"
if w == nil {
return errors.New(ctx, errors.InvalidParameter, op, "missing wrapper")
}
if w.AuthMethodId == "" {
return errors.New(ctx, errors.InvalidParameter, op, "missing auth method id")
}
if w.ScopeId == "" {
return errors.New(ctx, errors.InvalidParameter, op, "missing scope id")
}
if w.WrapperKeyId == "" {
return errors.New(ctx, errors.InvalidParameter, op, "missing wrapper key id")
}
if len(w.Ct) == 0 {
return errors.New(ctx, errors.InvalidParameter, op, "missing ct")
}
return nil
}
// Validate the request.Token
func (t *Token) Validate(ctx context.Context) error {
const op = "request.(Token).Validate"
if t == nil {
return errors.New(ctx, errors.InvalidParameter, op, "missing token")
}
if t.RequestId == "" {
return errors.New(ctx, errors.InvalidParameter, op, "missing request id")
}
if t.ExpirationTime == nil {
return errors.New(ctx, errors.InvalidParameter, op, "missing expiration time")
}
return nil
}