MCPcopy
hub / github.com/caddyserver/caddy / ParseCaddyfilePreferredChainsOptions

Function ParseCaddyfilePreferredChainsOptions

modules/caddytls/acmeissuer.go:699–748  ·  view source on GitHub ↗
(d *caddyfile.Dispenser)

Source from the content-addressed store, hash-verified

697}
698
699func ParseCaddyfilePreferredChainsOptions(d *caddyfile.Dispenser) (*ChainPreference, error) {
700 chainPref := new(ChainPreference)
701 if d.NextArg() {
702 smallestOpt := d.Val()
703 if smallestOpt == "smallest" {
704 trueBool := true
705 chainPref.Smallest = &trueBool
706 if d.NextArg() { // Only one argument allowed
707 return nil, d.ArgErr()
708 }
709 if d.NextBlock(d.Nesting()) { // Don't allow other options when smallest == true
710 return nil, d.Err("No more options are accepted when using the 'smallest' option")
711 }
712 } else { // Smallest option should always be 'smallest' or unset
713 return nil, d.Errf("Invalid argument '%s'", smallestOpt)
714 }
715 }
716 for nesting := d.Nesting(); d.NextBlock(nesting); {
717 switch d.Val() {
718 case "root_common_name":
719 rootCommonNameOpt := d.RemainingArgs()
720 chainPref.RootCommonName = append(chainPref.RootCommonName, rootCommonNameOpt...)
721 if rootCommonNameOpt == nil {
722 return nil, d.ArgErr()
723 }
724 if chainPref.AnyCommonName != nil {
725 return nil, d.Err("Can't set root_common_name when any_common_name is already set")
726 }
727
728 case "any_common_name":
729 anyCommonNameOpt := d.RemainingArgs()
730 chainPref.AnyCommonName = append(chainPref.AnyCommonName, anyCommonNameOpt...)
731 if anyCommonNameOpt == nil {
732 return nil, d.ArgErr()
733 }
734 if chainPref.RootCommonName != nil {
735 return nil, d.Err("Can't set any_common_name when root_common_name is already set")
736 }
737
738 default:
739 return nil, d.Errf("Received unrecognized parameter '%s'", d.Val())
740 }
741 }
742
743 if chainPref.Smallest == nil && chainPref.RootCommonName == nil && chainPref.AnyCommonName == nil {
744 return nil, d.Err("No options for preferred_chains received")
745 }
746
747 return chainPref, nil
748}
749
750// ChainPreference describes the client's preferred certificate chain,
751// useful if the CA offers alternate chains. The first matching chain

Callers 2

parseOptPreferredChainsFunction · 0.92
UnmarshalCaddyfileMethod · 0.85

Calls 8

NextArgMethod · 0.80
ValMethod · 0.80
ArgErrMethod · 0.80
NextBlockMethod · 0.80
NestingMethod · 0.80
ErrMethod · 0.80
ErrfMethod · 0.80
RemainingArgsMethod · 0.80

Tested by

no test coverage detected