diff --git a/client/changelist/change.go b/client/changelist/change.go index dab0ed3129..403c66cb1c 100644 --- a/client/changelist/change.go +++ b/client/changelist/change.go @@ -4,7 +4,7 @@ import ( "github.com/docker/notary/tuf/data" ) -// Scopes for TufChanges are simply the TUF roles. +// Scopes for TUFChanges are simply the TUF roles. // Unfortunately because of targets delegations, we can only // cover the base roles. const ( @@ -14,7 +14,7 @@ const ( ScopeTimestamp = "timestamp" ) -// Types for TufChanges are namespaced by the Role they +// Types for TUFChanges are namespaced by the Role they // are relevant for. The Root and Targets roles are the // only ones for which user action can cause a change, as // all changes in Snapshot and Timestamp are programmatically @@ -25,8 +25,8 @@ const ( TypeTargetsDelegation = "delegation" ) -// TufChange represents a change to a TUF repo -type TufChange struct { +// TUFChange represents a change to a TUF repo +type TUFChange struct { // Abbreviated because Go doesn't permit a field and method of the same name Actn string `json:"action"` Role string `json:"role"` @@ -35,16 +35,16 @@ type TufChange struct { Data []byte `json:"data"` } -// TufRootData represents a modification of the keys associated +// TUFRootData represents a modification of the keys associated // with a role that appears in the root.json -type TufRootData struct { +type TUFRootData struct { Keys data.KeyList `json:"keys"` RoleName string `json:"role"` } -// NewTufChange initializes a TufChange object -func NewTufChange(action string, role, changeType, changePath string, content []byte) *TufChange { - return &TufChange{ +// NewTUFChange initializes a TUFChange object +func NewTUFChange(action string, role, changeType, changePath string, content []byte) *TUFChange { + return &TUFChange{ Actn: action, Role: role, ChangeType: changeType, @@ -54,34 +54,34 @@ func NewTufChange(action string, role, changeType, changePath string, content [] } // Action return c.Actn -func (c TufChange) Action() string { +func (c TUFChange) Action() string { return c.Actn } // Scope returns c.Role -func (c TufChange) Scope() string { +func (c TUFChange) Scope() string { return c.Role } // Type returns c.ChangeType -func (c TufChange) Type() string { +func (c TUFChange) Type() string { return c.ChangeType } // Path return c.ChangePath -func (c TufChange) Path() string { +func (c TUFChange) Path() string { return c.ChangePath } // Content returns c.Data -func (c TufChange) Content() []byte { +func (c TUFChange) Content() []byte { return c.Data } -// TufDelegation represents a modification to a target delegation +// TUFDelegation represents a modification to a target delegation // this includes creating a delegations. This format is used to avoid // unexpected race conditions between humans modifying the same delegation -type TufDelegation struct { +type TUFDelegation struct { NewName string `json:"new_name,omitempty"` NewThreshold int `json:"threshold, omitempty"` AddKeys data.KeyList `json:"add_keys, omitempty"` @@ -91,8 +91,8 @@ type TufDelegation struct { ClearAllPaths bool `json:"clear_paths,omitempty"` } -// ToNewRole creates a fresh role object from the TufDelegation data -func (td TufDelegation) ToNewRole(scope string) (*data.Role, error) { +// ToNewRole creates a fresh role object from the TUFDelegation data +func (td TUFDelegation) ToNewRole(scope string) (*data.Role, error) { name := scope if td.NewName != "" { name = td.NewName diff --git a/client/changelist/change_test.go b/client/changelist/change_test.go index da10d04d4e..94ef4182fc 100644 --- a/client/changelist/change_test.go +++ b/client/changelist/change_test.go @@ -8,12 +8,12 @@ import ( "github.com/stretchr/testify/require" ) -func TestTufDelegation(t *testing.T) { +func TestTUFDelegation(t *testing.T) { cs := signed.NewEd25519() key, err := cs.Create("targets/new_name", "gun", data.ED25519Key) require.NoError(t, err) kl := data.KeyList{key} - td := TufDelegation{ + td := TUFDelegation{ NewName: "targets/new_name", NewThreshold: 1, AddKeys: kl, diff --git a/client/changelist/changelist_test.go b/client/changelist/changelist_test.go index be0a5e0d35..b2b486c9c7 100644 --- a/client/changelist/changelist_test.go +++ b/client/changelist/changelist_test.go @@ -9,7 +9,7 @@ import ( func TestMemChangelist(t *testing.T) { cl := memChangelist{} - c := NewTufChange(ActionCreate, "targets", "target", "test/targ", []byte{1}) + c := NewTUFChange(ActionCreate, "targets", "target", "test/targ", []byte{1}) err := cl.Add(c) require.Nil(t, err, "Non-nil error while adding change") @@ -36,13 +36,13 @@ func TestMemChangeIterator(t *testing.T) { require.Nil(t, err, "Non-nil error from NewIterator") require.False(t, it.HasNext(), "HasNext returns false for empty ChangeList") - c1 := NewTufChange(ActionCreate, "t1", "target1", "test/targ1", []byte{1}) + c1 := NewTUFChange(ActionCreate, "t1", "target1", "test/targ1", []byte{1}) cl.Add(c1) - c2 := NewTufChange(ActionUpdate, "t2", "target2", "test/targ2", []byte{2}) + c2 := NewTUFChange(ActionUpdate, "t2", "target2", "test/targ2", []byte{2}) cl.Add(c2) - c3 := NewTufChange(ActionUpdate, "t3", "target3", "test/targ3", []byte{3}) + c3 := NewTUFChange(ActionUpdate, "t3", "target3", "test/targ3", []byte{3}) cl.Add(c3) cs := cl.List() diff --git a/client/changelist/file_changelist.go b/client/changelist/file_changelist.go index 5ab237d82e..6874275474 100644 --- a/client/changelist/file_changelist.go +++ b/client/changelist/file_changelist.go @@ -49,9 +49,9 @@ func getFileNames(dirName string) ([]os.FileInfo, error) { return fileInfos, nil } -// Read a JSON formatted file from disk; convert to TufChange struct -func unmarshalFile(dirname string, f os.FileInfo) (*TufChange, error) { - c := &TufChange{} +// Read a JSON formatted file from disk; convert to TUFChange struct +func unmarshalFile(dirname string, f os.FileInfo) (*TUFChange, error) { + c := &TUFChange{} raw, err := ioutil.ReadFile(path.Join(dirname, f.Name())) if err != nil { return c, err diff --git a/client/changelist/file_changelist_test.go b/client/changelist/file_changelist_test.go index 1313f0bb31..eda64d1cf9 100644 --- a/client/changelist/file_changelist_test.go +++ b/client/changelist/file_changelist_test.go @@ -19,7 +19,7 @@ func TestAdd(t *testing.T) { cl, err := NewFileChangelist(tmpDir) require.Nil(t, err, "Error initializing fileChangelist") - c := NewTufChange(ActionCreate, "targets", "target", "test/targ", []byte{1}) + c := NewTUFChange(ActionCreate, "targets", "target", "test/targ", []byte{1}) err = cl.Add(c) require.Nil(t, err, "Non-nil error while adding change") @@ -73,11 +73,11 @@ func TestListOrder(t *testing.T) { cl, err := NewFileChangelist(tmpDir) require.Nil(t, err, "Error initializing fileChangelist") - c1 := NewTufChange(ActionCreate, "targets", "target", "test/targ1", []byte{1}) + c1 := NewTUFChange(ActionCreate, "targets", "target", "test/targ1", []byte{1}) err = cl.Add(c1) require.Nil(t, err, "Non-nil error while adding change") - c2 := NewTufChange(ActionCreate, "targets", "target", "test/targ2", []byte{1}) + c2 := NewTUFChange(ActionCreate, "targets", "target", "test/targ2", []byte{1}) err = cl.Add(c2) require.Nil(t, err, "Non-nil error while adding change") @@ -111,13 +111,13 @@ func TestFileChangeIterator(t *testing.T) { require.Nil(t, err, "Error initializing iterator") require.False(t, it.HasNext(), "HasNext returns false for empty ChangeList") - c1 := NewTufChange(ActionCreate, "t1", "target1", "test/targ1", []byte{1}) + c1 := NewTUFChange(ActionCreate, "t1", "target1", "test/targ1", []byte{1}) cl.Add(c1) - c2 := NewTufChange(ActionUpdate, "t2", "target2", "test/targ2", []byte{2}) + c2 := NewTUFChange(ActionUpdate, "t2", "target2", "test/targ2", []byte{2}) cl.Add(c2) - c3 := NewTufChange(ActionUpdate, "t3", "target3", "test/targ3", []byte{3}) + c3 := NewTUFChange(ActionUpdate, "t3", "target3", "test/targ3", []byte{3}) cl.Add(c3) cs := cl.List() diff --git a/client/client.go b/client/client.go index 300a46fc08..06cdf4b67a 100644 --- a/client/client.go +++ b/client/client.go @@ -314,7 +314,7 @@ func addChange(cl *changelist.FileChangelist, c changelist.Change, roles ...stri } } - changes = append(changes, changelist.NewTufChange( + changes = append(changes, changelist.NewTUFChange( c.Action(), role, c.Type(), @@ -352,7 +352,7 @@ func (r *NotaryRepository) AddTarget(target *Target, roles ...string) error { return err } - template := changelist.NewTufChange( + template := changelist.NewTUFChange( changelist.ActionCreate, "", changelist.TypeTargetsTarget, target.Name, metaJSON) return addChange(cl, template, roles...) @@ -368,7 +368,7 @@ func (r *NotaryRepository) RemoveTarget(targetName string, roles ...string) erro return err } logrus.Debugf("Removing target \"%s\"", targetName) - template := changelist.NewTufChange(changelist.ActionDelete, "", + template := changelist.NewTUFChange(changelist.ActionDelete, "", changelist.TypeTargetsTarget, targetName, nil) return addChange(cl, template, roles...) } @@ -930,7 +930,7 @@ func (r *NotaryRepository) RotateKey(role string, serverManagesKey bool) error { func (r *NotaryRepository) rootFileKeyChange(cl changelist.Changelist, role, action string, key data.PublicKey) error { kl := make(data.KeyList, 0, 1) kl = append(kl, key) - meta := changelist.TufRootData{ + meta := changelist.TUFRootData{ RoleName: role, Keys: kl, } @@ -939,7 +939,7 @@ func (r *NotaryRepository) rootFileKeyChange(cl changelist.Changelist, role, act return err } - c := changelist.NewTufChange( + c := changelist.NewTUFChange( action, changelist.ScopeRoot, changelist.TypeRootRole, diff --git a/client/client_test.go b/client/client_test.go index 926f457db1..4c4401f1e9 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -2414,7 +2414,7 @@ func TestPublishRemoveDelegationKeyFromDelegationRole(t *testing.T) { // note there is no removekeyfromdelegation yet, so here's a hack to do so newKey, err := ownerRepo.CryptoService.Create("targets/a", ownerRepo.gun, data.ECDSAKey) require.NoError(t, err) - tdJSON, err := json.Marshal(&changelist.TufDelegation{ + tdJSON, err := json.Marshal(&changelist.TUFDelegation{ NewThreshold: 1, AddKeys: data.KeyList([]data.PublicKey{newKey}), RemoveKeys: []string{aKey.ID()}, @@ -2422,7 +2422,7 @@ func TestPublishRemoveDelegationKeyFromDelegationRole(t *testing.T) { require.NoError(t, err) cl, err := changelist.NewFileChangelist(filepath.Join(ownerRepo.tufRepoPath, "changelist")) - require.NoError(t, cl.Add(changelist.NewTufChange( + require.NoError(t, cl.Add(changelist.NewTUFChange( changelist.ActionUpdate, "targets/a", changelist.TypeTargetsDelegation, @@ -3048,7 +3048,7 @@ func TestFullAddDelegationChangefileApplicable(t *testing.T) { delegationName := "targets/a" // manually create the changelist object to load multiple keys - tdJSON, err := json.Marshal(&changelist.TufDelegation{ + tdJSON, err := json.Marshal(&changelist.TUFDelegation{ NewThreshold: notary.MinThreshold, AddKeys: data.KeyList([]data.PublicKey{rootPubKey, key2}), AddPaths: []string{"abc", "123", "xyz"}, @@ -3098,7 +3098,7 @@ func TestFullRemoveDelegationChangefileApplicable(t *testing.T) { require.Len(t, targetRole.Signed.Delegations.Keys, 2) // manually create the changelist object to load multiple keys - tdJSON, err := json.Marshal(&changelist.TufDelegation{ + tdJSON, err := json.Marshal(&changelist.TUFDelegation{ RemoveKeys: []string{key2CanonicalID}, RemovePaths: []string{"abc", "123"}, }) diff --git a/client/delegations.go b/client/delegations.go index c15551015d..5925466e2a 100644 --- a/client/delegations.go +++ b/client/delegations.go @@ -50,7 +50,7 @@ func (r *NotaryRepository) AddDelegationRoleAndKeys(name string, delegationKeys name, notary.MinThreshold, len(delegationKeys)) // Defaulting to threshold of 1, since we don't allow for larger thresholds at the moment. - tdJSON, err := json.Marshal(&changelist.TufDelegation{ + tdJSON, err := json.Marshal(&changelist.TUFDelegation{ NewThreshold: notary.MinThreshold, AddKeys: data.KeyList(delegationKeys), }) @@ -78,7 +78,7 @@ func (r *NotaryRepository) AddDelegationPaths(name string, paths []string) error logrus.Debugf(`Adding %s paths to delegation %s\n`, paths, name) - tdJSON, err := json.Marshal(&changelist.TufDelegation{ + tdJSON, err := json.Marshal(&changelist.TUFDelegation{ AddPaths: paths, }) if err != nil { @@ -141,7 +141,7 @@ func (r *NotaryRepository) RemoveDelegationPaths(name string, paths []string) er logrus.Debugf(`Removing %s paths from delegation "%s"\n`, paths, name) - tdJSON, err := json.Marshal(&changelist.TufDelegation{ + tdJSON, err := json.Marshal(&changelist.TUFDelegation{ RemovePaths: paths, }) if err != nil { @@ -169,7 +169,7 @@ func (r *NotaryRepository) RemoveDelegationKeys(name string, keyIDs []string) er logrus.Debugf(`Removing %s keys from delegation "%s"\n`, keyIDs, name) - tdJSON, err := json.Marshal(&changelist.TufDelegation{ + tdJSON, err := json.Marshal(&changelist.TUFDelegation{ RemoveKeys: keyIDs, }) if err != nil { @@ -195,7 +195,7 @@ func (r *NotaryRepository) ClearDelegationPaths(name string) error { logrus.Debugf(`Removing all paths from delegation "%s"\n`, name) - tdJSON, err := json.Marshal(&changelist.TufDelegation{ + tdJSON, err := json.Marshal(&changelist.TUFDelegation{ ClearAllPaths: true, }) if err != nil { @@ -206,8 +206,8 @@ func (r *NotaryRepository) ClearDelegationPaths(name string) error { return addChange(cl, template, name) } -func newUpdateDelegationChange(name string, content []byte) *changelist.TufChange { - return changelist.NewTufChange( +func newUpdateDelegationChange(name string, content []byte) *changelist.TUFChange { + return changelist.NewTUFChange( changelist.ActionUpdate, name, changelist.TypeTargetsDelegation, @@ -216,8 +216,8 @@ func newUpdateDelegationChange(name string, content []byte) *changelist.TufChang ) } -func newCreateDelegationChange(name string, content []byte) *changelist.TufChange { - return changelist.NewTufChange( +func newCreateDelegationChange(name string, content []byte) *changelist.TUFChange { + return changelist.NewTUFChange( changelist.ActionCreate, name, changelist.TypeTargetsDelegation, @@ -226,8 +226,8 @@ func newCreateDelegationChange(name string, content []byte) *changelist.TufChang ) } -func newDeleteDelegationChange(name string, content []byte) *changelist.TufChange { - return changelist.NewTufChange( +func newDeleteDelegationChange(name string, content []byte) *changelist.TUFChange { + return changelist.NewTUFChange( changelist.ActionDelete, name, changelist.TypeTargetsDelegation, diff --git a/client/helpers.go b/client/helpers.go index cd5cd1c6cb..495c8cab3f 100644 --- a/client/helpers.go +++ b/client/helpers.go @@ -73,7 +73,7 @@ func applyTargetsChange(repo *tuf.Repo, c changelist.Change) error { func changeTargetsDelegation(repo *tuf.Repo, c changelist.Change) error { switch c.Action() { case changelist.ActionCreate: - td := changelist.TufDelegation{} + td := changelist.TUFDelegation{} err := json.Unmarshal(c.Content(), &td) if err != nil { return err @@ -87,7 +87,7 @@ func changeTargetsDelegation(repo *tuf.Repo, c changelist.Change) error { } return repo.UpdateDelegationPaths(c.Scope(), td.AddPaths, []string{}, false) case changelist.ActionUpdate: - td := changelist.TufDelegation{} + td := changelist.TUFDelegation{} err := json.Unmarshal(c.Content(), &td) if err != nil { return err @@ -175,7 +175,7 @@ func applyRootRoleChange(repo *tuf.Repo, c changelist.Change) error { switch c.Action() { case changelist.ActionCreate: // replaces all keys for a role - d := &changelist.TufRootData{} + d := &changelist.TUFRootData{} err := json.Unmarshal(c.Content(), d) if err != nil { return err diff --git a/client/helpers_test.go b/client/helpers_test.go index 38f856ea51..0efe5d4d38 100644 --- a/client/helpers_test.go +++ b/client/helpers_test.go @@ -26,7 +26,7 @@ func TestApplyTargetsChange(t *testing.T) { fjson, err := json.Marshal(f) require.NoError(t, err) - addChange := &changelist.TufChange{ + addChange := &changelist.TUFChange{ Actn: changelist.ActionCreate, Role: changelist.ScopeTargets, ChangeType: "target", @@ -37,7 +37,7 @@ func TestApplyTargetsChange(t *testing.T) { require.NoError(t, err) require.NotNil(t, repo.Targets["targets"].Signed.Targets["latest"]) - removeChange := &changelist.TufChange{ + removeChange := &changelist.TUFChange{ Actn: changelist.ActionDelete, Role: changelist.ScopeTargets, ChangeType: "target", @@ -67,14 +67,14 @@ func TestApplyAddTargetTwice(t *testing.T) { require.NoError(t, err) cl := changelist.NewMemChangelist() - require.NoError(t, cl.Add(&changelist.TufChange{ + require.NoError(t, cl.Add(&changelist.TUFChange{ Actn: changelist.ActionCreate, Role: changelist.ScopeTargets, ChangeType: "target", ChangePath: "latest", Data: fjson, })) - require.NoError(t, cl.Add(&changelist.TufChange{ + require.NoError(t, cl.Add(&changelist.TUFChange{ Actn: changelist.ActionCreate, Role: changelist.ScopeTargets, ChangeType: "target", @@ -86,7 +86,7 @@ func TestApplyAddTargetTwice(t *testing.T) { require.Len(t, repo.Targets["targets"].Signed.Targets, 1) require.NotEmpty(t, repo.Targets["targets"].Signed.Targets["latest"]) - require.NoError(t, applyTargetsChange(repo, &changelist.TufChange{ + require.NoError(t, applyTargetsChange(repo, &changelist.TUFChange{ Actn: changelist.ActionCreate, Role: changelist.ScopeTargets, ChangeType: "target", @@ -113,7 +113,7 @@ func TestApplyChangelist(t *testing.T) { require.NoError(t, err) cl := changelist.NewMemChangelist() - addChange := &changelist.TufChange{ + addChange := &changelist.TUFChange{ Actn: changelist.ActionCreate, Role: changelist.ScopeTargets, ChangeType: "target", @@ -127,7 +127,7 @@ func TestApplyChangelist(t *testing.T) { cl.Clear("") - removeChange := &changelist.TufChange{ + removeChange := &changelist.TUFChange{ Actn: changelist.ActionDelete, Role: changelist.ScopeTargets, ChangeType: "target", @@ -157,7 +157,7 @@ func TestApplyChangelistMulti(t *testing.T) { require.NoError(t, err) cl := changelist.NewMemChangelist() - addChange := &changelist.TufChange{ + addChange := &changelist.TUFChange{ Actn: changelist.ActionCreate, Role: changelist.ScopeTargets, ChangeType: "target", @@ -165,7 +165,7 @@ func TestApplyChangelistMulti(t *testing.T) { Data: fjson, } - removeChange := &changelist.TufChange{ + removeChange := &changelist.TUFChange{ Actn: changelist.ActionDelete, Role: changelist.ScopeTargets, ChangeType: "target", @@ -191,7 +191,7 @@ func TestApplyTargetsDelegationCreateDelete(t *testing.T) { // create delegation kl := data.KeyList{newKey} - td := &changelist.TufDelegation{ + td := &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, AddPaths: []string{"level1"}, @@ -200,7 +200,7 @@ func TestApplyTargetsDelegationCreateDelete(t *testing.T) { tdJSON, err := json.Marshal(td) require.NoError(t, err) - ch := changelist.NewTufChange( + ch := changelist.NewTUFChange( changelist.ActionCreate, "targets/level1", changelist.TypeTargetsDelegation, @@ -225,13 +225,13 @@ func TestApplyTargetsDelegationCreateDelete(t *testing.T) { require.Equal(t, "level1", role.Paths[0]) // delete delegation - td = &changelist.TufDelegation{ + td = &changelist.TUFDelegation{ RemoveKeys: []string{newKey.ID()}, } tdJSON, err = json.Marshal(td) require.NoError(t, err) - ch = changelist.NewTufChange( + ch = changelist.NewTUFChange( changelist.ActionDelete, "targets/level1", changelist.TypeTargetsDelegation, @@ -255,7 +255,7 @@ func TestApplyTargetsDelegationCreate2SharedKey(t *testing.T) { // create first delegation kl := data.KeyList{newKey} - td := &changelist.TufDelegation{ + td := &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, AddPaths: []string{"level1"}, @@ -264,7 +264,7 @@ func TestApplyTargetsDelegationCreate2SharedKey(t *testing.T) { tdJSON, err := json.Marshal(td) require.NoError(t, err) - ch := changelist.NewTufChange( + ch := changelist.NewTUFChange( changelist.ActionCreate, "targets/level1", changelist.TypeTargetsDelegation, @@ -277,7 +277,7 @@ func TestApplyTargetsDelegationCreate2SharedKey(t *testing.T) { // create second delegation kl = data.KeyList{newKey} - td = &changelist.TufDelegation{ + td = &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, AddPaths: []string{"level2"}, @@ -286,7 +286,7 @@ func TestApplyTargetsDelegationCreate2SharedKey(t *testing.T) { tdJSON, err = json.Marshal(td) require.NoError(t, err) - ch = changelist.NewTufChange( + ch = changelist.NewTUFChange( changelist.ActionCreate, "targets/level2", changelist.TypeTargetsDelegation, @@ -314,12 +314,12 @@ func TestApplyTargetsDelegationCreate2SharedKey(t *testing.T) { require.Equal(t, "level2", role2.Paths[0]) // delete one delegation, ensure shared key remains - td = &changelist.TufDelegation{ + td = &changelist.TUFDelegation{ RemoveKeys: []string{newKey.ID()}, } tdJSON, err = json.Marshal(td) require.NoError(t, err) - ch = changelist.NewTufChange( + ch = changelist.NewTUFChange( changelist.ActionDelete, "targets/level1", changelist.TypeTargetsDelegation, @@ -334,7 +334,7 @@ func TestApplyTargetsDelegationCreate2SharedKey(t *testing.T) { require.Len(t, tgts.Signed.Delegations.Keys, 1) // delete other delegation, ensure key cleaned up - ch = changelist.NewTufChange( + ch = changelist.NewTUFChange( changelist.ActionDelete, "targets/level2", changelist.TypeTargetsDelegation, @@ -358,7 +358,7 @@ func TestApplyTargetsDelegationCreateEdit(t *testing.T) { // create delegation kl := data.KeyList{newKey} - td := &changelist.TufDelegation{ + td := &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, AddPaths: []string{"level1"}, @@ -367,7 +367,7 @@ func TestApplyTargetsDelegationCreateEdit(t *testing.T) { tdJSON, err := json.Marshal(td) require.NoError(t, err) - ch := changelist.NewTufChange( + ch := changelist.NewTUFChange( changelist.ActionCreate, "targets/level1", changelist.TypeTargetsDelegation, @@ -383,7 +383,7 @@ func TestApplyTargetsDelegationCreateEdit(t *testing.T) { require.NoError(t, err) kl = data.KeyList{newKey2} - td = &changelist.TufDelegation{ + td = &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, RemoveKeys: []string{newKey.ID()}, @@ -392,7 +392,7 @@ func TestApplyTargetsDelegationCreateEdit(t *testing.T) { tdJSON, err = json.Marshal(td) require.NoError(t, err) - ch = changelist.NewTufChange( + ch = changelist.NewTUFChange( changelist.ActionUpdate, "targets/level1", changelist.TypeTargetsDelegation, @@ -426,7 +426,7 @@ func TestApplyTargetsDelegationEditNonExisting(t *testing.T) { // create delegation kl := data.KeyList{newKey} - td := &changelist.TufDelegation{ + td := &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, AddPaths: []string{"level1"}, @@ -435,7 +435,7 @@ func TestApplyTargetsDelegationEditNonExisting(t *testing.T) { tdJSON, err := json.Marshal(td) require.NoError(t, err) - ch := changelist.NewTufChange( + ch := changelist.NewTUFChange( changelist.ActionUpdate, "targets/level1", changelist.TypeTargetsDelegation, @@ -457,7 +457,7 @@ func TestApplyTargetsDelegationCreateAlreadyExisting(t *testing.T) { // create delegation kl := data.KeyList{newKey} - td := &changelist.TufDelegation{ + td := &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, AddPaths: []string{"level1"}, @@ -466,7 +466,7 @@ func TestApplyTargetsDelegationCreateAlreadyExisting(t *testing.T) { tdJSON, err := json.Marshal(td) require.NoError(t, err) - ch := changelist.NewTufChange( + ch := changelist.NewTUFChange( changelist.ActionCreate, "targets/level1", changelist.TypeTargetsDelegation, @@ -484,7 +484,7 @@ func TestApplyTargetsDelegationCreateAlreadyExisting(t *testing.T) { // create delegation kl = data.KeyList{extraKey} - td = &changelist.TufDelegation{ + td = &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, AddPaths: []string{"level1"}, @@ -493,7 +493,7 @@ func TestApplyTargetsDelegationCreateAlreadyExisting(t *testing.T) { tdJSON, err = json.Marshal(td) require.NoError(t, err) - ch = changelist.NewTufChange( + ch = changelist.NewTUFChange( changelist.ActionCreate, "targets/level1", changelist.TypeTargetsDelegation, @@ -519,7 +519,7 @@ func TestApplyTargetsDelegationAlreadyExistingMergePaths(t *testing.T) { // create delegation kl := data.KeyList{newKey} - td := &changelist.TufDelegation{ + td := &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, AddPaths: []string{"level1"}, @@ -528,7 +528,7 @@ func TestApplyTargetsDelegationAlreadyExistingMergePaths(t *testing.T) { tdJSON, err := json.Marshal(td) require.NoError(t, err) - ch := changelist.NewTufChange( + ch := changelist.NewTUFChange( changelist.ActionCreate, "targets/level1", changelist.TypeTargetsDelegation, @@ -547,7 +547,7 @@ func TestApplyTargetsDelegationAlreadyExistingMergePaths(t *testing.T) { tdJSON, err = json.Marshal(td) require.NoError(t, err) - ch = changelist.NewTufChange( + ch = changelist.NewTUFChange( changelist.ActionCreate, "targets/level1", changelist.TypeTargetsDelegation, @@ -575,7 +575,7 @@ func TestApplyTargetsDelegationInvalidRole(t *testing.T) { // create delegation kl := data.KeyList{newKey} - td := &changelist.TufDelegation{ + td := &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, AddPaths: []string{"level1"}, @@ -584,7 +584,7 @@ func TestApplyTargetsDelegationInvalidRole(t *testing.T) { tdJSON, err := json.Marshal(td) require.NoError(t, err) - ch := changelist.NewTufChange( + ch := changelist.NewTUFChange( changelist.ActionCreate, "bad role", changelist.TypeTargetsDelegation, @@ -605,7 +605,7 @@ func TestApplyTargetsDelegationInvalidJSONContent(t *testing.T) { // create delegation kl := data.KeyList{newKey} - td := &changelist.TufDelegation{ + td := &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, AddPaths: []string{"level1"}, @@ -614,7 +614,7 @@ func TestApplyTargetsDelegationInvalidJSONContent(t *testing.T) { tdJSON, err := json.Marshal(td) require.NoError(t, err) - ch := changelist.NewTufChange( + ch := changelist.NewTUFChange( changelist.ActionCreate, "targets/level1", changelist.TypeTargetsDelegation, @@ -630,7 +630,7 @@ func TestApplyTargetsDelegationInvalidAction(t *testing.T) { repo, _, err := testutils.EmptyRepo("docker.com/notary") require.NoError(t, err) - ch := changelist.NewTufChange( + ch := changelist.NewTUFChange( "bad action", "targets/level1", changelist.TypeTargetsDelegation, @@ -646,7 +646,7 @@ func TestApplyTargetsChangeInvalidType(t *testing.T) { repo, _, err := testutils.EmptyRepo("docker.com/notary") require.NoError(t, err) - ch := changelist.NewTufChange( + ch := changelist.NewTUFChange( changelist.ActionCreate, "targets/level1", "badType", @@ -667,7 +667,7 @@ func TestApplyTargetsDelegationCreate2Deep(t *testing.T) { // create delegation kl := data.KeyList{newKey} - td := &changelist.TufDelegation{ + td := &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, AddPaths: []string{"level1"}, @@ -676,7 +676,7 @@ func TestApplyTargetsDelegationCreate2Deep(t *testing.T) { tdJSON, err := json.Marshal(td) require.NoError(t, err) - ch := changelist.NewTufChange( + ch := changelist.NewTUFChange( changelist.ActionCreate, "targets/level1", changelist.TypeTargetsDelegation, @@ -704,7 +704,7 @@ func TestApplyTargetsDelegationCreate2Deep(t *testing.T) { // operation repo.InitTargets("targets/level1") - td = &changelist.TufDelegation{ + td = &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, AddPaths: []string{"level1/level2"}, @@ -713,7 +713,7 @@ func TestApplyTargetsDelegationCreate2Deep(t *testing.T) { tdJSON, err = json.Marshal(td) require.NoError(t, err) - ch = changelist.NewTufChange( + ch = changelist.NewTUFChange( changelist.ActionCreate, "targets/level1/level2", changelist.TypeTargetsDelegation, @@ -753,7 +753,7 @@ func TestApplyTargetsDelegationParentDoesntExist(t *testing.T) { // create delegation kl := data.KeyList{newKey} - td := &changelist.TufDelegation{ + td := &changelist.TUFDelegation{ NewThreshold: 1, AddKeys: kl, } @@ -761,7 +761,7 @@ func TestApplyTargetsDelegationParentDoesntExist(t *testing.T) { tdJSON, err := json.Marshal(td) require.NoError(t, err) - ch := changelist.NewTufChange( + ch := changelist.NewTUFChange( changelist.ActionCreate, "targets/level1/level2", changelist.TypeTargetsDelegation, @@ -798,7 +798,7 @@ func TestApplyChangelistCreatesDelegation(t *testing.T) { require.NoError(t, err) cl := changelist.NewMemChangelist() - require.NoError(t, cl.Add(&changelist.TufChange{ + require.NoError(t, cl.Add(&changelist.TUFChange{ Actn: changelist.ActionCreate, Role: "targets/level1", ChangeType: "target", @@ -842,14 +842,14 @@ func TestApplyChangelistTargetsToMultipleRoles(t *testing.T) { require.NoError(t, err) cl := changelist.NewMemChangelist() - require.NoError(t, cl.Add(&changelist.TufChange{ + require.NoError(t, cl.Add(&changelist.TUFChange{ Actn: changelist.ActionCreate, Role: "targets/level1", ChangeType: "target", ChangePath: "latest", Data: fjson, })) - require.NoError(t, cl.Add(&changelist.TufChange{ + require.NoError(t, cl.Add(&changelist.TUFChange{ Actn: changelist.ActionDelete, Role: "targets/level2", ChangeType: "target", @@ -880,7 +880,7 @@ func TestApplyChangelistTargetsFailsNonexistentRole(t *testing.T) { require.NoError(t, err) cl := changelist.NewMemChangelist() - require.NoError(t, cl.Add(&changelist.TufChange{ + require.NoError(t, cl.Add(&changelist.TUFChange{ Actn: changelist.ActionCreate, Role: "targets/level1/level2/level3/level4", ChangeType: "target", @@ -893,7 +893,7 @@ func TestApplyChangelistTargetsFailsNonexistentRole(t *testing.T) { // now try a delete and assert the same error cl = changelist.NewMemChangelist() - require.NoError(t, cl.Add(&changelist.TufChange{ + require.NoError(t, cl.Add(&changelist.TUFChange{ Actn: changelist.ActionDelete, Role: "targets/level1/level2/level3/level4", ChangeType: "target", @@ -921,7 +921,7 @@ func TestChangeTargetMetaFailsInvalidRole(t *testing.T) { fjson, err := json.Marshal(f) require.NoError(t, err) - err = changeTargetMeta(repo, &changelist.TufChange{ + err = changeTargetMeta(repo, &changelist.TUFChange{ Actn: changelist.ActionCreate, Role: "ruhroh", ChangeType: "target", @@ -955,7 +955,7 @@ func TestChangeTargetMetaFailsIfPrefixError(t *testing.T) { fjson, err := json.Marshal(f) require.NoError(t, err) - err = changeTargetMeta(repo, &changelist.TufChange{ + err = changeTargetMeta(repo, &changelist.TUFChange{ Actn: changelist.ActionCreate, Role: "targets/level1", ChangeType: "target", diff --git a/cmd/notary/integration_test.go b/cmd/notary/integration_test.go index d24d9a8596..68271cc7b6 100644 --- a/cmd/notary/integration_test.go +++ b/cmd/notary/integration_test.go @@ -83,7 +83,7 @@ func setupServer() *httptest.Server { // Initializes a repo, adds a target, publishes the target, lists the target, // verifies the target, and then removes the target. -func TestClientTufInteraction(t *testing.T) { +func TestClientTUFInteraction(t *testing.T) { // -- setup -- setUp(t) @@ -156,7 +156,7 @@ func TestClientTufInteraction(t *testing.T) { // Initializes a repo, adds a target, publishes the target by hash, lists the target, // verifies the target, and then removes the target. -func TestClientTufAddByHashInteraction(t *testing.T) { +func TestClientTUFAddByHashInteraction(t *testing.T) { // -- setup -- setUp(t) diff --git a/cmd/notary/main.go b/cmd/notary/main.go index 712484a736..796a564f6f 100644 --- a/cmd/notary/main.go +++ b/cmd/notary/main.go @@ -180,7 +180,7 @@ func (n *notaryCommander) GetCommand() *cobra.Command { retriever: n.getRetriever(), } - cmdTufGenerator := &tufCommander{ + cmdTUFGenerator := &tufCommander{ configGetter: n.parseConfig, retriever: n.getRetriever(), } @@ -188,7 +188,7 @@ func (n *notaryCommander) GetCommand() *cobra.Command { notaryCmd.AddCommand(cmdKeyGenerator.GetCommand()) notaryCmd.AddCommand(cmdDelegationGenerator.GetCommand()) - cmdTufGenerator.AddToCommand(¬aryCmd) + cmdTUFGenerator.AddToCommand(¬aryCmd) return ¬aryCmd } diff --git a/cmd/notary/tuf.go b/cmd/notary/tuf.go index d851d33622..dc7cedbe1f 100644 --- a/cmd/notary/tuf.go +++ b/cmd/notary/tuf.go @@ -26,55 +26,55 @@ import ( "github.com/spf13/viper" ) -var cmdTufListTemplate = usageTemplate{ +var cmdTUFListTemplate = usageTemplate{ Use: "list [ GUN ]", Short: "Lists targets for a remote trusted collection.", Long: "Lists all targets for a remote trusted collection identified by the Globally Unique Name. This is an online operation.", } -var cmdTufAddTemplate = usageTemplate{ +var cmdTUFAddTemplate = usageTemplate{ Use: "add [ GUN ] ", Short: "Adds the file as a target to the trusted collection.", Long: "Adds the file as a target to the local trusted collection identified by the Globally Unique Name. This is an offline operation. Please then use `publish` to push the changes to the remote trusted collection.", } -var cmdTufAddHashTemplate = usageTemplate{ +var cmdTUFAddHashTemplate = usageTemplate{ Use: "addhash [ GUN ] ", Short: "Adds the byte size and hash(es) as a target to the trusted collection.", Long: "Adds the specified byte size and hash(es) as a target to the local trusted collection identified by the Globally Unique Name. This is an offline operation. Please then use `publish` to push the changes to the remote trusted collection.", } -var cmdTufRemoveTemplate = usageTemplate{ +var cmdTUFRemoveTemplate = usageTemplate{ Use: "remove [ GUN ] ", Short: "Removes a target from a trusted collection.", Long: "Removes a target from the local trusted collection identified by the Globally Unique Name. This is an offline operation. Please then use `publish` to push the changes to the remote trusted collection.", } -var cmdTufInitTemplate = usageTemplate{ +var cmdTUFInitTemplate = usageTemplate{ Use: "init [ GUN ]", Short: "Initializes a local trusted collection.", Long: "Initializes a local trusted collection identified by the Globally Unique Name. This is an online operation.", } -var cmdTufLookupTemplate = usageTemplate{ +var cmdTUFLookupTemplate = usageTemplate{ Use: "lookup [ GUN ] ", Short: "Looks up a specific target in a remote trusted collection.", Long: "Looks up a specific target in a remote trusted collection identified by the Globally Unique Name.", } -var cmdTufPublishTemplate = usageTemplate{ +var cmdTUFPublishTemplate = usageTemplate{ Use: "publish [ GUN ]", Short: "Publishes the local trusted collection.", Long: "Publishes the local trusted collection identified by the Globally Unique Name, sending the local changes to a remote trusted server.", } -var cmdTufStatusTemplate = usageTemplate{ +var cmdTUFStatusTemplate = usageTemplate{ Use: "status [ GUN ]", Short: "Displays status of unpublished changes to the local trusted collection.", Long: "Displays status of unpublished changes to the local trusted collection identified by the Globally Unique Name.", } -var cmdTufVerifyTemplate = usageTemplate{ +var cmdTUFVerifyTemplate = usageTemplate{ Use: "verify [ GUN ] ", Short: "Verifies if the content is included in the remote trusted collection", Long: "Verifies if the data passed in STDIN is included in the remote trusted collection identified by the Global Unique Name.", @@ -96,35 +96,35 @@ type tufCommander struct { } func (t *tufCommander) AddToCommand(cmd *cobra.Command) { - cmd.AddCommand(cmdTufInitTemplate.ToCommand(t.tufInit)) - cmd.AddCommand(cmdTufStatusTemplate.ToCommand(t.tufStatus)) - cmd.AddCommand(cmdTufPublishTemplate.ToCommand(t.tufPublish)) - cmd.AddCommand(cmdTufLookupTemplate.ToCommand(t.tufLookup)) + cmd.AddCommand(cmdTUFInitTemplate.ToCommand(t.tufInit)) + cmd.AddCommand(cmdTUFStatusTemplate.ToCommand(t.tufStatus)) + cmd.AddCommand(cmdTUFPublishTemplate.ToCommand(t.tufPublish)) + cmd.AddCommand(cmdTUFLookupTemplate.ToCommand(t.tufLookup)) - cmdTufList := cmdTufListTemplate.ToCommand(t.tufList) - cmdTufList.Flags().StringSliceVarP( + cmdTUFList := cmdTUFListTemplate.ToCommand(t.tufList) + cmdTUFList.Flags().StringSliceVarP( &t.roles, "roles", "r", nil, "Delegation roles to list targets for (will shadow targets role)") - cmd.AddCommand(cmdTufList) + cmd.AddCommand(cmdTUFList) - cmdTufAdd := cmdTufAddTemplate.ToCommand(t.tufAdd) - cmdTufAdd.Flags().StringSliceVarP(&t.roles, "roles", "r", nil, "Delegation roles to add this target to") - cmd.AddCommand(cmdTufAdd) + cmdTUFAdd := cmdTUFAddTemplate.ToCommand(t.tufAdd) + cmdTUFAdd.Flags().StringSliceVarP(&t.roles, "roles", "r", nil, "Delegation roles to add this target to") + cmd.AddCommand(cmdTUFAdd) - cmdTufRemove := cmdTufRemoveTemplate.ToCommand(t.tufRemove) - cmdTufRemove.Flags().StringSliceVarP(&t.roles, "roles", "r", nil, "Delegation roles to remove this target from") - cmd.AddCommand(cmdTufRemove) + cmdTUFRemove := cmdTUFRemoveTemplate.ToCommand(t.tufRemove) + cmdTUFRemove.Flags().StringSliceVarP(&t.roles, "roles", "r", nil, "Delegation roles to remove this target from") + cmd.AddCommand(cmdTUFRemove) - cmdTufAddHash := cmdTufAddHashTemplate.ToCommand(t.tufAddByHash) - cmdTufAddHash.Flags().StringSliceVarP(&t.roles, "roles", "r", nil, "Delegation roles to add this target to") - cmdTufAddHash.Flags().StringVar(&t.sha256, notary.SHA256, "", "hex encoded sha256 of the target to add") - cmdTufAddHash.Flags().StringVar(&t.sha512, notary.SHA512, "", "hex encoded sha512 of the target to add") - cmd.AddCommand(cmdTufAddHash) + cmdTUFAddHash := cmdTUFAddHashTemplate.ToCommand(t.tufAddByHash) + cmdTUFAddHash.Flags().StringSliceVarP(&t.roles, "roles", "r", nil, "Delegation roles to add this target to") + cmdTUFAddHash.Flags().StringVar(&t.sha256, notary.SHA256, "", "hex encoded sha256 of the target to add") + cmdTUFAddHash.Flags().StringVar(&t.sha512, notary.SHA512, "", "hex encoded sha512 of the target to add") + cmd.AddCommand(cmdTUFAddHash) - cmdTufVerify := cmdTufVerifyTemplate.ToCommand(t.tufVerify) - cmdTufVerify.Flags().StringVarP(&t.input, "input", "i", "", "Read from a file, instead of STDIN") - cmdTufVerify.Flags().StringVarP(&t.output, "output", "o", "", "Write to a file, instead of STDOUT") - cmdTufVerify.Flags().BoolVarP(&t.quiet, "quiet", "q", false, "No output except for errors") - cmd.AddCommand(cmdTufVerify) + cmdTUFVerify := cmdTUFVerifyTemplate.ToCommand(t.tufVerify) + cmdTUFVerify.Flags().StringVarP(&t.input, "input", "i", "", "Read from a file, instead of STDIN") + cmdTUFVerify.Flags().StringVarP(&t.output, "output", "o", "", "Write to a file, instead of STDOUT") + cmdTUFVerify.Flags().BoolVarP(&t.quiet, "quiet", "q", false, "No output except for errors") + cmd.AddCommand(cmdTUFVerify) } func (t *tufCommander) tufAddByHash(cmd *cobra.Command, args []string) error { diff --git a/server/server.go b/server/server.go index 7a359ba5c7..d18415356a 100644 --- a/server/server.go +++ b/server/server.go @@ -145,7 +145,7 @@ func RootHandler(ac auth.AccessController, ctx context.Context, trust signed.Cry r.Methods("GET").Path("/v2/").Handler(authWrapper(handlers.MainHandler)) r.Methods("POST").Path("/v2/{imageName:.*}/_trust/tuf/").Handler(createHandler(_serverEndpoint{ - OperationName: "UpdateTuf", + OperationName: "UpdateTUF", ErrorIfGUNInvalid: invalidGUNErr, ServerHandler: handlers.AtomicUpdateHandler, PermissionsRequired: []string{"push", "pull"}, @@ -174,7 +174,7 @@ func RootHandler(ac auth.AccessController, ctx context.Context, trust signed.Cry PermissionsRequired: []string{"push", "pull"}, })) r.Methods("DELETE").Path("/v2/{imageName:.*}/_trust/tuf/").Handler(createHandler(_serverEndpoint{ - OperationName: "DeleteTuf", + OperationName: "DeleteTUF", ErrorIfGUNInvalid: notFoundError, ServerHandler: handlers.DeleteHandler, PermissionsRequired: []string{"push", "pull"}, diff --git a/trustmanager/x509utils_test.go b/trustmanager/x509utils_test.go index c40298ce83..383b8fef09 100644 --- a/trustmanager/x509utils_test.go +++ b/trustmanager/x509utils_test.go @@ -175,7 +175,7 @@ func TestRSAX509PublickeyID(t *testing.T) { privKey, err := ParsePEMPrivateKey(fileBytes, "") require.NoError(t, err) - expectedTufID := privKey.ID() + expectedTUFID := privKey.ID() cert, err := LoadCertFromFile("../fixtures/notary-server.crt") require.NoError(t, err) @@ -183,13 +183,13 @@ func TestRSAX509PublickeyID(t *testing.T) { rsaKeyBytes, err := x509.MarshalPKIXPublicKey(cert.PublicKey) require.NoError(t, err) - sameWayTufID := data.NewPublicKey(data.RSAKey, rsaKeyBytes).ID() + sameWayTUFID := data.NewPublicKey(data.RSAKey, rsaKeyBytes).ID() - actualTufKey := CertToKey(cert) - actualTufID, err := X509PublicKeyID(actualTufKey) + actualTUFKey := CertToKey(cert) + actualTUFID, err := X509PublicKeyID(actualTUFKey) - require.Equal(t, sameWayTufID, actualTufID) - require.Equal(t, expectedTufID, actualTufID) + require.Equal(t, sameWayTUFID, actualTUFID) + require.Equal(t, expectedTUFID, actualTUFID) } // X509PublickeyID returns the public key ID of an ECDSA X509 key rather than