mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-07-03 16:50:13 +00:00
fix: review comments
This commit is contained in:
@@ -51,3 +51,6 @@ config.certify.yml
|
||||
|
||||
# deepsec
|
||||
/.deepsec
|
||||
|
||||
# jetbrains
|
||||
/.idea/
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
func configCmd(tconfig *model.Config, loaders []cli.ResourceLoader) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "config",
|
||||
Description: "Dump the current configuration in JSON format, useful for debugging",
|
||||
Description: "Dump the current configuration in YAML format, useful for debugging",
|
||||
Configuration: tconfig,
|
||||
Resources: loaders,
|
||||
Run: func(_ []string) error {
|
||||
@@ -30,11 +30,15 @@ func configCmd(tconfig *model.Config, loaders []cli.ResourceLoader) *cli.Command
|
||||
if l == "" {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(strings.TrimLeft(l, " "), "- ") {
|
||||
buf.WriteString(greenStyle.Render(l))
|
||||
buf.WriteString("\n")
|
||||
continue
|
||||
}
|
||||
lp := strings.SplitN(l, ":", 2)
|
||||
buf.WriteString(redStyle.Render(lp[0]))
|
||||
buf.WriteString(grayStyle.Render(":"))
|
||||
if len(lp) == 2 {
|
||||
buf.WriteString("")
|
||||
buf.WriteString(greenStyle.Render(lp[1]))
|
||||
}
|
||||
buf.WriteString("\n")
|
||||
|
||||
@@ -53,19 +53,37 @@ func createOidcClientCmd() *cli.Command {
|
||||
|
||||
// end variables
|
||||
fmt.Fprintf(&buf, "Environment variables:\n\n")
|
||||
renderToBuf(&buf, map[string]string{
|
||||
fmt.Sprintf("TINYAUTH_OIDC_CLIENTS_%s_CLIENTID", uclientName): clientId,
|
||||
fmt.Sprintf("TINYAUTH_OIDC_CLIENTS_%s_CLIENTSECRET", uclientName): clientSecret,
|
||||
fmt.Sprintf("TINYAUTH_OIDC_CLIENTS_%s_NAME", uclientName): utils.Capitalize(lclientName),
|
||||
renderToBuf(&buf, []kv{
|
||||
{
|
||||
k: fmt.Sprintf("TINYAUTH_OIDC_CLIENTS_%s_CLIENTID", uclientName),
|
||||
v: clientId,
|
||||
},
|
||||
{
|
||||
k: fmt.Sprintf("TINYAUTH_OIDC_CLIENTS_%s_CLIENTSECRET", uclientName),
|
||||
v: clientSecret,
|
||||
},
|
||||
{
|
||||
k: fmt.Sprintf("TINYAUTH_OIDC_CLIENTS_%s_NAME", uclientName),
|
||||
v: utils.Capitalize(lclientName),
|
||||
},
|
||||
}, "=")
|
||||
fmt.Fprintf(&buf, "\n")
|
||||
|
||||
// cli flags
|
||||
fmt.Fprintf(&buf, "CLI flags:\n\n")
|
||||
renderToBuf(&buf, map[string]string{
|
||||
fmt.Sprintf("--oidc-clients-%s-clientid", lclientName): clientId,
|
||||
fmt.Sprintf("--oidc-clients-%s-clientsecret", lclientName): clientSecret,
|
||||
fmt.Sprintf("--oidc-clients-%s-name", lclientName): utils.Capitalize(lclientName),
|
||||
renderToBuf(&buf, []kv{
|
||||
{
|
||||
k: fmt.Sprintf("--oidc-clients-%s-clientid", lclientName),
|
||||
v: clientId,
|
||||
},
|
||||
{
|
||||
k: fmt.Sprintf("--oidc-clients-%s-clientsecret", lclientName),
|
||||
v: clientSecret,
|
||||
},
|
||||
{
|
||||
k: fmt.Sprintf("--oidc-clients-%s-name", lclientName),
|
||||
v: utils.Capitalize(lclientName),
|
||||
},
|
||||
}, "=")
|
||||
fmt.Fprintf(&buf, "\n")
|
||||
|
||||
|
||||
@@ -88,13 +88,14 @@ func createUserCmd() *cli.Command {
|
||||
|
||||
// Only the docker compose output needs $ escaped, the raw hash is correct everywhere else
|
||||
passwdStr := string(passwd)
|
||||
dockerStr := passwdStr
|
||||
outputStr := passwdStr
|
||||
|
||||
if tCfg.Docker {
|
||||
dockerStr = strings.ReplaceAll(passwdStr, "$", "$$")
|
||||
outputStr = strings.ReplaceAll(passwdStr, "$", "$$")
|
||||
}
|
||||
|
||||
user := fmt.Sprintf("%s:%s", tCfg.Username, dockerStr)
|
||||
escapedUser := strings.ReplaceAll(user, "$", "$$")
|
||||
user := fmt.Sprintf("%s:%s", tCfg.Username, passwdStr)
|
||||
escapedUser := fmt.Sprintf("%s:%s", tCfg.Username, outputStr)
|
||||
escapedUser = `"` + escapedUser + `"`
|
||||
|
||||
buf := strings.Builder{}
|
||||
@@ -104,14 +105,14 @@ func createUserCmd() *cli.Command {
|
||||
|
||||
// environment variable
|
||||
fmt.Fprint(&buf, "Environment variable:\n\n")
|
||||
renderToBuf(&buf, map[string]string{
|
||||
"TINYAUTH_AUTH_USERS": escapedUser,
|
||||
renderToBuf(&buf, []kv{
|
||||
{"TINYAUTH_AUTH_USERS", escapedUser},
|
||||
}, "=")
|
||||
|
||||
// cli flags
|
||||
fmt.Fprint(&buf, "\nCLI flags:\n\n")
|
||||
renderToBuf(&buf, map[string]string{
|
||||
"--auth.users": escapedUser,
|
||||
renderToBuf(&buf, []kv{
|
||||
{"--auth.users", escapedUser},
|
||||
}, "=")
|
||||
|
||||
// yaml config
|
||||
|
||||
@@ -168,11 +168,16 @@ func fatalf(err error, msg string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func renderToBuf(buf *strings.Builder, kv map[string]string, sep string) {
|
||||
for k, v := range kv {
|
||||
buf.WriteString(redStyle.Render(k))
|
||||
type kv struct {
|
||||
k string
|
||||
v string
|
||||
}
|
||||
|
||||
func renderToBuf(buf *strings.Builder, kv []kv, sep string) {
|
||||
for _, i := range kv {
|
||||
buf.WriteString(redStyle.Render(i.k))
|
||||
buf.WriteString(grayStyle.Render(sep))
|
||||
buf.WriteString(greenStyle.Render(v))
|
||||
buf.WriteString(greenStyle.Render(i.v))
|
||||
buf.WriteString("\n")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user