Skip to content

Commit

Permalink
feat!: add new sync proto, rm old sync proto (#99)
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <[email protected]>
  • Loading branch information
toddbaert authored Feb 6, 2024
1 parent 9698f93 commit fed2389
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
9 changes: 7 additions & 2 deletions sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ Test the sync from the command line with [grpcurl](https://github.com/fullstoryd

```shell
# request all flags
grpcurl -import-path '/path/to/proto/dir' -proto sync.proto -plaintext localhost:9090 sync.v1.FlagSyncService/FetchAllFlags
grpcurl -import-path '/path/to/proto/dir' -proto sync.proto -plaintext localhost:9090 flagd.sync.v1.FlagSyncService/FetchAllFlags
```

```shell
# open a stream for getting flag changes
grpcurl -import-path '/path/to/proto/dir' -proto sync.proto -plaintext localhost:9090 sync.v1.FlagSyncService/SyncFlags
grpcurl -import-path '/path/to/proto/dir' -proto sync.proto -plaintext localhost:9090 flagd.sync.v1.FlagSyncService/SyncFlags
```

```shell
# get metadata
grpcurl -import-path '/path/to/proto/dir' -proto sync.proto -plaintext localhost:9090 flagd.sync.v1.FlagSyncService/GetMetadata
```

### Generate certificates ?
Expand Down
22 changes: 16 additions & 6 deletions sync/pkg/server.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package sync

import (
"buf.build/gen/go/open-feature/flagd/grpc/go/sync/v1/syncv1grpc"
v1 "buf.build/gen/go/open-feature/flagd/protocolbuffers/go/sync/v1"
"context"
"crypto/tls"
"fmt"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"log"
"net"
"sync"

"buf.build/gen/go/open-feature/flagd/grpc/go/flagd/sync/v1/syncv1grpc"
v1 "buf.build/gen/go/open-feature/flagd/protocolbuffers/go/flagd/sync/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)

type Server struct {
Expand Down Expand Up @@ -92,7 +93,6 @@ func (s *SyncImpl) SyncFlags(req *v1.SyncFlagsRequest, stream syncv1grpc.FlagSyn
// initial read
err := stream.Send(&v1.SyncFlagsResponse{
FlagConfiguration: string(s.fw.getCurrentData()),
State: v1.SyncState_SYNC_STATE_ALL,
})
if err != nil {
log.Printf("Error sending initial stream: %v\n", err)
Expand All @@ -108,7 +108,6 @@ func (s *SyncImpl) SyncFlags(req *v1.SyncFlagsRequest, stream syncv1grpc.FlagSyn
case data := <-listener:
err = stream.Send(&v1.SyncFlagsResponse{
FlagConfiguration: string(data),
State: v1.SyncState_SYNC_STATE_ALL,
})
if err != nil {
// this is probably a close
Expand All @@ -131,3 +130,14 @@ func (s *SyncImpl) FetchAllFlags(context.Context, *v1.FetchAllFlagsRequest) (*v1
FlagConfiguration: string(marshalled),
}, nil
}

func (s *SyncImpl) GetMetadata(context.Context, *v1.GetMetadataRequest) (*v1.GetMetadataResponse, error) {
return &v1.GetMetadataResponse{
Metadata: []*v1.KeyValue{
{
Key: "paths",
Value: fmt.Sprintf("%v", s.fw.paths),
},
},
}, nil
}

0 comments on commit fed2389

Please sign in to comment.