2020-12-07 16:10:29 +08:00
|
|
|
package s3api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2021-08-05 07:25:46 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
2020-12-07 16:10:29 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2022-06-17 19:07:39 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/s3api/s3_constants"
|
2021-08-05 07:25:46 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2020-12-07 16:10:29 +08:00
|
|
|
)
|
|
|
|
|
2021-10-17 16:04:19 +08:00
|
|
|
func (s3a *S3ApiServer) subscribeMetaEvents(clientName string, prefix string, lastTsNs int64) {
|
2020-12-07 16:10:29 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2022-06-15 21:07:55 +08:00
|
|
|
fileName := message.NewEntry.Name
|
|
|
|
content := message.NewEntry.Content
|
|
|
|
|
|
|
|
_ = s3a.onIamConfigUpdate(dir, fileName, content)
|
2022-06-17 17:11:18 +08:00
|
|
|
_ = s3a.onCircuitBreakerConfigUpdate(dir, fileName, content)
|
2020-12-07 16:10:29 +08:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:04:19 +08:00
|
|
|
util.RetryForever("followIamChanges", func() error {
|
2022-06-02 01:28:47 +08:00
|
|
|
return pb.WithFilerClientFollowMetadata(s3a, clientName, s3a.randomClientId, prefix, &lastTsNs, 0, 0, processEventFn, pb.FatalOnError)
|
2021-10-17 16:04:19 +08:00
|
|
|
}, func(err error) bool {
|
|
|
|
glog.V(0).Infof("iam follow metadata changes: %v", err)
|
|
|
|
return true
|
2021-08-05 07:25:46 +08:00
|
|
|
})
|
2022-06-15 21:07:55 +08:00
|
|
|
}
|
2020-12-07 16:10:29 +08:00
|
|
|
|
2022-06-15 21:07:55 +08:00
|
|
|
//reload iam config
|
|
|
|
func (s3a *S3ApiServer) onIamConfigUpdate(dir, filename string, content []byte) error {
|
|
|
|
if dir == filer.IamConfigDirecotry && filename == filer.IamIdentityFile {
|
|
|
|
if err := s3a.iam.LoadS3ApiConfigurationFromBytes(content); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
glog.V(0).Infof("updated %s/%s", dir, filename)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//reload circuit breaker config
|
2022-06-17 17:11:18 +08:00
|
|
|
func (s3a *S3ApiServer) onCircuitBreakerConfigUpdate(dir, filename string, content []byte) error {
|
2022-06-17 19:07:39 +08:00
|
|
|
if dir == s3_constants.CircuitBreakerConfigDir && filename == s3_constants.CircuitBreakerConfigFile {
|
2022-06-15 21:07:55 +08:00
|
|
|
if err := s3a.cb.LoadS3ApiConfigurationFromBytes(content); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
glog.V(0).Infof("updated %s/%s", dir, filename)
|
|
|
|
}
|
|
|
|
return nil
|
2020-12-07 16:10:29 +08:00
|
|
|
}
|