Skip to content

Commit

Permalink
Added put-file command to enable importing file based secrets.
Browse files Browse the repository at this point in the history
Fixes #2
  • Loading branch information
wolfeidau committed Dec 24, 2015
1 parent 3d4b1db commit 11829eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cmd/unicreds/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"os"

"github.com/alecthomas/kingpin"
Expand Down Expand Up @@ -31,7 +32,12 @@ var (
cmdPut = app.Command("put", "Put a credential in the store.")
cmdPutName = cmdPut.Arg("credential", "The name of the credential to get.").Required().String()
cmdPutSecret = cmdPut.Arg("value", "The value of the credential to store.").Required().String()
cmdPutVersion = cmdPut.Arg("version", "The version to store with the credential.").Int()
cmdPutVersion = cmdPut.Arg("version", "Version to store with the credential.").Int()

cmdPutFile = app.Command("put-file", "Put a credential in the store.")
cmdPutFileName = cmdPutFile.Arg("credential", "The name of the credential to get.").Required().String()
cmdPutFileSecretPath = cmdPutFile.Arg("value", "Path to file containing the credential to store.").Required().String()
cmdPutFileVersion = cmdPutFile.Arg("version", "Version to store with the credential.").Int()

cmdDelete = app.Command("delete", "Delete a credential from the store.")
cmdDeleteName = cmdDelete.Arg("credential", "The name of the credential to get.").Required().String()
Expand Down Expand Up @@ -73,6 +79,22 @@ func main() {
printFatalError(err)
}
fmt.Printf("%s has been stored\n", *cmdPutName)
case cmdPutFile.FullCommand():
var version string
if *cmdPutFileVersion != 0 {
version = fmt.Sprintf("%d", *cmdPutFileVersion)
}

data, err := ioutil.ReadFile(*cmdPutFileSecretPath)
if err != nil {
printFatalError(err)
}

err = unicreds.PutSecret(*cmdPutFileName, string(data), version)
if err != nil {
printFatalError(err)
}
fmt.Printf("%s has been stored\n", *cmdPutFileName)
case cmdList.FullCommand():
creds, err := unicreds.ListSecrets()
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ func PutSecret(name, secret, version string) error {
}

dk, err := GenerateDataKey(KmsKey, 64)
if err != nil {
return err
}

dataKey := dk.Plaintext[:32]
hmacKey := dk.Plaintext[32:]
Expand Down

0 comments on commit 11829eb

Please sign in to comment.