filer_etc_store.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package filer_etc
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/credential"
  5. "github.com/seaweedfs/seaweedfs/weed/pb"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  7. "github.com/seaweedfs/seaweedfs/weed/util"
  8. "google.golang.org/grpc"
  9. )
  10. func init() {
  11. credential.Stores = append(credential.Stores, &FilerEtcStore{})
  12. }
  13. // FilerEtcStore implements CredentialStore using SeaweedFS filer for storage
  14. type FilerEtcStore struct {
  15. filerGrpcAddress string
  16. grpcDialOption grpc.DialOption
  17. }
  18. func (store *FilerEtcStore) GetName() credential.CredentialStoreTypeName {
  19. return credential.StoreTypeFilerEtc
  20. }
  21. func (store *FilerEtcStore) Initialize(configuration util.Configuration, prefix string) error {
  22. // Handle nil configuration gracefully
  23. if configuration != nil {
  24. store.filerGrpcAddress = configuration.GetString(prefix + "filer")
  25. // TODO: Initialize grpcDialOption based on configuration
  26. }
  27. // Note: filerGrpcAddress can be set later via SetFilerClient method
  28. return nil
  29. }
  30. // SetFilerClient sets the filer client details for the file store
  31. func (store *FilerEtcStore) SetFilerClient(filerAddress string, grpcDialOption grpc.DialOption) {
  32. store.filerGrpcAddress = filerAddress
  33. store.grpcDialOption = grpcDialOption
  34. }
  35. // withFilerClient executes a function with a filer client
  36. func (store *FilerEtcStore) withFilerClient(fn func(client filer_pb.SeaweedFilerClient) error) error {
  37. if store.filerGrpcAddress == "" {
  38. return fmt.Errorf("filer address not configured")
  39. }
  40. // Use the pb.WithGrpcFilerClient helper similar to existing code
  41. return pb.WithGrpcFilerClient(false, 0, pb.ServerAddress(store.filerGrpcAddress), store.grpcDialOption, fn)
  42. }
  43. func (store *FilerEtcStore) Shutdown() {
  44. // No cleanup needed for file store
  45. }