Skip to content

Commit

Permalink
finalize grpcs wiring
Browse files Browse the repository at this point in the history
Signed-off-by: Kavindu Dodanduwa <[email protected]>
  • Loading branch information
Kavindu-Dodan committed Mar 8, 2023
1 parent 09c6d13 commit aed4118
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 24 deletions.
21 changes: 11 additions & 10 deletions docs/configuration/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ Config file expects the keys to have the exact naming as the flags.

Any URI passed to flagd via the `--uri` flag must follow one of the 4 following patterns to ensure that it is passed to the correct implementation:

| Sync | Pattern | Example |
|------------|------------------------------------|---------------------------------------|
| Sync | Pattern | Example |
|------------|---------------------------------------|---------------------------------------|
| Kubernetes | `core.openfeature.dev/namespace/name` | `core.openfeature.dev/default/my-crd` |
| Filepath | `file:path/to/my/flag` | `file:etc/flagd/my-flags.json` |
| Remote | `http(s)://flag-source-url` | `https://my-flags.com/flags` |
| Grpc | `grpc://flag-source-url` | `grpc://my-flags-server` |
| Filepath | `file:path/to/my/flag` | `file:etc/flagd/my-flags.json` |
| Remote | `http(s)://flag-source-url` | `https://my-flags.com/flags` |
| Grpc | `grpc(s)://flag-source-url` | `grpc://my-flags-server` |


### Customising sync providers
Expand All @@ -42,11 +42,12 @@ While a URI may be passed to flagd via the `--uri` flag, some implementations ma
The flag takes a string argument, which should be a JSON representation of an array of `ProviderConfig` objects. Alternatively, these configurations should be passed to
flagd via config file, specified using the `--config` flag.

| Field | Type |
|------------|------------------------------------|
| uri | required `string` | |
| provider | required `string` (`file`, `kubernetes`, `http` or `grpc`) |
| bearerToken | optional `string` |
| Field | Type | Note |
|-------------|------------------------------------------------------------|----------------------------------------------------|
| uri | required `string` | |
| provider | required `string` (`file`, `kubernetes`, `http` or `grpc`) | |
| bearerToken | optional `string` | Used for http sync |
| certPath | optional `string` | Used for grpcs sync when TLS certificate is needed |

The `uri` field values do not need to follow the [URI patterns](#uri-patterns), the provider type is instead derived from the provider field.

Expand Down
17 changes: 10 additions & 7 deletions pkg/runtime/from_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ const (
)

var (
regCrd *regexp.Regexp
regURL *regexp.Regexp
regGRPC *regexp.Regexp
regFile *regexp.Regexp
regCrd *regexp.Regexp
regURL *regexp.Regexp
regGRPC *regexp.Regexp
regGRPCSecure *regexp.Regexp
regFile *regexp.Regexp
)

func init() {
regCrd = regexp.MustCompile("^core.openfeature.dev/")
regURL = regexp.MustCompile("^https?://")
regGRPC = regexp.MustCompile("^" + grpc.Prefix)
regGRPCSecure = regexp.MustCompile("^" + grpc.PrefixSecure)
regFile = regexp.MustCompile("^file:")
}

Expand Down Expand Up @@ -121,7 +123,8 @@ func (r *Runtime) newGRPC(config sync.ProviderConfig, logger *logger.Logger) *gr
zap.String("component", "sync"),
zap.String("sync", "grpc"),
),
Mux: &msync.RWMutex{},
CertPath: config.CertPath,
Mux: &msync.RWMutex{},
}
}

Expand Down Expand Up @@ -196,14 +199,14 @@ func SyncProvidersFromURIs(uris []string) ([]sync.ProviderConfig, error) {
URI: uri,
Provider: syncProviderHTTP,
})
case regGRPC.Match(uriB):
case regGRPC.Match(uriB), regGRPCSecure.Match(uriB):
syncProvidersParsed = append(syncProvidersParsed, sync.ProviderConfig{
URI: uri,
Provider: syncProviderGrpc,
})
default:
return syncProvidersParsed, fmt.Errorf("invalid sync uri argument: %s, must start with 'file:', "+
"'http(s)://', 'grpc://', or 'core.openfeature.dev'", uri)
"'http(s)://', 'grpc(s)://', or 'core.openfeature.dev'", uri)
}
}
return syncProvidersParsed, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/sync/grpc/grpc_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (g *Sync) Sync(ctx context.Context, dataSync chan<- sync.DataSync) error {

syncClient, err := g.client.SyncFlags(ctx, &v1.SyncFlagsRequest{ProviderId: g.ProviderID})
if err != nil {
return nil
return err
}

err = g.handleFlagSync(syncClient, dataSync)
Expand Down
8 changes: 3 additions & 5 deletions pkg/sync/http/http_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,9 @@ func TestHTTPSync_Fetch(t *testing.T) {
tt.setup(t, mockClient)

httpSync := Sync{
URI: tt.uri,
Client: mockClient,
Config: sync.ProviderConfig{
BearerToken: tt.bearerToken,
},
URI: tt.uri,
Client: mockClient,
BearerToken: tt.bearerToken,
LastBodySHA: tt.lastBodySHA,
Logger: logger.NewLogger(nil, false),
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sync/isync.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ type ProviderConfig struct {
Provider string `json:"provider"`

BearerToken string `json:"bearerToken,omitempty"`
CertPath string `json:"certPath,omitempty"`
}
1 change: 0 additions & 1 deletion pkg/sync/kubernetes/kubernetes_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var (

type Sync struct {
Logger *logger.Logger
client client.Client
Source string
URI string
ready bool
Expand Down

0 comments on commit aed4118

Please sign in to comment.