Skip to content

Commit

Permalink
fix: go: automatically use paths compatible with cli/prod (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop authored Mar 5, 2024
1 parent 2373bd7 commit d8915e5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
postInstall = ''
wrapProgram $out/bin/hasura-auth \
--suffix PATH : ${pkgs.nodejs-slim_18}/bin \
--prefix NODE_SERVER_PATH : ${node-auth}
--prefix AUTH_NODE_SERVER_PATH : ${node-auth}
'';
};

Expand Down
17 changes: 16 additions & 1 deletion go/cmd/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"net/smtp"
"os"
"path/filepath"

"github.com/nhost/hasura-auth/go/notifications"
Expand All @@ -17,8 +18,22 @@ func getEmailer(cCtx *cli.Context, logger *slog.Logger) (*notifications.Email, e
headers["X-SMTPAPI"] = cCtx.String(flagSMTPAPIHedaer)
}

templates, err := notifications.NewTemplatesFromFilesystem(
var templatesPath string
for _, p := range []string{
cCtx.String(flagEmailTemplatesPath),
filepath.Join(cCtx.String(flagNodeServerPath), "email-templates"),
} {
if _, err := os.Stat(p); err == nil {
templatesPath = p
break
}
}
if templatesPath == "" {
return nil, errors.New("templates path not found") //nolint:goerr113
}

templates, err := notifications.NewTemplatesFromFilesystem(
templatesPath,
cCtx.String(flagDefaultLocale),
logger.With(slog.String("component", "mailer")),
)
Expand Down
14 changes: 11 additions & 3 deletions go/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (
flagHasuraAdminSecret = "hasura-admin-secret" //nolint:gosec
flagPasswordMinLength = "password-min-length"
flagPasswordHIBPEnabled = "password-hibp-enabled"
flagEmailTemplatesPath = "templates-path"
)

func CommandServe() *cli.Command { //nolint:funlen
Expand All @@ -86,13 +87,13 @@ func CommandServe() *cli.Command { //nolint:funlen
Name: flagDebug,
Usage: "enable debug logging",
Category: "general",
EnvVars: []string{"DEBUG"},
EnvVars: []string{"AUTH_DEBUG"},
},
&cli.BoolFlag{ //nolint: exhaustruct
Name: flagLogFormatTEXT,
Usage: "format logs in plain text",
Category: "general",
EnvVars: []string{"LOG_FORMAT_TEXT"},
EnvVars: []string{"AUTH_LOG_FORMAT_TEXT"},
},
&cli.StringFlag{ //nolint: exhaustruct
Name: flagPostgresConnection,
Expand All @@ -106,7 +107,7 @@ func CommandServe() *cli.Command { //nolint:funlen
Usage: "Path to the node server",
Value: ".",
Category: "node",
EnvVars: []string{"NODE_SERVER_PATH"},
EnvVars: []string{"AUTH_NODE_SERVER_PATH"},
},
&cli.BoolFlag{ //nolint: exhaustruct
Name: flagDisableSignup,
Expand Down Expand Up @@ -331,6 +332,13 @@ func CommandServe() *cli.Command { //nolint:funlen
Category: "signup",
EnvVars: []string{"AUTH_PASSWORD_HIBP_ENABLED"},
},
&cli.StringFlag{ //nolint: exhaustruct
Name: flagEmailTemplatesPath,
Usage: "Path to the email templates. Default to included ones if path isn't found",
Value: "/app/email-templates",
Category: "email",
EnvVars: []string{"AUTH_EMAIL_TEMPLATES_PATH"},
},
},
Action: serve,
}
Expand Down

0 comments on commit d8915e5

Please sign in to comment.