github.com/lestrrat-go/jwx/v2@v2.0.21/jwk/options_gen.go (about)

     1  // Code generated by tools/cmd/genoptions/main.go. DO NOT EDIT.
     2  
     3  package jwk
     4  
     5  import (
     6  	"crypto"
     7  	"io/fs"
     8  	"time"
     9  
    10  	"github.com/lestrrat-go/jwx/v2/internal/json"
    11  	"github.com/lestrrat-go/option"
    12  )
    13  
    14  type Option = option.Interface
    15  
    16  type AssignKeyIDOption interface {
    17  	Option
    18  	assignKeyIDOption()
    19  }
    20  
    21  type assignKeyIDOption struct {
    22  	Option
    23  }
    24  
    25  func (*assignKeyIDOption) assignKeyIDOption() {}
    26  
    27  // CacheOption is a type of Option that can be passed to the
    28  // the `jwk.NewCache()` function.
    29  type CacheOption interface {
    30  	Option
    31  	cacheOption()
    32  }
    33  
    34  type cacheOption struct {
    35  	Option
    36  }
    37  
    38  func (*cacheOption) cacheOption() {}
    39  
    40  // FetchOption is a type of Option that can be passed to `jwk.Fetch()`
    41  // FetchOption also implements the `RegisterOption`, and thus can
    42  // safely be passed to `(*jwk.Cache).Register()`
    43  type FetchOption interface {
    44  	Option
    45  	fetchOption()
    46  	parseOption()
    47  	registerOption()
    48  }
    49  
    50  type fetchOption struct {
    51  	Option
    52  }
    53  
    54  func (*fetchOption) fetchOption() {}
    55  
    56  func (*fetchOption) parseOption() {}
    57  
    58  func (*fetchOption) registerOption() {}
    59  
    60  // ParseOption is a type of Option that can be passed to `jwk.Parse()`
    61  // ParseOption also implmentsthe `ReadFileOption` and `CacheOption`,
    62  // and thus safely be passed to `jwk.ReadFile` and `(*jwk.Cache).Configure()`
    63  type ParseOption interface {
    64  	Option
    65  	fetchOption()
    66  	registerOption()
    67  	readFileOption()
    68  }
    69  
    70  type parseOption struct {
    71  	Option
    72  }
    73  
    74  func (*parseOption) fetchOption() {}
    75  
    76  func (*parseOption) registerOption() {}
    77  
    78  func (*parseOption) readFileOption() {}
    79  
    80  // ReadFileOption is a type of `Option` that can be passed to `jwk.ReadFile`
    81  type ReadFileOption interface {
    82  	Option
    83  	readFileOption()
    84  }
    85  
    86  type readFileOption struct {
    87  	Option
    88  }
    89  
    90  func (*readFileOption) readFileOption() {}
    91  
    92  // RegisterOption desribes options that can be passed to `(jwk.Cache).Register()`
    93  type RegisterOption interface {
    94  	Option
    95  	registerOption()
    96  }
    97  
    98  type registerOption struct {
    99  	Option
   100  }
   101  
   102  func (*registerOption) registerOption() {}
   103  
   104  type identErrSink struct{}
   105  type identFS struct{}
   106  type identFetchWhitelist struct{}
   107  type identHTTPClient struct{}
   108  type identIgnoreParseError struct{}
   109  type identLocalRegistry struct{}
   110  type identMinRefreshInterval struct{}
   111  type identPEM struct{}
   112  type identPostFetcher struct{}
   113  type identRefreshInterval struct{}
   114  type identRefreshWindow struct{}
   115  type identThumbprintHash struct{}
   116  
   117  func (identErrSink) String() string {
   118  	return "WithErrSink"
   119  }
   120  
   121  func (identFS) String() string {
   122  	return "WithFS"
   123  }
   124  
   125  func (identFetchWhitelist) String() string {
   126  	return "WithFetchWhitelist"
   127  }
   128  
   129  func (identHTTPClient) String() string {
   130  	return "WithHTTPClient"
   131  }
   132  
   133  func (identIgnoreParseError) String() string {
   134  	return "WithIgnoreParseError"
   135  }
   136  
   137  func (identLocalRegistry) String() string {
   138  	return "withLocalRegistry"
   139  }
   140  
   141  func (identMinRefreshInterval) String() string {
   142  	return "WithMinRefreshInterval"
   143  }
   144  
   145  func (identPEM) String() string {
   146  	return "WithPEM"
   147  }
   148  
   149  func (identPostFetcher) String() string {
   150  	return "WithPostFetcher"
   151  }
   152  
   153  func (identRefreshInterval) String() string {
   154  	return "WithRefreshInterval"
   155  }
   156  
   157  func (identRefreshWindow) String() string {
   158  	return "WithRefreshWindow"
   159  }
   160  
   161  func (identThumbprintHash) String() string {
   162  	return "WithThumbprintHash"
   163  }
   164  
   165  // WithErrSink specifies the `httprc.ErrSink` object that handles errors
   166  // that occurred during the cache's execution.
   167  //
   168  // See the documentation in `httprc.WithErrSink` for more details.
   169  func WithErrSink(v ErrSink) CacheOption {
   170  	return &cacheOption{option.New(identErrSink{}, v)}
   171  }
   172  
   173  // WithFS specifies the source `fs.FS` object to read the file from.
   174  func WithFS(v fs.FS) ReadFileOption {
   175  	return &readFileOption{option.New(identFS{}, v)}
   176  }
   177  
   178  // WithFetchWhitelist specifies the Whitelist object to use when
   179  // fetching JWKs from a remote source. This option can be passed
   180  // to both `jwk.Fetch()`, `jwk.NewCache()`, and `(*jwk.Cache).Configure()`
   181  func WithFetchWhitelist(v Whitelist) FetchOption {
   182  	return &fetchOption{option.New(identFetchWhitelist{}, v)}
   183  }
   184  
   185  // WithHTTPClient allows users to specify the "net/http".Client object that
   186  // is used when fetching jwk.Set objects.
   187  func WithHTTPClient(v HTTPClient) FetchOption {
   188  	return &fetchOption{option.New(identHTTPClient{}, v)}
   189  }
   190  
   191  // WithIgnoreParseError is only applicable when used with `jwk.Parse()`
   192  // (i.e. to parse JWK sets). If passed to `jwk.ParseKey()`, the function
   193  // will return an error no matter what the input is.
   194  //
   195  // DO NOT USE WITHOUT EXHAUSTING ALL OTHER ROUTES FIRST.
   196  //
   197  // The option specifies that errors found during parsing of individual
   198  // keys are ignored. For example, if you had keys A, B, C where B is
   199  // invalid (e.g. it does not contain the required fields), then the
   200  // resulting JWKS will contain keys A and C only.
   201  //
   202  // This options exists as an escape hatch for those times when a
   203  // key in a JWKS that is irrelevant for your use case is causing
   204  // your JWKS parsing to fail, and you want to get to the rest of the
   205  // keys in the JWKS.
   206  //
   207  // Again, DO NOT USE unless you have exhausted all other routes.
   208  // When you use this option, you will not be able to tell if you are
   209  // using a faulty JWKS, except for when there are JSON syntax errors.
   210  func WithIgnoreParseError(v bool) ParseOption {
   211  	return &parseOption{option.New(identIgnoreParseError{}, v)}
   212  }
   213  
   214  // This option is only available for internal code. Users don't get to play with it
   215  func withLocalRegistry(v *json.Registry) ParseOption {
   216  	return &parseOption{option.New(identLocalRegistry{}, v)}
   217  }
   218  
   219  // WithMinRefreshInterval specifies the minimum refresh interval to be used
   220  // when using `jwk.Cache`. This value is ONLY used if you did not specify
   221  // a user-supplied static refresh interval via `WithRefreshInterval`.
   222  //
   223  // This value is used as a fallback value when tokens are refreshed.
   224  //
   225  // When we fetch the key from a remote URL, we first look at the max-age
   226  // directive from Cache-Control response header. If this value is present,
   227  // we compare the max-age value and the value specified by this option
   228  // and take the larger one.
   229  //
   230  // Next we check for the Expires header, and similarly if the header is
   231  // present, we compare it against the value specified by this option,
   232  // and take the larger one.
   233  //
   234  // Finally, if neither of the above headers are present, we use the
   235  // value specified by this option as the next refresh timing
   236  //
   237  // If unspecified, the minimum refresh interval is 1 hour
   238  func WithMinRefreshInterval(v time.Duration) RegisterOption {
   239  	return &registerOption{option.New(identMinRefreshInterval{}, v)}
   240  }
   241  
   242  // WithPEM specifies that the input to `Parse()` is a PEM encoded key.
   243  func WithPEM(v bool) ParseOption {
   244  	return &parseOption{option.New(identPEM{}, v)}
   245  }
   246  
   247  // WithPostFetcher specifies the PostFetcher object to be used on the
   248  // jwk.Set object obtained in `jwk.Cache`. This option can be used
   249  // to, for example, modify the jwk.Set to give it key IDs or algorithm
   250  // names after it has been fetched and parsed, but before it is cached.
   251  func WithPostFetcher(v PostFetcher) RegisterOption {
   252  	return &registerOption{option.New(identPostFetcher{}, v)}
   253  }
   254  
   255  // WithRefreshInterval specifies the static interval between refreshes
   256  // of jwk.Set objects controlled by jwk.Cache.
   257  //
   258  // Providing this option overrides the adaptive token refreshing based
   259  // on Cache-Control/Expires header (and jwk.WithMinRefreshInterval),
   260  // and refreshes will *always* happen in this interval.
   261  func WithRefreshInterval(v time.Duration) RegisterOption {
   262  	return &registerOption{option.New(identRefreshInterval{}, v)}
   263  }
   264  
   265  // WithRefreshWindow specifies the interval between checks for refreshes.
   266  //
   267  // See the documentation in `httprc.WithRefreshWindow` for more details.
   268  func WithRefreshWindow(v time.Duration) CacheOption {
   269  	return &cacheOption{option.New(identRefreshWindow{}, v)}
   270  }
   271  
   272  func WithThumbprintHash(v crypto.Hash) AssignKeyIDOption {
   273  	return &assignKeyIDOption{option.New(identThumbprintHash{}, v)}
   274  }