Skip to content
This repository has been archived by the owner on Aug 14, 2018. It is now read-only.

Commit

Permalink
feat(ctl): add call to retreive a key
Browse files Browse the repository at this point in the history
  • Loading branch information
paralin committed Dec 1, 2016
1 parent fb97390 commit 7ed1c9b
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 30 deletions.
125 changes: 95 additions & 30 deletions ctl/ctl-service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions ctl/ctl-service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,18 @@ message GetGrantsResponse {
repeated data.SignedData grants = 1;
}

message GetKeyRequest {
string key = 1;
}

message GetKeyResponse {
tx.Transaction transaction = 1;
}

service ControlService {
rpc PutGrant(PutGrantRequest) returns (PutGrantResponse) {}
rpc BuildTransaction(BuildTransactionRequest) returns (BuildTransactionResponse) {}
rpc PutTransaction(PutTransactionRequest) returns (PutTransactionResponse) {}
rpc GetGrants(GetGrantsRequest) returns (GetGrantsResponse) {}
rpc GetKey(GetKeyRequest) returns (GetKeyResponse) {}
}
16 changes: 16 additions & 0 deletions ctl/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

log "github.com/Sirupsen/logrus"
"github.com/boltdb/bolt"
"github.com/fuserobotics/kvgossip/data"
"github.com/fuserobotics/kvgossip/db"
"github.com/fuserobotics/kvgossip/grant"
Expand Down Expand Up @@ -116,6 +117,21 @@ func (ct *CtlServer) PutTransaction(ctx context.Context, req *PutTransactionRequ
return &PutTransactionResponse{}, nil
}

func (ct *CtlServer) GetKey(ctx context.Context, req *GetKeyRequest) (*GetKeyResponse, error) {
if req.Key == "" {
return nil, errors.New("Must specify key.")
}
res := &GetKeyResponse{}
err := ct.DB.DB.View(func(tx *bolt.Tx) error {
res.Transaction = ct.DB.GetTransaction(tx, req.Key)
return nil
})
if err != nil {
return nil, err
}
return res, nil
}

func (ct *CtlServer) Start(listen string) error {
if ct.server != nil {
return nil
Expand Down

0 comments on commit 7ed1c9b

Please sign in to comment.