Skip to content

Commit

Permalink
Merge pull request #65 from kaleido-io/api-spec
Browse files Browse the repository at this point in the history
API spec
  • Loading branch information
peterbroadhurst authored Dec 29, 2021
2 parents fe6e97a + 51991a4 commit 00f16ec
Show file tree
Hide file tree
Showing 8 changed files with 584 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/otiai10/copy v1.6.0
github.com/pkg/errors v0.9.1
github.com/prometheus/procfs v0.6.0 // indirect
github.com/rs/cors v1.8.2
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.9.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,8 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
Binary file added images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions internal/messages/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ type LedgerQueryResult struct {
// TransactionReceipt is sent when a transaction has been successfully mined
type TransactionReceipt struct {
ReplyCommon
BlockNumber uint64 `json:"blockNumber"`
SignerMSP string `json:"signerMSP"`
Signer string `json:"signer"`
TransactionID string `json:"transactionID"`
Status string `json:"status"`
}

type ErrorReply struct {
Expand Down
21 changes: 20 additions & 1 deletion internal/rest/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ import (
"github.com/hyperledger/firefly-fabconnect/internal/rest/identity"
restsync "github.com/hyperledger/firefly-fabconnect/internal/rest/sync"
restutil "github.com/hyperledger/firefly-fabconnect/internal/rest/utils"
"github.com/hyperledger/firefly-fabconnect/internal/utils"
"github.com/hyperledger/firefly-fabconnect/internal/ws"
"github.com/julienschmidt/httprouter"

"github.com/rs/cors"
log "github.com/sirupsen/logrus"
)

Expand All @@ -50,17 +52,22 @@ type router struct {
}

func newRouter(syncDispatcher restsync.SyncDispatcher, asyncDispatcher restasync.AsyncDispatcher, idClient identity.IdentityClient, sm events.SubscriptionManager, ws ws.WebSocketServer) *router {
r := httprouter.New()
cors.Default().Handler(r)
return &router{
syncDispatcher: syncDispatcher,
asyncDispatcher: asyncDispatcher,
identityClient: idClient,
subManager: sm,
ws: ws,
httpRouter: httprouter.New(),
httpRouter: r,
}
}

func (r *router) addRoutes() {
r.httpRouter.GET("/api", r.serveSwaggerUI)
r.httpRouter.GET("/spec.yaml", r.serveSwagger)

r.httpRouter.POST("/identities", r.registerUser)
r.httpRouter.POST("/identities/:username/enroll", r.enrollUser)
r.httpRouter.GET("/identities", r.listUsers)
Expand Down Expand Up @@ -120,6 +127,18 @@ func (r *router) statusHandler(res http.ResponseWriter, req *http.Request, _ htt
_, _ = res.Write(reply)
}

func (r *router) serveSwagger(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
log.Infof("--> %s %s", req.Method, req.URL)
fs := http.FileServer(http.Dir("./openapi"))
fs.ServeHTTP(res, req)
}

func (r *router) serveSwaggerUI(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
log.Infof("--> %s %s", req.Method, req.URL)
res.Header().Add("Content-Type", "text/html")
_, _ = res.Write(utils.SwaggerUIHTML(req.Context()))
}

func (r *router) queryChaincode(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
log.Infof("--> %s %s", req.Method, req.URL)

Expand Down
6 changes: 6 additions & 0 deletions internal/tx/txprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ func (p *txProcessor) waitForCompletion(inflight *inflightTx, initialWaitDelay t
reply.Headers.MsgType = messages.MsgTypeTransactionFailure
}

reply.Status = receipt.Status.String()
reply.BlockNumber = receipt.BlockNumber
reply.Signer = receipt.Signer
reply.SignerMSP = receipt.SignerMSP
reply.TransactionID = receipt.TransactionID

inflight.txContext.Reply(&reply)
}

Expand Down
66 changes: 66 additions & 0 deletions internal/utils/swagger-ui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 utils

import (
"context"
)

var swaggerUIHTML = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16" />
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@3/swagger-ui.css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js" charset="UTF-8"></script>
<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js" charset="UTF-8"></script>
<script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "/spec.yaml",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
// End Swagger UI call region
window.ui = ui;
};
</script>
</body>
</html>
`

func SwaggerUIHTML(ctx context.Context) []byte {
return []byte(swaggerUIHTML)
}
Loading

0 comments on commit 00f16ec

Please sign in to comment.