github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/util/acme/options.go (about)

     1  // Copyright 2020 Asim Aslam
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  // Original source: github.com/micro/go-micro/v3/api/server/acme/options.go
    16  
    17  package acme
    18  
    19  import "github.com/go-acme/lego/v3/challenge"
    20  
    21  // Option (or Options) are passed to New() to configure providers
    22  type Option func(o *Options)
    23  
    24  // Options represents various options you can present to ACME providers
    25  type Options struct {
    26  	// AcceptTLS must be set to true to indicate that you have read your
    27  	// provider's terms of service.
    28  	AcceptToS bool
    29  	// CA is the CA to use
    30  	CA string
    31  	// ChallengeProvider is a go-acme/lego challenge provider. Set this if you
    32  	// want to use DNS Challenges. Otherwise, tls-alpn-01 will be used
    33  	ChallengeProvider challenge.Provider
    34  	// Issue certificates for domains on demand. Otherwise, certs will be
    35  	// retrieved / issued on start-up.
    36  	OnDemand bool
    37  	// Cache is a storage interface. Most ACME libraries have an cache, but
    38  	// there's no defined interface, so if you consume this option
    39  	// sanity check it before using.
    40  	Cache interface{}
    41  }
    42  
    43  // AcceptToS indicates whether you accept your CA's terms of service
    44  func AcceptToS(b bool) Option {
    45  	return func(o *Options) {
    46  		o.AcceptToS = b
    47  	}
    48  }
    49  
    50  // CA sets the CA of an acme.Options
    51  func CA(CA string) Option {
    52  	return func(o *Options) {
    53  		o.CA = CA
    54  	}
    55  }
    56  
    57  // ChallengeProvider sets the Challenge provider of an acme.Options
    58  // if set, it enables the DNS challenge, otherwise tls-alpn-01 will be used.
    59  func ChallengeProvider(p challenge.Provider) Option {
    60  	return func(o *Options) {
    61  		o.ChallengeProvider = p
    62  	}
    63  }
    64  
    65  // OnDemand enables on-demand certificate issuance. Not recommended for use
    66  // with the DNS challenge, as the first connection may be very slow.
    67  func OnDemand(b bool) Option {
    68  	return func(o *Options) {
    69  		o.OnDemand = b
    70  	}
    71  }
    72  
    73  // Cache provides a cache / storage interface to the underlying ACME library
    74  // as there is no standard, this needs to be validated by the underlying
    75  // implentation.
    76  func Cache(c interface{}) Option {
    77  	return func(o *Options) {
    78  		o.Cache = c
    79  	}
    80  }
    81  
    82  // DefaultOptions uses the Let's Encrypt Production CA, with DNS Challenge disabled.
    83  func DefaultOptions() Options {
    84  	return Options{
    85  		AcceptToS: true,
    86  		CA:        LetsEncryptProductionCA,
    87  		OnDemand:  true,
    88  	}
    89  }