Skip to content
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
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ on:
release:
types:
- published

pull_request:
paths-ignore:
- '**.md'
env:
BLOBBER_REGISTRY: ${{ secrets.BLOBBER_REGISTRY }}
VALIDATOR_REGISTRY: ${{ secrets.VALIDATOR_REGISTRY }}
Expand Down
5 changes: 5 additions & 0 deletions code/go/0chain.net/blobbercore/blobberHTTP/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/readmarker"
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference"
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/writemarker"
"github.com/0chain/blobber/code/go/0chain.net/core/common"
)

type UploadResult struct {
Expand Down Expand Up @@ -51,3 +52,7 @@ type DownloadResponse struct {
Path string `json:"-"`
LatestRM *readmarker.ReadMarker `json:"latest_rm"`
}

type UpdateObjectAttributesResponse struct {
WhoPaysForReads common.WhoPays `json:"who_pays_for_reads,omitempty"`
}
785 changes: 483 additions & 302 deletions code/go/0chain.net/blobbercore/blobbergrpc/blobber.pb.go

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions code/go/0chain.net/blobbercore/blobbergrpc/blobber.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions code/go/0chain.net/blobbercore/blobbergrpc/blobber_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions code/go/0chain.net/blobbercore/blobbergrpc/proto/blobber.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ service Blobber {
};
}

rpc UpdateObjectAttributes(UpdateObjectAttributesRequest) returns (UpdateObjectAttributesResponse) {
option (google.api.http) = {
post: "/v2/file/attributes/{allocation}"
body: "*"
};
}

rpc Collaborator(CollaboratorRequest) returns (CollaboratorResponse) {
option (google.api.http) = {
post: "/v2/file/collaborator/{allocation}"
Expand Down Expand Up @@ -243,6 +250,17 @@ message GetAllocationResponse {
Allocation allocation = 1;
}

message UpdateObjectAttributesRequest {
string allocation = 1;
string path = 2;
string path_hash = 3;
string connection_id = 4;
string attributes = 5;
}
message UpdateObjectAttributesResponse {
int64 who_pays_for_reads = 1;
}

message Allocation {
string ID = 1;
string Tx = 2;
Expand Down
8 changes: 8 additions & 0 deletions code/go/0chain.net/blobbercore/convert/responseHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package convert
import (
"context"
"encoding/json"
"github.com/0chain/blobber/code/go/0chain.net/core/common"

"github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation"
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobberHTTP"
Expand Down Expand Up @@ -141,3 +142,10 @@ func CollaboratorResponse(response *blobbergrpc.CollaboratorResponse) interface{

return nil
}

func UpdateObjectAttributesResponseHandler(
updateAttributesResponse *blobbergrpc.UpdateObjectAttributesResponse) *blobberHTTP.UpdateObjectAttributesResponse {
return &blobberHTTP.UpdateObjectAttributesResponse{
WhoPaysForReads: common.WhoPays(updateAttributesResponse.WhoPaysForReads),
}
}
39 changes: 24 additions & 15 deletions code/go/0chain.net/blobbercore/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ func SetupHandlers(r *mux.Router) {
r.HandleFunc("/v1/file/download/{allocation}", common.UserRateLimit(common.ToByteStream(WithConnection(DownloadHandler))))
r.HandleFunc("/v1/file/rename/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(RenameHandler))))
r.HandleFunc("/v1/file/copy/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(CopyHandler))))
r.HandleFunc("/v1/file/attributes/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(UpdateAttributesHandler))))
r.HandleFunc("/v1/file/attributes/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(UpdateAttributesHandler(svc))))).Methods(http.MethodPost)

r.HandleFunc("/v1/connection/commit/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(CommitHandler(svc))))).Methods("POST")
r.HandleFunc("/v1/file/commitmetatxn/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(CommitMetaTxnHandler(svc))))).Methods(http.MethodPost)
r.HandleFunc("/v1/file/collaborator/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(CollaboratorHandler(svc))))).Methods(http.MethodGet, http.MethodPost, http.MethodDelete)
r.HandleFunc("/v1/file/calculatehash/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(CalculateHashHandler(svc))))).Methods(http.MethodPost)

//object info related apis
r.HandleFunc("/allocation", common.UserRateLimit(common.ToJSONResponse(WithConnection(AllocationHandler(svc))))).Methods("GET")
r.HandleFunc("/v1/file/meta/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithReadOnlyConnection(FileMetaHandler(svc))))).Methods("POST")
r.HandleFunc("/v1/file/stats/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithReadOnlyConnection(FileStatsHandler(svc))))).Methods("POST")
r.HandleFunc("/v1/file/list/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithReadOnlyConnection(ListHandler(svc))))).Methods("GET")
r.HandleFunc("/v1/file/objectpath/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithReadOnlyConnection(ObjectPathHandler(svc))))).Methods("GET")
r.HandleFunc("/v1/file/referencepath/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithReadOnlyConnection(ReferencePathHandler(svc))))).Methods("GET")
r.HandleFunc("/v1/file/objecttree/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithReadOnlyConnection(ObjectTreeHandler(svc))))).Methods("GET")
r.HandleFunc("/allocation", common.UserRateLimit(common.ToJSONResponse(WithConnection(AllocationHandler(svc))))).Methods(http.MethodGet)
r.HandleFunc("/v1/file/meta/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithReadOnlyConnection(FileMetaHandler(svc))))).Methods(http.MethodPost)
r.HandleFunc("/v1/file/stats/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithReadOnlyConnection(FileStatsHandler(svc))))).Methods(http.MethodPost)
r.HandleFunc("/v1/file/list/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithReadOnlyConnection(ListHandler(svc))))).Methods(http.MethodGet)
r.HandleFunc("/v1/file/objectpath/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithReadOnlyConnection(ObjectPathHandler(svc))))).Methods(http.MethodGet)
r.HandleFunc("/v1/file/referencepath/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithReadOnlyConnection(ReferencePathHandler(svc))))).Methods(http.MethodGet)
r.HandleFunc("/v1/file/objecttree/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithReadOnlyConnection(ObjectTreeHandler(svc))))).Methods(http.MethodGet)

//admin related
r.HandleFunc("/_debug", common.UserRateLimit(common.ToJSONResponse(DumpGoRoutines)))
Expand Down Expand Up @@ -337,14 +337,23 @@ func UploadHandler(ctx context.Context, r *http.Request) (interface{}, error) {
return response, nil
}

func UpdateAttributesHandler(ctx context.Context, r *http.Request) (interface{}, error) {
ctx = setupHandlerContext(ctx, r)
response, err := storageHandler.UpdateObjectAttributes(ctx, r)
if err != nil {
return nil, err
}
func UpdateAttributesHandler(svc *blobberGRPCService) func(ctx context.Context, r *http.Request) (interface{}, error) {
return func(ctx context.Context, r *http.Request) (interface{}, error) {
ctx = setupHandlerGRPCContext(ctx, r)

return response, nil
updateAttrResp, err := svc.UpdateObjectAttributes(ctx, &blobbergrpc.UpdateObjectAttributesRequest{
Path: r.FormValue("path"),
PathHash: r.FormValue("path_hash"),
Allocation: mux.Vars(r)["allocation"],
ConnectionId: r.FormValue("connection_id"),
Attributes: r.FormValue("attributes"),
})
if err != nil {
return nil, err
}

return convert.UpdateObjectAttributesResponseHandler(updateAttrResp), nil
}
}

func CalculateHashHandler(svc *blobberGRPCService) func(ctx context.Context, r *http.Request) (interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion code/go/0chain.net/blobbercore/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func setupHandlers() (*mux.Router, map[string]string) {
aName := "Attributes"
router.HandleFunc(aPath, common.UserRateLimit(
common.ToJSONResponse(
WithReadOnlyConnection(UpdateAttributesHandler),
WithReadOnlyConnection(UpdateAttributesHandler(svc)),
),
),
).Name(aName)
Expand Down
Loading