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