mirror of
https://github.com/gregtwallace/apc-p15-tool.git
synced 2025-07-04 23:36:33 +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
|
@ -1,7 +1,6 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"apc-p15-tool/pkg/pkcs15"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -29,42 +28,13 @@ func (app *app) cmdCreate(_ context.Context, args []string) error {
|
|||
}
|
||||
|
||||
// validation done
|
||||
app.logger.Infof("create: making apc p15 file from pem files")
|
||||
|
||||
// Read in PEM files
|
||||
keyPem, err := os.ReadFile(*app.config.create.keyPemFilePath)
|
||||
// make p15 file
|
||||
apcFile, err := app.pemToAPCP15(*app.config.create.keyPemFilePath, *app.config.create.certPemFilePath, "create")
|
||||
if err != nil {
|
||||
return fmt.Errorf("create: failed to read key file (%s)", err)
|
||||
return err
|
||||
}
|
||||
|
||||
certPem, err := os.ReadFile(*app.config.create.certPemFilePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create: failed to read cert file (%s)", err)
|
||||
}
|
||||
|
||||
// make p15 struct
|
||||
p15, err := pkcs15.ParsePEMToPKCS15(keyPem, certPem)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create: failed to parse pem files (%s)", err)
|
||||
}
|
||||
|
||||
app.logger.Infof("create: successfully loaded pem files")
|
||||
|
||||
// make file bytes
|
||||
p15File, err := p15.ToP15File()
|
||||
if err != nil {
|
||||
return fmt.Errorf("create: failed to make p15 file (%s)", err)
|
||||
}
|
||||
|
||||
// make header for file bytes
|
||||
apcHeader, err := makeFileHeader(p15File)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create: failed to make p15 file header (%s)", err)
|
||||
}
|
||||
|
||||
// combine header with file
|
||||
apcFile := append(apcHeader, p15File...)
|
||||
|
||||
// determine file name (should already be done by flag parsing, but avoid nil just in case)
|
||||
fileName := createDefaultOutFilePath
|
||||
if app.config.create.outFilePath != nil && *app.config.create.outFilePath != "" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue