Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/tuf/tuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var (
ErrGlobalRuleAlreadyExists = errors.New("global rule already exists")
ErrCannotUpdateGlobalRuleType = errors.New("cannot change type of global rule")
ErrPropagationDirectiveNotFound = errors.New("specified propagation directive not found")
ErrPropagationDirectiveAlreadyExists = errors.New("specified propagation directive already exists")
ErrNotAControllerRepository = errors.New("current repository is not marked as a controller repository")
ErrDuplicatedHookName = errors.New("two hooks with same name found in policy")
ErrInvalidHookStage = errors.New("invalid stage for hook")
Expand Down
11 changes: 10 additions & 1 deletion internal/tuf/v01/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,16 @@ func (r *RootMetadata) UpdateGlobalRule(globalRule tuf.GlobalRule) error {

// AddPropagationDirective adds a propagation directive to the root metadata.
func (r *RootMetadata) AddPropagationDirective(directive tuf.PropagationDirective) error {
// TODO: handle duplicates
for _, existing := range r.Propagations {
if existing.GetUpstreamRepository() == directive.GetUpstreamRepository() &&
existing.GetUpstreamReference() == directive.GetUpstreamReference() &&
existing.GetUpstreamPath() == directive.GetUpstreamPath() &&
existing.GetDownstreamReference() == directive.GetDownstreamReference() &&
existing.GetDownstreamPath() == directive.GetDownstreamPath() {
return tuf.ErrPropagationDirectiveAlreadyExists
}
}

r.Propagations = append(r.Propagations, directive)
return nil
}
Expand Down
6 changes: 6 additions & 0 deletions internal/tuf/v01/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ func TestRootMetadata(t *testing.T) {
assert.Equal(t, 1, len(directives))
assert.Equal(t, directive, directives[0])

err = rootMetadata.AddPropagationDirective(directive)
assert.ErrorIs(t, err, tuf.ErrPropagationDirectiveAlreadyExists)
directives = rootMetadata.GetPropagationDirectives()
assert.Equal(t, 1, len(directives))
assert.Equal(t, directive, directives[0])

updatedDirective := &PropagationDirective{
Name: "test",
UpstreamRepository: "https://example.org/git/repository",
Expand Down
11 changes: 10 additions & 1 deletion internal/tuf/v02/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,16 @@ func (r *RootMetadata) GetGlobalRules() []tuf.GlobalRule {

// AddPropagationDirective adds a propagation directive to the root metadata.
func (r *RootMetadata) AddPropagationDirective(directive tuf.PropagationDirective) error {
// TODO: handle duplicates
for _, existing := range r.Propagations {
if existing.GetUpstreamRepository() == directive.GetUpstreamRepository() &&
existing.GetUpstreamReference() == directive.GetUpstreamReference() &&
existing.GetUpstreamPath() == directive.GetUpstreamPath() &&
existing.GetDownstreamReference() == directive.GetDownstreamReference() &&
existing.GetDownstreamPath() == directive.GetDownstreamPath() {
return tuf.ErrPropagationDirectiveAlreadyExists
}
}

r.Propagations = append(r.Propagations, directive)
return nil
}
Expand Down
6 changes: 6 additions & 0 deletions internal/tuf/v02/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ func TestRootMetadata(t *testing.T) {
assert.Equal(t, 1, len(directives))
assert.Equal(t, directive, directives[0])

err = rootMetadata.AddPropagationDirective(directive)
assert.ErrorIs(t, err, tuf.ErrPropagationDirectiveAlreadyExists)
directives = rootMetadata.GetPropagationDirectives()
assert.Equal(t, 1, len(directives))
assert.Equal(t, directive, directives[0])

updatedDirective := &PropagationDirective{
Name: "test",
UpstreamRepository: "https://example.org/git/repository",
Expand Down