From fd5c117c11fbe5e2e61c43336e78a10d0ae008c5 Mon Sep 17 00:00:00 2001 From: Brandt Keller Date: Wed, 12 Feb 2025 21:02:36 +0000 Subject: [PATCH] feat: new publishopts creation --- src/internal/packager2/publish.go | 28 ++++++++++++++++++++++++-- src/internal/packager2/publish_test.go | 23 ++++++++++++--------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/internal/packager2/publish.go b/src/internal/packager2/publish.go index 84d057ce85..3c2b17717b 100644 --- a/src/internal/packager2/publish.go +++ b/src/internal/packager2/publish.go @@ -3,17 +3,41 @@ package packager2 -import "context" +import ( + "context" + "fmt" +) type PublishOpts struct { + Path string + Registry string + IsSkeleton bool SigningKeyPath string SigningKeyPassword string SkipSignatureValidation bool } +func NewPublishOpts(path string, registry string, skeleton bool, signingKeyPath string, signingKeyPassword string, skipSignaturevalidation bool) (PublishOpts, error) { + + if registry == "" { + return PublishOpts{}, fmt.Errorf("registry must be specified") + } + + opts := PublishOpts{ + Path: path, + Registry: registry, + IsSkeleton: skeleton, + SigningKeyPath: signingKeyPath, + SigningKeyPassword: signingKeyPassword, + SkipSignatureValidation: skipSignaturevalidation, + } + + return opts, nil +} + // Takes directory/tar file & OCI Registry // TODO Dir points to a location on disk and registry is a URL. -func Publish(ctx context.Context, dir string, registry string, opts PublishOpts) error { +func Publish(ctx context.Context, path string, registry string, opts PublishOpts) error { return nil } diff --git a/src/internal/packager2/publish_test.go b/src/internal/packager2/publish_test.go index 07ddab89ba..995504044b 100644 --- a/src/internal/packager2/publish_test.go +++ b/src/internal/packager2/publish_test.go @@ -9,26 +9,29 @@ import ( func TestPublish(t *testing.T) { tt := []struct { - name string - dir string - opts PublishOpts + name string + dir string + registry string + opts PublishOpts }{ { - name: "simple", - dir: "testdata/simple", - opts: PublishOpts{}, + name: "simple", + dir: "testdata/simple", + registry: "", + opts: PublishOpts{}, }, { - name: "simple", - dir: "testdata/simple", - opts: PublishOpts{}, + name: "simple", + dir: "testdata/simple", + registry: "", + opts: PublishOpts{}, }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { t.Parallel() - err := Publish(context.Background(), tc.opts) + err := Publish(context.Background(), tc.dir, tc.registry, tc.opts) require.NoError(t, err) }) }