Skip to content

Commit

Permalink
Implement fine-grained mobile/client side access
Browse files Browse the repository at this point in the history
  • Loading branch information
drichelson committed May 27, 2024
1 parent eef72b1 commit 2970a65
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 30 deletions.
13 changes: 7 additions & 6 deletions internal/dorkly/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ const (

// FlagBase contains the common flag fields shared between environments
type FlagBase struct {
key string
Description string `yaml:"description"`
Type FlagType `yaml:"type"`
ServerSideOnly bool `yaml:"serverSideOnly"`
key string
Description string `yaml:"description"`
Type FlagType `yaml:"type"`
EnableMobileKey bool `yaml:"enableMobileKey"`
EnableBrowser bool `yaml:"enableBrowser"`
}

type FlagType string
Expand Down Expand Up @@ -70,8 +71,8 @@ func (f *FlagBase) ldFeatureFlagBase() ldmodel.FeatureFlag {
return ldmodel.FeatureFlag{
Key: f.key,
ClientSideAvailability: ldmodel.ClientSideAvailability{
UsingMobileKey: !f.ServerSideOnly,
UsingEnvironmentID: !f.ServerSideOnly,
UsingMobileKey: f.EnableMobileKey,
UsingEnvironmentID: f.EnableBrowser,
},
// TODO: ld-relay archive json files also contain a "clientSide": boolean field.. do we need it?

Expand Down
15 changes: 10 additions & 5 deletions internal/dorkly/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Test_FlagBoolean_ToLdFlag(t *testing.T) {
{
name: "true,client-side ok",
flag: FlagBoolean{Variation: true},
flagBase: FlagBase{key: "test-key"},
flagBase: FlagBase{key: "test-key", EnableBrowser: true, EnableMobileKey: true},
expected: ldmodel.FeatureFlag{
Key: "test-key",
ClientSideAvailability: ldmodel.ClientSideAvailability{
Expand All @@ -35,8 +35,9 @@ func Test_FlagBoolean_ToLdFlag(t *testing.T) {
name: "false,server-side only",
flag: FlagBoolean{Variation: false},
flagBase: FlagBase{
key: "test-key-2",
ServerSideOnly: true,
key: "test-key-2",
EnableBrowser: false,
EnableMobileKey: false,
},
expected: ldmodel.FeatureFlag{
Key: "test-key-2",
Expand Down Expand Up @@ -73,7 +74,9 @@ func Test_FlagBooleanRollout_ToLdFlag(t *testing.T) {
PercentRollout: 100.0,
},
flagBase: FlagBase{
key: "test-key",
key: "test-key",
EnableBrowser: true,
EnableMobileKey: true,
},
expected: ldmodel.FeatureFlag{
Key: "test-key",
Expand Down Expand Up @@ -109,7 +112,9 @@ func Test_FlagBooleanRollout_ToLdFlag(t *testing.T) {
PercentRollout: 10.0,
},
flagBase: FlagBase{
key: "test-key-10",
key: "test-key-10",
EnableBrowser: true,
EnableMobileKey: true,
},
expected: ldmodel.FeatureFlag{
Key: "test-key-10",
Expand Down
18 changes: 10 additions & 8 deletions internal/dorkly/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ var (
Flags: map[string]Flag{
"boolean1": {
FlagBase: FlagBase{
key: "boolean1",
Description: "Human-readable description of the flag.",
Type: "boolean",
ServerSideOnly: false,
key: "boolean1",
Description: "Human-readable description of the flag.",
Type: "boolean",
EnableBrowser: true,
EnableMobileKey: true,
},
envConfigs: map[string]FlagConfigForEnv{
"production": &FlagBoolean{Variation: false},
Expand All @@ -30,10 +31,11 @@ var (
},
"rollout1": {
FlagBase: FlagBase{
key: "rollout1",
Description: "Human-readable description of the flag.",
Type: "booleanRollout",
ServerSideOnly: false,
key: "rollout1",
Description: "Human-readable description of the flag.",
Type: "booleanRollout",
EnableBrowser: true,
EnableMobileKey: true,
},
envConfigs: map[string]FlagConfigForEnv{
"production": &FlagBooleanRollout{PercentRollout: 31.0},
Expand Down
9 changes: 1 addition & 8 deletions internal/dorkly/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,7 @@ func (b booleanFlagBuilder) toLdFlag() ldmodel.FeatureFlag {
Variation: b.variationV,
}

flagBase := FlagBase{
key: b.key,
Description: "",
Type: FlagTypeBoolean,
ServerSideOnly: false,
}

ldFlag := f.ToLdFlag(flagBase)
ldFlag := f.ToLdFlag(b.FlagBase)
ldFlag.Version = b.versionV
ldFlag.Deleted = b.isDeleted

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type: boolean
description: "Human-readable description of the flag."
serverSideOnly: false
enableBrowser: true
enableMobileKey: true
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type: booleanRollout
description: "Human-readable description of the flag."
serverSideOnly: false
enableBrowser: true
enableMobileKey: true
3 changes: 2 additions & 1 deletion tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- [x] Secrets: terraform: generate and store in aws secrets manager
- [x] Secrets: dorkly go code: read from aws secrets manager and inject into each environment's config
- [x] Use localstack to test s3
- [...] Terraform: Repo-level readme should contain: general tips on connecting using ld sdk + injected url, sdk keys, etc for each env.
- [...] Terraform: generated Repo-level readme should contain: general tips on connecting using ld sdk + injected url, sdk keys, etc for each env.
- [...] Create project overview in README.md
- [ ] Terraform: Add option per-env: Disable checking in sdk keys. (for production environments).
- [ ] Good docs on client-side (js) sdk setup.
Expand All @@ -24,6 +24,7 @@
- [ ] Terraform: Consider a command line tool to quickly create new flags and maybe turn them off in all envs
- [ ] Terraform: Use freeform workflow with human input to create flags
- [ ] Use localstack to do end to end testing (if possible)
- [ ] Maybe never: Implement mobile key and client-side sdk setup (for now people should just use the client id)


## Pending DX tasks
Expand Down

0 comments on commit 2970a65

Please sign in to comment.