Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for getObjectACL and deleteObjectACL #1832

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions fakestorage/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,59 @@ func (s *Server) listObjectACL(r *http.Request) jsonResponse {
return jsonResponse{data: newACLListResponse(obj.ObjectAttrs)}
}

func (s *Server) deleteObjectACL(r *http.Request) jsonResponse {
vars := unescapeMuxVars(mux.Vars(r))

obj, err := s.GetObjectStreaming(vars["bucketName"], vars["objectName"])
if err != nil {
return jsonResponse{status: http.StatusNotFound}
}
defer obj.Close()
entity := vars["entity"]

var newAcls []storage.ACLRule
for _, aclRule := range obj.ObjectAttrs.ACL {
if entity != string(aclRule.Entity) {
newAcls = append(newAcls, aclRule)
}
}

obj.ACL = newAcls
obj, err = s.createObject(obj, backend.NoConditions{})
if err != nil {
return errToJsonResponse(err)
}
defer obj.Close()

return jsonResponse{status: http.StatusOK}
}

func (s *Server) getObjectACL(r *http.Request) jsonResponse {
vars := unescapeMuxVars(mux.Vars(r))

obj, err := s.backend.GetObject(vars["bucketName"], vars["objectName"])
if err != nil {
return jsonResponse{status: http.StatusNotFound}
}
defer obj.Close()
entity := vars["entity"]

for _, aclRule := range obj.ObjectAttrs.ACL {
if entity == string(aclRule.Entity) {
oac := &objectAccessControl{
Bucket: obj.BucketName,
Entity: string(aclRule.Entity),
Object: obj.Name,
Role: string(aclRule.Role),
Etag: "RVRhZw==",
Kind: "storage#objectAccessControl",
}
return jsonResponse{data: oac}
}
}
return jsonResponse{status: http.StatusNotFound}
}

func (s *Server) setObjectACL(r *http.Request) jsonResponse {
vars := unescapeMuxVars(mux.Vars(r))

Expand Down
17 changes: 17 additions & 0 deletions fakestorage/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,23 @@ func TestServerClientObjectSetAclPrivate(t *testing.T) {
t.Fatal("acl role not set to RoleReader")
return
}

err = objHandle.ACL().Delete(ctx, storage.AllAuthenticatedUsers)
if err != nil {
t.Fatalf("unexpected error while deleting acl %+v", err)
return
}

rules, err = objHandle.ACL().List(ctx)
if err != nil {
t.Fatalf("unexpected error while getting acl %+v", err)
return
}

if len(rules) != 0 {
t.Fatalf("acl has unexpected rules: %+v", rules)
return
}
})
})
}
Expand Down
2 changes: 2 additions & 0 deletions fakestorage/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ func (s *Server) buildMuxer() {
r.Path("/b/{bucketName}/o/{objectName:.+}").Methods(http.MethodPatch).HandlerFunc(jsonToHTTPHandler(s.patchObject))
r.Path("/b/{bucketName}/o/{objectName:.+}/acl").Methods(http.MethodGet).HandlerFunc(jsonToHTTPHandler(s.listObjectACL))
r.Path("/b/{bucketName}/o/{objectName:.+}/acl").Methods(http.MethodPost).HandlerFunc(jsonToHTTPHandler(s.setObjectACL))
r.Path("/b/{bucketName}/o/{objectName:.+}/acl/{entity}").Methods(http.MethodDelete).HandlerFunc(jsonToHTTPHandler(s.deleteObjectACL))
r.Path("/b/{bucketName}/o/{objectName:.+}/acl/{entity}").Methods(http.MethodGet).HandlerFunc(jsonToHTTPHandler(s.getObjectACL))
r.Path("/b/{bucketName}/o/{objectName:.+}/acl/{entity}").Methods(http.MethodPut).HandlerFunc(jsonToHTTPHandler(s.setObjectACL))
r.Path("/b/{bucketName}/o/{objectName:.+}").Methods(http.MethodGet, http.MethodHead).HandlerFunc(s.getObject)
r.Path("/b/{bucketName}/o/{objectName:.+}").Methods(http.MethodDelete).HandlerFunc(jsonToHTTPHandler(s.deleteObject))
Expand Down