2020-12-07 08:10:29 +00:00
|
|
|
package s3api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2021-08-04 23:25:46 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
2020-12-07 08:10:29 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2021-08-04 23:25:46 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2020-12-07 08:10:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s3a *S3ApiServer) subscribeMetaEvents(clientName string, prefix string, lastTsNs int64) error {
|
|
|
|
|
|
|
|
processEventFn := func(resp *filer_pb.SubscribeMetadataResponse) error {
|
|
|
|
|
|
|
|
message := resp.EventNotification
|
|
|
|
if message.NewEntry == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
dir := resp.Directory
|
|
|
|
|
|
|
|
if message.NewParentPath != "" {
|
|
|
|
dir = message.NewParentPath
|
|
|
|
}
|
|
|
|
if dir == filer.IamConfigDirecotry && message.NewEntry.Name == filer.IamIdentityFile {
|
2020-12-10 08:15:22 +00:00
|
|
|
if err := s3a.iam.loadS3ApiConfigurationFromBytes(message.NewEntry.Content); err != nil {
|
2020-12-07 08:10:29 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-12-10 08:15:22 +00:00
|
|
|
glog.V(0).Infof("updated %s/%s", filer.IamConfigDirecotry, filer.IamIdentityFile)
|
2020-12-07 08:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-04 23:25:46 +00:00
|
|
|
return util.Retry("followIamChanges", func() error {
|
|
|
|
return pb.WithFilerClientFollowMetadata(s3a, clientName, prefix, lastTsNs, 0, processEventFn, true)
|
|
|
|
})
|
2020-12-07 08:10:29 +00:00
|
|
|
|
|
|
|
}
|