wire_options.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package wire
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. // Options holds the Wire ACME extension options
  7. type Options struct {
  8. OIDC *OIDCOptions `json:"oidc,omitempty"`
  9. DPOP *DPOPOptions `json:"dpop,omitempty"`
  10. }
  11. // GetOIDCOptions returns the OIDC options.
  12. func (o *Options) GetOIDCOptions() *OIDCOptions {
  13. if o == nil {
  14. return nil
  15. }
  16. return o.OIDC
  17. }
  18. // GetDPOPOptions returns the DPoP options.
  19. func (o *Options) GetDPOPOptions() *DPOPOptions {
  20. if o == nil {
  21. return nil
  22. }
  23. return o.DPOP
  24. }
  25. // Validate validates and initializes the Wire OIDC and DPoP options.
  26. //
  27. // TODO(hs): find a good way to perform this only once.
  28. func (o *Options) Validate() error {
  29. if oidc := o.GetOIDCOptions(); oidc != nil {
  30. if err := oidc.validateAndInitialize(); err != nil {
  31. return fmt.Errorf("failed initializing OIDC options: %w", err)
  32. }
  33. } else {
  34. return errors.New("no OIDC options available")
  35. }
  36. if dpop := o.GetDPOPOptions(); dpop != nil {
  37. if err := dpop.validateAndInitialize(); err != nil {
  38. return fmt.Errorf("failed initializing DPoP options: %w", err)
  39. }
  40. } else {
  41. return errors.New("no DPoP options available")
  42. }
  43. return nil
  44. }