Browse Source

nil handling

pull/7481/head
chrislu 3 weeks ago
parent
commit
34b4584ee0
  1. 4
      weed/s3api/s3api_bucket_policy_handlers.go
  2. 4
      weed/s3api/s3api_server.go

4
weed/s3api/s3api_bucket_policy_handlers.go

@ -91,10 +91,12 @@ func (s3a *S3ApiServer) PutBucketPolicyHandler(w http.ResponseWriter, r *http.Re
// Immediately load into policy engine to avoid race condition // Immediately load into policy engine to avoid race condition
// (The subscription system will also do this async, but we want immediate effect) // (The subscription system will also do this async, but we want immediate effect)
if s3a.policyEngine != nil {
if err := s3a.policyEngine.LoadBucketPolicyFromCache(bucket, &policyDoc); err != nil { if err := s3a.policyEngine.LoadBucketPolicyFromCache(bucket, &policyDoc); err != nil {
glog.Warningf("Failed to immediately load bucket policy into engine for %s: %v", bucket, err) glog.Warningf("Failed to immediately load bucket policy into engine for %s: %v", bucket, err)
// Don't fail the request since the subscription will eventually sync it // Don't fail the request since the subscription will eventually sync it
} }
}
// Update IAM integration with new bucket policy // Update IAM integration with new bucket policy
if s3a.iam.iamIntegration != nil { if s3a.iam.iamIntegration != nil {
@ -132,10 +134,12 @@ func (s3a *S3ApiServer) DeleteBucketPolicyHandler(w http.ResponseWriter, r *http
// Immediately remove from policy engine to avoid race condition // Immediately remove from policy engine to avoid race condition
// (The subscription system will also do this async, but we want immediate effect) // (The subscription system will also do this async, but we want immediate effect)
if s3a.policyEngine != nil {
if err := s3a.policyEngine.DeleteBucketPolicy(bucket); err != nil { if err := s3a.policyEngine.DeleteBucketPolicy(bucket); err != nil {
glog.Warningf("Failed to immediately remove bucket policy from engine for %s: %v", bucket, err) glog.Warningf("Failed to immediately remove bucket policy from engine for %s: %v", bucket, err)
// Don't fail the request since the subscription will eventually sync it // Don't fail the request since the subscription will eventually sync it
} }
}
// Update IAM integration to remove bucket policy // Update IAM integration to remove bucket policy
if s3a.iam.iamIntegration != nil { if s3a.iam.iamIntegration != nil {

4
weed/s3api/s3api_server.go

@ -168,6 +168,10 @@ func NewS3ApiServerWithStore(router *mux.Router, option *S3ApiServerOption, expl
// This helper method centralizes the logic for loading bucket policies into the engine // This helper method centralizes the logic for loading bucket policies into the engine
// to avoid duplication and ensure consistent error handling // to avoid duplication and ensure consistent error handling
func (s3a *S3ApiServer) syncBucketPolicyToEngine(bucket string, policyDoc *policy.PolicyDocument) { func (s3a *S3ApiServer) syncBucketPolicyToEngine(bucket string, policyDoc *policy.PolicyDocument) {
if s3a.policyEngine == nil {
return
}
if policyDoc != nil { if policyDoc != nil {
if err := s3a.policyEngine.LoadBucketPolicyFromCache(bucket, policyDoc); err != nil { if err := s3a.policyEngine.LoadBucketPolicyFromCache(bucket, policyDoc); err != nil {
glog.Errorf("Failed to sync bucket policy for %s to policy engine: %v", bucket, err) glog.Errorf("Failed to sync bucket policy for %s to policy engine: %v", bucket, err)

Loading…
Cancel
Save