(config *server.Config)
| 785 | } |
| 786 | |
| 787 | func (c *ServerCommand) setupStorage(config *server.Config) (physical.Backend, error) { |
| 788 | // Ensure that a backend is provided |
| 789 | if config.Storage == nil { |
| 790 | return nil, errors.New("A storage backend must be specified") |
| 791 | } |
| 792 | |
| 793 | // Initialize the backend |
| 794 | factory, exists := c.PhysicalBackends[config.Storage.Type] |
| 795 | if !exists { |
| 796 | return nil, fmt.Errorf("Unknown storage type %s", config.Storage.Type) |
| 797 | } |
| 798 | |
| 799 | // Do any custom configuration needed per backend |
| 800 | switch config.Storage.Type { |
| 801 | case storageTypeConsul: |
| 802 | if config.ServiceRegistration == nil { |
| 803 | // If Consul is configured for storage and service registration is unconfigured, |
| 804 | // use Consul for service registration without requiring additional configuration. |
| 805 | // This maintains backward-compatibility. |
| 806 | config.ServiceRegistration = &server.ServiceRegistration{ |
| 807 | Type: "consul", |
| 808 | Config: config.Storage.Config, |
| 809 | } |
| 810 | } |
| 811 | case storageTypeRaft: |
| 812 | if envCA := os.Getenv("VAULT_CLUSTER_ADDR"); envCA != "" { |
| 813 | config.ClusterAddr = configutil.NormalizeAddr(envCA) |
| 814 | } |
| 815 | if len(config.ClusterAddr) == 0 { |
| 816 | return nil, errors.New("Cluster address must be set when using raft storage") |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | namedStorageLogger := c.logger.Named("storage." + config.Storage.Type) |
| 821 | c.allLoggers = append(c.allLoggers, namedStorageLogger) |
| 822 | backend, err := factory(config.Storage.Config, namedStorageLogger) |
| 823 | if err != nil { |
| 824 | return nil, fmt.Errorf("Error initializing storage of type %s: %w", config.Storage.Type, err) |
| 825 | } |
| 826 | |
| 827 | return backend, nil |
| 828 | } |
| 829 | |
| 830 | func beginServiceRegistration(c *ServerCommand, config *server.Config) (sr.ServiceRegistration, error) { |
| 831 | sdFactory, ok := c.ServiceRegistrations[config.ServiceRegistration.Type] |
no test coverage detected