-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into listen
- Loading branch information
Showing
37 changed files
with
2,095 additions
and
929 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,45 @@ | ||
// 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" | ||
|
||
"github.com/hyperledger/firefly/internal/coreconfig" | ||
"github.com/hyperledger/firefly/internal/coremsgs" | ||
"github.com/hyperledger/firefly/internal/oapispec" | ||
"github.com/hyperledger/firefly/pkg/fftypes" | ||
) | ||
|
||
var getContractAPIInterface = &oapispec.Route{ | ||
Name: "getContractAPIInterface", | ||
Path: "namespaces/{ns}/apis/{apiName}/interface", | ||
Method: http.MethodGet, | ||
PathParams: []*oapispec.PathParam{ | ||
{Name: "ns", ExampleFromConf: coreconfig.NamespacesDefault, Description: coremsgs.APIMessageTBD}, | ||
{Name: "apiName", Description: coremsgs.APIMessageTBD}, | ||
}, | ||
QueryParams: nil, | ||
FilterFactory: nil, | ||
Description: coremsgs.APIMessageTBD, | ||
JSONInputValue: nil, | ||
JSONOutputValue: func() interface{} { return &fftypes.FFI{} }, | ||
JSONOutputCodes: []int{http.StatusOK}, | ||
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) { | ||
return getOr(r.Ctx).Contracts().GetContractAPIInterface(r.Ctx, r.PP["ns"], r.PP["apiName"]) | ||
}, | ||
} |
47 changes: 47 additions & 0 deletions
47
internal/apiserver/route_get_contract_api_interface_test.go
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,47 @@ | ||
// 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 ( | ||
"bytes" | ||
"encoding/json" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly/mocks/contractmocks" | ||
"github.com/hyperledger/firefly/pkg/fftypes" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func TestGetContractAPIInterface(t *testing.T) { | ||
o, r := newTestAPIServer() | ||
mcm := &contractmocks.Manager{} | ||
o.On("Contracts").Return(mcm) | ||
input := fftypes.Datatype{} | ||
var buf bytes.Buffer | ||
json.NewEncoder(&buf).Encode(&input) | ||
req := httptest.NewRequest("GET", "/api/v1/namespaces/ns1/apis/banana/interface", &buf) | ||
req.Header.Set("Content-Type", "application/json; charset=utf-8") | ||
res := httptest.NewRecorder() | ||
|
||
mcm.On("GetContractAPIInterface", mock.Anything, "ns1", "banana"). | ||
Return(&fftypes.FFI{}, nil) | ||
r.ServeHTTP(res, req) | ||
|
||
assert.Equal(t, 200, 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
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,41 @@ | ||
// 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" | ||
|
||
"github.com/hyperledger/firefly/internal/coremsgs" | ||
"github.com/hyperledger/firefly/internal/oapispec" | ||
"github.com/hyperledger/firefly/pkg/fftypes" | ||
) | ||
|
||
var getStatusWebSockets = &oapispec.Route{ | ||
Name: "getStatusWebSockets", | ||
Path: "status/websockets", | ||
Method: http.MethodGet, | ||
PathParams: nil, | ||
QueryParams: nil, | ||
FilterFactory: nil, | ||
Description: coremsgs.APIMessageTBD, | ||
JSONInputValue: nil, | ||
JSONOutputValue: func() interface{} { return &fftypes.WebSocketStatus{} }, | ||
JSONOutputCodes: []int{http.StatusOK}, | ||
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) { | ||
return getOr(r.Ctx).Events().GetWebSocketStatus(), nil | ||
}, | ||
} |
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,40 @@ | ||
// 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/eventmocks" | ||
"github.com/hyperledger/firefly/pkg/fftypes" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetStatusWebSockets(t *testing.T) { | ||
o, r := newTestAPIServer() | ||
mem := &eventmocks.EventManager{} | ||
o.On("Events").Return(mem) | ||
req := httptest.NewRequest("GET", "/api/v1/status/websockets", nil) | ||
req.Header.Set("Content-Type", "application/json; charset=utf-8") | ||
res := httptest.NewRecorder() | ||
|
||
mem.On("GetWebSocketStatus").Return(&fftypes.WebSocketStatus{}) | ||
r.ServeHTTP(res, req) | ||
|
||
assert.Equal(t, 200, 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
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.