Skip to content

Commit

Permalink
gofumpt
Browse files Browse the repository at this point in the history
linter fixes
  • Loading branch information
Kyle Ishie committed Jan 12, 2024
1 parent 9478fb4 commit 7876f55
Show file tree
Hide file tree
Showing 24 changed files with 101 additions and 52 deletions.
2 changes: 1 addition & 1 deletion build/mage/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
3 changes: 2 additions & 1 deletion cmd/beskar-ostree/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion cmd/beskar-static/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion cmd/beskar-yum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions cmd/beskarctl/ostree/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/repository/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package repository
import (
"context"
"errors"
"go.ciq.dev/beskar/internal/pkg/gossip"
"io"
"net"
"os"
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions internal/plugins/ostree/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package ostree

import (
"context"

"github.com/RussellLuo/kun/pkg/werror"
"github.com/RussellLuo/kun/pkg/werror/gcode"

Expand Down
3 changes: 3 additions & 0 deletions internal/plugins/ostree/pkg/libostree/errors.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions internal/plugins/ostree/pkg/libostree/glib_helpers.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,6 +10,7 @@ package libostree
// #include <stdlib.h>
// #include "glib_helpers.go.h"
import "C"

import (
"errors"
)
Expand Down
10 changes: 7 additions & 3 deletions internal/plugins/ostree/pkg/libostree/options.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))

Expand Down
3 changes: 3 additions & 0 deletions internal/plugins/ostree/pkg/libostree/ostree.go
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved
// SPDX-License-Identifier: Apache-2.0

package libostree
4 changes: 4 additions & 0 deletions internal/plugins/ostree/pkg/libostree/pull.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -6,6 +9,7 @@ package libostree
// #include <ostree.h>
// #include "pull.go.h"
import "C"

import (
"context"
"unsafe"
Expand Down
13 changes: 8 additions & 5 deletions internal/plugins/ostree/pkg/libostree/pull_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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()
Expand All @@ -40,7 +43,7 @@ func TestRepo_Pull(t *testing.T) {
RepoModeBare,
RepoModeBareUser,
RepoModeBareUserOnly,
//RepoModeBareSplitXAttrs,
// RepoModeBareSplitXAttrs,
}

// Test pull for each mode
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions internal/plugins/ostree/pkg/libostree/repo.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,6 +10,7 @@ package libostree
// #include <gio/gio.h>
// #include <ostree.h>
import "C"

import (
"runtime"
"unsafe"
Expand Down
17 changes: 7 additions & 10 deletions internal/plugins/ostree/pkg/ostreerepository/api.go
Original file line number Diff line number Diff line change
@@ -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"

Check failure on line 14 in internal/plugins/ostree/pkg/ostreerepository/api.go

View workflow job for this annotation

GitHub Actions / lint

could not import go.ciq.dev/beskar/internal/plugins/ostree/pkg/libostree (-: go build 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) {
Expand All @@ -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) {

Check failure on line 39 in internal/plugins/ostree/pkg/ostreerepository/api.go

View workflow job for this annotation

GitHub Actions / tests

undefined: libostree.Repo

// Add user provided remotes
// We do not need to add beskar remote here
for _, remote := range properties.Remotes {
Expand All @@ -51,7 +54,6 @@ func (h *Handler) CreateRepository(ctx context.Context, properties *apiv1.OSTree
}

return true, nil

}, SkipPull())
}

Expand Down Expand Up @@ -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) {

Check failure on line 85 in internal/plugins/ostree/pkg/ostreerepository/api.go

View workflow job for this annotation

GitHub Actions / tests

undefined: libostree.Repo

// 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)
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -159,7 +158,6 @@ func (h *Handler) AddRemote(ctx context.Context, remote *apiv1.OSTreeRemotePrope
}

return true, nil

}, SkipPull())
}

Expand Down Expand Up @@ -209,7 +207,6 @@ func (h *Handler) SyncRepository(ctx context.Context, properties *apiv1.OSTreeRe
}

return true, nil

})
}()

Expand Down
16 changes: 10 additions & 6 deletions internal/plugins/ostree/pkg/ostreerepository/handler.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 13 additions & 8 deletions internal/plugins/ostree/pkg/ostreerepository/local.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)

Check failure on line 27 in internal/plugins/ostree/pkg/ostreerepository/local.go

View workflow job for this annotation

GitHub Actions / tests

undefined: libostree.Repo
TransactionOptions struct {
skipPull bool
}
)

type TransactionOption func(*TransactionOptions)

Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions internal/plugins/ostree/pkg/ostreerepository/sync.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright (c) 2023, CIQ, Inc. All rights reserved
// SPDX-License-Identifier: Apache-2.0

package ostreerepository

import (
Expand Down
Loading

0 comments on commit 7876f55

Please sign in to comment.