-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add dev server (AKA LaunchDevly) (#364)
This adds a new command to the cli, dev-server. When you start it, an HTTP server starts running on port 8765. It provides APIs that mimic the APIs that LaunchDarkly SDKs use. You can add-projects to the dev server and they will be populated with flag values from the source-environment. You can also add-overrides to change the value served by a given flag. There's also a UI that will display which flag values are being served and allow you to set overrides. These features combine to provide a more portable solution for local & ephemeral development environments of projects using LaunchDarkly than the current state of the art: creating real environments in LaunchDarkly for each of these environments.
- Loading branch information
Showing
754 changed files
with
421,906 additions
and
4,658 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
dist/ | ||
*.log | ||
node_modules/ | ||
devserver.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,44 @@ | ||
package cliflags | ||
|
||
const ( | ||
BaseURIDefault = "https://app.launchdarkly.com" | ||
BaseURIDefault = "https://app.launchdarkly.com" | ||
DevStreamURIDefault = "https://stream.launchdarkly.com" | ||
PortDefault = "8765" | ||
|
||
AccessTokenFlag = "access-token" | ||
AnalyticsOptOut = "analytics-opt-out" | ||
BaseURIFlag = "base-uri" | ||
DataFlag = "data" | ||
EmailsFlag = "emails" | ||
EnvironmentFlag = "environment" | ||
FlagFlag = "flag" | ||
OutputFlag = "output" | ||
ProjectFlag = "project" | ||
RoleFlag = "role" | ||
AccessTokenFlag = "access-token" | ||
AnalyticsOptOut = "analytics-opt-out" | ||
BaseURIFlag = "base-uri" | ||
DataFlag = "data" | ||
DevStreamURIFlag = "dev-stream-uri" | ||
EmailsFlag = "emails" | ||
EnvironmentFlag = "environment" | ||
FlagFlag = "flag" | ||
OutputFlag = "output" | ||
PortFlag = "port" | ||
ProjectFlag = "project" | ||
RoleFlag = "role" | ||
|
||
AccessTokenFlagDescription = "LaunchDarkly access token with write-level access" | ||
AnalyticsOptOutDescription = "Opt out of analytics tracking" | ||
BaseURIFlagDescription = "LaunchDarkly base URI" | ||
DevStreamURIDescription = "Streaming service endpoint that the dev server uses to obtain authoritative flag data. This may be a LaunchDarkly or Relay Proxy endpoint" | ||
EnvironmentFlagDescription = "Default environment key" | ||
FlagFlagDescription = "Default feature flag key" | ||
OutputFlagDescription = "Command response output format in either JSON or plain text" | ||
PortFlagDescription = "Port for the dev server to run on" | ||
ProjectFlagDescription = "Default project key" | ||
) | ||
|
||
func AllFlagsHelp() map[string]string { | ||
return map[string]string{ | ||
AccessTokenFlag: AccessTokenFlagDescription, | ||
AnalyticsOptOut: AnalyticsOptOutDescription, | ||
BaseURIFlag: BaseURIFlagDescription, | ||
EnvironmentFlag: EnvironmentFlagDescription, | ||
FlagFlag: FlagFlagDescription, | ||
OutputFlag: OutputFlagDescription, | ||
ProjectFlag: ProjectFlagDescription, | ||
AccessTokenFlag: AccessTokenFlagDescription, | ||
AnalyticsOptOut: AnalyticsOptOutDescription, | ||
BaseURIFlag: BaseURIFlagDescription, | ||
DevStreamURIFlag: DevStreamURIDescription, | ||
EnvironmentFlag: EnvironmentFlagDescription, | ||
FlagFlag: FlagFlagDescription, | ||
OutputFlag: OutputFlagDescription, | ||
PortFlag: PortFlagDescription, | ||
ProjectFlag: ProjectFlagDescription, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package dev_server | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/launchdarkly/ldcli/cmd/cliflags" | ||
resourcecmd "github.com/launchdarkly/ldcli/cmd/resources" | ||
"github.com/launchdarkly/ldcli/internal/dev_server" | ||
"github.com/launchdarkly/ldcli/internal/resources" | ||
) | ||
|
||
func NewDevServerCmd(client resources.Client, ldClient dev_server.Client) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "dev-server", | ||
Short: "Development server", | ||
Long: "Start and use a local development server for overriding flag values.", | ||
} | ||
|
||
cmd.PersistentFlags().String( | ||
cliflags.DevStreamURIFlag, | ||
cliflags.DevStreamURIDefault, | ||
cliflags.DevStreamURIDescription, | ||
) | ||
_ = viper.BindPFlag(cliflags.DevStreamURIFlag, cmd.PersistentFlags().Lookup(cliflags.DevStreamURIFlag)) | ||
|
||
cmd.PersistentFlags().String( | ||
cliflags.PortFlag, | ||
cliflags.PortDefault, | ||
cliflags.PortFlagDescription, | ||
) | ||
|
||
_ = viper.BindPFlag(cliflags.PortFlag, cmd.PersistentFlags().Lookup(cliflags.PortFlag)) | ||
|
||
// Add subcommands here | ||
cmd.AddGroup(&cobra.Group{ID: "projects", Title: "Project commands:"}) | ||
cmd.AddCommand(NewListProjectsCmd(client)) | ||
cmd.AddCommand(NewGetProjectCmd(client)) | ||
cmd.AddCommand(NewSyncProjectCmd(client)) | ||
cmd.AddCommand(NewRemoveProjectCmd(client)) | ||
cmd.AddCommand(NewAddProjectCmd(client)) | ||
|
||
cmd.AddGroup(&cobra.Group{ID: "overrides", Title: "Override commands:"}) | ||
cmd.AddCommand(NewAddOverrideCmd(client)) | ||
cmd.AddCommand(NewRemoveOverrideCmd(client)) | ||
cmd.AddGroup(&cobra.Group{ID: "server", Title: "Server commands:"}) | ||
|
||
cmd.AddCommand(NewStartServerCmd(ldClient)) | ||
cmd.AddCommand(NewUICmd()) | ||
|
||
cmd.SetUsageTemplate(resourcecmd.SubcommandUsageTemplate()) | ||
|
||
return cmd | ||
} | ||
|
||
func getDevServerUrl() string { | ||
return fmt.Sprintf("http://localhost:%s", viper.GetString(cliflags.PortFlag)) | ||
} |
Oops, something went wrong.