diff --git a/build/mage/build.go b/build/mage/build.go index 6f94e4e..189801d 100644 --- a/build/mage/build.go +++ b/build/mage/build.go @@ -104,7 +104,7 @@ var binaries = map[string]binaryConfig{ }, useProto: true, // NOTE: restore in case alpine createrepo_c package is broken again - //baseImage: "debian:bullseye-slim", + // baseImage: "debian:bullseye-slim", integrationTest: &integrationTest{ isPlugin: true, envs: map[string]string{ diff --git a/cmd/beskar-ostree/main.go b/cmd/beskar-ostree/main.go index 4ae53d4..ad93634 100644 --- a/cmd/beskar-ostree/main.go +++ b/cmd/beskar-ostree/main.go @@ -6,12 +6,13 @@ package main import ( "flag" "fmt" - "go.ciq.dev/beskar/internal/plugins/ostree/pkg/ostreerepository" "log" "net" "os" "syscall" + "go.ciq.dev/beskar/internal/plugins/ostree/pkg/ostreerepository" + "go.ciq.dev/beskar/internal/pkg/pluginsrv" "go.ciq.dev/beskar/internal/plugins/ostree" "go.ciq.dev/beskar/internal/plugins/ostree/pkg/config" diff --git a/cmd/beskar-static/main.go b/cmd/beskar-static/main.go index 9f8e7f4..c870ef2 100644 --- a/cmd/beskar-static/main.go +++ b/cmd/beskar-static/main.go @@ -6,12 +6,13 @@ package main import ( "flag" "fmt" - "go.ciq.dev/beskar/internal/plugins/static/pkg/staticrepository" "log" "net" "os" "syscall" + "go.ciq.dev/beskar/internal/plugins/static/pkg/staticrepository" + "go.ciq.dev/beskar/internal/pkg/pluginsrv" "go.ciq.dev/beskar/internal/plugins/static" "go.ciq.dev/beskar/internal/plugins/static/pkg/config" diff --git a/cmd/beskar-yum/main.go b/cmd/beskar-yum/main.go index f4b5a6c..76cc659 100644 --- a/cmd/beskar-yum/main.go +++ b/cmd/beskar-yum/main.go @@ -6,12 +6,13 @@ package main import ( "flag" "fmt" - "go.ciq.dev/beskar/internal/plugins/yum/pkg/yumrepository" "log" "net" "os" "syscall" + "go.ciq.dev/beskar/internal/plugins/yum/pkg/yumrepository" + "go.ciq.dev/beskar/internal/pkg/pluginsrv" "go.ciq.dev/beskar/internal/plugins/yum" "go.ciq.dev/beskar/internal/plugins/yum/pkg/config" diff --git a/cmd/beskarctl/ostree/repo.go b/cmd/beskarctl/ostree/repo.go index fb339ac..0dcce7d 100644 --- a/cmd/beskarctl/ostree/repo.go +++ b/cmd/beskarctl/ostree/repo.go @@ -5,6 +5,7 @@ package ostree import ( "context" + "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/v1/remote" diff --git a/internal/pkg/repository/handler.go b/internal/pkg/repository/handler.go index 10b9eca..e5c7331 100644 --- a/internal/pkg/repository/handler.go +++ b/internal/pkg/repository/handler.go @@ -6,7 +6,6 @@ package repository import ( "context" "errors" - "go.ciq.dev/beskar/internal/pkg/gossip" "io" "net" "os" @@ -16,6 +15,8 @@ import ( "sync/atomic" "time" + "go.ciq.dev/beskar/internal/pkg/gossip" + "github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/v1/remote" eventv1 "go.ciq.dev/beskar/pkg/api/event/v1" diff --git a/internal/plugins/ostree/api.go b/internal/plugins/ostree/api.go index c605019..6a343d9 100644 --- a/internal/plugins/ostree/api.go +++ b/internal/plugins/ostree/api.go @@ -5,6 +5,7 @@ package ostree import ( "context" + "github.com/RussellLuo/kun/pkg/werror" "github.com/RussellLuo/kun/pkg/werror/gcode" diff --git a/internal/plugins/ostree/pkg/libostree/errors.go b/internal/plugins/ostree/pkg/libostree/errors.go index 0151579..d7e1f18 100644 --- a/internal/plugins/ostree/pkg/libostree/errors.go +++ b/internal/plugins/ostree/pkg/libostree/errors.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved +// SPDX-License-Identifier: Apache-2.0 + package libostree type Err string diff --git a/internal/plugins/ostree/pkg/libostree/glib_helpers.go b/internal/plugins/ostree/pkg/libostree/glib_helpers.go index 8c1fb39..a388095 100644 --- a/internal/plugins/ostree/pkg/libostree/glib_helpers.go +++ b/internal/plugins/ostree/pkg/libostree/glib_helpers.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved +// SPDX-License-Identifier: Apache-2.0 + package libostree // #cgo pkg-config: glib-2.0 gobject-2.0 @@ -7,6 +10,7 @@ package libostree // #include // #include "glib_helpers.go.h" import "C" + import ( "errors" ) diff --git a/internal/plugins/ostree/pkg/libostree/options.go b/internal/plugins/ostree/pkg/libostree/options.go index 8df0a81..cc476ed 100644 --- a/internal/plugins/ostree/pkg/libostree/options.go +++ b/internal/plugins/ostree/pkg/libostree/options.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved +// SPDX-License-Identifier: Apache-2.0 + package libostree // #cgo pkg-config: ostree-1 glib-2.0 gobject-2.0 @@ -13,12 +16,13 @@ import "unsafe" // Option defines an option for pulling ostree repos. // It is used to build a *C.GVariant via a *C.GVariantBuilder. // free is an optional function that frees the memory allocated by the option. free may be called more than once. -type Option func(builder *C.GVariantBuilder, free freeFunc) -type freeFunc func(...unsafe.Pointer) +type ( + Option func(builder *C.GVariantBuilder, free freeFunc) + freeFunc func(...unsafe.Pointer) +) // ToGVariant converts the given Options to a GVariant using a GVaraintBuilder. func toGVariant(opts ...Option) *C.GVariant { - typeStr := (*C.gchar)(C.CString("a{sv}")) defer C.free(unsafe.Pointer(typeStr)) diff --git a/internal/plugins/ostree/pkg/libostree/ostree.go b/internal/plugins/ostree/pkg/libostree/ostree.go index 67201a1..c21ff1c 100644 --- a/internal/plugins/ostree/pkg/libostree/ostree.go +++ b/internal/plugins/ostree/pkg/libostree/ostree.go @@ -1 +1,4 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved +// SPDX-License-Identifier: Apache-2.0 + package libostree diff --git a/internal/plugins/ostree/pkg/libostree/pull.go b/internal/plugins/ostree/pkg/libostree/pull.go index c7157ad..820f26d 100644 --- a/internal/plugins/ostree/pkg/libostree/pull.go +++ b/internal/plugins/ostree/pkg/libostree/pull.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved +// SPDX-License-Identifier: Apache-2.0 + package libostree // #cgo pkg-config: ostree-1 glib-2.0 gobject-2.0 @@ -6,6 +9,7 @@ package libostree // #include // #include "pull.go.h" import "C" + import ( "context" "unsafe" diff --git a/internal/plugins/ostree/pkg/libostree/pull_test.go b/internal/plugins/ostree/pkg/libostree/pull_test.go index 26f4262..71235ec 100644 --- a/internal/plugins/ostree/pkg/libostree/pull_test.go +++ b/internal/plugins/ostree/pkg/libostree/pull_test.go @@ -1,15 +1,19 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved +// SPDX-License-Identifier: Apache-2.0 + package libostree import ( "context" "fmt" - "github.com/stretchr/testify/assert" "log" "net/http" "net/http/httptest" "os" "strings" "testing" + + "github.com/stretchr/testify/assert" ) func TestMain(m *testing.M) { @@ -22,7 +26,6 @@ func TestMain(m *testing.M) { } func TestRepo_Pull(t *testing.T) { - fmt.Println(os.Getwd()) svr := httptest.NewServer(http.FileServer(http.Dir("testdata/repo"))) defer svr.Close() @@ -40,7 +43,7 @@ func TestRepo_Pull(t *testing.T) { RepoModeBare, RepoModeBareUser, RepoModeBareUserOnly, - //RepoModeBareSplitXAttrs, + // RepoModeBareSplitXAttrs, } // Test pull for each mode @@ -118,7 +121,7 @@ func TestRepo_Pull(t *testing.T) { } }) - //TODO: Repeat the following tests for only a specific ref + // TODO: Repeat the following tests for only a specific ref t.Run("should pull entire repo", func(t *testing.T) { err := repo.Pull( context.TODO(), @@ -153,7 +156,7 @@ func TestRepo_Pull(t *testing.T) { for _, ref := range refs { checksum := ref.Checksum assert.NotEmpty(t, checksum) - for sum, _ := range expectedChecksums { + for sum := range expectedChecksums { if sum == checksum { expectedChecksums[sum] = true } diff --git a/internal/plugins/ostree/pkg/libostree/repo.go b/internal/plugins/ostree/pkg/libostree/repo.go index 8498f81..7471970 100644 --- a/internal/plugins/ostree/pkg/libostree/repo.go +++ b/internal/plugins/ostree/pkg/libostree/repo.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved +// SPDX-License-Identifier: Apache-2.0 + package libostree // #cgo pkg-config: ostree-1 glib-2.0 gobject-2.0 @@ -7,6 +10,7 @@ package libostree // #include // #include import "C" + import ( "runtime" "unsafe" diff --git a/internal/plugins/ostree/pkg/ostreerepository/api.go b/internal/plugins/ostree/pkg/ostreerepository/api.go index 52458fd..72264c2 100644 --- a/internal/plugins/ostree/pkg/ostreerepository/api.go +++ b/internal/plugins/ostree/pkg/ostreerepository/api.go @@ -1,17 +1,21 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved +// SPDX-License-Identifier: Apache-2.0 + package ostreerepository import ( "context" "fmt" + "os" + "path/filepath" + "time" + "go.ciq.dev/beskar/cmd/beskarctl/ctl" "go.ciq.dev/beskar/internal/plugins/ostree/pkg/libostree" "go.ciq.dev/beskar/pkg/orasostree" apiv1 "go.ciq.dev/beskar/pkg/plugins/ostree/api/v1" "go.ciq.dev/beskar/pkg/utils" "golang.org/x/sync/errgroup" - "os" - "path/filepath" - "time" ) func (h *Handler) CreateRepository(ctx context.Context, properties *apiv1.OSTreeRepositoryProperties) (err error) { @@ -33,7 +37,6 @@ func (h *Handler) CreateRepository(ctx context.Context, properties *apiv1.OSTree defer h.clearState() return h.BeginLocalRepoTransaction(ctx, func(ctx context.Context, repo *libostree.Repo) (bool, error) { - // Add user provided remotes // We do not need to add beskar remote here for _, remote := range properties.Remotes { @@ -51,7 +54,6 @@ func (h *Handler) CreateRepository(ctx context.Context, properties *apiv1.OSTree } return true, nil - }, SkipPull()) } @@ -81,7 +83,6 @@ func (h *Handler) DeleteRepository(ctx context.Context) (err error) { h.logger.Debug("deleting repository") err := h.BeginLocalRepoTransaction(context.Background(), func(ctx context.Context, repo *libostree.Repo) (bool, error) { - // Create a worker pool to deleting each file in the repository concurrently. // ctx will be cancelled on error, and the error will be returned. eg, ctx := errgroup.WithContext(ctx) @@ -125,9 +126,7 @@ func (h *Handler) DeleteRepository(ctx context.Context) (err error) { // We don't want to push any changes to beskar. return false, eg.Wait() - }) - if err != nil { h.logger.Error("deleting repository", "error", err.Error()) } @@ -159,7 +158,6 @@ func (h *Handler) AddRemote(ctx context.Context, remote *apiv1.OSTreeRemotePrope } return true, nil - }, SkipPull()) } @@ -209,7 +207,6 @@ func (h *Handler) SyncRepository(ctx context.Context, properties *apiv1.OSTreeRe } return true, nil - }) }() diff --git a/internal/plugins/ostree/pkg/ostreerepository/handler.go b/internal/plugins/ostree/pkg/ostreerepository/handler.go index d836a77..549f001 100644 --- a/internal/plugins/ostree/pkg/ostreerepository/handler.go +++ b/internal/plugins/ostree/pkg/ostreerepository/handler.go @@ -1,13 +1,11 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved +// SPDX-License-Identifier: Apache-2.0 + package ostreerepository import ( "context" "fmt" - "github.com/RussellLuo/kun/pkg/werror" - "github.com/RussellLuo/kun/pkg/werror/gcode" - "go.ciq.dev/beskar/cmd/beskarctl/ctl" - "go.ciq.dev/beskar/internal/pkg/repository" - eventv1 "go.ciq.dev/beskar/pkg/api/event/v1" "io" "log/slog" "net/http" @@ -16,6 +14,12 @@ import ( "path/filepath" "sync" "sync/atomic" + + "github.com/RussellLuo/kun/pkg/werror" + "github.com/RussellLuo/kun/pkg/werror/gcode" + "go.ciq.dev/beskar/cmd/beskarctl/ctl" + "go.ciq.dev/beskar/internal/pkg/repository" + eventv1 "go.ciq.dev/beskar/pkg/api/event/v1" ) const ( @@ -127,7 +131,7 @@ func (h *Handler) Start(ctx context.Context) { // pullConfig pulls the config file from beskar. func (h *Handler) pullFile(_ context.Context, filename string) error { - //TODO: Replace with appropriate puller mechanism + // TODO: Replace with appropriate puller mechanism url := "http://" + h.Params.GetBeskarRegistryHostPort() + path.Join("/", h.Repository, "repo", filename) resp, err := http.Get(url) if err != nil { diff --git a/internal/plugins/ostree/pkg/ostreerepository/local.go b/internal/plugins/ostree/pkg/ostreerepository/local.go index 8a0267a..7d7d9ee 100644 --- a/internal/plugins/ostree/pkg/ostreerepository/local.go +++ b/internal/plugins/ostree/pkg/ostreerepository/local.go @@ -1,13 +1,17 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved +// SPDX-License-Identifier: Apache-2.0 + package ostreerepository import ( "context" - "go.ciq.dev/beskar/cmd/beskarctl/ctl" - "go.ciq.dev/beskar/internal/plugins/ostree/pkg/libostree" - "go.ciq.dev/beskar/pkg/orasostree" "os" "path" "path/filepath" + + "go.ciq.dev/beskar/cmd/beskarctl/ctl" + "go.ciq.dev/beskar/internal/plugins/ostree/pkg/libostree" + "go.ciq.dev/beskar/pkg/orasostree" ) // checkRepoExists checks if the ostree repository exists in beskar. @@ -19,10 +23,12 @@ func (h *Handler) checkRepoExists(_ context.Context) bool { return err == nil } -type TransactionFn func(ctx context.Context, repo *libostree.Repo) (commit bool, err error) -type TransactionOptions struct { - skipPull bool -} +type ( + TransactionFn func(ctx context.Context, repo *libostree.Repo) (commit bool, err error) + TransactionOptions struct { + skipPull bool + } +) type TransactionOption func(*TransactionOptions) @@ -41,7 +47,6 @@ func SkipPull() TransactionOption { // 5. If the transactorFn returns true, the local ostree repository is pushed to beskar. If false, all local changes are discarded. // 6. The temporary directory is removed. func (h *Handler) BeginLocalRepoTransaction(ctx context.Context, tFn TransactionFn, opts ...TransactionOption) error { - options := TransactionOptions{} for _, opt := range opts { opt(&options) diff --git a/internal/plugins/ostree/pkg/ostreerepository/sync.go b/internal/plugins/ostree/pkg/ostreerepository/sync.go index 8abecc4..7ed8973 100644 --- a/internal/plugins/ostree/pkg/ostreerepository/sync.go +++ b/internal/plugins/ostree/pkg/ostreerepository/sync.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved +// SPDX-License-Identifier: Apache-2.0 + package ostreerepository import ( diff --git a/internal/plugins/ostree/plugin.go b/internal/plugins/ostree/plugin.go index 2c52696..e6fdc67 100644 --- a/internal/plugins/ostree/plugin.go +++ b/internal/plugins/ostree/plugin.go @@ -6,6 +6,12 @@ package ostree import ( "context" _ "embed" + "net" + "net/http" + "net/http/pprof" + "path/filepath" + "strconv" + "github.com/RussellLuo/kun/pkg/httpcodec" "github.com/go-chi/chi" "github.com/google/go-containerregistry/pkg/name" @@ -20,11 +26,6 @@ import ( "go.ciq.dev/beskar/pkg/mtls" apiv1 "go.ciq.dev/beskar/pkg/plugins/ostree/api/v1" "go.ciq.dev/beskar/pkg/version" - "net" - "net/http" - "net/http/pprof" - "path/filepath" - "strconv" ) const ( diff --git a/internal/plugins/static/pkg/staticrepository/api.go b/internal/plugins/static/pkg/staticrepository/api.go index ea51025..82b1e0e 100644 --- a/internal/plugins/static/pkg/staticrepository/api.go +++ b/internal/plugins/static/pkg/staticrepository/api.go @@ -7,10 +7,11 @@ import ( "context" "errors" "fmt" - "go.ciq.dev/beskar/pkg/utils" "path/filepath" "time" + "go.ciq.dev/beskar/pkg/utils" + "github.com/RussellLuo/kun/pkg/werror" "github.com/RussellLuo/kun/pkg/werror/gcode" "github.com/hashicorp/go-multierror" diff --git a/internal/plugins/yum/pkg/yumrepository/api.go b/internal/plugins/yum/pkg/yumrepository/api.go index 633349d..75a2cb4 100644 --- a/internal/plugins/yum/pkg/yumrepository/api.go +++ b/internal/plugins/yum/pkg/yumrepository/api.go @@ -9,10 +9,11 @@ import ( "encoding/gob" "errors" "fmt" - "go.ciq.dev/beskar/pkg/utils" "path/filepath" "time" + "go.ciq.dev/beskar/pkg/utils" + "github.com/RussellLuo/kun/pkg/werror" "github.com/RussellLuo/kun/pkg/werror/gcode" "github.com/google/go-containerregistry/pkg/v1/remote/transport" diff --git a/pkg/orasostree/push.go b/pkg/orasostree/push.go index 110b9e8..6bc6a22 100644 --- a/pkg/orasostree/push.go +++ b/pkg/orasostree/push.go @@ -1,16 +1,20 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved +// SPDX-License-Identifier: Apache-2.0 + package orasostree import ( "context" "fmt" - "github.com/google/go-containerregistry/pkg/name" - "github.com/google/go-containerregistry/pkg/v1/remote" - "go.ciq.dev/beskar/pkg/oras" - "golang.org/x/sync/errgroup" "log/slog" "os" "path/filepath" "strings" + + "github.com/google/go-containerregistry/pkg/name" + "github.com/google/go-containerregistry/pkg/v1/remote" + "go.ciq.dev/beskar/pkg/oras" + "golang.org/x/sync/errgroup" ) type OSTreeRepositoryPusher struct { @@ -108,7 +112,6 @@ func (p *OSTreeRepositoryPusher) Push() error { func (p *OSTreeRepositoryPusher) push(path string) error { pusher, err := NewOSTreeFilePusher(p.dir, path, p.repo, p.nameOpts...) if err != nil { - return fmt.Errorf("while creating OSTree pusher: %w", err) } diff --git a/pkg/plugins/ostree/api/v1/api.go b/pkg/plugins/ostree/api/v1/api.go index 40797eb..0ea979d 100644 --- a/pkg/plugins/ostree/api/v1/api.go +++ b/pkg/plugins/ostree/api/v1/api.go @@ -58,10 +58,10 @@ type SyncStatus struct { EndTime string `json:"end_time"` SyncError string `json:"sync_error"` - //TODO: Implement these + // TODO: Implement these // The data for these is present when performing a pull via the ostree cli, so it is in the libostree code base. - //SyncedMetadata int `json:"synced_metadata"` - //SyncedObjects int `json:"synced_objects"` + // SyncedMetadata int `json:"synced_metadata"` + // SyncedObjects int `json:"synced_objects"` } // OSTree is used for managing ostree repositories. diff --git a/pkg/utils/time.go b/pkg/utils/time.go index 3e29d4f..c215c3c 100644 --- a/pkg/utils/time.go +++ b/pkg/utils/time.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved +// SPDX-License-Identifier: Apache-2.0 + package utils import "time"