Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
api/v2: add in primary and secondary krab clients
Browse files Browse the repository at this point in the history
  • Loading branch information
potsables committed Feb 18, 2019
1 parent ba1ce06 commit a3bc321
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
11 changes: 7 additions & 4 deletions api/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strconv"
"time"

clients "github.com/RTradeLtd/Temporal/grpc-clients"
gClients "github.com/RTradeLtd/Temporal/grpc-clients"

"github.com/streadway/amqp"
Expand Down Expand Up @@ -47,7 +46,7 @@ var (
type API struct {
ipfs rtfs.Manager
ipfsCluster *rtfscluster.ClusterManager
keys *clients.KaasClient
keys keys
r *gin.Engine
cfg *config.TemporalConfig
dbm *database.Manager
Expand Down Expand Up @@ -170,7 +169,11 @@ func new(cfg *config.TemporalConfig, router *gin.Engine, l *zap.SugaredLogger, c
Blockchain: networkVersion,
Token: cfg.APIKeys.ChainRider,
})
keys, err := gClients.NewKaasClient(cfg.Services, false)
kb1, err := gClients.NewKaasClient(cfg.Services, false)
if err != nil {
return nil, err
}
kb2, err := gClients.NewKaasClient(cfg.Services, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -219,7 +222,7 @@ func new(cfg *config.TemporalConfig, router *gin.Engine, l *zap.SugaredLogger, c
return &API{
ipfs: ipfs,
ipfsCluster: ipfsCluster,
keys: keys,
keys: keys{kb1: kb1, kb2: kb2},
cfg: cfg,
service: "api",
r: router,
Expand Down
14 changes: 11 additions & 3 deletions api/v2/routes_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (api *API) exportKey(c *gin.Context) {
return
}
// get private key from krab keystore
resp, err := api.keys.GetPrivateKey(context.Background(), &pb.KeyGet{Name: keyName})
resp, err := api.keys.kb1.GetPrivateKey(context.Background(), &pb.KeyGet{Name: keyName})
if err != nil {
api.LogError(c, err, eh.KeyExportError)(http.StatusBadRequest)
return
Expand All @@ -133,8 +133,16 @@ func (api *API) exportKey(c *gin.Context) {
api.LogError(c, err, eh.KeyExportError)(http.StatusBadRequest)
return
}
// after successful parsing delete key from krab
if resp, err := api.keys.DeletePrivateKey(context.Background(), &pb.KeyDelete{Name: keyName}); err != nil {
// after successful parsing delete key from krab primary
if resp, err := api.keys.kb1.DeletePrivateKey(context.Background(), &pb.KeyDelete{Name: keyName}); err != nil {
api.LogError(c, err, "failed to delete key")(http.StatusBadRequest)
return
} else if resp.Status != "private key deleted" {
Fail(c, errors.New("failed to delete private key"))
return
}
// after successful parsing delete key from krab fallback
if resp, err := api.keys.kb2.DeletePrivateKey(context.Background(), &pb.KeyDelete{Name: keyName}); err != nil {
api.LogError(c, err, "failed to delete key")(http.StatusBadRequest)
return
} else if resp.Status != "private key deleted" {
Expand Down
7 changes: 7 additions & 0 deletions api/v2/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v2

import (
clients "github.com/RTradeLtd/Temporal/grpc-clients"
"github.com/RTradeLtd/Temporal/queue"
)

Expand All @@ -20,3 +21,9 @@ type queues struct {
dash *queue.Manager
eth *queue.Manager
}

// kaas key managers
type keys struct {
kb1 *clients.KaasClient
kb2 *clients.KaasClient
}

0 comments on commit a3bc321

Please sign in to comment.