From 0ae9414d48264b4d7ec93389640627f919f2017d Mon Sep 17 00:00:00 2001 From: dwertent Date: Wed, 14 Aug 2024 15:28:19 -0400 Subject: [PATCH 1/4] chore: Remove getIdentityByDID route Signed-off-by: dwertent --- Makefile | 4 +- go.mod | 2 +- internal/apiserver/ffi2swagger.go | 4 +- .../apiserver/route_get_identity_by_did.go | 50 ---------------- .../route_get_identity_by_did_test.go | 59 ------------------- .../apiserver/route_get_identity_by_id.go | 32 ++++++++-- .../route_get_identity_by_id_test.go | 32 ++++++++++ ...e_get_subscription_events_filtered_test.go | 2 +- internal/apiserver/routes.go | 1 - internal/apiserver/server.go | 20 +++---- internal/coremsgs/en_api_translations.go | 4 +- internal/database/sqlcommon/event_sql_test.go | 5 +- internal/events/event_manager_test.go | 2 +- internal/events/subscription_manager.go | 2 +- internal/events/websockets/websockets_test.go | 2 +- internal/reference/reference.go | 6 +- internal/syncasync/sync_async_bridge.go | 4 +- 17 files changed, 87 insertions(+), 144 deletions(-) delete mode 100644 internal/apiserver/route_get_identity_by_did.go delete mode 100644 internal/apiserver/route_get_identity_by_did_test.go diff --git a/Makefile b/Makefile index bcd40335e..2b560e889 100644 --- a/Makefile +++ b/Makefile @@ -82,9 +82,9 @@ $(eval $(call makemock, internal/apiserver, Server, apiser $(eval $(call makemock, internal/events/websockets, WebSocketsNamespaced, websocketsmocks)) firefly-nocgo: ${GOFILES} - CGO_ENABLED=0 $(VGO) build -o ${BINARY_NAME}-nocgo -ldflags "-X main.buildDate=$(DATE) -X main.buildVersion=$(BUILD_VERSION) -X 'github.com/hyperledger/firefly/cmd.BuildVersionOverride=$(BUILD_VERSION)' -X 'github.com/hyperledger/firefly/cmd.BuildDate=$(DATE)' -X 'github.com/hyperledger/firefly/cmd.BuildCommit=$(GIT_REF)'" -tags=prod -tags=prod -v + CGO_ENABLED=0 $(VGO) build -o ${BINARY_NAME}-nocgo -ldflags "-X main.buildDate=$(DATE) -X main.buildVersion=$(BUILD_VERSION) -X 'github.com/hyperledger/firefly/cmd.BuildVersionOverride=$(BUILD_VERSION)' -X 'github.com/hyperledger/firefly/cmd.BuildDate=$(DATE)' -X 'github.com/hyperledger/firefly/cmd.BuildCommit=$(GIT_REF)'" -tags=prod -v firefly: ${GOFILES} - $(VGO) build -o ${BINARY_NAME} -ldflags "-X main.buildDate=$(DATE) -X main.buildVersion=$(BUILD_VERSION) -X 'github.com/hyperledger/firefly/cmd.BuildVersionOverride=$(BUILD_VERSION)' -X 'github.com/hyperledger/firefly/cmd.BuildDate=$(DATE)' -X 'github.com/hyperledger/firefly/cmd.BuildCommit=$(GIT_REF)'" -tags=prod -tags=prod -v + $(VGO) build -o ${BINARY_NAME} -ldflags "-X main.buildDate=$(DATE) -X main.buildVersion=$(BUILD_VERSION) -X 'github.com/hyperledger/firefly/cmd.BuildVersionOverride=$(BUILD_VERSION)' -X 'github.com/hyperledger/firefly/cmd.BuildDate=$(DATE)' -X 'github.com/hyperledger/firefly/cmd.BuildCommit=$(GIT_REF)'" -tags=prod -v go-mod-tidy: .ALWAYS $(VGO) mod tidy build: firefly-nocgo firefly diff --git a/go.mod b/go.mod index 2d6c72a2a..5a90d6e65 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/ghodss/yaml v1.0.0 github.com/go-resty/resty/v2 v2.11.0 github.com/golang-migrate/migrate/v4 v4.17.0 + github.com/google/uuid v1.5.0 github.com/gorilla/mux v1.8.1 github.com/gorilla/websocket v1.5.1 github.com/hyperledger/firefly-common v1.4.6 @@ -44,7 +45,6 @@ require ( github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-openapi/jsonpointer v0.20.2 // indirect github.com/go-openapi/swag v0.22.7 // indirect - github.com/google/uuid v1.5.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/hcl v1.0.0 // indirect diff --git a/internal/apiserver/ffi2swagger.go b/internal/apiserver/ffi2swagger.go index b5699b50d..c7c337312 100644 --- a/internal/apiserver/ffi2swagger.go +++ b/internal/apiserver/ffi2swagger.go @@ -81,7 +81,7 @@ func (swg *ffiSwaggerGen) Build(ctx context.Context, api *core.ContractAPI, ffi func addFFIMethod(ctx context.Context, routes []*ffapi.Route, method *fftypes.FFIMethod, hasLocation bool) []*ffapi.Route { description := method.Description - if method.Details != nil && len(method.Details) > 0 { + if len(method.Details) > 0 { additionalDetailsHeader := i18n.Expand(ctx, coremsgs.APISmartContractDetails) description = fmt.Sprintf("%s\n\n%s:\n\n%s", description, additionalDetailsHeader, buildDetailsTable(ctx, method.Details)) } @@ -117,7 +117,7 @@ func addFFIMethod(ctx context.Context, routes []*ffapi.Route, method *fftypes.FF func addFFIEvent(ctx context.Context, routes []*ffapi.Route, event *fftypes.FFIEvent, hasLocation bool) []*ffapi.Route { description := event.Description - if event.Details != nil && len(event.Details) > 0 { + if len(event.Details) > 0 { additionalDetailsHeader := i18n.Expand(ctx, coremsgs.APISmartContractDetails) description = fmt.Sprintf("%s\n\n%s:\n\n%s", description, additionalDetailsHeader, buildDetailsTable(ctx, event.Details)) } diff --git a/internal/apiserver/route_get_identity_by_did.go b/internal/apiserver/route_get_identity_by_did.go deleted file mode 100644 index e8025c0c0..000000000 --- a/internal/apiserver/route_get_identity_by_did.go +++ /dev/null @@ -1,50 +0,0 @@ -// 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" - "strings" - - "github.com/hyperledger/firefly-common/pkg/ffapi" - "github.com/hyperledger/firefly/internal/coremsgs" - "github.com/hyperledger/firefly/pkg/core" -) - -var getIdentityByDID = &ffapi.Route{ - Name: "getIdentityByDID", - Path: "identities/{did:did:.+}", - Method: http.MethodGet, - QueryParams: []*ffapi.QueryParam{ - {Name: "fetchverifiers", Example: "true", Description: coremsgs.APIParamsFetchVerifiers, IsBool: true}, - }, - PathParams: []*ffapi.PathParam{ - {Name: "did", Description: coremsgs.APIParamsDID}, - }, - Description: coremsgs.APIEndpointsGetIdentityByDID, - JSONInputValue: nil, - JSONOutputValue: func() interface{} { return &core.IdentityWithVerifiers{} }, - JSONOutputCodes: []int{http.StatusOK}, - Extensions: &coreExtensions{ - CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { - if strings.EqualFold(r.QP["fetchverifiers"], "true") { - return cr.or.NetworkMap().GetIdentityByDIDWithVerifiers(cr.ctx, r.PP["did"]) - } - return cr.or.NetworkMap().GetIdentityByDID(cr.ctx, r.PP["did"]) - }, - }, -} diff --git a/internal/apiserver/route_get_identity_by_did_test.go b/internal/apiserver/route_get_identity_by_did_test.go deleted file mode 100644 index 7052a2a70..000000000 --- a/internal/apiserver/route_get_identity_by_did_test.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright © 2021 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/mocks/networkmapmocks" - "github.com/hyperledger/firefly/pkg/core" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" -) - -func TestGetIdentityByDID(t *testing.T) { - o, r := newTestAPIServer() - o.On("Authorize", mock.Anything, mock.Anything).Return(nil) - nmn := &networkmapmocks.Manager{} - o.On("NetworkMap").Return(nmn) - req := httptest.NewRequest("GET", "/api/v1/identities/did:firefly:org/org_1", nil) - req.Header.Set("Content-Type", "application/json; charset=utf-8") - res := httptest.NewRecorder() - - nmn.On("GetIdentityByDID", mock.Anything, "did:firefly:org/org_1"). - Return(&core.Identity{}, nil) - r.ServeHTTP(res, req) - - assert.Equal(t, 200, res.Result().StatusCode) -} - -func TestGetIdentityByDIDWithVerifiers(t *testing.T) { - o, r := newTestAPIServer() - o.On("Authorize", mock.Anything, mock.Anything).Return(nil) - nmn := &networkmapmocks.Manager{} - o.On("NetworkMap").Return(nmn) - req := httptest.NewRequest("GET", "/api/v1/identities/did:firefly:org/org_1?fetchverifiers", nil) - req.Header.Set("Content-Type", "application/json; charset=utf-8") - res := httptest.NewRecorder() - - nmn.On("GetIdentityByDIDWithVerifiers", mock.Anything, "did:firefly:org/org_1"). - Return(&core.IdentityWithVerifiers{}, nil) - r.ServeHTTP(res, req) - - assert.Equal(t, 200, res.Result().StatusCode) -} diff --git a/internal/apiserver/route_get_identity_by_id.go b/internal/apiserver/route_get_identity_by_id.go index f48968299..794cf98bf 100644 --- a/internal/apiserver/route_get_identity_by_id.go +++ b/internal/apiserver/route_get_identity_by_id.go @@ -20,17 +20,19 @@ import ( "net/http" "strings" + "github.com/google/uuid" "github.com/hyperledger/firefly-common/pkg/ffapi" + "github.com/hyperledger/firefly-common/pkg/i18n" "github.com/hyperledger/firefly/internal/coremsgs" "github.com/hyperledger/firefly/pkg/core" ) var getIdentityByID = &ffapi.Route{ Name: "getIdentityByID", - Path: "identities/{iid}", + Path: "identities/{id:.+}", Method: http.MethodGet, PathParams: []*ffapi.PathParam{ - {Name: "iid", Example: "id", Description: coremsgs.APIParamsIdentityID}, + {Name: "id", Example: "id", Description: coremsgs.APIParamsIdentityID}, }, QueryParams: []*ffapi.QueryParam{ {Name: "fetchverifiers", Example: "true", Description: coremsgs.APIParamsFetchVerifiers, IsBool: true}, @@ -41,10 +43,30 @@ var getIdentityByID = &ffapi.Route{ JSONOutputCodes: []int{http.StatusOK}, Extensions: &coreExtensions{ CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { - if strings.EqualFold(r.QP["fetchverifiers"], "true") { - return cr.or.NetworkMap().GetIdentityByIDWithVerifiers(cr.ctx, r.PP["iid"]) + switch id := r.PP["id"]; { + case isUUID(id): + if strings.EqualFold(r.QP["fetchverifiers"], "true") { + return cr.or.NetworkMap().GetIdentityByIDWithVerifiers(cr.ctx, id) + } + return cr.or.NetworkMap().GetIdentityByID(cr.ctx, id) + case isDID(id): + if strings.EqualFold(r.QP["fetchverifiers"], "true") { + return cr.or.NetworkMap().GetIdentityByDIDWithVerifiers(cr.ctx, id) + } + return cr.or.NetworkMap().GetIdentityByDID(cr.ctx, id) } - return cr.or.NetworkMap().GetIdentityByID(cr.ctx, r.PP["iid"]) + return nil, i18n.NewError(cr.ctx, i18n.MsgUnknownIdentityType) }, }, } + +// isUUID checks if the given string is a UUID +func isUUID(s string) bool { + _, err := uuid.Parse(s) + return err == nil +} + +// isDID checks if the given string is a potential DID +func isDID(s string) bool { + return strings.HasPrefix(s, "did:") +} diff --git a/internal/apiserver/route_get_identity_by_id_test.go b/internal/apiserver/route_get_identity_by_id_test.go index b5c1b7828..9fca0e889 100644 --- a/internal/apiserver/route_get_identity_by_id_test.go +++ b/internal/apiserver/route_get_identity_by_id_test.go @@ -55,3 +55,35 @@ func TestGetIdentityByIDWithVerifiers(t *testing.T) { assert.Equal(t, 200, res.Result().StatusCode) } + +func TestGetIdentityByDID(t *testing.T) { + o, r := newTestAPIServer() + o.On("Authorize", mock.Anything, mock.Anything).Return(nil) + nmn := &networkmapmocks.Manager{} + o.On("NetworkMap").Return(nmn) + req := httptest.NewRequest("GET", "/api/v1/identities/did:firefly:org/org_1", nil) + req.Header.Set("Content-Type", "application/json; charset=utf-8") + res := httptest.NewRecorder() + + nmn.On("GetIdentityByDID", mock.Anything, "did:firefly:org/org_1"). + Return(&core.Identity{}, nil) + r.ServeHTTP(res, req) + + assert.Equal(t, 200, res.Result().StatusCode) +} + +func TestGetIdentityByDIDWithVerifiers(t *testing.T) { + o, r := newTestAPIServer() + o.On("Authorize", mock.Anything, mock.Anything).Return(nil) + nmn := &networkmapmocks.Manager{} + o.On("NetworkMap").Return(nmn) + req := httptest.NewRequest("GET", "/api/v1/identities/did:firefly:org/org_1?fetchverifiers", nil) + req.Header.Set("Content-Type", "application/json; charset=utf-8") + res := httptest.NewRecorder() + + nmn.On("GetIdentityByDIDWithVerifiers", mock.Anything, "did:firefly:org/org_1"). + Return(&core.IdentityWithVerifiers{}, nil) + r.ServeHTTP(res, req) + + assert.Equal(t, 200, res.Result().StatusCode) +} diff --git a/internal/apiserver/route_get_subscription_events_filtered_test.go b/internal/apiserver/route_get_subscription_events_filtered_test.go index fd480294d..152e4637a 100644 --- a/internal/apiserver/route_get_subscription_events_filtered_test.go +++ b/internal/apiserver/route_get_subscription_events_filtered_test.go @@ -82,4 +82,4 @@ func TestGetSubscriptionEventsFilteredNoSequenceIDsProvided(t *testing.T) { r.ServeHTTP(res, req) assert.Equal(t, 200, res.Result().StatusCode) -} \ No newline at end of file +} diff --git a/internal/apiserver/routes.go b/internal/apiserver/routes.go index 3f146cca5..fc04d120a 100644 --- a/internal/apiserver/routes.go +++ b/internal/apiserver/routes.go @@ -86,7 +86,6 @@ var routes = append( getGroupByHash, getGroups, getIdentities, - getIdentityByDID, getIdentityByID, getIdentityDID, getIdentityVerifiers, diff --git a/internal/apiserver/server.go b/internal/apiserver/server.go index ca1671a05..04e5beda1 100644 --- a/internal/apiserver/server.go +++ b/internal/apiserver/server.go @@ -288,7 +288,7 @@ func (as *apiServer) nsOpenAPIHandlerFactory(req *http.Request, publicURL string } } -func (as *apiServer) namespacedSwaggerHandler(hf *ffapi.HandlerFactory, r *mux.Router, publicURL, relativePath string, format ffapi.OpenAPIFormat) { +func (as *apiServer) namespacedSwaggerHandler(hf *ffapi.HandlerFactory, r *mux.Router, publicURL, relativePath string) { r.HandleFunc(`/api/v1/namespaces/{ns}`+relativePath, hf.APIWrapper(func(res http.ResponseWriter, req *http.Request) (status int, err error) { return as.nsOpenAPIHandlerFactory(req, publicURL).OpenAPIHandler("", ffapi.OpenAPIFormatJSON, nsRoutes)(res, req) })) @@ -300,7 +300,7 @@ func (as *apiServer) namespacedSwaggerUI(hf *ffapi.HandlerFactory, r *mux.Router })) } -func (as *apiServer) namespacedContractSwaggerGenerator(hf *ffapi.HandlerFactory, r *mux.Router, mgr namespace.Manager, publicURL, relativePath string, format ffapi.OpenAPIFormat) { +func (as *apiServer) namespacedContractSwaggerGenerator(hf *ffapi.HandlerFactory, r *mux.Router, mgr namespace.Manager, relativePath string, format ffapi.OpenAPIFormat) { r.HandleFunc(`/api/v1/namespaces/{ns}/apis/{apiName}`+relativePath, hf.APIWrapper(func(res http.ResponseWriter, req *http.Request) (status int, err error) { vars := mux.Vars(req) or, err := mgr.Orchestrator(req.Context(), vars["ns"], false) @@ -372,16 +372,16 @@ func (as *apiServer) createMuxRouter(ctx context.Context, mgr namespace.Manager) r.HandleFunc(`/api/openapi.yaml`, hf.APIWrapper(oaf.OpenAPIHandler(`/api/v1`, ffapi.OpenAPIFormatYAML, routes))) r.HandleFunc(`/api`, hf.APIWrapper(oaf.SwaggerUIHandler(`/api/openapi.yaml`))) // Namespace relative APIs - as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/swagger.json`, ffapi.OpenAPIFormatJSON) - as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/openapi.json`, ffapi.OpenAPIFormatJSON) - as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/swagger.yaml`, ffapi.OpenAPIFormatYAML) - as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/openapi.yaml`, ffapi.OpenAPIFormatYAML) + as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/swagger.json`) + as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/openapi.json`) + as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/swagger.yaml`) + as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/openapi.yaml`) as.namespacedSwaggerUI(hf, r, as.apiPublicURL, `/api`) // Dynamic swagger for namespaced contract APIs - as.namespacedContractSwaggerGenerator(hf, r, mgr, as.apiPublicURL, `/api/swagger.json`, ffapi.OpenAPIFormatJSON) - as.namespacedContractSwaggerGenerator(hf, r, mgr, as.apiPublicURL, `/api/openapi.json`, ffapi.OpenAPIFormatJSON) - as.namespacedContractSwaggerGenerator(hf, r, mgr, as.apiPublicURL, `/api/swagger.yaml`, ffapi.OpenAPIFormatYAML) - as.namespacedContractSwaggerGenerator(hf, r, mgr, as.apiPublicURL, `/api/openapi.yaml`, ffapi.OpenAPIFormatYAML) + as.namespacedContractSwaggerGenerator(hf, r, mgr, `/api/swagger.json`, ffapi.OpenAPIFormatJSON) + as.namespacedContractSwaggerGenerator(hf, r, mgr, `/api/openapi.json`, ffapi.OpenAPIFormatJSON) + as.namespacedContractSwaggerGenerator(hf, r, mgr, `/api/swagger.yaml`, ffapi.OpenAPIFormatYAML) + as.namespacedContractSwaggerGenerator(hf, r, mgr, `/api/openapi.yaml`, ffapi.OpenAPIFormatYAML) as.namespacedContractSwaggerUI(hf, r, as.apiPublicURL, `/api`) r.HandleFunc(`/favicon{any:.*}.png`, favIcons) diff --git a/internal/coremsgs/en_api_translations.go b/internal/coremsgs/en_api_translations.go index 02f1a96d5..db50680ca 100644 --- a/internal/coremsgs/en_api_translations.go +++ b/internal/coremsgs/en_api_translations.go @@ -47,7 +47,7 @@ var ( APIParamsFetchReference = ffm("api.params.fetchReference", "When set, the API will return the record that this item references in its 'reference' field") APIParamsGroupHash = ffm("api.params.groupID", "The hash of the group") APIParamsFetchVerifiers = ffm("api.params.fetchVerifiers", "When set, the API will return the verifier for this identity") - APIParamsIdentityID = ffm("api.params.identityID", "The identity ID, which is a UUID generated by FireFly") + APIParamsIdentityID = ffm("api.params.identityID", "The identity ID, which is a UUID generated by FireFly or the identity DID") APIParamsMessageID = ffm("api.params.messageID", "The message ID") APIParamsDID = ffm("api.params.DID", "The identity DID") APIParamsNodeNameOrID = ffm("api.params.nodeNameOrID", "The name or ID of the node") @@ -107,7 +107,7 @@ var ( APIEndpointsGetGroupByHash = ffm("api.endpoints.getGroupByHash", "Gets a group by its ID (hash)") APIEndpointsGetGroups = ffm("api.endpoints.getGroups", "Gets a list of groups") APIEndpointsGetIdentities = ffm("api.endpoints.getIdentities", "Gets a list of all identities that have been registered in the namespace") - APIEndpointsGetIdentityByID = ffm("api.endpoints.getIdentityByID", "Gets an identity by its ID") + APIEndpointsGetIdentityByID = ffm("api.endpoints.getIdentityByID", "Gets an identity by its ID (UUID/DID)") APIEndpointsGetIdentityDID = ffm("api.endpoints.getIdentityDID", "Gets the DID for an identity based on its ID") APIEndpointsGetIdentityVerifiers = ffm("api.endpoints.getIdentityVerifiers", "Gets the verifiers for an identity") APIEndpointsGetMsgByID = ffm("api.endpoints.getMsgByID", "Gets a message by its ID") diff --git a/internal/database/sqlcommon/event_sql_test.go b/internal/database/sqlcommon/event_sql_test.go index 17a95f0ad..06d74a0c7 100644 --- a/internal/database/sqlcommon/event_sql_test.go +++ b/internal/database/sqlcommon/event_sql_test.go @@ -107,7 +107,7 @@ func TestGetEventsInSequenceRangeE2EWithDB(t *testing.T) { Type: core.EventTypeMessageConfirmed, Reference: fftypes.NewUUID(), Correlator: fftypes.NewUUID(), - Topic: fmt.Sprintf("topic%d", i % 2), + Topic: fmt.Sprintf("topic%d", i%2), Created: fftypes.Now(), } err := s.InsertEvent(ctx, event) @@ -322,10 +322,9 @@ func TestGetEventsInSequenceRangeBuildQueryFail(t *testing.T) { func TestGetEventsInSequenceRangeShouldCallGetEventsWhenNoSequencedProvidedAndThrowAnError(t *testing.T) { s, mock := newMockProvider().init() - mock.ExpectQuery("SELECT .*").WillReturnRows(sqlmock.NewRows([]string{"id", }).AddRow("only one")) + mock.ExpectQuery("SELECT .*").WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow("only one")) f := database.EventQueryFactory.NewFilter(context.Background()).And() _, _, err := s.GetEventsInSequenceRange(context.Background(), "ns1", f, -1, -1) assert.NotNil(t, err) assert.NoError(t, mock.ExpectationsWereMet()) } - diff --git a/internal/events/event_manager_test.go b/internal/events/event_manager_test.go index f634108c4..ac06c88c0 100644 --- a/internal/events/event_manager_test.go +++ b/internal/events/event_manager_test.go @@ -681,7 +681,7 @@ func TestEventFilterOnSubscriptionMatchesEventType(t *testing.T) { filteredEvents, _ = em.FilterHistoricalEventsOnSubscription(context.Background(), events, subscription) assert.NotNil(t, filteredEvents) assert.Equal(t, 1, len(filteredEvents)) - + listenerUuid := fftypes.NewUUID() events[0].Event.Topic = "" diff --git a/internal/events/subscription_manager.go b/internal/events/subscription_manager.go index a31b937e5..470ca7b88 100644 --- a/internal/events/subscription_manager.go +++ b/internal/events/subscription_manager.go @@ -534,7 +534,7 @@ func (sm *subscriptionManager) connectionClosed(ei events.Plugin, connID string) sm.mux.Lock() conn, ok := sm.connections[connID] if ok && conn.ei != ei { - log.L(sm.ctx).Warnf(i18n.ExpandWithCode(sm.ctx, i18n.MessageKey(coremsgs.MsgMismatchedTransport), connID, ei.Name(), conn.ei.Name())) + log.L(sm.ctx).Warnln(i18n.ExpandWithCode(sm.ctx, i18n.MessageKey(coremsgs.MsgMismatchedTransport), connID, ei.Name(), conn.ei.Name())) sm.mux.Unlock() return } diff --git a/internal/events/websockets/websockets_test.go b/internal/events/websockets/websockets_test.go index 031adebdf..cba25ebfa 100644 --- a/internal/events/websockets/websockets_test.go +++ b/internal/events/websockets/websockets_test.go @@ -1219,4 +1219,4 @@ func TestHandleStartWrongNamespace(t *testing.T) { err := wc.handleStart(startMessage) assert.Error(t, err) assert.Regexp(t, "FF10462", err) -} \ No newline at end of file +} diff --git a/internal/reference/reference.go b/internal/reference/reference.go index 699c6aab1..067f34b77 100644 --- a/internal/reference/reference.go +++ b/internal/reference/reference.go @@ -790,14 +790,14 @@ func generateObjectReferenceMarkdown(ctx context.Context, descRequired bool, exa if typeReferenceDoc.Description != nil { buff.Write(typeReferenceDoc.Description) } - if typeReferenceDoc.Example != nil && len(typeReferenceDoc.Example) > 0 { + if len(typeReferenceDoc.Example) > 0 { if sectionCount > 1 { buff.WriteString("### Example\n\n```json\n") } buff.Write(typeReferenceDoc.Example) buff.WriteString("\n```\n\n") } - if typeReferenceDoc.FieldDescriptions != nil && len(typeReferenceDoc.FieldDescriptions) > 0 { + if len(typeReferenceDoc.FieldDescriptions) > 0 { if sectionCount > 1 { buff.WriteString("### Field Descriptions\n\n") } @@ -805,7 +805,7 @@ func generateObjectReferenceMarkdown(ctx context.Context, descRequired bool, exa buff.WriteString("\n") } - if typeReferenceDoc.SubFieldTables != nil && len(typeReferenceDoc.SubFieldTables) > 0 { + if len(typeReferenceDoc.SubFieldTables) > 0 { buff.Write(typeReferenceDoc.SubFieldTables) } diff --git a/internal/syncasync/sync_async_bridge.go b/internal/syncasync/sync_async_bridge.go index 6328ab9c2..864cce44a 100644 --- a/internal/syncasync/sync_async_bridge.go +++ b/internal/syncasync/sync_async_bridge.go @@ -155,7 +155,7 @@ func (sa *syncAsyncBridge) getInFlight(ns string, reqType requestType, id *fftyp return nil } inflightNS := sa.inflight[ns] - if inflightNS != nil && id != nil { + if inflightNS != nil { inflight := inflightNS[*id] if inflight != nil && inflight.reqType == reqType { return inflight @@ -615,7 +615,7 @@ func (sa *syncAsyncBridge) resolveSuccessfulOperation(inflight *inflightRequest, func (sa *syncAsyncBridge) resolveFailedOperation(inflight *inflightRequest, typeName string, op *core.Operation) { log.L(sa.ctx).Debugf("Resolving %s request '%s' with error '%s'", typeName, inflight.id, op.Error) - inflight.response <- inflightResponse{err: fmt.Errorf(op.Error)} + inflight.response <- inflightResponse{err: fmt.Errorf("%s", op.Error)} } func (sa *syncAsyncBridge) sendAndWait(ctx context.Context, ns string, id *fftypes.UUID, reqType requestType, send SendFunction) (interface{}, error) { From bedbcf2b1b60f298daeed5e621737c2f90a6e7db Mon Sep 17 00:00:00 2001 From: dwertent Date: Wed, 14 Aug 2024 16:10:12 -0400 Subject: [PATCH 2/4] chore: Update route parameter name in getIdentityByID and patchUpdateIdentity routes The route parameter name "id" was updated in the getIdentityByID and patchUpdateIdentity routes to improve clarity and consistency. Signed-off-by: dwertent --- internal/apiserver/route_get_identity_by_id.go | 2 +- internal/apiserver/route_patch_update_identity.go | 7 +++---- internal/coremsgs/en_api_translations.go | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/apiserver/route_get_identity_by_id.go b/internal/apiserver/route_get_identity_by_id.go index 794cf98bf..1ce7b2e45 100644 --- a/internal/apiserver/route_get_identity_by_id.go +++ b/internal/apiserver/route_get_identity_by_id.go @@ -32,7 +32,7 @@ var getIdentityByID = &ffapi.Route{ Path: "identities/{id:.+}", Method: http.MethodGet, PathParams: []*ffapi.PathParam{ - {Name: "id", Example: "id", Description: coremsgs.APIParamsIdentityID}, + {Name: "id", Example: "id", Description: coremsgs.APIParamsIdentityIDs}, }, QueryParams: []*ffapi.QueryParam{ {Name: "fetchverifiers", Example: "true", Description: coremsgs.APIParamsFetchVerifiers, IsBool: true}, diff --git a/internal/apiserver/route_patch_update_identity.go b/internal/apiserver/route_patch_update_identity.go index 46ec71e84..4670eb453 100644 --- a/internal/apiserver/route_patch_update_identity.go +++ b/internal/apiserver/route_patch_update_identity.go @@ -27,10 +27,10 @@ import ( var patchUpdateIdentity = &ffapi.Route{ Name: "patchUpdateIdentity", - Path: "identities/{iid}", + Path: "identities/{id}", Method: http.MethodPatch, PathParams: []*ffapi.PathParam{ - {Name: "iid", Description: coremsgs.APIParamsIdentityID}, + {Name: "id", Description: coremsgs.APIParamsIdentityID}, }, QueryParams: []*ffapi.QueryParam{ {Name: "confirm", Description: coremsgs.APIConfirmMsgQueryParam, IsBool: true}, @@ -43,8 +43,7 @@ var patchUpdateIdentity = &ffapi.Route{ CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { waitConfirm := strings.EqualFold(r.QP["confirm"], "true") r.SuccessStatus = syncRetcode(waitConfirm) - org, err := cr.or.NetworkMap().UpdateIdentity(cr.ctx, r.PP["iid"], r.Input.(*core.IdentityUpdateDTO), waitConfirm) - return org, err + return cr.or.NetworkMap().UpdateIdentity(cr.ctx, r.PP["id"], r.Input.(*core.IdentityUpdateDTO), waitConfirm) }, }, } diff --git a/internal/coremsgs/en_api_translations.go b/internal/coremsgs/en_api_translations.go index db50680ca..3684f6005 100644 --- a/internal/coremsgs/en_api_translations.go +++ b/internal/coremsgs/en_api_translations.go @@ -47,7 +47,8 @@ var ( APIParamsFetchReference = ffm("api.params.fetchReference", "When set, the API will return the record that this item references in its 'reference' field") APIParamsGroupHash = ffm("api.params.groupID", "The hash of the group") APIParamsFetchVerifiers = ffm("api.params.fetchVerifiers", "When set, the API will return the verifier for this identity") - APIParamsIdentityID = ffm("api.params.identityID", "The identity ID, which is a UUID generated by FireFly or the identity DID") + APIParamsIdentityID = ffm("api.params.identityID", "The identity ID, which is a UUID generated by FireFly") + APIParamsIdentityIDs = ffm("api.params.identityIDs", "The identity ID, which is a UUID generated by FireFly or the identity DID") APIParamsMessageID = ffm("api.params.messageID", "The message ID") APIParamsDID = ffm("api.params.DID", "The identity DID") APIParamsNodeNameOrID = ffm("api.params.nodeNameOrID", "The name or ID of the node") From ab093be333fb123d7cbae4691fcb5facdb4f39e4 Mon Sep 17 00:00:00 2001 From: dwertent Date: Thu, 15 Aug 2024 11:00:59 -0400 Subject: [PATCH 3/4] wip: reverting linter fixes Signed-off-by: dwertent --- internal/apiserver/server.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/apiserver/server.go b/internal/apiserver/server.go index 04e5beda1..ca1671a05 100644 --- a/internal/apiserver/server.go +++ b/internal/apiserver/server.go @@ -288,7 +288,7 @@ func (as *apiServer) nsOpenAPIHandlerFactory(req *http.Request, publicURL string } } -func (as *apiServer) namespacedSwaggerHandler(hf *ffapi.HandlerFactory, r *mux.Router, publicURL, relativePath string) { +func (as *apiServer) namespacedSwaggerHandler(hf *ffapi.HandlerFactory, r *mux.Router, publicURL, relativePath string, format ffapi.OpenAPIFormat) { r.HandleFunc(`/api/v1/namespaces/{ns}`+relativePath, hf.APIWrapper(func(res http.ResponseWriter, req *http.Request) (status int, err error) { return as.nsOpenAPIHandlerFactory(req, publicURL).OpenAPIHandler("", ffapi.OpenAPIFormatJSON, nsRoutes)(res, req) })) @@ -300,7 +300,7 @@ func (as *apiServer) namespacedSwaggerUI(hf *ffapi.HandlerFactory, r *mux.Router })) } -func (as *apiServer) namespacedContractSwaggerGenerator(hf *ffapi.HandlerFactory, r *mux.Router, mgr namespace.Manager, relativePath string, format ffapi.OpenAPIFormat) { +func (as *apiServer) namespacedContractSwaggerGenerator(hf *ffapi.HandlerFactory, r *mux.Router, mgr namespace.Manager, publicURL, relativePath string, format ffapi.OpenAPIFormat) { r.HandleFunc(`/api/v1/namespaces/{ns}/apis/{apiName}`+relativePath, hf.APIWrapper(func(res http.ResponseWriter, req *http.Request) (status int, err error) { vars := mux.Vars(req) or, err := mgr.Orchestrator(req.Context(), vars["ns"], false) @@ -372,16 +372,16 @@ func (as *apiServer) createMuxRouter(ctx context.Context, mgr namespace.Manager) r.HandleFunc(`/api/openapi.yaml`, hf.APIWrapper(oaf.OpenAPIHandler(`/api/v1`, ffapi.OpenAPIFormatYAML, routes))) r.HandleFunc(`/api`, hf.APIWrapper(oaf.SwaggerUIHandler(`/api/openapi.yaml`))) // Namespace relative APIs - as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/swagger.json`) - as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/openapi.json`) - as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/swagger.yaml`) - as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/openapi.yaml`) + as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/swagger.json`, ffapi.OpenAPIFormatJSON) + as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/openapi.json`, ffapi.OpenAPIFormatJSON) + as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/swagger.yaml`, ffapi.OpenAPIFormatYAML) + as.namespacedSwaggerHandler(hf, r, as.apiPublicURL, `/api/openapi.yaml`, ffapi.OpenAPIFormatYAML) as.namespacedSwaggerUI(hf, r, as.apiPublicURL, `/api`) // Dynamic swagger for namespaced contract APIs - as.namespacedContractSwaggerGenerator(hf, r, mgr, `/api/swagger.json`, ffapi.OpenAPIFormatJSON) - as.namespacedContractSwaggerGenerator(hf, r, mgr, `/api/openapi.json`, ffapi.OpenAPIFormatJSON) - as.namespacedContractSwaggerGenerator(hf, r, mgr, `/api/swagger.yaml`, ffapi.OpenAPIFormatYAML) - as.namespacedContractSwaggerGenerator(hf, r, mgr, `/api/openapi.yaml`, ffapi.OpenAPIFormatYAML) + as.namespacedContractSwaggerGenerator(hf, r, mgr, as.apiPublicURL, `/api/swagger.json`, ffapi.OpenAPIFormatJSON) + as.namespacedContractSwaggerGenerator(hf, r, mgr, as.apiPublicURL, `/api/openapi.json`, ffapi.OpenAPIFormatJSON) + as.namespacedContractSwaggerGenerator(hf, r, mgr, as.apiPublicURL, `/api/swagger.yaml`, ffapi.OpenAPIFormatYAML) + as.namespacedContractSwaggerGenerator(hf, r, mgr, as.apiPublicURL, `/api/openapi.yaml`, ffapi.OpenAPIFormatYAML) as.namespacedContractSwaggerUI(hf, r, as.apiPublicURL, `/api`) r.HandleFunc(`/favicon{any:.*}.png`, favIcons) From 0ebc1d8ac291f6d7615c55df6807fdef4ee93e98 Mon Sep 17 00:00:00 2001 From: dwertent Date: Thu, 15 Aug 2024 11:01:33 -0400 Subject: [PATCH 4/4] wip: renaming the api function Signed-off-by: dwertent --- internal/apiserver/route_get_identity_by_id.go | 8 ++++---- internal/apiserver/routes.go | 2 +- internal/coremsgs/en_api_translations.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/apiserver/route_get_identity_by_id.go b/internal/apiserver/route_get_identity_by_id.go index 1ce7b2e45..d5c3fe9ae 100644 --- a/internal/apiserver/route_get_identity_by_id.go +++ b/internal/apiserver/route_get_identity_by_id.go @@ -27,9 +27,9 @@ import ( "github.com/hyperledger/firefly/pkg/core" ) -var getIdentityByID = &ffapi.Route{ - Name: "getIdentityByID", - Path: "identities/{id:.+}", +var getIdentityByIDOrDID = &ffapi.Route{ + Name: "getIdentityByIDOrDID", + Path: "identities/{id:.+}", // Allow any character in the ID (including slashes), othrwise the DID will be split into multiple path segments Method: http.MethodGet, PathParams: []*ffapi.PathParam{ {Name: "id", Example: "id", Description: coremsgs.APIParamsIdentityIDs}, @@ -37,7 +37,7 @@ var getIdentityByID = &ffapi.Route{ QueryParams: []*ffapi.QueryParam{ {Name: "fetchverifiers", Example: "true", Description: coremsgs.APIParamsFetchVerifiers, IsBool: true}, }, - Description: coremsgs.APIEndpointsGetIdentityByID, + Description: coremsgs.APIEndpointsGetIdentityByIDOrDID, JSONInputValue: nil, JSONOutputValue: func() interface{} { return &core.Identity{} }, JSONOutputCodes: []int{http.StatusOK}, diff --git a/internal/apiserver/routes.go b/internal/apiserver/routes.go index fc04d120a..98eda5eee 100644 --- a/internal/apiserver/routes.go +++ b/internal/apiserver/routes.go @@ -86,7 +86,7 @@ var routes = append( getGroupByHash, getGroups, getIdentities, - getIdentityByID, + getIdentityByIDOrDID, getIdentityDID, getIdentityVerifiers, getMsgByID, diff --git a/internal/coremsgs/en_api_translations.go b/internal/coremsgs/en_api_translations.go index 3684f6005..255a4012b 100644 --- a/internal/coremsgs/en_api_translations.go +++ b/internal/coremsgs/en_api_translations.go @@ -108,7 +108,7 @@ var ( APIEndpointsGetGroupByHash = ffm("api.endpoints.getGroupByHash", "Gets a group by its ID (hash)") APIEndpointsGetGroups = ffm("api.endpoints.getGroups", "Gets a list of groups") APIEndpointsGetIdentities = ffm("api.endpoints.getIdentities", "Gets a list of all identities that have been registered in the namespace") - APIEndpointsGetIdentityByID = ffm("api.endpoints.getIdentityByID", "Gets an identity by its ID (UUID/DID)") + APIEndpointsGetIdentityByIDOrDID = ffm("api.endpoints.getIdentityByIDOrDID", "Gets an identity by its ID or DID") APIEndpointsGetIdentityDID = ffm("api.endpoints.getIdentityDID", "Gets the DID for an identity based on its ID") APIEndpointsGetIdentityVerifiers = ffm("api.endpoints.getIdentityVerifiers", "Gets the verifiers for an identity") APIEndpointsGetMsgByID = ffm("api.endpoints.getMsgByID", "Gets a message by its ID")