Skip to content

Commit 611f2a6

Browse files
authored
Merge pull request #363 from kaleido-io/pin-only
Fix send-to-self for private messages, and add group query URLs
2 parents 0eae821 + 8775dcd commit 611f2a6

File tree

21 files changed

+484
-67
lines changed

21 files changed

+484
-67
lines changed

docs/swagger/swagger.yaml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,168 @@ paths:
21442144
description: Success
21452145
default:
21462146
description: ""
2147+
/namespaces/{ns}/groups:
2148+
get:
2149+
description: 'TODO: Description'
2150+
operationId: getGroups
2151+
parameters:
2152+
- description: 'TODO: Description'
2153+
in: path
2154+
name: ns
2155+
required: true
2156+
schema:
2157+
example: default
2158+
type: string
2159+
- description: Server-side request timeout (millseconds, or set a custom suffix
2160+
like 10s)
2161+
in: header
2162+
name: Request-Timeout
2163+
schema:
2164+
default: 120s
2165+
type: string
2166+
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
2167+
in: query
2168+
name: created
2169+
schema:
2170+
type: string
2171+
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
2172+
in: query
2173+
name: description
2174+
schema:
2175+
type: string
2176+
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
2177+
in: query
2178+
name: hash
2179+
schema:
2180+
type: string
2181+
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
2182+
in: query
2183+
name: ledger
2184+
schema:
2185+
type: string
2186+
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
2187+
in: query
2188+
name: message
2189+
schema:
2190+
type: string
2191+
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
2192+
in: query
2193+
name: namespace
2194+
schema:
2195+
type: string
2196+
- description: Sort field. For multi-field sort use comma separated values (or
2197+
multiple query values) with '-' prefix for descending
2198+
in: query
2199+
name: sort
2200+
schema:
2201+
type: string
2202+
- description: Ascending sort order (overrides all fields in a multi-field sort)
2203+
in: query
2204+
name: ascending
2205+
schema:
2206+
type: string
2207+
- description: Descending sort order (overrides all fields in a multi-field
2208+
sort)
2209+
in: query
2210+
name: descending
2211+
schema:
2212+
type: string
2213+
- description: 'The number of records to skip (max: 1,000). Unsuitable for bulk
2214+
operations'
2215+
in: query
2216+
name: skip
2217+
schema:
2218+
type: string
2219+
- description: 'The maximum number of records to return (max: 1,000)'
2220+
in: query
2221+
name: limit
2222+
schema:
2223+
example: "25"
2224+
type: string
2225+
- description: Return a total count as well as items (adds extra database processing)
2226+
in: query
2227+
name: count
2228+
schema:
2229+
type: string
2230+
responses:
2231+
"200":
2232+
content:
2233+
application/json:
2234+
schema:
2235+
items:
2236+
properties:
2237+
created: {}
2238+
hash: {}
2239+
ledger: {}
2240+
members:
2241+
items:
2242+
properties:
2243+
identity:
2244+
type: string
2245+
node: {}
2246+
type: object
2247+
type: array
2248+
message: {}
2249+
name:
2250+
type: string
2251+
namespace:
2252+
type: string
2253+
type: object
2254+
type: array
2255+
description: Success
2256+
default:
2257+
description: ""
2258+
/namespaces/{ns}/groups/{groupid}:
2259+
get:
2260+
description: 'TODO: Description'
2261+
operationId: getGroupByHash
2262+
parameters:
2263+
- description: 'TODO: Description'
2264+
in: path
2265+
name: ns
2266+
required: true
2267+
schema:
2268+
example: default
2269+
type: string
2270+
- description: 'TODO: Description'
2271+
in: path
2272+
name: groupid
2273+
required: true
2274+
schema:
2275+
type: string
2276+
- description: Server-side request timeout (millseconds, or set a custom suffix
2277+
like 10s)
2278+
in: header
2279+
name: Request-Timeout
2280+
schema:
2281+
default: 120s
2282+
type: string
2283+
responses:
2284+
"200":
2285+
content:
2286+
application/json:
2287+
schema:
2288+
properties:
2289+
created: {}
2290+
hash: {}
2291+
ledger: {}
2292+
members:
2293+
items:
2294+
properties:
2295+
identity:
2296+
type: string
2297+
node: {}
2298+
type: object
2299+
type: array
2300+
message: {}
2301+
name:
2302+
type: string
2303+
namespace:
2304+
type: string
2305+
type: object
2306+
description: Success
2307+
default:
2308+
description: ""
21472309
/namespaces/{ns}/messages:
21482310
get:
21492311
description: 'TODO: Description'
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright © 2021 Kaleido, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package apiserver
18+
19+
import (
20+
"net/http"
21+
22+
"github.com/hyperledger/firefly/internal/config"
23+
"github.com/hyperledger/firefly/internal/i18n"
24+
"github.com/hyperledger/firefly/internal/oapispec"
25+
"github.com/hyperledger/firefly/pkg/fftypes"
26+
)
27+
28+
var getGroupByHash = &oapispec.Route{
29+
Name: "getGroupByHash",
30+
Path: "namespaces/{ns}/groups/{groupid}",
31+
Method: http.MethodGet,
32+
PathParams: []*oapispec.PathParam{
33+
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
34+
{Name: "groupid", Description: i18n.MsgTBD},
35+
},
36+
QueryParams: nil,
37+
FilterFactory: nil,
38+
Description: i18n.MsgTBD,
39+
JSONInputValue: nil,
40+
JSONOutputValue: func() interface{} { return &fftypes.Group{} },
41+
JSONOutputCodes: []int{http.StatusOK},
42+
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
43+
output, err = r.Or.PrivateMessaging().GetGroupByID(r.Ctx, r.PP["groupid"])
44+
return output, err
45+
},
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright © 2021 Kaleido, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package apiserver
18+
19+
import (
20+
"net/http/httptest"
21+
"testing"
22+
23+
"github.com/hyperledger/firefly/mocks/privatemessagingmocks"
24+
"github.com/hyperledger/firefly/pkg/fftypes"
25+
"github.com/stretchr/testify/assert"
26+
"github.com/stretchr/testify/mock"
27+
)
28+
29+
func TestGetGroupByHash(t *testing.T) {
30+
o, r := newTestAPIServer()
31+
req := httptest.NewRequest("GET", "/api/v1/namespaces/mynamespace/groups/abcd12345", nil)
32+
req.Header.Set("Content-Type", "application/json; charset=utf-8")
33+
res := httptest.NewRecorder()
34+
35+
mpm := &privatemessagingmocks.Manager{}
36+
o.On("PrivateMessaging").Return(mpm)
37+
mpm.On("GetGroupByID", mock.Anything, "abcd12345").
38+
Return(&fftypes.Group{}, nil)
39+
r.ServeHTTP(res, req)
40+
41+
assert.Equal(t, 200, res.Result().StatusCode)
42+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright © 2021 Kaleido, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package apiserver
18+
19+
import (
20+
"net/http"
21+
22+
"github.com/hyperledger/firefly/internal/config"
23+
"github.com/hyperledger/firefly/internal/i18n"
24+
"github.com/hyperledger/firefly/internal/oapispec"
25+
"github.com/hyperledger/firefly/pkg/database"
26+
"github.com/hyperledger/firefly/pkg/fftypes"
27+
)
28+
29+
var getGroups = &oapispec.Route{
30+
Name: "getGroups",
31+
Path: "namespaces/{ns}/groups",
32+
Method: http.MethodGet,
33+
PathParams: []*oapispec.PathParam{
34+
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
35+
},
36+
QueryParams: nil,
37+
FilterFactory: database.GroupQueryFactory,
38+
Description: i18n.MsgTBD,
39+
JSONInputValue: nil,
40+
JSONOutputValue: func() interface{} { return []*fftypes.Group{} },
41+
JSONOutputCodes: []int{http.StatusOK},
42+
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
43+
return filterResult(r.Or.PrivateMessaging().GetGroupsNS(r.Ctx, r.PP["ns"], r.Filter))
44+
},
45+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright © 2021 Kaleido, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package apiserver
18+
19+
import (
20+
"net/http/httptest"
21+
"testing"
22+
23+
"github.com/hyperledger/firefly/mocks/privatemessagingmocks"
24+
"github.com/hyperledger/firefly/pkg/fftypes"
25+
"github.com/stretchr/testify/assert"
26+
"github.com/stretchr/testify/mock"
27+
)
28+
29+
func TestGetGroups(t *testing.T) {
30+
o, r := newTestAPIServer()
31+
req := httptest.NewRequest("GET", "/api/v1/namespaces/mynamespace/groups", nil)
32+
req.Header.Set("Content-Type", "application/json; charset=utf-8")
33+
res := httptest.NewRecorder()
34+
35+
mpm := &privatemessagingmocks.Manager{}
36+
o.On("PrivateMessaging").Return(mpm)
37+
mpm.On("GetGroupsNS", mock.Anything, "mynamespace", mock.Anything).
38+
Return([]*fftypes.Group{}, nil, nil)
39+
r.ServeHTTP(res, req)
40+
41+
assert.Equal(t, 200, res.Result().StatusCode)
42+
}

internal/apiserver/routes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ var routes = []*oapispec.Route{
5656
getDataMsgs,
5757
getEventByID,
5858
getEvents,
59+
getGroups,
60+
getGroupByHash,
5961
getMsgByID,
6062
getMsgData,
6163
getMsgEvents,

internal/definitions/definition_handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ func (dh *definitionHandlers) GetGroupByID(ctx context.Context, id string) (*fft
7474
return dh.messaging.GetGroupByID(ctx, id)
7575
}
7676

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

8181
func (dh *definitionHandlers) ResolveInitGroup(ctx context.Context, msg *fftypes.Message) (*fftypes.Group, error) {

internal/definitions/definition_handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ func TestPrivateMessagingPassthroughs(t *testing.T) {
7878
dh := newTestDefinitionHandlers(t)
7979
mpm := dh.messaging.(*privatemessagingmocks.Manager)
8080
mpm.On("GetGroupByID", ctx, mock.Anything).Return(nil, nil)
81-
mpm.On("GetGroups", ctx, mock.Anything).Return(nil, nil, nil)
81+
mpm.On("GetGroupsNS", ctx, "ns1", mock.Anything).Return(nil, nil, nil)
8282
mpm.On("ResolveInitGroup", ctx, mock.Anything).Return(nil, nil)
8383
mpm.On("EnsureLocalGroup", ctx, mock.Anything).Return(false, nil)
8484

8585
_, _ = dh.GetGroupByID(ctx, fftypes.NewUUID().String())
86-
_, _, _ = dh.GetGroups(ctx, nil)
86+
_, _, _ = dh.GetGroupsNS(ctx, "ns1", nil)
8787
_, _ = dh.ResolveInitGroup(ctx, nil)
8888
_, _ = dh.EnsureLocalGroup(ctx, nil)
8989

0 commit comments

Comments
 (0)