Skip to content

Commit

Permalink
Check Command to check completeness of a component version graph (#644)
Browse files Browse the repository at this point in the history
### ## Description

The new command `ocm check componentversion` checks component versions
in an OCM
repository to be complete. All directly or indirectly references
versions must also be
available in the repository of the initially checked one.

Additionally, it checks for cycles and may be more consistency
conditions in the future.

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

- [x] 🍕 Feature
- [ ] 🐛 Bug Fix
- [x] 📝 Documentation Update
- [ ] 🎨 Style
- [ ] 🧑‍💻 Code Refactor
- [ ] 🔥 Performance Improvements
- [x] ✅ 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?

- [x] 👍 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 authored Feb 16, 2024
1 parent 84bb593 commit ed906a3
Show file tree
Hide file tree
Showing 31 changed files with 986 additions and 24 deletions.
21 changes: 16 additions & 5 deletions cmds/ocm/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/open-component-model/ocm/cmds/ocm/commands/toicmds"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/add"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/bootstrap"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/check"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/clean"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/controller"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/create"
Expand Down Expand Up @@ -82,7 +83,7 @@ type CLIOptions struct {
keyoption.Option

Completed bool
Config string
Config []string
ConfigSets []string
Credentials []string
Context clictx.Context
Expand Down Expand Up @@ -231,6 +232,7 @@ func newCliCommand(opts *CLIOptions, mod ...func(clictx.Context, *cobra.Command)

cmd.AddCommand(NewVersionCommand(opts.Context))

cmd.AddCommand(check.NewCommand(opts.Context))
cmd.AddCommand(get.NewCommand(opts.Context))
cmd.AddCommand(create.NewCommand(opts.Context))
cmd.AddCommand(add.NewCommand(opts.Context))
Expand Down Expand Up @@ -306,7 +308,7 @@ func newCliCommand(opts *CLIOptions, mod ...func(clictx.Context, *cobra.Command)
}

func (o *CLIOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVarP(&o.Config, "config", "", "", "configuration file")
fs.StringArrayVarP(&o.Config, "config", "", nil, "configuration file")
fs.StringSliceVarP(&o.ConfigSets, "config-set", "", nil, "apply configuration set")
fs.StringArrayVarP(&o.Credentials, "cred", "C", nil, "credential setting")
fs.StringArrayVarP(&o.Settings, "attribute", "X", nil, "attribute setting")
Expand Down Expand Up @@ -335,9 +337,18 @@ func (o *CLIOptions) Complete() error {
if err != nil {
return err
}
_, err = utils.Configure(o.Context.OCMContext(), o.Config, vfsattr.Get(o.Context))
if err != nil {
return err

if len(o.Config) == 0 {
_, err = utils.Configure(o.Context.OCMContext(), "", vfsattr.Get(o.Context))
if err != nil {
return err
}
}
for _, config := range o.Config {
_, err = utils.Configure(o.Context.OCMContext(), config, vfsattr.Get(o.Context))
if err != nil {
return err
}
}

err = o.Option.Configure(o.Context)
Expand Down
33 changes: 32 additions & 1 deletion cmds/ocm/commands/common/options/failonerroroption/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package failonerroroption

import (
"github.com/open-component-model/ocm/pkg/errors"
"github.com/spf13/pflag"

"github.com/open-component-model/ocm/cmds/ocm/pkg/options"
Expand All @@ -22,10 +23,40 @@ func New() *Option {

type Option struct {
Fail bool
err error
}

func (o *Option) AddFlags(fs *pflag.FlagSet) {
fs.BoolVarP(&o.Fail, "fail-on-error", "", false, "fail on label validation error")
fs.BoolVarP(&o.Fail, "fail-on-error", "", false, "fail on validation error")
}

var _ options.Options = (*Option)(nil)

func (o *Option) GetError() error {
return o.err
}
func (o *Option) SetError(err error) {
o.err = err
}

func (o *Option) AddError(err error) {
if err == nil {
return
}
if o.err == nil {
o.err = errors.ErrList().Add(err)
} else {
if l, ok := o.err.(*errors.ErrorList); ok {
l.Add(err)
} else {
o.err = errors.ErrList().Add(o.err, err)
}
}
}

func (o *Option) ActivatedError() error {
if o.Fail {
return o.err
}
return nil
}
18 changes: 14 additions & 4 deletions cmds/ocm/commands/misccmds/credentials/get/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (
"sort"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/open-component-model/ocm/cmds/ocm/commands/misccmds/names"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs"
"github.com/open-component-model/ocm/cmds/ocm/pkg/output"
Expand All @@ -19,6 +16,9 @@ import (
"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"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

var (
Expand All @@ -32,7 +32,8 @@ type Command struct {
Consumer credentials.ConsumerIdentity
Matcher credentials.IdentityMatcher

Type string
Type string
Sloppy bool
}

var _ utils.OCMCommand = (*Command)(nil)
Expand Down Expand Up @@ -75,6 +76,7 @@ The usage of a dedicated matcher can be enforced by the option <code>--matcher</

func (o *Command) AddFlags(set *pflag.FlagSet) {
set.StringVarP(&o.Type, "matcher", "m", "", "matcher type override")
set.BoolVarP(&o.Sloppy, "sloppy", "s", false, "sloppy matching of consumer type")
}

func (o *Command) Complete(args []string) error {
Expand Down Expand Up @@ -111,6 +113,14 @@ func (o *Command) Complete(args []string) error {
}

func (o *Command) Run() error {
if o.Sloppy {
fix := credentials.GuessConsumerType(o, o.Consumer.Type())
if fix != o.Consumer.Type() {
out.Outf(o, "Correcting consumer type to %q\n", fix)
o.Consumer[credentials.ID_TYPE] = fix
}
}

creds, err := credentials.RequiredCredentialsForConsumer(o.CredentialsContext(), o.Consumer, o.Matcher)
if err != nil {
return err
Expand Down
Loading

0 comments on commit ed906a3

Please sign in to comment.