Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dynamic plugin should support pulling image with digest #1280

Merged
merged 9 commits into from
Jan 29, 2024
3 changes: 2 additions & 1 deletion pkg/common/plugin/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@
}

// download the first blob to the target path
blobReference := fmt.Sprintf("%s@%s", source, referenceManifest.Blobs[0].Digest)
blobReference := fmt.Sprintf("%s", referenceManifest.Blobs[0].Digest)

Check failure on line 130 in pkg/common/plugin/download.go

View workflow job for this annotation

GitHub Actions / lint

S1025: should use String() instead of fmt.Sprintf (gosimple)

Check warning on line 131 in pkg/common/plugin/download.go

View check run for this annotation

Codecov / codecov/patch

pkg/common/plugin/download.go#L130-L131

Added lines #L130 - L131 were not covered by tests
logrus.Debugf("Downloading blob %s", blobReference)
_, blobReader, err := repository.Blobs().FetchReference(ctx, blobReference)
if err != nil {
Expand Down
65 changes: 42 additions & 23 deletions pkg/referrerstore/factory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,37 +95,56 @@
func TestCreateStoresFromConfig_DynamicPluginStores_ReturnsExpected(t *testing.T) {
os.Setenv("RATIFY_EXPERIMENTAL_DYNAMIC_PLUGINS", "1")
featureflag.InitFeatureFlagsFromEnv()
storeConfig := map[string]interface{}{
"name": "plugin-store",
"source": map[string]interface{}{
"artifact": "wabbitnetworks.azurecr.io/test/sample-verifier-plugin:v1",
testCases := []struct {
name string
artifact string
}{
{
name: "image specified by tag",
artifact: "wabbitnetworks.azurecr.io/test/sample-store-plugin:v1",
},
{
name: "image specified by digest",
artifact: "wabbitnetworks.azurecr.io/test/sample-store-plugin@sha256:96ba9f9636cde32df87d62dcad4e430d055e708b9f173475c5d7468b732d6566",
},
}

storesConfig := config.StoresConfig{
Stores: []config.StorePluginConfig{storeConfig},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
storeConfig := map[string]interface{}{
"name": "plugin-store",
"source": map[string]interface{}{
"artifact": tc.artifact,
},
}

stores, err := CreateStoresFromConfig(storesConfig, "")
storesConfig := config.StoresConfig{
Stores: []config.StorePluginConfig{storeConfig},
}

if err != nil {
t.Fatalf("create stores failed with err %v", err)
}
stores, err := CreateStoresFromConfig(storesConfig, "")

if len(stores) != 1 {
t.Fatalf("expected to have %d stores, actual count %d", 1, len(stores))
}
if err != nil {
t.Fatalf("create stores failed with err %v", err)
}

if stores[0].Name() != "plugin-store" {
t.Fatalf("expected to create plugin store")
}
if len(stores) != 1 {
t.Fatalf("expected to have %d stores, actual count %d", 1, len(stores))
}

if _, ok := stores[0].(*plugin.StorePlugin); !ok {
t.Fatalf("type assertion failed expected a plugin store")
}
if stores[0].Name() != "plugin-store" {
t.Fatalf("expected to create plugin store")
}

pluginPath := path.Join(stores[0].GetConfig().PluginBinDirs[0], stores[0].Name())
if _, err := os.Stat(pluginPath); errors.Is(err, os.ErrNotExist) {
t.Fatalf("downloaded plugin not found in path")
if _, ok := stores[0].(*plugin.StorePlugin); !ok {
t.Fatalf("type assertion failed expected a plugin store")
}

pluginPath := path.Join(stores[0].GetConfig().PluginBinDirs[0], stores[0].Name())
if _, err := os.Stat(pluginPath); errors.Is(err, os.ErrNotExist) {
t.Fatalf("downloaded plugin not found in path")
}
})
}

Check failure on line 149 in pkg/referrerstore/factory/factory_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
}
Loading