forked from hyperledger/firefly
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hyperledger#1132 from kaleido-io/delete-data
Add DELETE method for data API
- Loading branch information
Showing
93 changed files
with
1,139 additions
and
307 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
db/migrations/postgres/000105_add_namespace_and_data_id_to_blobs.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
BEGIN; | ||
|
||
DROP INDEX blobs_namespace_data_id; | ||
DROP INDEX blobs_payload_ref; | ||
ALTER TABLE blobs DROP COLUMN namespace; | ||
ALTER TABLE blobs DROP COLUMN data_id; | ||
CREATE INDEX blob_hash ON blobs(hash); | ||
|
||
COMMIT; |
25 changes: 25 additions & 0 deletions
25
db/migrations/postgres/000105_add_namespace_and_data_id_to_blobs.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
BEGIN; | ||
|
||
CREATE TABLE temp_blobs ( | ||
seq SERIAL PRIMARY KEY, | ||
namespace VARCHAR(64) NOT NULL, | ||
hash CHAR(64) NOT NULL, | ||
payload_ref VARCHAR(1024) NOT NULL, | ||
created BIGINT NOT NULL, | ||
peer VARCHAR(256) NOT NULL, | ||
size BIGINT, | ||
data_id UUID NOT NULL | ||
); | ||
INSERT INTO temp_blobs (namespace, data_id, hash, payload_ref, created, peer, size) | ||
SELECT DISTINCT data.namespace, data.id, data.blob_hash, blobs.payload_ref, blobs.created, blobs.peer, blobs.size | ||
FROM data | ||
LEFT JOIN blobs ON blobs.hash = data.blob_hash | ||
WHERE data.blob_hash IS NOT NULL | ||
; | ||
DROP INDEX blobs_hash; | ||
DROP TABLE blobs; | ||
ALTER TABLE temp_blobs RENAME TO blobs; | ||
CREATE INDEX blobs_namespace_data_id ON blobs(namespace, data_id); | ||
CREATE INDEX blobs_payload_ref ON blobs(payload_ref); | ||
|
||
COMMIT; |
5 changes: 5 additions & 0 deletions
5
db/migrations/sqlite/000105_add_namespace_and_data_id_to_blobs.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
DROP INDEX blobs_namespace_data_id; | ||
DROP INDEX blobs_payload_ref; | ||
ALTER TABLE blobs DROP COLUMN namespace; | ||
ALTER TABLE blobs DROP COLUMN data_id; | ||
CREATE INDEX blob_hash ON blobs(hash); |
21 changes: 21 additions & 0 deletions
21
db/migrations/sqlite/000105_add_namespace_and_data_id_to_blobs.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CREATE TABLE temp_blobs ( | ||
seq INTEGER PRIMARY KEY AUTOINCREMENT, | ||
namespace VARCHAR(64) NOT NULL, | ||
hash CHAR(64) NOT NULL, | ||
payload_ref VARCHAR(1024) NOT NULL, | ||
created BIGINT NOT NULL, | ||
peer VARCHAR(256) NOT NULL, | ||
size BIGINT, | ||
data_id UUID NOT NULL | ||
); | ||
INSERT INTO temp_blobs (namespace, data_id, hash, payload_ref, created, peer, size) | ||
SELECT DISTINCT data.namespace, data.id, data.blob_hash, blobs.payload_ref, blobs.created, blobs.peer, blobs.size | ||
FROM data | ||
LEFT JOIN blobs ON blobs.hash = data.blob_hash | ||
WHERE data.blob_hash IS NOT NULL | ||
; | ||
DROP INDEX blobs_hash; | ||
DROP TABLE blobs; | ||
ALTER TABLE temp_blobs RENAME TO blobs; | ||
CREATE INDEX blobs_namespace_data_id ON blobs(namespace, data_id); | ||
CREATE INDEX blobs_payload_ref ON blobs(payload_ref); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright © 2022 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package apiserver | ||
|
||
import ( | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-common/pkg/fftypes" | ||
"github.com/hyperledger/firefly/mocks/datamocks" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func TestDeleteDataByID(t *testing.T) { | ||
o, r := newTestAPIServer() | ||
o.On("Authorize", mock.Anything, mock.Anything).Return(nil) | ||
dmm := &datamocks.Manager{} | ||
o.On("Data").Return(dmm) | ||
id := fftypes.NewUUID() | ||
req := httptest.NewRequest("DELETE", "/api/v1/namespaces/mynamespace/data/"+id.String(), nil) | ||
req.Header.Set("Content-Type", "application/json; charset=utf-8") | ||
res := httptest.NewRecorder() | ||
|
||
dmm.On("DeleteData", mock.Anything, id.String()). | ||
Return(nil, nil) | ||
r.ServeHTTP(res, req) | ||
|
||
assert.Equal(t, 204, res.Result().StatusCode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright © 2023 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package apiserver | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/hyperledger/firefly-common/pkg/ffapi" | ||
"github.com/hyperledger/firefly/internal/coremsgs" | ||
) | ||
|
||
var deleteData = &ffapi.Route{ | ||
Name: "deleteData", | ||
Path: "data/{dataid}", | ||
Method: http.MethodDelete, | ||
PathParams: []*ffapi.PathParam{ | ||
{Name: "dataid", Description: coremsgs.APIParamsDataID}, | ||
}, | ||
QueryParams: nil, | ||
Description: coremsgs.APIEndpointsDeleteData, | ||
JSONInputValue: nil, | ||
JSONOutputValue: nil, | ||
JSONOutputCodes: []int{http.StatusNoContent}, | ||
Extensions: &coreExtensions{ | ||
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { | ||
err = cr.or.Data().DeleteData(cr.ctx, r.PP["dataid"]) | ||
return nil, err | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.