fix: add warning for long secret names #359
@ -2,6 +2,7 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/pkg/autocomplete"
|
"coopcloud.tech/abra/pkg/autocomplete"
|
||||||
@ -125,6 +126,10 @@ var appNewCommand = cli.Command{
|
|||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := ensureSecretLengths(secrets, internal.Domain); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
secretCols := []string{"Name", "Value"}
|
secretCols := []string{"Name", "Value"}
|
||||||
secretTable = formatter.CreateTable(secretCols)
|
secretTable = formatter.CreateTable(secretCols)
|
||||||
for name, val := range secrets {
|
for name, val := range secrets {
|
||||||
@ -256,3 +261,21 @@ func ensureServerFlag() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ensureSecretLengths(secrets AppSecrets, domain string) error {
|
||||||
|
domainLength := len(domain)
|
||||||
decentral1se marked this conversation as resolved
Outdated
|
|||||||
|
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
decentral1se
commented
nitpick: drop extra newline? nitpick: drop extra newline?
rix
commented
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
decentral1se
commented
Maybe Maybe `64` can also go in `pkg/config/env.go` while we're at it?
|
|||||||
|
}
|
||||||
decentral1se marked this conversation as resolved
Outdated
decentral1se
commented
I think it would be simpler to just error out here. Also a simpler/clearer error message to write?
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)
```
rix
commented
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 : )
|
|||||||
|
Loading…
x
Reference in New Issue
Block a user
Maybe it's time to abstract this
45
to aconst
inpkg/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.Done : )