From 2ee7218dd5b5ced430c4410b7018933f083b37f6 Mon Sep 17 00:00:00 2001 From: Thinh TRUONG <75013885+td2thinh@users.noreply.github.com> Date: Wed, 13 Aug 2025 16:27:23 +0200 Subject: [PATCH] Add custom api key and secret options --- generate/options.go | 20 ++++++++++--------- generate/production.go | 45 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/generate/options.go b/generate/options.go index 2a2d8e6..c0b0769 100644 --- a/generate/options.go +++ b/generate/options.go @@ -55,15 +55,17 @@ func CloudInitFromDescription(str string) StartupScriptKind { // ServerOptions contains options for the SFU type ServerOptions struct { - IncludeEgress bool - IncludeIngress bool - Domain string - TURNDomain string - WHIPDomain string // optional, only if WHIP is desired - ServerVersion string - ZeroSSLAPIKey string - LocalRedis bool - CloudInit StartupScriptKind + IncludeEgress bool + IncludeIngress bool + Domain string + TURNDomain string + WHIPDomain string // optional, only if WHIP is desired + ServerVersion string + ZeroSSLAPIKey string + LocalRedis bool + CloudInit StartupScriptKind + CustomApiKey string + CustomApiSecret string Files ConfigFiles } diff --git a/generate/production.go b/generate/production.go index 36582e9..136d7a8 100644 --- a/generate/production.go +++ b/generate/production.go @@ -91,6 +91,41 @@ func generateProduction() error { return err } + customKeySecret := false + customKeySecretPrompt := promptui.Select{ + Label: "Use custom API key and secret?", + Items: []string{ + "No - (we'll generate a random one)", + "Yes", + }, + Stdout: BellSkipper, + } + idx, _, err = customKeySecretPrompt.Run() + if err != nil { + return err + } + if idx == 1 { + customKeySecret = true + } + + if customKeySecret { + prompt = promptui.Prompt{ + Label: "Custom API key", + Stdout: BellSkipper, + } + if opts.CustomApiKey, err = prompt.Run(); err != nil { + return err + } + + prompt = promptui.Prompt{ + Label: "Custom API secret", + Stdout: BellSkipper, + } + if opts.CustomApiSecret, err = prompt.Run(); err != nil { + return err + } + } + if opts.IncludeIngress { prompt = promptui.Prompt{ Label: "Ingress WHIP domain name (optional, i.e. livekit-whip.myhost.com)", @@ -304,8 +339,14 @@ func getLatestVersion() (string, error) { } func generateLiveKit(opts *ServerOptions, baseDir string) (*config.Config, error) { - apiKey := utils.NewGuid(utils.APIKeyPrefix) - apiSecret := utils.RandomSecret() + var apiKey, apiSecret string + if opts.CustomApiKey != "" && opts.CustomApiSecret != "" { + apiKey = opts.CustomApiKey + apiSecret = opts.CustomApiSecret + } else { + apiKey = utils.NewGuid(utils.APIKeyPrefix) + apiSecret = utils.RandomSecret() + } conf := config.Config{ Keys: map[string]string{ apiKey: apiSecret,