Skip to content

Commit

Permalink
feat: add support for signing keys APIs (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerburdsall authored Apr 27, 2022
1 parent 9f02dcc commit 1556f83
Show file tree
Hide file tree
Showing 12 changed files with 980 additions and 48 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,15 @@ client, err = NewSimpleCacheClient(authToken, itemDefaultTtlSeconds, WithRequest
```bash
TEST_AUTH_TOKEN=<auth token> TEST_CACHE_NAME=<cache name> go test -v ./momento
```

## Updating GRPC protos
1. Follow the [quick-start instructions](https://grpc.io/docs/languages/go/quickstart/) to set up your environment
2. Checkout the latest changes from https://github.com/momentohq/client_protos
3. Copy the `.proto` files from `client_protos/proto` to `client-sdk-go/internal/protos/`
4. `cd` to the `internal` directory and run:

```protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative protos/*.proto
```

You should now have updated auto-generated files with the updated protos
63 changes: 63 additions & 0 deletions internal/models/responses.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package models

import (
"encoding/json"
"time"

"github.com/momentohq/client-sdk-go/internal/momentoerrors"
pb "github.com/momentohq/client-sdk-go/internal/protos"
)
Expand Down Expand Up @@ -38,6 +41,66 @@ func NewCacheInfo(cache *pb.XCache) CacheInfo {
return CacheInfo{Name: cache.CacheName}
}

type CreateSigningKeyRequest struct {
TtlMinutes uint32
}

type CreateSigningKeyResponse struct {
KeyId string
Endpoint string
Key string
ExpiresAt time.Time
}

func NewCreateSigningKeyResponse(endpoint string, resp *pb.XCreateSigningKeyResponse) (*CreateSigningKeyResponse, error) {
var keyObj map[string]string
err := json.Unmarshal([]byte(resp.GetKey()), &keyObj)
if err != nil {
return nil, err
}
return &CreateSigningKeyResponse{
KeyId: keyObj["kid"],
Endpoint: endpoint,
Key: resp.GetKey(),
ExpiresAt: time.Unix(int64(resp.GetExpiresAt()), 0),
}, nil
}

type RevokeSigningKeyRequest struct {
KeyId string
}

type ListSigningKeysRequest struct {
NextToken string
}

type ListSigningKeysResponse struct {
NextToken string
SigningKeys []SigningKey
}

func NewListSigningKeysResponse(endpoint string, resp *pb.XListSigningKeysResponse) *ListSigningKeysResponse {
var signingKeys []SigningKey
for _, signingKey := range resp.SigningKey {
signingKeys = append(signingKeys, NewSigningKey(endpoint, signingKey))
}
return &ListSigningKeysResponse{NextToken: resp.GetNextToken(), SigningKeys: signingKeys}
}

type SigningKey struct {
KeyId string
Endpoint string
ExpiresAt time.Time
}

func NewSigningKey(endpoint string, signingKey *pb.XSigningKey) SigningKey {
return SigningKey{
KeyId: signingKey.GetKeyId(),
Endpoint: endpoint,
ExpiresAt: time.Unix(int64(signingKey.GetExpiresAt()), 0),
}
}

const (
HIT string = "HIT"
MISS string = "MISS"
Expand Down
2 changes: 1 addition & 1 deletion internal/protos/cacheclient.pb.go

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

Loading

0 comments on commit 1556f83

Please sign in to comment.