auth_credentials_subscribe.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package s3api
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/filer"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/chrislusf/seaweedfs/weed/pb"
  6. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  7. "github.com/chrislusf/seaweedfs/weed/util"
  8. )
  9. func (s3a *S3ApiServer) subscribeMetaEvents(clientName string, prefix string, lastTsNs int64) {
  10. processEventFn := func(resp *filer_pb.SubscribeMetadataResponse) error {
  11. message := resp.EventNotification
  12. if message.NewEntry == nil {
  13. return nil
  14. }
  15. dir := resp.Directory
  16. if message.NewParentPath != "" {
  17. dir = message.NewParentPath
  18. }
  19. if dir == filer.IamConfigDirecotry && message.NewEntry.Name == filer.IamIdentityFile {
  20. if err := s3a.iam.loadS3ApiConfigurationFromBytes(message.NewEntry.Content); err != nil {
  21. return err
  22. }
  23. glog.V(0).Infof("updated %s/%s", filer.IamConfigDirecotry, filer.IamIdentityFile)
  24. }
  25. return nil
  26. }
  27. util.RetryForever("followIamChanges", func() error {
  28. return pb.WithFilerClientFollowMetadata(s3a, clientName, s3a.randomClientId, prefix, &lastTsNs, 0, processEventFn, true)
  29. }, func(err error) bool {
  30. glog.V(0).Infof("iam follow metadata changes: %v", err)
  31. return true
  32. })
  33. }