Documentation ¶
Index ¶
- Variables
- func AddCommands()
- func Execute()
- func InitializeCertAuthConfig(logger log.Logger) error
- func InitializeConfig(writer io.Writer) error
- func InitializeMainConfig(logger log.Logger) error
- func InitializeNewCertConfig(logger log.Logger) error
- func InitializeServerConfig(logger log.Logger) error
Constants ¶
This section is empty.
Variables ¶
Command line args
var ( Name string ForceOverwrite bool )
Command line args
var ( SSHKey string AdminCert string CACert string TLSCert string TLSKey string DataPath string SSHListen string HTTPListen string )
Command line args
var (
ConfigPath string
)
Command line args
var InitCACmd = &cobra.Command{ Use: "init-ca", Short: "init-ca creates a new certificate authority", Long: ``, Run: func(cmd *cobra.Command, args []string) { writer := log.NewConcurrentWriter(os.Stdout) logger := log.NewLogger(writer, "init-ca") err := InitializeConfig(writer) if err != nil { return } if err := auth.CreatePkiDirectories(logger, "."); err != nil { return } pki := path.Join(".", "pki") crtFile := path.Join(pki, "ca.crt") privFile := path.Join(pki, "private", "ca.key") if !viper.GetBool("ForceOverwrite") { var files []string for _, filename := range []string{privFile, crtFile} { if _, err := os.Stat(filename); err == nil { files = append(files, filename) } } if len(files) > 0 { var input string fmt.Println("This operation will overwrite these existing files:") for _, file := range files { fmt.Println("\t", file) } fmt.Print("Are you sure you want to overwrite these files (yN)? ") fmt.Scanln(&input) if !strings.Contains(strings.ToLower(input), "y") { fmt.Println("New certificate was not created.") return } } } privatekey, err := rsa.GenerateKey(rand.Reader, viper.GetInt("Bits")) if err != nil { logger.Warn("Error generating private key") return } cert, err := auth.CreateCertificateAuthority(logger, privatekey, viper.GetInt("Years"), viper.GetString("Organization"), viper.GetString("Country"), viper.GetString("Hosts")) if err != nil { logger.Warn("Error creating CA", "err", err.Error()) return } auth.SaveCertificate(logger, cert, crtFile) auth.SavePrivateKey(logger, privatekey, privFile) }, }
InitCACmd is the kappa root command.
var KappaCmd = &cobra.Command{ Use: "kappa", Short: "Kappa is a NoSQL database centered around replicated logs and views.", Long: ``, Run: func(cmd *cobra.Command, args []string) { fmt.Println(cmd.Help()) }, }
KappaCmd is the subsilent root command.
var NewCertCmd = &cobra.Command{ Use: "new-cert", Short: "new-cert creates a new certificate", Long: ``, Run: func(cmd *cobra.Command, args []string) { writer := log.NewConcurrentWriter(os.Stdout) logger := log.NewLogger(writer, "new-cert") err := InitializeConfig(writer) if err != nil { return } if err := auth.CreatePkiDirectories(logger, "."); err != nil { return } pki := path.Join(".", "pki") reqFile := path.Join(pki, "reqs", viper.GetString("Name")+".req") privFile := path.Join(pki, "private", viper.GetString("Name")+".key") crtFile := path.Join(pki, "public", viper.GetString("Name")+".crt") if !viper.GetBool("ForceOverwrite") { var files []string for _, filename := range []string{reqFile, privFile, crtFile} { if _, err := os.Stat(filename); err == nil { files = append(files, filename) } } if len(files) > 0 { var input string fmt.Println("This operation will overwrite these existing files:") for _, file := range files { fmt.Println("\t", file) } fmt.Print("Are you sure you want to overwrite these files (yN)? ") fmt.Scanln(&input) if !strings.Contains(strings.ToLower(input), "y") { fmt.Println("New certificate was not created.") return } } } privatekey, err := rsa.GenerateKey(rand.Reader, viper.GetInt("Bits")) if err != nil { logger.Warn("Error generating private key") return } csr, req, err := auth.CreateCertificateRequest(logger, privatekey, viper.GetString("Name"), viper.GetString("Organization"), viper.GetString("Country"), viper.GetString("Hosts")) if err != nil { logger.Warn("Error creating CA", "err", err.Error()) return } crt, err := auth.CreateCertificate(logger, csr, privatekey, viper.GetInt("Years"), viper.GetString("Hosts")) if err != nil { logger.Warn("Error creating certificate", "err", err.Error()) return } auth.SaveCertificateRequest(logger, req, reqFile) auth.SavePrivateKey(logger, privatekey, privFile) auth.SaveCertificate(logger, crt, crtFile) }, }
NewCertCmd is the kappa root command.
var ServerCmd = &cobra.Command{ Use: "server", Short: "server starts the database server", Long: ``, Run: func(cmd *cobra.Command, args []string) { writer := log.NewConcurrentWriter(os.Stdout) logger := log.NewLogger(writer, "kappa") err := InitializeConfig(writer) if err != nil { return } if err := os.MkdirAll(viper.GetString("DataPath"), os.ModeDir|0655); err != nil { logger.Warn("Could not create data directory", "err", err.Error()) return } cwd, err := os.Getwd() if err != nil { logger.Error("Could not get working directory", "error", err.Error()) return } file := path.Join(cwd, viper.GetString("DataPath"), "meta.db") logger.Info("Connecting to database", "file", file) system, err := datamodel.NewSystem(file) if err != nil { logger.Error("Could not connect to database", "error", err.Error()) return } sshKeyFile := viper.GetString("SSHKey") logger.Info("Reading private key", "file", sshKeyFile) privateKey, err := auth.ReadPrivateKey(logger, sshKeyFile) if err != nil { return } adminCertFile := viper.GetString("AdminCert") logger.Info("Reading admin public key", "file", adminCertFile) cert, err := ioutil.ReadFile(adminCertFile) if err != nil { logger.Error("admin certificate could not be read", "filename", viper.GetString("AdminCert")) return } userStore, err := system.Users() if err != nil { logger.Error("could not get user store", "error", err.Error()) return } admin, err := userStore.Create("admin") if err != nil { logger.Error("error creating admin account", "error", err.Error()) return } keyRing := admin.KeyRing() fingerprint, err := keyRing.AddPublicKey(cert) if err != nil { logger.Error("admin certificate could not be added", "error", err.Error()) return } logger.Info("Added admin certificate", "fingerprint", fingerprint) rootPem, err := ioutil.ReadFile(viper.GetString("CACert")) if err != nil { logger.Error("root certificate could not be read", "filename", viper.GetString("CACert")) return } roots := x509.NewCertPool() if ok := roots.AppendCertsFromPEM(rootPem); !ok { logger.Error("failed to parse root certificate") return } sshLogger := log.NewLogger(writer, "ssh") sshServer, err := ssh.NewSSHServer(sshLogger, system, privateKey, roots) if err != nil { logger.Error("SSH Server could not be configured", "error", err.Error()) return } closer := make(chan bool) sshServer.Run(logger, closer) sig := make(chan os.Signal, 1) signal.Notify(sig, os.Interrupt, os.Kill) logger.Info("Ready to serve requests") <-sig logger.Info("Shutting down servers.") sshServer.Wait() <-closer }, }
ServerCmd is the kappa root command.
Functions ¶
func AddCommands ¶
func AddCommands()
AddCommands add all of the subcommands to the main entry point.
func InitializeCertAuthConfig ¶
InitializeCertAuthConfig sets up the command line options for creating a CA
func InitializeConfig ¶
InitializeConfig reads the configuration file and sets up the application settings via Viper.
func InitializeMainConfig ¶
InitializeMainConfig sets up the config options for the kappa command
func InitializeNewCertConfig ¶
InitializeNewCertConfig sets up the command line options for creating a new certificate
func InitializeServerConfig ¶
InitializeServerConfig sets up the config options for the database servers.
Types ¶
This section is empty.