Skip to content

Commit

Permalink
externalize general go utilities in packages pkg{errors,exceptions,ge…
Browse files Browse the repository at this point in the history
…nerics,finalizer} (#761)

## Description

Some general utility functions so far part of the ocm library are now
externalized, and can later be removed from the project.

## What type of PR is this? (check all applicable)

- [ ] 🍕 Feature
- [x] 🎇 Restructuring
- [x] 🐛 Bug Fix
- [ ] 📝 Documentation Update
- [ ] 🎨 Style
- [x] 🧑‍💻 Code Refactor
- [ ] 🔥 Performance Improvements
- [ ] ✅ Test
- [ ] 🤖 Build
- [ ] 🔁 CI
- [ ] 📦 Chore (Release)
- [ ] ⏩ Revert

## Related Tickets & Documents

<!-- 
Please use this format link issue numbers: Fixes #123

https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
-->
- Related Issue # (issue)
- Closes # (issue)
- Fixes # (issue)
> Remove if not applicable

## Screenshots

<!-- Visual changes require screenshots -->


## Added tests?

- [ ] 👍 yes
- [ ] 🙅 no, because they aren't needed
- [ ] 🙋 no, because I need help
- [ ] Separate ticket for tests # (issue/pr)

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration


## Added to documentation?

- [ ] 📜 README.md
- [ ] 🙅 no documentation needed

## Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
  • Loading branch information
mandelsoft committed May 15, 2024
1 parent 7889729 commit ccbbef5
Show file tree
Hide file tree
Showing 518 changed files with 1,197 additions and 949 deletions.
2 changes: 1 addition & 1 deletion cmds/demoplugin/accessmethods/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/mandelsoft/filepath/pkg/filepath"
"github.com/mandelsoft/goutils/errors"

"github.com/open-component-model/ocm/cmds/demoplugin/common"
"github.com/open-component-model/ocm/cmds/demoplugin/config"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/credentials/cpi"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/options"
"github.com/open-component-model/ocm/pkg/contexts/ocm/plugin/ppi"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/runtime"
)

Expand Down
2 changes: 1 addition & 1 deletion cmds/demoplugin/uploaders/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/mandelsoft/filepath/pkg/filepath"
"github.com/mandelsoft/goutils/errors"

"github.com/open-component-model/ocm/cmds/demoplugin/accessmethods"
"github.com/open-component-model/ocm/cmds/demoplugin/common"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/oci/identity"
"github.com/open-component-model/ocm/pkg/contexts/credentials/cpi"
"github.com/open-component-model/ocm/pkg/contexts/ocm/plugin/ppi"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/runtime"
)

Expand Down
2 changes: 1 addition & 1 deletion cmds/demoplugin/uploaders/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"os"

"github.com/mandelsoft/filepath/pkg/filepath"
"github.com/mandelsoft/goutils/errors"

"github.com/open-component-model/ocm/cmds/demoplugin/accessmethods"
"github.com/open-component-model/ocm/pkg/common"
"github.com/open-component-model/ocm/pkg/contexts/ocm/plugin/ppi"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/iotools"
"github.com/open-component-model/ocm/pkg/runtime"
)
Expand Down
13 changes: 7 additions & 6 deletions cmds/demoplugin/valuesets/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
out "fmt"
"strings"

"github.com/mandelsoft/goutils/errors"
"github.com/mandelsoft/goutils/set"

"github.com/open-component-model/ocm/pkg/cobrautils/flagsets"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/options"
"github.com/open-component-model/ocm/pkg/contexts/ocm/plugin/descriptor"
"github.com/open-component-model/ocm/pkg/contexts/ocm/plugin/ppi"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/generics"
"github.com/open-component-model/ocm/pkg/runtime"
"github.com/open-component-model/ocm/pkg/utils"
)
Expand All @@ -32,7 +33,7 @@ const (
STATUS_SKIPPED = "skipped"
)

var status = generics.Set[string]{}.Add(STATUS_PASSED, STATUS_FAILED, STATUS_SKIPPED)
var status = set.New[string](STATUS_PASSED, STATUS_FAILED, STATUS_SKIPPED)

var (
StatusOption = options.NewStringMapOptionType("checkStatus", out.Sprintf("status value for check (%s)", strings.Join(utils.StringMapKeys(status), ", ")))
Expand All @@ -50,7 +51,7 @@ func New() ppi.ValueSet {
The status entry has the following format:
- **<code>status</code> *string* status code (passed, failed)
- **<code>message</code> *string* mwssage
- **<code>message</code> *string* message
`),
}
}
Expand All @@ -62,7 +63,7 @@ func (v ValueSet) Options() []options.OptionType {
}
}

func (v ValueSet) ValidateSpecification(p ppi.Plugin, spec runtime.TypedObject) (*ppi.ValueSetInfo, error) {
func (v ValueSet) ValidateSpecification(_ ppi.Plugin, spec runtime.TypedObject) (*ppi.ValueSetInfo, error) {
var info ppi.ValueSetInfo

my := spec.(*Value)
Expand All @@ -86,7 +87,7 @@ func (v ValueSet) ValidateSpecification(p ppi.Plugin, spec runtime.TypedObject)
return &info, nil
}

func (v ValueSet) ComposeSpecification(p ppi.Plugin, opts ppi.Config, config ppi.Config) error {
func (v ValueSet) ComposeSpecification(_ ppi.Plugin, opts ppi.Config, config ppi.Config) error {
list := errors.ErrListf("configuring options")

if v, ok := opts.GetValue(StatusOption.GetName()); ok {
Expand Down
1 change: 1 addition & 0 deletions cmds/demoplugin/valuesets/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var _ = Describe("demoplugin", func() {
Expect(registration.RegisterExtensions(env)).To(Succeed())
p := registry.Get("demo")
Expect(p).NotTo(BeNil())
Expect(p.Error()).To(Equal(""))

env.OCMCompositionRepository("test", func() {
env.ComponentVersion(COMP, VERS, func() {
Expand Down
2 changes: 1 addition & 1 deletion cmds/ecrplugin/actions/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/ecr"
"github.com/aws/aws-sdk-go-v2/service/ecr/types"
"github.com/mandelsoft/goutils/errors"

ocmcreds "github.com/open-component-model/ocm/pkg/contexts/credentials"
"github.com/open-component-model/ocm/pkg/contexts/oci/actions/oci-repository-prepare"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/s3/identity"
"github.com/open-component-model/ocm/pkg/contexts/ocm/plugin/ppi"
"github.com/open-component-model/ocm/pkg/errors"
)

type Action struct{}
Expand Down
3 changes: 2 additions & 1 deletion cmds/helminstaller/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package app
import (
"encoding/json"

"github.com/mandelsoft/goutils/errors"

v1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
"github.com/open-component-model/ocm/pkg/contexts/ocm/utils/localize"
"github.com/open-component-model/ocm/pkg/errors"
)

type Config struct {
Expand Down
6 changes: 3 additions & 3 deletions cmds/helminstaller/app/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"fmt"
"strings"

. "github.com/open-component-model/ocm/pkg/exception"
. "github.com/open-component-model/ocm/pkg/finalizer"
. "github.com/mandelsoft/goutils/exception"
. "github.com/mandelsoft/goutils/finalizer"

"github.com/mandelsoft/filepath/pkg/filepath"
"github.com/mandelsoft/goutils/errors"
"github.com/mandelsoft/vfs/pkg/projectionfs"
"github.com/mandelsoft/vfs/pkg/vfs"

Expand All @@ -19,7 +20,6 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/ocm/download"
"github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes"
"github.com/open-component-model/ocm/pkg/contexts/ocm/utils"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/helm/loader"
"github.com/open-component-model/ocm/pkg/out"
"github.com/open-component-model/ocm/pkg/runtime"
Expand Down
2 changes: 1 addition & 1 deletion cmds/helminstaller/app/executor.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package app

import (
"github.com/mandelsoft/goutils/errors"
"github.com/mandelsoft/vfs/pkg/osfs"

"github.com/open-component-model/ocm/cmds/helminstaller/app/driver"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/runtime"
"github.com/open-component-model/ocm/pkg/toi/support"
)
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
_ "github.com/open-component-model/ocm/pkg/contexts/clictx/config"
_ "github.com/open-component-model/ocm/pkg/contexts/ocm/attrs"

"github.com/mandelsoft/goutils/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -70,7 +71,6 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/ocm/registration"
"github.com/open-component-model/ocm/pkg/contexts/ocm/utils"
"github.com/open-component-model/ocm/pkg/contexts/ocm/utils/defaultconfigregistry"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/out"
"github.com/open-component-model/ocm/pkg/signing"
"github.com/open-component-model/ocm/pkg/version"
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/cachecmds/clean/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"time"

"github.com/mandelsoft/goutils/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

Expand All @@ -14,7 +15,6 @@ import (
"github.com/open-component-model/ocm/pkg/common/accessio"
"github.com/open-component-model/ocm/pkg/contexts/clictx"
"github.com/open-component-model/ocm/pkg/contexts/oci/attrs/cacheattr"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/out"
utils2 "github.com/open-component-model/ocm/pkg/utils"
)
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/cachecmds/describe/cmd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package describe

import (
"github.com/mandelsoft/goutils/errors"
"github.com/spf13/cobra"

"github.com/open-component-model/ocm/cmds/ocm/commands/cachecmds/names"
Expand All @@ -9,7 +10,6 @@ import (
"github.com/open-component-model/ocm/pkg/common/accessio"
"github.com/open-component-model/ocm/pkg/contexts/clictx"
"github.com/open-component-model/ocm/pkg/contexts/oci/attrs/cacheattr"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/out"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package failonerroroption

import (
"github.com/mandelsoft/goutils/errors"
"github.com/spf13/pflag"

"github.com/open-component-model/ocm/cmds/ocm/pkg/options"
"github.com/open-component-model/ocm/pkg/errors"
)

func From(o options.OptionSetProvider) *Option {
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/common/options/keyoption/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"reflect"
"strings"

"github.com/mandelsoft/goutils/errors"
"github.com/spf13/pflag"

"github.com/open-component-model/ocm/cmds/ocm/pkg/options"
"github.com/open-component-model/ocm/pkg/contexts/clictx"
ocmsign "github.com/open-component-model/ocm/pkg/contexts/ocm/signing"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/signing"
"github.com/open-component-model/ocm/pkg/signing/signutils"
"github.com/open-component-model/ocm/pkg/utils"
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/misccmds/action/execute/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"strings"

"github.com/mandelsoft/goutils/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

Expand All @@ -14,7 +15,6 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/clictx"
"github.com/open-component-model/ocm/pkg/contexts/credentials"
"github.com/open-component-model/ocm/pkg/contexts/datacontext/action"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/out"
"github.com/open-component-model/ocm/pkg/runtime"
utils2 "github.com/open-component-model/ocm/pkg/utils"
Expand Down
4 changes: 2 additions & 2 deletions cmds/ocm/commands/misccmds/credentials/get/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"sort"
"strings"

"github.com/mandelsoft/goutils/errors"
"github.com/open-component-model/ocm/pkg/listformat"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

Expand All @@ -13,8 +15,6 @@ import (
"github.com/open-component-model/ocm/cmds/ocm/pkg/utils"
"github.com/open-component-model/ocm/pkg/contexts/clictx"
"github.com/open-component-model/ocm/pkg/contexts/credentials"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/listformat"
"github.com/open-component-model/ocm/pkg/out"
)

Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/misccmds/hash/sign/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strings"

"github.com/mandelsoft/goutils/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

Expand All @@ -15,7 +16,6 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/clictx"
"github.com/open-component-model/ocm/pkg/contexts/ocm/attrs/signingattr"
"github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/out"
"github.com/open-component-model/ocm/pkg/signing"
"github.com/open-component-model/ocm/pkg/signing/handlers/rsa"
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/misccmds/rsakeypair/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"github.com/mandelsoft/goutils/errors"
parse "github.com/mandelsoft/spiff/dynaml/x509"
"github.com/mandelsoft/vfs/pkg/vfs"
"github.com/spf13/cobra"
Expand All @@ -22,7 +23,6 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/rootcertsattr"
"github.com/open-component-model/ocm/pkg/contexts/ocm/attrs/signingattr"
"github.com/open-component-model/ocm/pkg/encrypt"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/out"
"github.com/open-component-model/ocm/pkg/signing"
"github.com/open-component-model/ocm/pkg/signing/handlers/rsa"
Expand Down
4 changes: 2 additions & 2 deletions cmds/ocm/commands/ocicmds/artifacts/describe/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package describe
import (
"fmt"

"github.com/mandelsoft/goutils/general"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

Expand All @@ -18,7 +19,6 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/clictx"
"github.com/open-component-model/ocm/pkg/contexts/oci"
"github.com/open-component-model/ocm/pkg/contexts/oci/ociutils"
"github.com/open-component-model/ocm/pkg/generics"
"github.com/open-component-model/ocm/pkg/out"
)

Expand Down Expand Up @@ -99,7 +99,7 @@ var outputs = output.NewOutputs(getRegular, output.Outputs{}).AddChainedManifest

func getRegular(opts *output.Options) output.Output {
return output.NewProcessingFunctionOutput(opts, processing.Chain(opts.LogContext()),
generics.Conditional(From(opts).BlobFiles, outInfoWithFiles, outInfo))
general.Conditional(From(opts).BlobFiles, outInfoWithFiles, outInfo))
}

func infoChain(options *output.Options) processing.ProcessChain {
Expand Down
4 changes: 2 additions & 2 deletions cmds/ocm/commands/ocicmds/artifacts/download/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io"
"strings"

"github.com/mandelsoft/goutils/errors"
"github.com/mandelsoft/goutils/finalizer"
"github.com/mandelsoft/vfs/pkg/projectionfs"
"github.com/mandelsoft/vfs/pkg/vfs"
"github.com/spf13/cobra"
Expand All @@ -25,8 +27,6 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/oci"
"github.com/open-component-model/ocm/pkg/contexts/oci/repositories/artifactset"
"github.com/open-component-model/ocm/pkg/contexts/ocm/download/handlers/dirtree"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/finalizer"
"github.com/open-component-model/ocm/pkg/out"
"github.com/open-component-model/ocm/pkg/utils/tarutils"
)
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/ocicmds/artifacts/transfer/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"path"

"github.com/mandelsoft/goutils/errors"
"github.com/opencontainers/go-digest"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand All @@ -18,7 +19,6 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/oci"
"github.com/open-component-model/ocm/pkg/contexts/oci/repositories/ctf"
"github.com/open-component-model/ocm/pkg/contexts/oci/transfer"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/out"
)

Expand Down

0 comments on commit ccbbef5

Please sign in to comment.