options.go 1.2 KB

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