gofmt across the baord

Signed-off-by: Nathan McCauley <nathan.mccauley@docker.com>
This commit is contained in:
Nathan McCauley 2015-07-19 17:33:23 -07:00
parent de6f65b7e7
commit 38fe6bd45b
14 changed files with 32 additions and 47 deletions

View File

@ -49,7 +49,7 @@ test:
pwd: $BASE_STABLE pwd: $BASE_STABLE
# VET # VET
- gvm use stable && go vet ./...: - gvm use stable && test -z "$(go tool vet -printf=false . 2>&1 | grep -v Godeps/_workspace/src/ | tee /dev/stderr)":
pwd: $BASE_STABLE pwd: $BASE_STABLE
# LINT # LINT

View File

@ -21,7 +21,7 @@ type SignedRSARootTemplate struct {
RootPem string RootPem string
} }
var passphraseRetriever = func (string, string, bool, int) (string, bool, error) { return "passphrase", false, nil} var passphraseRetriever = func(string, string, bool, int) (string, bool, error) { return "passphrase", false, nil }
const validPEMEncodedRSARoot = `LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUZLekNDQXhXZ0F3SUJBZ0lRUnlwOVFxY0pmZDNheXFkaml6OHhJREFMQmdrcWhraUc5dzBCQVFzd09ERWEKTUJnR0ExVUVDaE1SWkc5amEyVnlMbU52YlM5dWIzUmhjbmt4R2pBWUJnTlZCQU1URVdSdlkydGxjaTVqYjIwdgpibTkwWVhKNU1CNFhEVEUxTURjeE56QTJNelF5TTFvWERURTNNRGN4TmpBMk16UXlNMW93T0RFYU1CZ0dBMVVFCkNoTVJaRzlqYTJWeUxtTnZiUzl1YjNSaGNua3hHakFZQmdOVkJBTVRFV1J2WTJ0bGNpNWpiMjB2Ym05MFlYSjUKTUlJQ0lqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FnOEFNSUlDQ2dLQ0FnRUFvUWZmcnpzWW5zSDh2R2Y0Smg1NQpDajV3cmpVR3pEL3NIa2FGSHB0ako2VG9KR0p2NXlNQVB4enlJbnU1c0lvR0xKYXBuWVZCb0FVMFlnSTlxbEFjCllBNlN4YVN3Z202cnB2bW5sOFFuMHFjNmdlcjNpbnBHYVVK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RZQW5jTE5KUlQ3SFpCTVBHU3daCjBQTkp1Z2xubHIzc3JWemRXMWR6MnhRamR2THd4eTZtTlVGNnJiUUJXQT09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K`

View File

@ -44,10 +44,9 @@ func init() {
func passphraseRetriever(keyName, alias string, createNew bool, attempts int) (passphrase string, giveup bool, err error) { func passphraseRetriever(keyName, alias string, createNew bool, attempts int) (passphrase string, giveup bool, err error) {
//TODO(mccauley) Read from config once we have locked keys in notary-signer //TODO(mccauley) Read from config once we have locked keys in notary-signer
return "", false, nil; return "", false, nil
} }
func main() { func main() {
flag.Usage = usage flag.Usage = usage
flag.Parse() flag.Parse()

View File

@ -86,10 +86,9 @@ func init() {
fatalf("could not create Certificate X509FileStore: %v", err) fatalf("could not create Certificate X509FileStore: %v", err)
} }
//TODO(mccauley): Appears unused? Remove it? Or is it here for early failure? //TODO(mccauley): Appears unused? Remove it? Or is it here for early failure?
privKeyStore, err = trustmanager.NewKeyFileStore(finalPrivDir, privKeyStore, err = trustmanager.NewKeyFileStore(finalPrivDir,
func (string, string, bool, int) (string, bool, error) { return "", false, nil}) func(string, string, bool, int) (string, bool, error) { return "", false, nil })
if err != nil { if err != nil {
fatalf("could not create KeyFileStore: %v", err) fatalf("could not create KeyFileStore: %v", err)
} }

View File

@ -14,9 +14,9 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/term" "github.com/docker/docker/pkg/term"
notaryclient "github.com/docker/notary/client" notaryclient "github.com/docker/notary/client"
"github.com/docker/notary/trustmanager"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/docker/notary/trustmanager"
) )
// FIXME: This should not be hardcoded // FIXME: This should not be hardcoded
@ -272,23 +272,17 @@ func verify(cmd *cobra.Command, args []string) {
return return
} }
func getNotaryPassphraseRetriever() (trustmanager.PassphraseRetriever) { func getNotaryPassphraseRetriever() trustmanager.PassphraseRetriever {
userEnteredTargetsSnapshotsPass := false userEnteredTargetsSnapshotsPass := false
targetsSnapshotsPass := "" targetsSnapshotsPass := ""
return func(keyID string, alias string, createNew bool, numAttempts int) (string, bool, error) { return func(keyID string, alias string, createNew bool, numAttempts int) (string, bool, error) {
fmt.Printf("userEnteredTargetsSnapshotsPass: %s\n", userEnteredTargetsSnapshotsPass)
fmt.Printf("targetsSnapshotsPass: %s\n", targetsSnapshotsPass)
fmt.Printf("keyID: %s\n", keyID)
fmt.Printf("alias: %s\n", alias)
fmt.Printf("numAttempts: %s\n", numAttempts)
if numAttempts == 0 && userEnteredTargetsSnapshotsPass && (alias == "snapshot" || alias == "targets") { if numAttempts == 0 && userEnteredTargetsSnapshotsPass && (alias == "snapshot" || alias == "targets") {
fmt.Println("return cached value") fmt.Println("return cached value")
return targetsSnapshotsPass, false, nil; return targetsSnapshotsPass, false, nil
} }
if (numAttempts > 3 && !createNew) { if numAttempts > 3 && !createNew {
return "", true, errors.New("Too many attempts") return "", true, errors.New("Too many attempts")
} }
@ -303,7 +297,7 @@ func getNotaryPassphraseRetriever() (trustmanager.PassphraseRetriever) {
if createNew { if createNew {
fmt.Printf("Enter passphrase for new %s key with id %s: ", alias, keyID) fmt.Printf("Enter passphrase for new %s key with id %s: ", alias, keyID)
}else { } else {
fmt.Printf("Enter key passphrase for %s key with id %s: ", alias, keyID) fmt.Printf("Enter key passphrase for %s key with id %s: ", alias, keyID)
} }
@ -320,7 +314,7 @@ func getNotaryPassphraseRetriever() (trustmanager.PassphraseRetriever) {
userEnteredTargetsSnapshotsPass = true userEnteredTargetsSnapshotsPass = true
targetsSnapshotsPass = retPass targetsSnapshotsPass = retPass
} }
return string(passphrase), false, nil; return string(passphrase), false, nil
} }
if len(passphrase) < 8 { if len(passphrase) < 8 {

View File

@ -23,8 +23,8 @@ const (
// CryptoService implements Sign and Create, holding a specific GUN and keystore to // CryptoService implements Sign and Create, holding a specific GUN and keystore to
// operate on // operate on
type CryptoService struct { type CryptoService struct {
gun string gun string
keyStore trustmanager.KeyStore keyStore trustmanager.KeyStore
} }
// NewCryptoService returns an instance of CryptoService // NewCryptoService returns an instance of CryptoService

View File

@ -17,8 +17,7 @@ func TestCryptoService(t *testing.T) {
} }
} }
var passphraseretriever = func (string, string, bool, int) (string, bool, error) { return "", false, nil} var passphraseretriever = func(string, string, bool, int) (string, bool, error) { return "", false, nil }
func testCryptoService(t *testing.T, keyAlgo data.KeyAlgorithm, verifier signed.Verifier) { func testCryptoService(t *testing.T, keyAlgo data.KeyAlgorithm, verifier signed.Verifier) {
content := []byte("this is a secret") content := []byte("this is a secret")

View File

@ -9,8 +9,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
var passphraseRetriever = func (string, string, bool, int) (string, bool, error) { return "passphrase", false, nil} var passphraseRetriever = func(string, string, bool, int) (string, bool, error) { return "passphrase", false, nil }
func TestUnlockedSigner(t *testing.T) { func TestUnlockedSigner(t *testing.T) {
privKey, err := trustmanager.GenerateECDSAKey(rand.Reader) privKey, err := trustmanager.GenerateECDSAKey(rand.Reader)

View File

@ -11,9 +11,9 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"fmt"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/notary/trustmanager" "github.com/docker/notary/trustmanager"
"fmt"
) )
var ( var (
@ -37,7 +37,7 @@ var (
// ExportRootKey exports the specified root key to an io.Writer in PEM format. // ExportRootKey exports the specified root key to an io.Writer in PEM format.
// The key's existing encryption is preserved. // The key's existing encryption is preserved.
func (km *KeyStoreManager) ExportRootKey(dest io.Writer, keyID string) error { func (km *KeyStoreManager) ExportRootKey(dest io.Writer, keyID string) error {
pemBytes, err := km.rootKeyStore.Get(keyID+"_root") pemBytes, err := km.rootKeyStore.Get(keyID + "_root")
if err != nil { if err != nil {
return err return err
} }
@ -293,7 +293,6 @@ func (km *KeyStoreManager) ExportKeysByGUN(dest io.Writer, gun string, passphras
privNonRootKeysSubdir := filepath.Join(privDir, nonRootKeysSubdir) privNonRootKeysSubdir := filepath.Join(privDir, nonRootKeysSubdir)
// Create temporary keystore to use as a staging area // Create temporary keystore to use as a staging area
tempNonRootKeysPath := filepath.Join(tempBaseDir, privNonRootKeysSubdir) tempNonRootKeysPath := filepath.Join(tempBaseDir, privNonRootKeysSubdir)
tempNonRootKeyStore, err := trustmanager.NewKeyFileStore(tempNonRootKeysPath, passphraseRetriever) tempNonRootKeyStore, err := trustmanager.NewKeyFileStore(tempNonRootKeysPath, passphraseRetriever)

View File

@ -36,10 +36,11 @@ func createTestServer(t *testing.T) (*httptest.Server, *http.ServeMux) {
return ts, mux return ts, mux
} }
var oldPassphrase = "oldPassphrase" var oldPassphrase = "oldPassphrase"
var exportPassphrase = "exportPassphrase" var exportPassphrase = "exportPassphrase"
var oldPassphraseRetriever = func (string, string, bool, int) (string, bool, error) { return oldPassphrase, false, nil} var oldPassphraseRetriever = func(string, string, bool, int) (string, bool, error) { return oldPassphrase, false, nil }
var newPassphraseRetriever = func (string, string, bool, int) (string, bool, error) { return exportPassphrase, false, nil} var newPassphraseRetriever = func(string, string, bool, int) (string, bool, error) { return exportPassphrase, false, nil }
func TestImportExportZip(t *testing.T) { func TestImportExportZip(t *testing.T) {
gun := "docker.com/notary" gun := "docker.com/notary"

View File

@ -29,7 +29,7 @@ var (
createKeyBaseURL string createKeyBaseURL string
keyInfoBaseURL string keyInfoBaseURL string
signBaseURL string signBaseURL string
passphraseRetriever = func (string, string, bool, int) (string, bool, error) { return "passphrase", false, nil} passphraseRetriever = func(string, string, bool, int) (string, bool, error) { return "passphrase", false, nil }
) )
func SetupHSMEnv(t *testing.T) (*pkcs11.Ctx, pkcs11.SessionHandle) { func SetupHSMEnv(t *testing.T) (*pkcs11.Ctx, pkcs11.SessionHandle) {

View File

@ -25,11 +25,10 @@ var (
grpcServer *grpc.Server grpcServer *grpc.Server
void *pb.Void void *pb.Void
pr trustmanager.PassphraseRetriever pr trustmanager.PassphraseRetriever
) )
func init() { func init() {
pr = func (string, string, bool, int) (string, bool, error) { return "passphrase", false, nil} pr = func(string, string, bool, int) (string, bool, error) { return "passphrase", false, nil }
keyStore := trustmanager.NewKeyMemoryStore(pr) keyStore := trustmanager.NewKeyMemoryStore(pr)
cryptoService := cryptoservice.NewCryptoService("", keyStore) cryptoService := cryptoservice.NewCryptoService("", keyStore)
cryptoServices := signer.CryptoServiceIndex{data.ED25519Key: cryptoService, data.RSAKey: cryptoService, data.ECDSAKey: cryptoService} cryptoServices := signer.CryptoServiceIndex{data.ED25519Key: cryptoService, data.RSAKey: cryptoService, data.ECDSAKey: cryptoService}

View File

@ -4,13 +4,13 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/endophage/gotuf/data"
"errors" "errors"
"fmt" "fmt"
"github.com/endophage/gotuf/data"
) )
const ( const (
keyExtension = "key" keyExtension = "key"
aliasExtension = "alias" aliasExtension = "alias"
) )
@ -103,7 +103,6 @@ func (s *KeyMemoryStore) GetKeyAlias(name string) (string, error) {
return getKeyAlias(s, name) return getKeyAlias(s, name)
} }
// ListKeys returns a list of unique PublicKeys present on the KeyFileStore. // ListKeys returns a list of unique PublicKeys present on the KeyFileStore.
// There might be symlinks associating Certificate IDs to Public Keys, so this // There might be symlinks associating Certificate IDs to Public Keys, so this
// method only returns the IDs that aren't symlinks // method only returns the IDs that aren't symlinks
@ -116,7 +115,6 @@ func (s *KeyMemoryStore) RemoveKey(name string) error {
return removeKey(s, name) return removeKey(s, name)
} }
func addKey(s LimitedFileStore, passphraseRetriever PassphraseRetriever, name, alias string, privKey data.PrivateKey) error { func addKey(s LimitedFileStore, passphraseRetriever PassphraseRetriever, name, alias string, privKey data.PrivateKey) error {
pemPrivKey, err := KeyToPEM(privKey) pemPrivKey, err := KeyToPEM(privKey)
if err != nil { if err != nil {
@ -148,7 +146,7 @@ func addKey(s LimitedFileStore, passphraseRetriever PassphraseRetriever, name, a
} }
} }
return s.Add(name + "_" + alias, pemPrivKey) return s.Add(name+"_"+alias, pemPrivKey)
} }
func getKeyAlias(s LimitedFileStore, keyID string) (string, error) { func getKeyAlias(s LimitedFileStore, keyID string) (string, error) {
@ -160,8 +158,8 @@ func getKeyAlias(s LimitedFileStore, keyID string) (string, error) {
filename := file[lastPathSeparator+1:] filename := file[lastPathSeparator+1:]
if strings.HasPrefix(filename, name) { if strings.HasPrefix(filename, name) {
aliasPlusDotKey := strings.TrimPrefix(filename, name + "_") aliasPlusDotKey := strings.TrimPrefix(filename, name+"_")
retVal := strings.TrimSuffix(aliasPlusDotKey, "." + keyExtension) retVal := strings.TrimSuffix(aliasPlusDotKey, "."+keyExtension)
return retVal, nil return retVal, nil
} }
} }
@ -216,7 +214,7 @@ func listKeys(s LimitedFileStore) []string {
for _, f := range s.ListFiles(false) { for _, f := range s.ListFiles(false) {
keyID := strings.TrimSpace(strings.TrimSuffix(f, filepath.Ext(f))) keyID := strings.TrimSpace(strings.TrimSuffix(f, filepath.Ext(f)))
keyID = keyID[:strings.LastIndex(keyID,"_")] keyID = keyID[:strings.LastIndex(keyID, "_")]
keyIDList = append(keyIDList, keyID) keyIDList = append(keyIDList, keyID)
} }
return keyIDList return keyIDList

View File

@ -3,15 +3,15 @@ package trustmanager
import ( import (
"bytes" "bytes"
"crypto/rand" "crypto/rand"
"errors"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
"errors"
) )
var passphraseRetriever = func (keyID string, alias string, createNew bool, numAttempts int) (string, bool, error) { var passphraseRetriever = func(keyID string, alias string, createNew bool, numAttempts int) (string, bool, error) {
if numAttempts > 5 { if numAttempts > 5 {
giveup := true giveup := true
return "", giveup, errors.New("passPhraseRetriever failed after too many requests") return "", giveup, errors.New("passPhraseRetriever failed after too many requests")
@ -46,7 +46,7 @@ func TestAddKey(t *testing.T) {
} }
// Call the AddKey function // Call the AddKey function
err = store.AddKey(testName, "root", privKey) err = store.AddKey(testName, "root", privKey)
if err != nil { if err != nil {
t.Fatalf("failed to add file to store: %v", err) t.Fatalf("failed to add file to store: %v", err)
} }
@ -96,8 +96,7 @@ EMl3eFOJXjIch/wIesRSN+2dGOsl7neercjMh1i9RvpCwHDx/E0=
testAlias := "root" testAlias := "root"
perms := os.FileMode(0755) perms := os.FileMode(0755)
emptyPassphraseRetriever := func (string, string, bool, int) (string, bool, error) { return "", false, nil} emptyPassphraseRetriever := func(string, string, bool, int) (string, bool, error) { return "", false, nil }
// Temporary directory where test files will be created // Temporary directory where test files will be created
tempBaseDir, err := ioutil.TempDir("", "notary-test-") tempBaseDir, err := ioutil.TempDir("", "notary-test-")
@ -226,11 +225,10 @@ func TestGetDecryptedWithTamperedCipherText(t *testing.T) {
func TestGetDecryptedWithInvalidPassphrase(t *testing.T) { func TestGetDecryptedWithInvalidPassphrase(t *testing.T) {
// Make a passphraseRetriever that always returns a different passphrase in order to test // Make a passphraseRetriever that always returns a different passphrase in order to test
// decryption failure // decryption failure
a := "a" a := "a"
var invalidPassphraseRetriever = func (keyId string, alias string, createNew bool, numAttempts int) (string, bool, error) { var invalidPassphraseRetriever = func(keyId string, alias string, createNew bool, numAttempts int) (string, bool, error) {
if numAttempts > 5 { if numAttempts > 5 {
giveup := true giveup := true
return "", giveup, nil return "", giveup, nil