Repository navigation
feat(reverb): show the app's whole Reverb block for its .env #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |
| "os" | ||
| "path/filepath" | ||
| "strconv" | ||
| "strings" | ||
| "syscall" | ||
|
|
||
| "flock/internal/config" | ||
|
|
@@ -51,11 +52,36 @@ func Spec(root string, s Site) supervisor.Spec { | |
| } | ||
| } | ||
|
|
||
| // Env is what the app's .env needs for its broadcasts and its Echo client to go through the web | ||
| // server: the site's host, and the scheme and port it is served on. install:broadcasting's | ||
| // VITE_REVERB_* variables refer to these. | ||
| func Env(host, scheme string, port int) []string { | ||
| return []string{"REVERB_HOST=" + host, "REVERB_PORT=" + strconv.Itoa(port), "REVERB_SCHEME=" + scheme} | ||
| // Env is the app's whole Reverb block for its .env. The app's id, key and secret are a credential | ||
| // only the app and its own Reverb server share, both reading it from this .env: the ones the app | ||
| // has are kept (current returns a variable's value there, "" when unset), and an app without | ||
| // them gets ones named after the site. The host, scheme and port send its broadcasts and its | ||
| // Echo client through the web server. install:broadcasting's VITE_REVERB_* variables refer to | ||
| // these. | ||
| func Env(site, host, scheme string, port int, current func(key string) string) []string { | ||
| credential := func(key, fallback string) string { | ||
| if value := current(key); value != "" { | ||
| return key + "=" + dotenvValue(value) | ||
| } | ||
| return key + "=" + fallback | ||
| } | ||
| return []string{ | ||
| credential("REVERB_APP_ID", site), | ||
| credential("REVERB_APP_KEY", site+"_key"), | ||
| credential("REVERB_APP_SECRET", site+"_secret"), | ||
| "REVERB_HOST=" + host, | ||
| "REVERB_PORT=" + strconv.Itoa(port), | ||
| "REVERB_SCHEME=" + scheme, | ||
| } | ||
| } | ||
|
|
||
| // dotenvValue writes a value as a .env file takes it: in double quotes when it has a character | ||
| // that would end or change an unquoted one. | ||
| func dotenvValue(value string) string { | ||
| if !strings.ContainsAny(value, " \t#\"'\\$") { | ||
| return value | ||
| } | ||
| return `"` + strings.NewReplacer(`\`, `\\`, `"`, `\"`).Replace(value) + `"` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve literal dollar references when changing quotes. With Preserve the original quoting and interpolation semantics. Do not escape every dollar sign indiscriminately: existing double-quoted variable references must also keep their meaning.
|
||
| } | ||
|
|
||
| func exists(path string) bool { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an escape-aware reader for existing credentials.
For
REVERB_APP_SECRET="***REDACTED_SECRET_ASSIGNMENT***", the suppliedDotenv.Getstops at the escaped quote. It returnsabfollowed by a backslash, instead of the complete secret[REDACTED]. Escaped double quotes are valid in phpdotenv 5.6.2. (raw.githubusercontent.com)This new callback passes the truncated value to
reverb.Env. Pasting the displayed block then overwrites the existing credential. Update the reader to distinguish escaped quotes from closing quotes before using it for credential preservation. Keep the existing unquoted and space-containing cases valid.