Skip to content

Commit

Permalink
Allow using image id when on policy tag (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
carabasdaniel authored May 24, 2024
1 parent fa311d9 commit efa6433
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 10 additions & 1 deletion oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -287,7 +288,15 @@ func (o *Oci) Tag(existingRef, newRef string) error {

descriptor, ok := refs[existingRef]
if !ok {
return errors.Errorf("policy [%s] not found in the local store", existingRef)
for _, v := range refs {
if strings.HasPrefix(v.Digest.String(), fmt.Sprintf("sha256:%s", existingRef)) {
descriptor = v
break
}
}
if descriptor.Size == 0 {
return errors.Errorf("policy [%s] not found in the local store", existingRef)
}
}

_, err = cloneDescriptor(&descriptor)
Expand Down
12 changes: 8 additions & 4 deletions pkg/app/tag.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package app

import (
"strings"

"github.com/opcr-io/policy/oci"
"github.com/opcr-io/policy/parser"
"github.com/pkg/errors"
Expand All @@ -13,10 +15,12 @@ func (c *PolicyApp) Tag(existingRef, newRef string) error {
if err != nil {
return err
}

existingRefParsed, err := parser.CalculatePolicyRef(existingRef, c.Configuration.DefaultDomain)
if err != nil {
return err
existingRefParsed := existingRef
if strings.Contains(existingRef, ":") {
existingRefParsed, err = parser.CalculatePolicyRef(existingRef, c.Configuration.DefaultDomain)
if err != nil {
return err
}
}

parsed, err := parser.CalculatePolicyRef(newRef, c.Configuration.DefaultDomain)
Expand Down

0 comments on commit efa6433

Please sign in to comment.