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
162 changes: 162 additions & 0 deletions docs/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,168 @@ paths:
description: Success
default:
description: ""
/namespaces/{ns}/groups:
get:
description: 'TODO: Description'
operationId: getGroups
parameters:
- description: 'TODO: Description'
in: path
name: ns
required: true
schema:
example: default
type: string
- description: Server-side request timeout (millseconds, or set a custom suffix
like 10s)
in: header
name: Request-Timeout
schema:
default: 120s
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: created
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: description
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: hash
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: ledger
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: message
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: namespace
schema:
type: string
- description: Sort field. For multi-field sort use comma separated values (or
multiple query values) with '-' prefix for descending
in: query
name: sort
schema:
type: string
- description: Ascending sort order (overrides all fields in a multi-field sort)
in: query
name: ascending
schema:
type: string
- description: Descending sort order (overrides all fields in a multi-field
sort)
in: query
name: descending
schema:
type: string
- description: 'The number of records to skip (max: 1,000). Unsuitable for bulk
operations'
in: query
name: skip
schema:
type: string
- description: 'The maximum number of records to return (max: 1,000)'
in: query
name: limit
schema:
example: "25"
type: string
- description: Return a total count as well as items (adds extra database processing)
in: query
name: count
schema:
type: string
responses:
"200":
content:
application/json:
schema:
items:
properties:
created: {}
hash: {}
ledger: {}
members:
items:
properties:
identity:
type: string
node: {}
type: object
type: array
message: {}
name:
type: string
namespace:
type: string
type: object
type: array
description: Success
default:
description: ""
/namespaces/{ns}/groups/{groupid}:
get:
description: 'TODO: Description'
operationId: getGroupByHash
parameters:
- description: 'TODO: Description'
in: path
name: ns
required: true
schema:
example: default
type: string
- description: 'TODO: Description'
in: path
name: groupid
required: true
schema:
type: string
- description: Server-side request timeout (millseconds, or set a custom suffix
like 10s)
in: header
name: Request-Timeout
schema:
default: 120s
type: string
responses:
"200":
content:
application/json:
schema:
properties:
created: {}
hash: {}
ledger: {}
members:
items:
properties:
identity:
type: string
node: {}
type: object
type: array
message: {}
name:
type: string
namespace:
type: string
type: object
description: Success
default:
description: ""
/namespaces/{ns}/messages:
get:
description: 'TODO: Description'
Expand Down
46 changes: 46 additions & 0 deletions internal/apiserver/route_get_group_by_id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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"

"github.com/hyperledger/firefly/internal/config"
"github.com/hyperledger/firefly/internal/i18n"
"github.com/hyperledger/firefly/internal/oapispec"
"github.com/hyperledger/firefly/pkg/fftypes"
)

var getGroupByHash = &oapispec.Route{
Name: "getGroupByHash",
Path: "namespaces/{ns}/groups/{groupid}",
Method: http.MethodGet,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
{Name: "groupid", Description: i18n.MsgTBD},
},
QueryParams: nil,
FilterFactory: nil,
Description: i18n.MsgTBD,
JSONInputValue: nil,
JSONOutputValue: func() interface{} { return &fftypes.Group{} },
JSONOutputCodes: []int{http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
output, err = r.Or.PrivateMessaging().GetGroupByID(r.Ctx, r.PP["groupid"])
return output, err
},
}
42 changes: 42 additions & 0 deletions internal/apiserver/route_get_group_by_id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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/privatemessagingmocks"
"github.com/hyperledger/firefly/pkg/fftypes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestGetGroupByHash(t *testing.T) {
o, r := newTestAPIServer()
req := httptest.NewRequest("GET", "/api/v1/namespaces/mynamespace/groups/abcd12345", nil)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mpm := &privatemessagingmocks.Manager{}
o.On("PrivateMessaging").Return(mpm)
mpm.On("GetGroupByID", mock.Anything, "abcd12345").
Return(&fftypes.Group{}, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 200, res.Result().StatusCode)
}
45 changes: 45 additions & 0 deletions internal/apiserver/route_get_groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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"

"github.com/hyperledger/firefly/internal/config"
"github.com/hyperledger/firefly/internal/i18n"
"github.com/hyperledger/firefly/internal/oapispec"
"github.com/hyperledger/firefly/pkg/database"
"github.com/hyperledger/firefly/pkg/fftypes"
)

var getGroups = &oapispec.Route{
Name: "getGroups",
Path: "namespaces/{ns}/groups",
Method: http.MethodGet,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
},
QueryParams: nil,
FilterFactory: database.GroupQueryFactory,
Description: i18n.MsgTBD,
JSONInputValue: nil,
JSONOutputValue: func() interface{} { return []*fftypes.Group{} },
JSONOutputCodes: []int{http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
return filterResult(r.Or.PrivateMessaging().GetGroupsNS(r.Ctx, r.PP["ns"], r.Filter))
},
}
42 changes: 42 additions & 0 deletions internal/apiserver/route_get_groups_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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/privatemessagingmocks"
"github.com/hyperledger/firefly/pkg/fftypes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestGetGroups(t *testing.T) {
o, r := newTestAPIServer()
req := httptest.NewRequest("GET", "/api/v1/namespaces/mynamespace/groups", nil)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mpm := &privatemessagingmocks.Manager{}
o.On("PrivateMessaging").Return(mpm)
mpm.On("GetGroupsNS", mock.Anything, "mynamespace", mock.Anything).
Return([]*fftypes.Group{}, nil, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 200, res.Result().StatusCode)
}
2 changes: 2 additions & 0 deletions internal/apiserver/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var routes = []*oapispec.Route{
getDataMsgs,
getEventByID,
getEvents,
getGroups,
getGroupByHash,
getMsgByID,
getMsgData,
getMsgEvents,
Expand Down
4 changes: 2 additions & 2 deletions internal/definitions/definition_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func (dh *definitionHandlers) GetGroupByID(ctx context.Context, id string) (*fft
return dh.messaging.GetGroupByID(ctx, id)
}

func (dh *definitionHandlers) GetGroups(ctx context.Context, filter database.AndFilter) ([]*fftypes.Group, *database.FilterResult, error) {
return dh.messaging.GetGroups(ctx, filter)
func (dh *definitionHandlers) GetGroupsNS(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.Group, *database.FilterResult, error) {
return dh.messaging.GetGroupsNS(ctx, ns, filter)
}

func (dh *definitionHandlers) ResolveInitGroup(ctx context.Context, msg *fftypes.Message) (*fftypes.Group, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/definitions/definition_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ func TestPrivateMessagingPassthroughs(t *testing.T) {
dh := newTestDefinitionHandlers(t)
mpm := dh.messaging.(*privatemessagingmocks.Manager)
mpm.On("GetGroupByID", ctx, mock.Anything).Return(nil, nil)
mpm.On("GetGroups", ctx, mock.Anything).Return(nil, nil, nil)
mpm.On("GetGroupsNS", ctx, "ns1", mock.Anything).Return(nil, nil, nil)
mpm.On("ResolveInitGroup", ctx, mock.Anything).Return(nil, nil)
mpm.On("EnsureLocalGroup", ctx, mock.Anything).Return(false, nil)

_, _ = dh.GetGroupByID(ctx, fftypes.NewUUID().String())
_, _, _ = dh.GetGroups(ctx, nil)
_, _, _ = dh.GetGroupsNS(ctx, "ns1", nil)
_, _ = dh.ResolveInitGroup(ctx, nil)
_, _ = dh.EnsureLocalGroup(ctx, nil)

Expand Down
Loading