astefanutti commented on code in PR #4350:
URL: https://github.com/apache/camel-k/pull/4350#discussion_r1190699150


##########
pkg/kamelet/repository/oci_repository.go:
##########
@@ -0,0 +1,170 @@
+package repository
+
+import (
+       "context"
+       "encoding/json"
+       "fmt"
+       "github.com/containers/image/docker/reference"
+       "io/ioutil"
+       "path"
+       "path/filepath"
+       "sync"
+
+       camelv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
+       "k8s.io/apimachinery/pkg/util/yaml"
+
+       "os"
+       "strings"
+
+       "oras.land/oras-go/v2"
+       "oras.land/oras-go/v2/content/file"
+       "oras.land/oras-go/v2/registry/remote"
+       "oras.land/oras-go/v2/registry/remote/auth"
+       "oras.land/oras-go/v2/registry/remote/retry"
+)
+
+type ociKameletRepository struct {
+       once     sync.Once
+       image    string
+       relative string
+
+       kamelets map[string]string
+       pollRoot string
+       pollErr  error
+}
+
+func newOCIKameletRepository(image string) KameletRepository {
+       imageName := image
+       relativePath := ""
+
+       items := strings.Split(image, "?")
+       if len(items) == 2 {
+               imageName = items[0]
+               relativePath = items[1]
+       }
+
+       repo := ociKameletRepository{
+               image:    imageName,
+               relative: relativePath,
+               kamelets: make(map[string]string, 0),
+       }
+
+       return &repo
+}
+
+// Enforce type
+var _ KameletRepository = &ociKameletRepository{}
+
+func (r *ociKameletRepository) List(ctx context.Context) ([]string, error) {
+
+       r.pullAll(ctx)
+
+       if r.pollErr != nil {
+               return nil, r.pollErr
+       }
+
+       kamelets := make([]string, 0, len(r.kamelets))
+       for k := range r.kamelets {
+               kamelets = append(kamelets, k)
+       }
+
+       return kamelets, r.pollErr
+}
+
+func (r *ociKameletRepository) Get(ctx context.Context, name string) 
(*camelv1.Kamelet, error) {
+       r.pullAll(ctx)

Review Comment:
   +1 for 3) to keep things simple 👍🏼.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to