options.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package authority
  2. import (
  3. "crypto/x509"
  4. "github.com/smallstep/certificates/authority/provisioner"
  5. "github.com/smallstep/certificates/db"
  6. "github.com/smallstep/certificates/sshutil"
  7. )
  8. // Option sets options to the Authority.
  9. type Option func(*Authority)
  10. // WithDatabase sets an already initialized authority database to a new
  11. // authority. This option is intended to be use on graceful reloads.
  12. func WithDatabase(db db.AuthDB) Option {
  13. return func(a *Authority) {
  14. a.db = db
  15. }
  16. }
  17. // WithGetIdentityFunc sets a custom function to retrieve the identity from
  18. // an external resource.
  19. func WithGetIdentityFunc(fn func(p provisioner.Interface, email string) (*provisioner.Identity, error)) Option {
  20. return func(a *Authority) {
  21. a.getIdentityFunc = fn
  22. }
  23. }
  24. // WithSSHBastionFunc sets a custom function to get the bastion for a
  25. // given user-host pair.
  26. func WithSSHBastionFunc(fn func(user, host string) (*Bastion, error)) Option {
  27. return func(a *Authority) {
  28. a.sshBastionFunc = fn
  29. }
  30. }
  31. // WithSSHGetHosts sets a custom function to get the bastion for a
  32. // given user-host pair.
  33. func WithSSHGetHosts(fn func(cert *x509.Certificate) ([]sshutil.Host, error)) Option {
  34. return func(a *Authority) {
  35. a.sshGetHostsFunc = fn
  36. }
  37. }