Move secret checking to a shared location.
This commit is contained in:
parent
2abb7264b8
commit
66cf63a665
@ -111,7 +111,7 @@ var appNewCommand = cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
if err := ensureSecretLengths(secretsConfig, internal.Domain, sanitisedAppName); err != nil {
|
||||
if err := secret.EnsureSecretLengths(secretsConfig, internal.Domain, sanitisedAppName); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
@ -260,19 +260,3 @@ func ensureServerFlag() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ensureSecretLengths(secrets map[string]string, domainName string, sanitisedAppName string) error {
|
||||
if len(sanitisedAppName) > config.MAX_SANITISED_APP_NAME_LENGTH {
|
||||
sanitisedAppName = sanitisedAppName[:config.MAX_SANITISED_APP_NAME_LENGTH]
|
||||
}
|
||||
|
||||
domainAndFormatLength := len(sanitisedAppName) + 4
|
||||
for secretName := range secrets {
|
||||
|
||||
if len(secretName)+domainAndFormatLength > config.MAX_DOCKER_SECRET_LENGTH {
|
||||
return fmt.Errorf("secret %s is too long (> %d chars when combined with %s)", secretName, config.MAX_DOCKER_SECRET_LENGTH, sanitisedAppName)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/upstream/stack"
|
||||
loader "coopcloud.tech/abra/pkg/upstream/stack"
|
||||
"github.com/decentral1se/passgen"
|
||||
@ -209,3 +210,19 @@ func GenerateSecrets(cl *dockerClient.Client, secretsFromConfig map[string]strin
|
||||
|
||||
return secrets, nil
|
||||
}
|
||||
|
||||
func EnsureSecretLengths(secrets map[string]string, domainName string, sanitisedAppName string) error {
|
||||
if len(sanitisedAppName) > config.MAX_SANITISED_APP_NAME_LENGTH {
|
||||
sanitisedAppName = sanitisedAppName[:config.MAX_SANITISED_APP_NAME_LENGTH]
|
||||
}
|
||||
|
||||
domainAndFormatLength := len(sanitisedAppName) + 4
|
||||
for secretName := range secrets {
|
||||
|
||||
if len(secretName)+domainAndFormatLength > config.MAX_DOCKER_SECRET_LENGTH {
|
||||
return fmt.Errorf("secret %s is too long (> %d chars when combined with %s)", secretName, config.MAX_DOCKER_SECRET_LENGTH, sanitisedAppName)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user