fix: add warning for long secret names #359

Merged
decentral1se merged 14 commits from rix/abra:add-secret-length-linting into main 2024-04-06 21:41:37 +00:00
Showing only changes of commit 81d9e03800 - Show all commits

View File

@ -2,6 +2,7 @@ package app
import (
"fmt"
"strings"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/autocomplete"
@ -125,6 +126,10 @@ var appNewCommand = cli.Command{
logrus.Fatal(err)
}
if err := ensureSecretLengths(secrets, internal.Domain); err != nil {
logrus.Fatal(err)
}
secretCols := []string{"Name", "Value"}
secretTable = formatter.CreateTable(secretCols)
for name, val := range secrets {
@ -256,3 +261,21 @@ func ensureServerFlag() error {
return nil
}
func ensureSecretLengths(secrets AppSecrets, domain string) error {
domainLength := len(domain)
decentral1se marked this conversation as resolved Outdated

Maybe it's time to abstract this 45 to a const in pkg/config/env.go? We're starting to use it in several places and this will probably lead to confusion at best and bugs at worst as things change over time.

Maybe it's time to abstract this `45` to a `const` in `pkg/config/env.go`? We're starting to use it in several places and this will probably lead to confusion at best and bugs at worst as things change over time.
Outdated
Review

Done : )

Done : )
failingSecrets := []string{}
for secretName := range secrets {
if len(secretName)+domainLength > 64 {
failingSecrets = append(failingSecrets, secretName)
}
}
if len(failingSecrets) > 0 {
decentral1se marked this conversation as resolved Outdated

nitpick: drop extra newline?

nitpick: drop extra newline?
Outdated
Review

Think I've got this one now but let me know if I misinterpreted which line you were talking about : )

Think I've got this one now but let me know if I misinterpreted which line you were talking about : )
failedSecretsString := strings.Join(failingSecrets, ", ")
return fmt.Errorf("The following secrets are too long to work with the domain name %s, change their length or use a shorter domain name: %s", domain, failedSecretsString)
}
return nil
decentral1se marked this conversation as resolved Outdated

Maybe 64 can also go in pkg/config/env.go while we're at it?

Maybe `64` can also go in `pkg/config/env.go` while we're at it?
Outdated
Review

Done

Done
}
decentral1se marked this conversation as resolved Outdated

I think it would be simpler to just error out here. Also a simpler/clearer error message to write?

return fmt.Errorf("%s is too long (> 64 chars when combined with %s)", secretName, sanitisedAppName)
I think it would be simpler to just error out here. Also a simpler/clearer error message to write? ```go return fmt.Errorf("%s is too long (> 64 chars when combined with %s)", secretName, sanitisedAppName) ```
Outdated
Review

I've made it drop out after the first error now but I guess the side effect is that if there's more than one long secret it will be a bit of a whack-a-mole to find them all but I guess it's a pretty rare occurence so the trade off for cleaner code is probably worth it : )

I've made it drop out after the first error now but I guess the side effect is that if there's more than one long secret it will be a bit of a whack-a-mole to find them all but I guess it's a pretty rare occurence so the trade off for cleaner code is probably worth it : )