options.go 1.1 KB

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