2021-07-29 18:52:56 -06:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-02-02 17:15:17 -08:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2021-04-08 20:54:32 -04:00
|
|
|
package request
|
|
|
|
|
|
2021-07-29 18:52:56 -06:00
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/internal/errors"
|
|
|
|
|
)
|
2021-04-08 20:54:32 -04:00
|
|
|
|
|
|
|
|
// Validate the request.State
|
2021-07-29 18:52:56 -06:00
|
|
|
func (s *State) Validate(ctx context.Context) error {
|
2021-04-08 20:54:32 -04:00
|
|
|
const op = "request.(State).Validate"
|
|
|
|
|
if s == nil {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing state")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
if s.TokenRequestId == "" {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing token request id")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
if s.CreateTime == nil {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing create time")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
if s.ExpirationTime == nil {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing expiration time")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
if s.FinalRedirectUrl == "" {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing final redirect URL")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
if s.Nonce == "" {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing nonce")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
if s.ProviderConfigHash == 0 {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing provider config hash")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate the request.Wrapper
|
2021-07-29 18:52:56 -06:00
|
|
|
func (w *Wrapper) Validate(ctx context.Context) error {
|
2021-04-08 20:54:32 -04:00
|
|
|
const op = "request.(Wrapper).Validate"
|
|
|
|
|
if w == nil {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing wrapper")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
if w.AuthMethodId == "" {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing auth method id")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
if w.ScopeId == "" {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing scope id")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
if w.WrapperKeyId == "" {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing wrapper key id")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
if len(w.Ct) == 0 {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing ct")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate the request.Token
|
2021-07-29 18:52:56 -06:00
|
|
|
func (t *Token) Validate(ctx context.Context) error {
|
2021-04-08 20:54:32 -04:00
|
|
|
const op = "request.(Token).Validate"
|
|
|
|
|
if t == nil {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing token")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
if t.RequestId == "" {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing request id")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
if t.ExpirationTime == nil {
|
2021-07-29 18:52:56 -06:00
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing expiration time")
|
2021-04-08 20:54:32 -04:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|