diff --git a/cmd/server/commands.go b/cmd/server/commands.go index f34a6f475..65261f6d9 100644 --- a/cmd/server/commands.go +++ b/cmd/server/commands.go @@ -37,14 +37,27 @@ import ( "github.com/livekit/livekit-server/pkg/service" ) -func generateKeys(_ context.Context, _ *cli.Command) error { +func generateKeyFile(_ context.Context, c *cli.Command) error { + filename := c.String("key-file") + + file, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o600) + if err != nil { + return err + } + defer file.Close() + apiKey := guid.New(utils.APIKeyPrefix) secret := utils.RandomSecret() - fmt.Println("API Key: ", apiKey) - fmt.Println("API Secret: ", secret) + + file.WriteString(fmt.Sprintf("%s: %s", apiKey, secret)) + return nil } +func generateKeys(_ context.Context, _ *cli.Command) error { + return fmt.Errorf("DEPRECATED. Use generete-key-file instead") +} + func printPorts(_ context.Context, c *cli.Command) error { conf, err := getConfig(c) if err != nil { diff --git a/cmd/server/main.go b/cmd/server/main.go index b5e9741ef..9e99c367f 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -144,6 +144,18 @@ func main() { Usage: "generates an API key and secret pair", Action: generateKeys, }, + { + Name: "generate-key-file", + Usage: "generates an API key and secret pair and write them to a key file", + Action: generateKeyFile, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "key-file", + Usage: "filename for the key file", + Required: true, + }, + }, + }, { Name: "ports", Usage: "print ports that server is configured to use",