You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

  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, 0, processEventFn, pb.FatalOnError)
  29. }, func(err error) bool {
  30. glog.V(0).Infof("iam follow metadata changes: %v", err)
  31. return true
  32. })
  33. }