Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Command to check completeness of a component version graph #644

Merged
merged 6 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions cmds/ocm/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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 @@ -81,7 +82,7 @@ type CLIOptions struct {
keyoption.Option

Completed bool
Config string
Config []string
ConfigSets []string
Credentials []string
Context clictx.Context
Expand Down Expand Up @@ -221,6 +222,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 @@ -296,7 +298,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 @@ -325,9 +327,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
Loading