mirror of
https://github.com/gregtwallace/apc-p15-tool.git
synced 2025-07-08 16:56:34 +00:00
add install function
install pem files directly to an apc ups
This commit is contained in:
parent
4c154b2f27
commit
a089d12c87
9 changed files with 392 additions and 51 deletions
pkg/app
|
@ -2,6 +2,7 @@ package app
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"github.com/peterbourgon/ff/v4"
|
||||
)
|
||||
|
@ -18,18 +19,26 @@ type config struct {
|
|||
certPemFilePath *string
|
||||
outFilePath *string
|
||||
}
|
||||
install struct {
|
||||
keyPemFilePath *string
|
||||
certPemFilePath *string
|
||||
hostAndPort *string
|
||||
fingerprint *string
|
||||
username *string
|
||||
password *string
|
||||
}
|
||||
}
|
||||
|
||||
// getConfig returns the app's configuration from either command line args,
|
||||
// or environment variables
|
||||
func (app *app) getConfig() {
|
||||
func (app *app) getConfig() error {
|
||||
// make config
|
||||
cfg := &config{}
|
||||
|
||||
// commands:
|
||||
// create
|
||||
// install
|
||||
// TODO:
|
||||
// upload
|
||||
// unpack (both key & key+cert)
|
||||
|
||||
// apc-p15-tool -- root command
|
||||
|
@ -61,7 +70,33 @@ func (app *app) getConfig() {
|
|||
|
||||
rootCmd.Subcommands = append(rootCmd.Subcommands, createCmd)
|
||||
|
||||
// set app cmd & cfg
|
||||
app.cmd = rootCmd
|
||||
// install -- subcommand
|
||||
installFlags := ff.NewFlagSet("install").SetParent(rootFlags)
|
||||
|
||||
cfg.install.keyPemFilePath = installFlags.StringLong("keyfile", "", "path and filename of the rsa-2048 key in pem format")
|
||||
cfg.install.certPemFilePath = installFlags.StringLong("certfile", "", "path and filename of the certificate in pem format")
|
||||
cfg.install.hostAndPort = installFlags.StringLong("apchost", "", "hostname:port of the apc ups to install the certificate on")
|
||||
cfg.install.fingerprint = installFlags.StringLong("fingerprint", "", "the SHA256 fingerprint value of the ups' ssh server")
|
||||
cfg.install.username = installFlags.StringLong("username", "", "username to login to the apc ups")
|
||||
cfg.install.password = installFlags.StringLong("password", "", "password to login to the apc ups")
|
||||
|
||||
installCmd := &ff.Command{
|
||||
Name: "install",
|
||||
Usage: "apc-p15-tool upload --keyfile key.pem --certfile cert.pem --apchost example.com:22 --fingerprint 123abc --username apc --password test",
|
||||
ShortHelp: "install the specified key and cert pem files on an apc ups (they will be converted to a comaptible p15 file)",
|
||||
Flags: installFlags,
|
||||
Exec: app.cmdInstall,
|
||||
}
|
||||
|
||||
rootCmd.Subcommands = append(rootCmd.Subcommands, installCmd)
|
||||
|
||||
// set cfg & parse
|
||||
app.config = cfg
|
||||
app.cmd = rootCmd
|
||||
err := app.cmd.Parse(os.Args[1:], ff.WithEnvVarPrefix(environmentVarPrefix))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue