2021-12-06 05:08:17 +00:00
|
|
|
package actions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-12-08 19:32:10 +00:00
|
|
|
"os"
|
2021-12-06 05:08:17 +00:00
|
|
|
|
2022-01-13 17:40:15 +00:00
|
|
|
"git.t-juice.club/torjus/ezshare/certs"
|
|
|
|
"git.t-juice.club/torjus/ezshare/config"
|
2021-12-06 05:08:17 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ActionGencerts(c *cli.Context) error {
|
|
|
|
outDir := "."
|
|
|
|
if c.IsSet("out-dir") {
|
|
|
|
outDir = c.String("out-dir")
|
|
|
|
}
|
|
|
|
if !c.IsSet("hostname") {
|
|
|
|
return fmt.Errorf("--hostname required")
|
|
|
|
}
|
|
|
|
hostname := c.String("hostname")
|
|
|
|
return certs.GenAllCerts(outDir, hostname)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getConfig(c *cli.Context) (*config.Config, error) {
|
|
|
|
if c.IsSet("config") {
|
|
|
|
cfgPath := c.String("config")
|
|
|
|
return config.FromFile(cfgPath)
|
|
|
|
}
|
2021-12-08 19:32:10 +00:00
|
|
|
if val, ok := os.LookupEnv("EZSHARE_CONFIG"); ok {
|
|
|
|
return config.FromFile(val)
|
|
|
|
}
|
2021-12-06 05:08:17 +00:00
|
|
|
cfg, err := config.FromDefaultLocations()
|
|
|
|
if err == nil {
|
|
|
|
verbosePrint(c, fmt.Sprintf("Config loaded from %s", cfg.Location()))
|
|
|
|
}
|
2021-12-08 19:32:10 +00:00
|
|
|
if cfg == nil {
|
|
|
|
cfg = config.FromDefault()
|
|
|
|
}
|
|
|
|
cfg.UpdateFromEnv()
|
|
|
|
if cfg.Client.Valid() == nil || cfg.Server.Valid() == nil {
|
|
|
|
return cfg, nil
|
|
|
|
}
|
2021-12-06 05:08:17 +00:00
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func verbosePrint(c *cli.Context, message string) {
|
|
|
|
if c.Bool("verbose") {
|
|
|
|
fmt.Println(message)
|
|
|
|
}
|
|
|
|
}
|