Skip to content

Commit 980054a

Browse files
saschagrunertk8s-ci-robot
authored andcommitted
Allow relative paths on spoc push
The file store only supports absolute paths which means that we have to pre-calculate it before passing it in. Signed-off-by: Sascha Grunert <[email protected]>
1 parent b59cd38 commit 980054a

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

internal/pkg/artifact/artifact.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,12 @@ func (a *Artifact) Push(file, to, username, password string, annotations map[str
112112
defer cancel()
113113

114114
a.logger.Info("Adding profile to store: " + file)
115+
absPath, err := a.FilepathAbs(file)
116+
if err != nil {
117+
return fmt.Errorf("get absoluate file path: %w", err)
118+
}
115119
fileDescriptor, err := a.StoreAdd(
116-
ctx, store, defaultProfileYAML, "", file,
120+
ctx, store, defaultProfileYAML, "", absPath,
117121
)
118122
if err != nil {
119123
return fmt.Errorf("add profile to store: %w", err)

internal/pkg/artifact/artifact_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ func TestPush(t *testing.T) {
134134
require.ErrorIs(t, err, errTest)
135135
},
136136
},
137+
{
138+
name: "failure on FilepathAbs",
139+
prepare: func(mock *artifactfakes.FakeImpl) {
140+
mock.FilepathAbsReturns("", errTest)
141+
},
142+
assert: func(err error) {
143+
require.ErrorIs(t, err, errTest)
144+
},
145+
},
137146
{
138147
name: "failure on StoreAdd",
139148
prepare: func(mock *artifactfakes.FakeImpl) {

internal/pkg/artifact/artifactfakes/fake_impl.go

+79
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/pkg/artifact/impl.go

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package artifact
1919
import (
2020
"context"
2121
"os"
22+
"path/filepath"
2223

2324
ggcrname "github.com/google/go-containerregistry/pkg/name"
2425
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -42,6 +43,7 @@ type impl interface {
4243
RemoveAll(string) error
4344
FileNew(string) (*file.Store, error)
4445
FileClose(*file.Store) error
46+
FilepathAbs(string) (string, error)
4547
NewRepository(string) (*remote.Repository, error)
4648
Copy(context.Context, oras.ReadOnlyTarget, string, oras.Target, string, oras.CopyOptions) (ocispec.Descriptor, error)
4749
ReadFile(string) ([]byte, error)
@@ -74,6 +76,10 @@ func (*defaultImpl) FileClose(store *file.Store) error {
7476
return store.Close()
7577
}
7678

79+
func (*defaultImpl) FilepathAbs(path string) (string, error) {
80+
return filepath.Abs(path)
81+
}
82+
7783
func (*defaultImpl) NewRepository(reference string) (*remote.Repository, error) {
7884
return remote.NewRepository(reference)
7985
}

0 commit comments

Comments
 (0)