Skip to content

Commit

Permalink
extract optionutils + fix new usages of moved packages (#775)
Browse files Browse the repository at this point in the history
## Description

<!-- 
Please do not leave this blank 
This PR [adds/removes/fixes/replaces] the [feature/bug/etc]. 
-->

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context. List any dependencies that
are required for this change.


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

- [ ] 🍕 Feature
- [ ] 🎇 Restructuring
- [ ] 🐛 Bug Fix
- [ ] 📝 Documentation Update
- [ ] 🎨 Style
- [ ] 🧑‍💻 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

---------

Co-authored-by: Hilmar Falkenberg <hilmar.falkenberg@sap.com>
  • Loading branch information
mandelsoft and hilmarf authored May 27, 2024
1 parent edaf5ea commit 84b9231
Show file tree
Hide file tree
Showing 67 changed files with 107 additions and 81 deletions.
2 changes: 1 addition & 1 deletion cmds/ocm/commands/ocmcmds/components/check/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package check
import (
"fmt"

"github.com/mandelsoft/goutils/optionutils"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/util/json"

Expand All @@ -19,7 +20,6 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/clictx"
"github.com/open-component-model/ocm/pkg/contexts/ocm"
"github.com/open-component-model/ocm/pkg/contexts/ocm/utils/check"
"github.com/open-component-model/ocm/pkg/optionutils"
utils2 "github.com/open-component-model/ocm/pkg/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/ocmcmds/components/check/options.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package check

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

"github.com/open-component-model/ocm/cmds/ocm/pkg/options"
"github.com/open-component-model/ocm/pkg/contexts/ocm/utils/check"
"github.com/open-component-model/ocm/pkg/optionutils"
)

func From(o options.OptionSetProvider) *Option {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
github.com/klauspost/compress v1.17.8
github.com/klauspost/pgzip v1.2.6
github.com/mandelsoft/filepath v0.0.0-20240223090642-3e2777258aa3
github.com/mandelsoft/goutils v0.0.0-20240510154642-0f1a031c54cb
github.com/mandelsoft/goutils v0.0.0-20240523093855-5385ed52b460
github.com/mandelsoft/logging v0.0.0-20240201091719-67180059d6bf
github.com/mandelsoft/spiff v1.7.0-beta-5
github.com/mandelsoft/vfs v0.4.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,8 @@ github.com/mandelsoft/filepath v0.0.0-20240223090642-3e2777258aa3 h1:oo9nIgnyiBg
github.com/mandelsoft/filepath v0.0.0-20240223090642-3e2777258aa3/go.mod h1:LxhqC7khDoRENwooP6f/vWvia9ivj6TqLYrR39zqkN0=
github.com/mandelsoft/goutils v0.0.0-20240510154642-0f1a031c54cb h1:1d3Xxk4rkdKcIFP1AcRlPxUhcBhnFCTqrMhXztB1r5E=
github.com/mandelsoft/goutils v0.0.0-20240510154642-0f1a031c54cb/go.mod h1:EbNqk9JceSMq7MJuALB/vlOpoD4MAGE0TenM9TR+C0o=
github.com/mandelsoft/goutils v0.0.0-20240523093855-5385ed52b460 h1:q44fRqo/PC3eTexd8Q3pO2BTHTABVXsW6DBXRUhC97E=
github.com/mandelsoft/goutils v0.0.0-20240523093855-5385ed52b460/go.mod h1:EbNqk9JceSMq7MJuALB/vlOpoD4MAGE0TenM9TR+C0o=
github.com/mandelsoft/logging v0.0.0-20240201091719-67180059d6bf h1:WEmgzeArDbp6Aw34jmziMIE5ygo2zpl/atXRq3D7lSw=
github.com/mandelsoft/logging v0.0.0-20240201091719-67180059d6bf/go.mod h1:uO460C1lIB3IOOgrbXhAlz3AKsOv4T2K6ALBn3PwuSg=
github.com/mandelsoft/spiff v1.7.0-beta-5 h1:3kC10nTviDQhL8diSxp7i4IC2iSiDg6KPbH1CAq7Lfw=
Expand Down
2 changes: 1 addition & 1 deletion pkg/blobaccess/dirtree/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"fmt"

"github.com/mandelsoft/goutils/errors"
"github.com/mandelsoft/goutils/optionutils"
"github.com/mandelsoft/vfs/pkg/vfs"

"github.com/open-component-model/ocm/pkg/blobaccess"
"github.com/open-component-model/ocm/pkg/blobaccess/bpi"
"github.com/open-component-model/ocm/pkg/mime"
"github.com/open-component-model/ocm/pkg/optionutils"
"github.com/open-component-model/ocm/pkg/utils"
"github.com/open-component-model/ocm/pkg/utils/tarutils"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/blobaccess/dirtree/options.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package dirtree

import (
"github.com/mandelsoft/goutils/optionutils"
"github.com/mandelsoft/vfs/pkg/vfs"
"golang.org/x/exp/slices"

"github.com/open-component-model/ocm/pkg/optionutils"
"github.com/open-component-model/ocm/pkg/utils"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/blobaccess/dockerdaemon/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package dockerdaemon
import (
"fmt"

"github.com/mandelsoft/goutils/optionutils"

"github.com/open-component-model/ocm/pkg/blobaccess"
"github.com/open-component-model/ocm/pkg/blobaccess/bpi"
"github.com/open-component-model/ocm/pkg/contexts/oci"
"github.com/open-component-model/ocm/pkg/contexts/oci/annotations"
"github.com/open-component-model/ocm/pkg/contexts/oci/repositories/artifactset"
"github.com/open-component-model/ocm/pkg/contexts/oci/repositories/docker"
"github.com/open-component-model/ocm/pkg/optionutils"
)

func (o *Options) OCIContext() oci.Context {
Expand Down
3 changes: 2 additions & 1 deletion pkg/blobaccess/dockerdaemon/options.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package dockerdaemon

import (
"github.com/mandelsoft/goutils/optionutils"

"github.com/open-component-model/ocm/pkg/common"
"github.com/open-component-model/ocm/pkg/contexts/oci"
"github.com/open-component-model/ocm/pkg/optionutils"
"github.com/open-component-model/ocm/pkg/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/blobaccess/dockermulti/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
. "github.com/mandelsoft/goutils/finalizer"

"github.com/mandelsoft/goutils/errors"
"github.com/mandelsoft/goutils/optionutils"
"github.com/opencontainers/go-digest"

"github.com/open-component-model/ocm/pkg/blobaccess"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/oci/cpi"
"github.com/open-component-model/ocm/pkg/contexts/oci/repositories/artifactset"
"github.com/open-component-model/ocm/pkg/contexts/oci/repositories/docker"
"github.com/open-component-model/ocm/pkg/optionutils"
)

func (o *Options) OCIContext() oci.Context {
Expand Down
2 changes: 1 addition & 1 deletion pkg/blobaccess/dockermulti/options.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package dockermulti

import (
"github.com/mandelsoft/goutils/optionutils"
"golang.org/x/exp/slices"

"github.com/open-component-model/ocm/pkg/common"
"github.com/open-component-model/ocm/pkg/contexts/oci"
"github.com/open-component-model/ocm/pkg/optionutils"
)

type Option = optionutils.Option[*Options]
Expand Down
2 changes: 1 addition & 1 deletion pkg/blobaccess/helm/options.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package helm

import (
"github.com/mandelsoft/goutils/optionutils"
"github.com/mandelsoft/vfs/pkg/vfs"

"github.com/open-component-model/ocm/pkg/common"
"github.com/open-component-model/ocm/pkg/contexts/oci"
"github.com/open-component-model/ocm/pkg/optionutils"
"github.com/open-component-model/ocm/pkg/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/blobaccess/helm/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/mandelsoft/goutils/errors"
"github.com/mandelsoft/goutils/optionutils"
"github.com/mandelsoft/vfs/pkg/vfs"

"github.com/open-component-model/ocm/pkg/blobaccess"
Expand All @@ -14,7 +15,6 @@ import (
ocihelm "github.com/open-component-model/ocm/pkg/contexts/oci/ociutils/helm"
"github.com/open-component-model/ocm/pkg/helm"
"github.com/open-component-model/ocm/pkg/helm/loader"
"github.com/open-component-model/ocm/pkg/optionutils"
"github.com/open-component-model/ocm/pkg/utils"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/blobaccess/ociartifact/options.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ociartifact

import (
"github.com/mandelsoft/goutils/optionutils"

"github.com/open-component-model/ocm/pkg/common"
"github.com/open-component-model/ocm/pkg/contexts/oci"
"github.com/open-component-model/ocm/pkg/contexts/oci/transfer/filters"
"github.com/open-component-model/ocm/pkg/optionutils"
)

type Option = optionutils.Option[*Options]
Expand Down
3 changes: 2 additions & 1 deletion pkg/blobaccess/ociartifact/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package ociartifact
import (
"fmt"

"github.com/mandelsoft/goutils/optionutils"

"github.com/open-component-model/ocm/pkg/blobaccess"
"github.com/open-component-model/ocm/pkg/blobaccess/bpi"
"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/optionutils"
)

func BlobAccessForOCIArtifact(refname string, opts ...Option) (blobaccess.BlobAccess, string, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/blobaccess/wget/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"net/http"

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

"github.com/open-component-model/ocm/pkg/blobaccess"
"github.com/open-component-model/ocm/pkg/blobaccess/bpi"
"github.com/open-component-model/ocm/pkg/contexts/credentials"
"github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/wget/identity"
"github.com/open-component-model/ocm/pkg/contexts/ocm/cpi"
ocmmime "github.com/open-component-model/ocm/pkg/mime"
"github.com/open-component-model/ocm/pkg/optionutils"
"github.com/open-component-model/ocm/pkg/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/blobaccess/wget/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"io"
"net/http"

"github.com/mandelsoft/goutils/optionutils"
"github.com/mandelsoft/logging"

"github.com/open-component-model/ocm/pkg/contexts/credentials"
"github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/wget/identity"
ocmlog "github.com/open-component-model/ocm/pkg/logging"
"github.com/open-component-model/ocm/pkg/optionutils"
"github.com/open-component-model/ocm/pkg/utils"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/cobrautils/flagsets/flagsetscheme/types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package flagsetscheme

import (
"github.com/mandelsoft/goutils/optionutils"

"github.com/open-component-model/ocm/pkg/cobrautils/flagsets"
"github.com/open-component-model/ocm/pkg/optionutils"
"github.com/open-component-model/ocm/pkg/runtime"
"github.com/open-component-model/ocm/pkg/runtime/descriptivetype"
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/cobrautils/flagsets/flagsetscheme/types_options.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package flagsetscheme

import (
"github.com/mandelsoft/goutils/optionutils"

"github.com/open-component-model/ocm/pkg/cobrautils/flagsets"
"github.com/open-component-model/ocm/pkg/optionutils"
"github.com/open-component-model/ocm/pkg/runtime/descriptivetype"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/contexts/credentials/repositories/vault/options.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package vault

import (
"github.com/mandelsoft/goutils/optionutils"
"golang.org/x/exp/slices"

"github.com/open-component-model/ocm/pkg/optionutils"
"github.com/open-component-model/ocm/pkg/utils"
)

Expand Down
29 changes: 15 additions & 14 deletions pkg/contexts/credentials/repositories/vault/repo_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

"github.com/hashicorp/vault-client-go"
"github.com/hashicorp/vault-client-go/schema"
"github.com/mandelsoft/goutils/errors"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand All @@ -20,7 +22,6 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/credentials/identity/hostpath"
me "github.com/open-component-model/ocm/pkg/contexts/credentials/repositories/vault"
"github.com/open-component-model/ocm/pkg/contexts/credentials/repositories/vault/identity"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/runtime"
. "github.com/open-component-model/ocm/pkg/testutils"
)
Expand Down Expand Up @@ -328,7 +329,7 @@ path "secret/metadata/%s/*"
role := Must(vaultClient.Auth.AppRoleReadRoleId(ctx, VAULT_APP_ROLE1))
roleid := role.Data.RoleId
// Unfortunately, this function is currently bugged, therefore we fall back to the generic function
//secretid := Must(client.Auth.AppRoleWriteSecretId(ctx, VAULT_APP_ROLE, schema.AppRoleWriteSecretIdRequest{}))
// secretid := Must(client.Auth.AppRoleWriteSecretId(ctx, VAULT_APP_ROLE, schema.AppRoleWriteSecretIdRequest{}))
secret := Must(vaultClient.Write(ctx, fmt.Sprintf("/v1/auth/approle/role/%s/secret-id", VAULT_APP_ROLE1), map[string]interface{}{}))
secretid := secret.Data["secret_id"].(string)

Expand Down Expand Up @@ -385,18 +386,18 @@ path "secret/metadata/%s/*"
Expect(c).To(YAMLEqual(data))
})

//D(irect):
// D(irect):
// - has general credentials matching parent path of P2
// - has credentials for P1
//P1:
// P1:
// - has specialized credentials for P2
//P2:
// P2:
// - has credentials for C
//
//
//query C:
//- D: -> nothing
//- P1: query P1
// query C:
// - D: -> nothing
// - P1: query P1
// - D: -> found
// - P1: omit (recursion)
// - P2: query P2
Expand All @@ -406,7 +407,7 @@ path "secret/metadata/%s/*"
// explore, whether an additional attempt with P1 BUT only with credentialless providers / direct creds
// would work as a general solution.
// -> select D(P2) WRONG (a1)
//- P2: query P2
// - P2: query P2
// - D: -> found
// - P1: query P1
// - D: found
Expand All @@ -417,12 +418,12 @@ path "secret/metadata/%s/*"
// - P2: omit (recursion)
// -> select P1(P2) CORRECT (a2)
// -> found
//-> select P2(C)
// -> select P2(C)
//
// The Problem here is, that the case a1 and case b are formally indistinguishable. While a2 and b lead to the
// correct result, we would fail in a1.
It("recursive authentication with overlapping credentials", func() {
//TODO
// TODO
})
})
})
Expand All @@ -441,8 +442,8 @@ func StartVaultServer(mode vaultMode, rootToken, address string) (*exec.Cmd, *va
}

cmd := exec.CommandContext(cmdctx, "../../../../../bin/vault", "server", "-"+string(mode), fmt.Sprintf("-dev-root-token-id=%s", rootToken), fmt.Sprintf("-dev-listen-address=%s", address))
//cmd.Stdout = os.Stdout
//cmd.Stderr = os.Stderr
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr

vaultClient, err := vault.New(
vault.WithAddress(url),
Expand Down Expand Up @@ -494,7 +495,7 @@ func SetUpVaultAccess(ctx context.Context, credctx credentials.Context, client *
role := Must(client.Auth.AppRoleReadRoleId(ctx, VAULT_APP_ROLE))
roleid := role.Data.RoleId
// Unfortunately, this function is currently bugged, therefore we fall back to the generic function
//secretid := Must(client.Auth.AppRoleWriteSecretId(ctx, VAULT_APP_ROLE, schema.AppRoleWriteSecretIdRequest{}))
// secretid := Must(client.Auth.AppRoleWriteSecretId(ctx, VAULT_APP_ROLE, schema.AppRoleWriteSecretIdRequest{}))
secret := Must(client.Write(ctx, fmt.Sprintf("/v1/auth/approle/role/%s/secret-id", VAULT_APP_ROLE), map[string]interface{}{}))
secretid := secret.Data["secret_id"].(string)

Expand Down
2 changes: 1 addition & 1 deletion pkg/contexts/credentials/repositories/vault/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"encoding/json"
"fmt"

"github.com/mandelsoft/goutils/optionutils"
"golang.org/x/exp/slices"

"github.com/open-component-model/ocm/pkg/contexts/credentials/cpi"
"github.com/open-component-model/ocm/pkg/contexts/credentials/internal"
"github.com/open-component-model/ocm/pkg/contexts/credentials/repositories/vault/identity"
"github.com/open-component-model/ocm/pkg/optionutils"
"github.com/open-component-model/ocm/pkg/runtime"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/contexts/oci/grammar/grammar.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package grammar
import (
"strings"

. "github.com/open-component-model/ocm/pkg/regex"
. "github.com/mandelsoft/goutils/regexutils"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/contexts/oci/grammar/grammar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

tool "github.com/open-component-model/ocm/pkg/regex"
tool "github.com/mandelsoft/goutils/regexutils"
)

func TestConfig(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/contexts/oci/repositories/ocireg/uniform.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package ocireg

import (
regex "github.com/mandelsoft/goutils/regexutils"

"github.com/open-component-model/ocm/pkg/contexts/oci/cpi"
"github.com/open-component-model/ocm/pkg/contexts/oci/grammar"
"github.com/open-component-model/ocm/pkg/regex"
)

func init() {
Expand Down
Loading

0 comments on commit 84b9231

Please sign in to comment.