Skip to content

Commit 00f16ec

Browse files
Merge pull request #65 from kaleido-io/api-spec
API spec
2 parents fe6e97a + 51991a4 commit 00f16ec

File tree

8 files changed

+584
-1
lines changed

8 files changed

+584
-1
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ require (
2727
github.com/otiai10/copy v1.6.0
2828
github.com/pkg/errors v0.9.1
2929
github.com/prometheus/procfs v0.6.0 // indirect
30+
github.com/rs/cors v1.8.2
3031
github.com/sirupsen/logrus v1.8.1
3132
github.com/spf13/cobra v1.2.1
3233
github.com/spf13/viper v1.9.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
600600
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
601601
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
602602
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
603+
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
604+
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
603605
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
604606
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
605607
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=

images/logo.png

16.3 KB
Loading

internal/messages/messages.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ type LedgerQueryResult struct {
135135
// TransactionReceipt is sent when a transaction has been successfully mined
136136
type TransactionReceipt struct {
137137
ReplyCommon
138+
BlockNumber uint64 `json:"blockNumber"`
139+
SignerMSP string `json:"signerMSP"`
140+
Signer string `json:"signer"`
141+
TransactionID string `json:"transactionID"`
142+
Status string `json:"status"`
138143
}
139144

140145
type ErrorReply struct {

internal/rest/router.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ import (
3030
"github.com/hyperledger/firefly-fabconnect/internal/rest/identity"
3131
restsync "github.com/hyperledger/firefly-fabconnect/internal/rest/sync"
3232
restutil "github.com/hyperledger/firefly-fabconnect/internal/rest/utils"
33+
"github.com/hyperledger/firefly-fabconnect/internal/utils"
3334
"github.com/hyperledger/firefly-fabconnect/internal/ws"
3435
"github.com/julienschmidt/httprouter"
3536

37+
"github.com/rs/cors"
3638
log "github.com/sirupsen/logrus"
3739
)
3840

@@ -50,17 +52,22 @@ type router struct {
5052
}
5153

5254
func newRouter(syncDispatcher restsync.SyncDispatcher, asyncDispatcher restasync.AsyncDispatcher, idClient identity.IdentityClient, sm events.SubscriptionManager, ws ws.WebSocketServer) *router {
55+
r := httprouter.New()
56+
cors.Default().Handler(r)
5357
return &router{
5458
syncDispatcher: syncDispatcher,
5559
asyncDispatcher: asyncDispatcher,
5660
identityClient: idClient,
5761
subManager: sm,
5862
ws: ws,
59-
httpRouter: httprouter.New(),
63+
httpRouter: r,
6064
}
6165
}
6266

6367
func (r *router) addRoutes() {
68+
r.httpRouter.GET("/api", r.serveSwaggerUI)
69+
r.httpRouter.GET("/spec.yaml", r.serveSwagger)
70+
6471
r.httpRouter.POST("/identities", r.registerUser)
6572
r.httpRouter.POST("/identities/:username/enroll", r.enrollUser)
6673
r.httpRouter.GET("/identities", r.listUsers)
@@ -120,6 +127,18 @@ func (r *router) statusHandler(res http.ResponseWriter, req *http.Request, _ htt
120127
_, _ = res.Write(reply)
121128
}
122129

130+
func (r *router) serveSwagger(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
131+
log.Infof("--> %s %s", req.Method, req.URL)
132+
fs := http.FileServer(http.Dir("./openapi"))
133+
fs.ServeHTTP(res, req)
134+
}
135+
136+
func (r *router) serveSwaggerUI(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
137+
log.Infof("--> %s %s", req.Method, req.URL)
138+
res.Header().Add("Content-Type", "text/html")
139+
_, _ = res.Write(utils.SwaggerUIHTML(req.Context()))
140+
}
141+
123142
func (r *router) queryChaincode(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
124143
log.Infof("--> %s %s", req.Method, req.URL)
125144

internal/tx/txprocessor.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ func (p *txProcessor) waitForCompletion(inflight *inflightTx, initialWaitDelay t
241241
reply.Headers.MsgType = messages.MsgTypeTransactionFailure
242242
}
243243

244+
reply.Status = receipt.Status.String()
245+
reply.BlockNumber = receipt.BlockNumber
246+
reply.Signer = receipt.Signer
247+
reply.SignerMSP = receipt.SignerMSP
248+
reply.TransactionID = receipt.TransactionID
249+
244250
inflight.txContext.Reply(&reply)
245251
}
246252

internal/utils/swagger-ui.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 utils
18+
19+
import (
20+
"context"
21+
)
22+
23+
var swaggerUIHTML = `<!DOCTYPE html>
24+
<html lang="en">
25+
<head>
26+
<meta charset="UTF-8">
27+
<title>Swagger UI</title>
28+
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32" />
29+
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16" />
30+
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@3/swagger-ui.css">
31+
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
32+
</head>
33+
34+
<body>
35+
<div id="swagger-ui"></div>
36+
37+
<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js" charset="UTF-8"></script>
38+
<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js" charset="UTF-8"></script>
39+
<script>
40+
window.onload = function() {
41+
// Begin Swagger UI call region
42+
const ui = SwaggerUIBundle({
43+
url: "/spec.yaml",
44+
dom_id: '#swagger-ui',
45+
deepLinking: true,
46+
presets: [
47+
SwaggerUIBundle.presets.apis,
48+
SwaggerUIStandalonePreset
49+
],
50+
plugins: [
51+
SwaggerUIBundle.plugins.DownloadUrl
52+
],
53+
layout: "StandaloneLayout"
54+
});
55+
// End Swagger UI call region
56+
57+
window.ui = ui;
58+
};
59+
</script>
60+
</body>
61+
</html>
62+
`
63+
64+
func SwaggerUIHTML(ctx context.Context) []byte {
65+
return []byte(swaggerUIHTML)
66+
}

0 commit comments

Comments
 (0)