2021-08-02 01:10:41 +00:00
|
|
|
package app
|
|
|
|
|
2021-08-28 18:13:56 +00:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"coopcloud.tech/abra/cli/internal"
|
2021-12-11 23:17:39 +00:00
|
|
|
"coopcloud.tech/abra/pkg/autocomplete"
|
2021-09-05 19:37:03 +00:00
|
|
|
"coopcloud.tech/abra/pkg/config"
|
2021-08-28 18:13:56 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
2021-08-02 01:10:41 +00:00
|
|
|
|
|
|
|
var appCheckCommand = &cli.Command{
|
2021-08-28 18:13:56 +00:00
|
|
|
Name: "check",
|
2021-09-04 23:34:56 +00:00
|
|
|
Usage: "Check if app is configured correctly",
|
|
|
|
Aliases: []string{"c"},
|
2021-08-28 18:13:56 +00:00
|
|
|
ArgsUsage: "<service>",
|
|
|
|
Action: func(c *cli.Context) error {
|
2021-09-05 21:17:35 +00:00
|
|
|
app := internal.ValidateApp(c)
|
2021-08-28 18:13:56 +00:00
|
|
|
|
2021-12-25 13:04:07 +00:00
|
|
|
envSamplePath := path.Join(config.RECIPES_DIR, app.Type, ".env.sample")
|
2021-08-28 18:13:56 +00:00
|
|
|
if _, err := os.Stat(envSamplePath); err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
2021-12-25 01:03:09 +00:00
|
|
|
logrus.Fatalf("%s does not exist?", envSamplePath)
|
2021-08-28 18:13:56 +00:00
|
|
|
}
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
envSample, err := config.ReadEnv(envSamplePath)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var missing []string
|
2021-08-31 15:17:08 +00:00
|
|
|
for k := range envSample {
|
2021-09-05 21:17:35 +00:00
|
|
|
if _, ok := app.Env[k]; !ok {
|
2021-08-28 18:13:56 +00:00
|
|
|
missing = append(missing, k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(missing) > 0 {
|
2021-08-31 15:47:16 +00:00
|
|
|
missingEnvVars := strings.Join(missing, ", ")
|
2021-09-05 21:17:35 +00:00
|
|
|
logrus.Fatalf("%s is missing %s", app.Path, missingEnvVars)
|
2021-08-28 18:13:56 +00:00
|
|
|
}
|
|
|
|
|
2021-12-25 01:03:09 +00:00
|
|
|
logrus.Infof("all necessary environment variables defined for %s", app.Name)
|
2021-08-28 18:13:56 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
2021-12-11 23:17:39 +00:00
|
|
|
BashComplete: autocomplete.AppNameComplete,
|
2021-08-02 01:10:41 +00:00
|
|
|
}
|