1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

Started with upload processor.

This commit is contained in:
Sascha L. Teichmann 2021-12-07 12:12:52 +01:00
parent 19b4f1dfb2
commit f069593f87

View file

@ -7,6 +7,7 @@ import (
"github.com/jessevdk/go-flags" "github.com/jessevdk/go-flags"
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"golang.org/x/crypto/bcrypt"
"golang.org/x/crypto/ssh/terminal" "golang.org/x/crypto/ssh/terminal"
) )
@ -21,12 +22,44 @@ type options struct {
PassphraseInteractive bool `short:"I" long:"passphrase-interacive" description:"Enter passphrase interactively" no-ini:"true"` PassphraseInteractive bool `short:"I" long:"passphrase-interacive" description:"Enter passphrase interactively" no-ini:"true"`
} }
type processor struct {
opts *options
cachedAuth string
}
var iniPaths = []string{ var iniPaths = []string{
"~/.config/csaf/uploader.ini", "~/.config/csaf/uploader.ini",
"~/.csaf_uploader.ini", "~/.csaf_uploader.ini",
"csaf_uploader.ini", "csaf_uploader.ini",
} }
func newProcessor(opts *options) (*processor, error) {
p := processor{
opts: opts,
}
// pre-calc the auth header
if opts.Password != nil {
hash, err := bcrypt.GenerateFromPassword(
[]byte(*opts.Password), bcrypt.DefaultCost)
if err != nil {
return nil, err
}
p.cachedAuth = string(hash)
}
return &p, nil
}
func (p *processor) create() error {
// TODO: Implement me!
return nil
}
func (p *processor) process(filename string) error {
// TODO: Implement me!
return nil
}
func findIniFile() string { func findIniFile() string {
for _, f := range iniPaths { for _, f := range iniPaths {
name, err := homedir.Expand(f) name, err := homedir.Expand(f)
@ -102,15 +135,15 @@ func main() {
check(readInteractive("Enter OpenPGP passphrase: ", &opts.Passphrase)) check(readInteractive("Enter OpenPGP passphrase: ", &opts.Passphrase))
} }
if opts.Password != nil { p, err := newProcessor(&opts)
log.Printf("password: '%s'\n", *opts.Password) check(err)
}
if opts.Passphrase != nil { if opts.Action == "create" {
log.Printf("passphrase: '%s'\n", *opts.Passphrase) check(p.create())
return
} }
for _, arg := range args { for _, arg := range args {
log.Printf("arg: %s\n", arg) check(p.process(arg))
} }
} }