From 3a483ae3571fba59db46e33f0c26d928a2f5104f Mon Sep 17 00:00:00 2001 From: Uwe Krueger Date: Tue, 30 Aug 2022 18:41:10 +0200 Subject: [PATCH] Missing content of #59 (#79) * Deleted a bunch of things which significantly sped up build time * Apply suggestions from code review Co-authored-by: Balazs Nadasdi * Updated error message and added expected type information * Putting back the removed stuff * Renaming funcs with underscore in it. Co-authored-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> Co-authored-by: Balazs Nadasdi --- cmds/ocm/commands/ocicmds/artefacts/cmd.go | 7 +- .../ocicmds/artefacts/describe/cmd.go | 4 +- .../ocicmds/artefacts/download/cmd.go | 4 +- .../ocm/commands/ocicmds/artefacts/get/cmd.go | 24 +- .../ocmcmds/common/inputs/inputtype.go | 13 +- .../commands/ocmcmds/components/get/cmd.go | 24 +- .../commands/ocmcmds/references/get/cmd.go | 24 +- .../ocmcmds/resources/add/resources.go | 2 +- .../ocm/commands/ocmcmds/resources/get/cmd.go | 34 +- cmds/ocm/commands/ocmcmds/sources/get/cmd.go | 24 +- cmds/ocm/pkg/data/indexed.go | 6 - cmds/ocm/pkg/output/sort_test.go | 8 +- cmds/ocm/pkg/output/tableoutput.go | 4 +- cmds/ocm/pkg/processing/chain.go | 42 +-- cmds/ocm/pkg/processing/container.go | 295 ------------------ cmds/ocm/pkg/processing/pool.go | 12 +- cmds/ocm/pkg/processing/sequential.go | 41 +-- pkg/common/accessio/opts.go | 24 +- pkg/contexts/config/core/configtypes.go | 13 +- pkg/contexts/credentials/core/repotypes.go | 13 +- pkg/contexts/oci/core/repotypes.go | 13 +- .../ocm.gardener.cloud/v3alpha1/version.go | 80 ++--- .../ocm/compdesc/versions/v2/version.go | 80 ++--- pkg/contexts/ocm/core/repotypes.go | 13 +- pkg/env/builder/oci_artefact.go | 12 +- pkg/env/builder/oci_artefactset.go | 2 +- pkg/env/builder/oci_config.go | 10 +- pkg/env/builder/oci_ctf.go | 2 +- pkg/env/builder/oci_layer.go | 10 +- pkg/env/builder/oci_namespace.go | 8 +- pkg/env/builder/oci_repo.go | 6 +- pkg/env/builder/ocm_comparch.go | 2 +- pkg/env/builder/ocm_component.go | 8 +- pkg/env/builder/ocm_ctf.go | 2 +- pkg/env/builder/ocm_reference.go | 10 +- pkg/env/builder/ocm_repo.go | 6 +- pkg/env/builder/ocm_resource.go | 10 +- pkg/env/builder/ocm_source.go | 10 +- pkg/env/builder/ocm_version.go | 8 +- pkg/env/env.go | 8 +- pkg/runtime/scheme.go | 29 +- 41 files changed, 315 insertions(+), 632 deletions(-) delete mode 100644 cmds/ocm/pkg/processing/container.go diff --git a/cmds/ocm/commands/ocicmds/artefacts/cmd.go b/cmds/ocm/commands/ocicmds/artefacts/cmd.go index 043618d0a..9ff1080e3 100644 --- a/cmds/ocm/commands/ocicmds/artefacts/cmd.go +++ b/cmds/ocm/commands/ocicmds/artefacts/cmd.go @@ -17,15 +17,13 @@ package artefacts import ( "github.com/spf13/cobra" - "github.com/open-component-model/ocm/pkg/contexts/clictx" - - "github.com/open-component-model/ocm/cmds/ocm/pkg/utils" - "github.com/open-component-model/ocm/cmds/ocm/commands/ocicmds/artefacts/describe" "github.com/open-component-model/ocm/cmds/ocm/commands/ocicmds/artefacts/download" "github.com/open-component-model/ocm/cmds/ocm/commands/ocicmds/artefacts/get" "github.com/open-component-model/ocm/cmds/ocm/commands/ocicmds/artefacts/transfer" "github.com/open-component-model/ocm/cmds/ocm/commands/ocicmds/names" + "github.com/open-component-model/ocm/cmds/ocm/pkg/utils" + "github.com/open-component-model/ocm/pkg/contexts/clictx" ) var Names = names.Artefacts @@ -35,6 +33,7 @@ func NewCommand(ctx clictx.Context) *cobra.Command { cmd := utils.MassageCommand(&cobra.Command{ Short: "Commands acting on OCI artefacts", }, Names...) + cmd.AddCommand(get.NewCommand(ctx, get.Verb)) cmd.AddCommand(describe.NewCommand(ctx, describe.Verb)) cmd.AddCommand(transfer.NewCommand(ctx, transfer.Verb)) diff --git a/cmds/ocm/commands/ocicmds/artefacts/describe/cmd.go b/cmds/ocm/commands/ocicmds/artefacts/describe/cmd.go index af3531af6..c11b6bfcc 100644 --- a/cmds/ocm/commands/ocicmds/artefacts/describe/cmd.go +++ b/cmds/ocm/commands/ocicmds/artefacts/describe/cmd.go @@ -109,9 +109,9 @@ func (o *Command) Run() error { ///////////////////////////////////////////////////////////////////////////// -var outputs = output.NewOutputs(get_regular, output.Outputs{}).AddChainedManifestOutputs(infoChain) +var outputs = output.NewOutputs(getRegular, output.Outputs{}).AddChainedManifestOutputs(infoChain) -func get_regular(opts *output.Options) output.Output { +func getRegular(opts *output.Options) output.Output { return output.NewProcessingFunctionOutput(opts.Context, processing.Chain(), outInfo) } diff --git a/cmds/ocm/commands/ocicmds/artefacts/download/cmd.go b/cmds/ocm/commands/ocicmds/artefacts/download/cmd.go index 5b7f6a4ce..8628eb28c 100644 --- a/cmds/ocm/commands/ocicmds/artefacts/download/cmd.go +++ b/cmds/ocm/commands/ocicmds/artefacts/download/cmd.go @@ -91,9 +91,9 @@ func (o *Command) Run() error { //////////////////////////////////////////////////////////////////////////////// -var outputs = output.NewOutputs(get_download) +var outputs = output.NewOutputs(getDownload) -func get_download(opts *output.Options) output.Output { +func getDownload(opts *output.Options) output.Output { return &download{opts: opts} } diff --git a/cmds/ocm/commands/ocicmds/artefacts/get/cmd.go b/cmds/ocm/commands/ocicmds/artefacts/get/cmd.go index 4e778f264..1b10f7bbf 100644 --- a/cmds/ocm/commands/ocicmds/artefacts/get/cmd.go +++ b/cmds/ocm/commands/ocicmds/artefacts/get/cmd.go @@ -104,24 +104,24 @@ func TableOutput(opts *output.Options, mapping processing.MappingFunction, wide } } -var outputs = output.NewOutputs(get_regular, output.Outputs{ - "wide": get_wide, - "tree": get_tree, +var outputs = output.NewOutputs(getRegular, output.Outputs{ + "wide": getWide, + "tree": getTree, }).AddChainedManifestOutputs(OutputChainFunction()) -func get_regular(opts *output.Options) output.Output { - return closureoption.TableOutput(TableOutput(opts, map_get_regular_output)).New() +func getRegular(opts *output.Options) output.Output { + return closureoption.TableOutput(TableOutput(opts, mapGetRegularOutput)).New() } -func get_wide(opts *output.Options) output.Output { - return closureoption.TableOutput(TableOutput(opts, map_get_wide_output, "MIMETYPE", "CONFIGTYPE")).New() +func getWide(opts *output.Options) output.Output { + return closureoption.TableOutput(TableOutput(opts, mapGetWideOutput, "MIMETYPE", "CONFIGTYPE")).New() } -func get_tree(opts *output.Options) output.Output { - return output.TreeOutput(TableOutput(opts, map_get_regular_output), "NESTING").New() +func getTree(opts *output.Options) output.Output { + return output.TreeOutput(TableOutput(opts, mapGetRegularOutput), "NESTING").New() } -func map_get_regular_output(e interface{}) interface{} { +func mapGetRegularOutput(e interface{}) interface{} { digest := "unknown" p := e.(*artefacthdlr.Object) blob, err := p.Artefact.Blob() @@ -142,12 +142,12 @@ func map_get_regular_output(e interface{}) interface{} { return []string{p.Spec.UniformRepositorySpec.String(), p.Spec.Repository, kind, tag, digest} } -func map_get_wide_output(e interface{}) interface{} { +func mapGetWideOutput(e interface{}) interface{} { p := e.(*artefacthdlr.Object) config := "-" if p.Artefact.IsManifest() { config = p.Artefact.ManifestAccess().GetDescriptor().Config.MediaType } - return output.Fields(map_get_regular_output(e), p.Artefact.GetDescriptor().MimeType(), config) + return output.Fields(mapGetRegularOutput(e), p.Artefact.GetDescriptor().MimeType(), config) } diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/inputtype.go b/cmds/ocm/commands/ocmcmds/common/inputs/inputtype.go index c455f315e..73828eb0c 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/inputtype.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/inputtype.go @@ -100,16 +100,21 @@ func (t *inputTypeScheme) GetInputType(name string) InputType { func (t *inputTypeScheme) RegisterByDecoder(name string, decoder runtime.TypedObjectDecoder) error { if _, ok := decoder.(InputType); !ok { - errors.ErrInvalid("type", reflect.TypeOf(decoder).String()) + return errors.ErrInvalid("type", reflect.TypeOf(decoder).String()) } return t.Scheme.RegisterByDecoder(name, decoder) } -func (t *inputTypeScheme) AddKnownTypes(scheme runtime.Scheme) { +func (t *inputTypeScheme) AddKnownTypes(scheme runtime.Scheme) error { if _, ok := scheme.(InputTypeScheme); !ok { - panic("can only add RepositoryTypeSchemes") + return errors.ErrInvalid("type", reflect.TypeOf(scheme).String(), "expected", "InputTypeScheme") } - t.Scheme.AddKnownTypes(scheme) + + if err := t.Scheme.AddKnownTypes(scheme); err != nil { + return fmt.Errorf("failed to add known type in inputTypeScheme: %w", err) + } + + return nil } func (t *inputTypeScheme) Register(name string, rtype InputType) { diff --git a/cmds/ocm/commands/ocmcmds/components/get/cmd.go b/cmds/ocm/commands/ocmcmds/components/get/cmd.go index a6f7b5648..ed5ef21b3 100644 --- a/cmds/ocm/commands/ocmcmds/components/get/cmd.go +++ b/cmds/ocm/commands/ocmcmds/components/get/cmd.go @@ -139,24 +139,24 @@ func Format(opts *output.Options) processing.ProcessChain { ///////////////////////////////////////////////////////////////////////////// -var outputs = output.NewOutputs(get_regular, output.Outputs{ - "wide": get_wide, - "tree": get_tree, +var outputs = output.NewOutputs(getRegular, output.Outputs{ + "wide": getWide, + "tree": getTree, }).AddChainedManifestOutputs(output.ComposeChain(closureoption.OutputChainFunction(comphdlr.ClosureExplode, comphdlr.Sort), Format)) -func get_regular(opts *output.Options) output.Output { - return TableOutput(opts, map_get_regular_output).New() +func getRegular(opts *output.Options) output.Output { + return TableOutput(opts, mapGetRegularOutput).New() } -func get_wide(opts *output.Options) output.Output { - return TableOutput(opts, map_get_wide_output, "REPOSITORY").New() +func getWide(opts *output.Options) output.Output { + return TableOutput(opts, mapGetWideOutput, "REPOSITORY").New() } -func get_tree(opts *output.Options) output.Output { - return output.TreeOutput(TableOutput(opts, map_get_regular_output), "NESTING").New() +func getTree(opts *output.Options) output.Output { + return output.TreeOutput(TableOutput(opts, mapGetRegularOutput), "NESTING").New() } -func map_get_regular_output(e interface{}) interface{} { +func mapGetRegularOutput(e interface{}) interface{} { p := e.(*comphdlr.Object) tag := "-" @@ -169,7 +169,7 @@ func map_get_regular_output(e interface{}) interface{} { return []string{p.Spec.Component, tag, string(p.ComponentVersion.GetDescriptor().Provider.Name)} } -func map_get_wide_output(e interface{}) interface{} { +func mapGetWideOutput(e interface{}) interface{} { p := e.(*comphdlr.Object) - return output.Fields(map_get_regular_output(e), p.Spec.UniformRepositorySpec.String()) + return output.Fields(mapGetRegularOutput(e), p.Spec.UniformRepositorySpec.String()) } diff --git a/cmds/ocm/commands/ocmcmds/references/get/cmd.go b/cmds/ocm/commands/ocmcmds/references/get/cmd.go index d84061e70..f442934cd 100644 --- a/cmds/ocm/commands/ocmcmds/references/get/cmd.go +++ b/cmds/ocm/commands/ocmcmds/references/get/cmd.go @@ -134,29 +134,29 @@ func TableOutput(opts *output.Options, mapping processing.MappingFunction, wide } } -var outputs = output.NewOutputs(get_regular, output.Outputs{ - "wide": get_wide, - "tree": get_tree, +var outputs = output.NewOutputs(getRegular, output.Outputs{ + "wide": getWide, + "tree": getTree, }).AddManifestOutputs() -func get_regular(opts *output.Options) output.Output { - return closureoption.TableOutput(TableOutput(opts, map_get_regular_output)).New() +func getRegular(opts *output.Options) output.Output { + return closureoption.TableOutput(TableOutput(opts, mapGetRegularOutput)).New() } -func get_wide(opts *output.Options) output.Output { - return closureoption.TableOutput(TableOutput(opts, map_get_wide_output, "IDENTITY")).New() +func getWide(opts *output.Options) output.Output { + return closureoption.TableOutput(TableOutput(opts, mapGetWideOutput, "IDENTITY")).New() } -func get_tree(opts *output.Options) output.Output { - return output.TreeOutput(TableOutput(opts, map_get_wide_output, "IDENTITY"), "COMPONENTVERSION").New() +func getTree(opts *output.Options) output.Output { + return output.TreeOutput(TableOutput(opts, mapGetWideOutput, "IDENTITY"), "COMPONENTVERSION").New() } -func map_get_regular_output(e interface{}) interface{} { +func mapGetRegularOutput(e interface{}) interface{} { r := common.Elem(e) return output.Fields(r.GetName(), r.ComponentName, r.GetVersion()) } -func map_get_wide_output(e interface{}) interface{} { +func mapGetWideOutput(e interface{}) interface{} { o := e.(*elemhdlr.Object) - return output.Fields(map_get_regular_output(e), o.Id.String()) + return output.Fields(mapGetRegularOutput(e), o.Id.String()) } diff --git a/cmds/ocm/commands/ocmcmds/resources/add/resources.go b/cmds/ocm/commands/ocmcmds/resources/add/resources.go index 04224a894..e4202fd4f 100644 --- a/cmds/ocm/commands/ocmcmds/resources/add/resources.go +++ b/cmds/ocm/commands/ocmcmds/resources/add/resources.go @@ -71,7 +71,7 @@ func (ResourceSpecHandler) Set(v ocm.ComponentVersionAccess, r common.Resource, }, Type: spec.Type, Relation: spec.Relation, - SourceRef: compdescv2.Convert_SourceRefs_to(spec.SourceRef), + SourceRef: compdescv2.ConvertSourcerefsTo(spec.SourceRef), } return v.SetResource(meta, acc) } diff --git a/cmds/ocm/commands/ocmcmds/resources/get/cmd.go b/cmds/ocm/commands/ocmcmds/resources/get/cmd.go index bef13b58b..75c65a68e 100644 --- a/cmds/ocm/commands/ocmcmds/resources/get/cmd.go +++ b/cmds/ocm/commands/ocmcmds/resources/get/cmd.go @@ -101,37 +101,37 @@ func TableOutput(opts *output.Options, mapping processing.MappingFunction, wide } } -var outputs = output.NewOutputs(get_regular, output.Outputs{ - "wide": get_wide, - "tree": get_tree, - "treewide": get_treewide, +var outputs = output.NewOutputs(getRegular, output.Outputs{ + "wide": getWide, + "tree": getTree, + "treewide": getTreewide, }).AddManifestOutputs() -func get_regular(opts *output.Options) output.Output { - return closureoption.TableOutput(TableOutput(opts, map_get_regular_output)).New() +func getRegular(opts *output.Options) output.Output { + return closureoption.TableOutput(TableOutput(opts, mapGetRegularOutput)).New() } -func get_wide(opts *output.Options) output.Output { - return closureoption.TableOutput(TableOutput(opts, map_get_wide_output, elemhdlr.AccessOutput...)).New() +func getWide(opts *output.Options) output.Output { + return closureoption.TableOutput(TableOutput(opts, mapGetWideOutput, elemhdlr.AccessOutput...)).New() } -func get_tree(opts *output.Options) output.Output { - return output.TreeOutput(TableOutput(opts, map_get_regular_output), "COMPONENTVERSION").New() +func getTree(opts *output.Options) output.Output { + return output.TreeOutput(TableOutput(opts, mapGetRegularOutput), "COMPONENTVERSION").New() } -func get_treewide(opts *output.Options) output.Output { - return output.TreeOutput(TableOutput(opts, map_get_treewide_output, "ACCESS"), "COMPONENTVERSION").New() +func getTreewide(opts *output.Options) output.Output { + return output.TreeOutput(TableOutput(opts, mapGetTreewideOutput, "ACCESS"), "COMPONENTVERSION").New() } -func map_get_regular_output(e interface{}) interface{} { +func mapGetRegularOutput(e interface{}) interface{} { r := common.Elem(e) return append(elemhdlr.MapMetaOutput(e), r.Type, string(r.Relation)) } -func map_get_wide_output(e interface{}) interface{} { - return output.Fields(map_get_regular_output(e), elemhdlr.MapAccessOutput(common.Elem(e).Access)) +func mapGetWideOutput(e interface{}) interface{} { + return output.Fields(mapGetRegularOutput(e), elemhdlr.MapAccessOutput(common.Elem(e).Access)) } -func map_get_treewide_output(e interface{}) interface{} { - return output.Fields(map_get_regular_output(e), common.Elem(e).Access.GetKind()) +func mapGetTreewideOutput(e interface{}) interface{} { + return output.Fields(mapGetRegularOutput(e), common.Elem(e).Access.GetKind()) } diff --git a/cmds/ocm/commands/ocmcmds/sources/get/cmd.go b/cmds/ocm/commands/ocmcmds/sources/get/cmd.go index baefeb696..dd405a109 100644 --- a/cmds/ocm/commands/ocmcmds/sources/get/cmd.go +++ b/cmds/ocm/commands/ocmcmds/sources/get/cmd.go @@ -101,28 +101,28 @@ func TableOutput(opts *output.Options, mapping processing.MappingFunction, wide } } -var outputs = output.NewOutputs(get_regular, output.Outputs{ - "wide": get_wide, - "tree": get_tree, +var outputs = output.NewOutputs(getRegular, output.Outputs{ + "wide": getWide, + "tree": getTree, }).AddManifestOutputs() -func get_regular(opts *output.Options) output.Output { - return closureoption.TableOutput(TableOutput(opts, map_get_regular_output)).New() +func getRegular(opts *output.Options) output.Output { + return closureoption.TableOutput(TableOutput(opts, mapGetRegularOutput)).New() } -func get_wide(opts *output.Options) output.Output { - return closureoption.TableOutput(TableOutput(opts, map_get_wide_output, elemhdlr.AccessOutput...)).New() +func getWide(opts *output.Options) output.Output { + return closureoption.TableOutput(TableOutput(opts, mapGetWideOutput, elemhdlr.AccessOutput...)).New() } -func get_tree(opts *output.Options) output.Output { - return output.TreeOutput(TableOutput(opts, map_get_regular_output), "COMPONENTVERSION").New() +func getTree(opts *output.Options) output.Output { + return output.TreeOutput(TableOutput(opts, mapGetRegularOutput), "COMPONENTVERSION").New() } -func map_get_regular_output(e interface{}) interface{} { +func mapGetRegularOutput(e interface{}) interface{} { r := common.Elem(e) return append(elemhdlr.MapMetaOutput(e), r.Type) } -func map_get_wide_output(e interface{}) interface{} { - return append(map_get_regular_output(e).([]string), elemhdlr.MapAccessOutput(common.Elem(e).Access)...) +func mapGetWideOutput(e interface{}) interface{} { + return append(mapGetRegularOutput(e).([]string), elemhdlr.MapAccessOutput(common.Elem(e).Access)...) } diff --git a/cmds/ocm/pkg/data/indexed.go b/cmds/ocm/pkg/data/indexed.go index 846f2df64..18662f259 100644 --- a/cmds/ocm/pkg/data/indexed.go +++ b/cmds/ocm/pkg/data/indexed.go @@ -117,12 +117,6 @@ func (this IndexedSliceAccess) Copy() IndexedSliceAccess { return n } -/* -func (this IndexedSliceAccess) entry_iterator() entry_iterator { - return (&_slice_entry_iterator{}).new(this) -} -*/ - func NewSliceIterator(slice []interface{}) *IndexedIterator { return NewIndexedIterator(IndexedSliceAccess(slice)) } diff --git a/cmds/ocm/pkg/output/sort_test.go b/cmds/ocm/pkg/output/sort_test.go index 6fb726a1b..539042a6c 100644 --- a/cmds/ocm/pkg/output/sort_test.go +++ b/cmds/ocm/pkg/output/sort_test.go @@ -41,7 +41,7 @@ var _ = Describe("sort", func() { It("sort a", func() { slice := data.IndexedSliceAccess(values).Copy() - slice.Sort(compare_column(2)) + slice.Sort(compareColumn(2)) Expect(slice).To(Equal(data.IndexedSliceAccess{ h1i2a1b3, h2i2a1b3, @@ -53,7 +53,7 @@ var _ = Describe("sort", func() { }) It("sort b", func() { slice := data.IndexedSliceAccess(values).Copy() - slice.Sort(compare_column(3)) + slice.Sort(compareColumn(3)) Expect(slice).To(Equal(data.IndexedSliceAccess{ h1i2a2b1, h2i2a2b1, @@ -65,7 +65,7 @@ var _ = Describe("sort", func() { }) It("sort fixed h a", func() { slice := data.IndexedSliceAccess(values).Copy() - sortFixed(1, slice, compare_column(2)) + sortFixed(1, slice, compareColumn(2)) Expect(slice).To(Equal(data.IndexedSliceAccess{ h1i2a1b3, h1i2a2b1, @@ -85,7 +85,7 @@ var _ = Describe("sort", func() { } slice = data.IndexedSliceAccess(values) //slice.SortIndexed(compare_fixed_column(1, 2)) - sortFixed(1, slice, compare_column(2)) + sortFixed(1, slice, compareColumn(2)) Expect(slice).To(Equal(data.IndexedSliceAccess{ h1i2a1b3, h2i2a1b3, diff --git a/cmds/ocm/pkg/output/tableoutput.go b/cmds/ocm/pkg/output/tableoutput.go index b8116e05e..112515b34 100644 --- a/cmds/ocm/pkg/output/tableoutput.go +++ b/cmds/ocm/pkg/output/tableoutput.go @@ -98,7 +98,7 @@ func (this *TableProcessingOutput) Out() error { if n < this.opts.FixedColums { return errors.Newf("field '%s' not possible", k) } - cmp := compare_column(idxs[key]) + cmp := compareColumn(idxs[key]) if this.opts.FixedColums > 0 { sortFixed(this.opts.FixedColums, slice, cmp) } else { @@ -111,7 +111,7 @@ func (this *TableProcessingOutput) Out() error { return nil } -func compare_column(c int) CompareFunction { +func compareColumn(c int) CompareFunction { return func(a interface{}, b interface{}) int { aa := a.([]string) ab := b.([]string) diff --git a/cmds/ocm/pkg/processing/chain.go b/cmds/ocm/pkg/processing/chain.go index f6a199970..11395ffc9 100644 --- a/cmds/ocm/pkg/processing/chain.go +++ b/cmds/ocm/pkg/processing/chain.go @@ -38,11 +38,11 @@ type ProcessChain interface { Process(data data.Iterable) ProcessingResult } -type step_creator func(ProcessingResult) ProcessingResult +type stepCreator func(ProcessingResult) ProcessingResult type _ProcessChain struct { parent *_ProcessChain - creator step_creator + creator stepCreator } var _ ProcessChain = &_ProcessChain{} @@ -51,7 +51,7 @@ func Chain() ProcessChain { return (&_ProcessChain{}).new(nil, nil) } -func (this *_ProcessChain) new(p *_ProcessChain, creator step_creator) *_ProcessChain { +func (this *_ProcessChain) new(p *_ProcessChain, creator stepCreator) *_ProcessChain { if p != nil { if p.creator != nil { this.parent = p @@ -72,48 +72,48 @@ func (this *_ProcessChain) Transform(t TransformFunction) ProcessChain { if t == nil { return this } - return (&_ProcessChain{}).new(this, chain_transform(t)) + return (&_ProcessChain{}).new(this, chainTransform(t)) } func (this *_ProcessChain) Explode(e ExplodeFunction) ProcessChain { if e == nil { return this } - return (&_ProcessChain{}).new(this, chain_explode(e)) + return (&_ProcessChain{}).new(this, chainExplode(e)) } func (this *_ProcessChain) Map(m MappingFunction) ProcessChain { if m == nil { return this } - return (&_ProcessChain{}).new(this, chain_map(m)) + return (&_ProcessChain{}).new(this, chainMap(m)) } func (this *_ProcessChain) Filter(f FilterFunction) ProcessChain { if f == nil { return this } - return (&_ProcessChain{}).new(this, chain_filter(f)) + return (&_ProcessChain{}).new(this, chainFilter(f)) } func (this *_ProcessChain) Sort(c CompareFunction) ProcessChain { if c == nil { return this } - return (&_ProcessChain{}).new(this, chain_sort(c)) + return (&_ProcessChain{}).new(this, chainSort(c)) } func (this *_ProcessChain) WithPool(p ProcessorPool) ProcessChain { - return (&_ProcessChain{}).new(this, chain_with_pool(p)) + return (&_ProcessChain{}).new(this, chainWithPool(p)) } func (this *_ProcessChain) Unordered() ProcessChain { - return (&_ProcessChain{}).new(this, chain_unordered) + return (&_ProcessChain{}).new(this, chainUnordered) } func (this *_ProcessChain) Parallel(n int) ProcessChain { - return (&_ProcessChain{}).new(this, chain_parallel(n)) + return (&_ProcessChain{}).new(this, chainParallel(n)) } func (this *_ProcessChain) Append(p ProcessChain) ProcessChain { if p == nil { return this } - return (&_ProcessChain{}).new(this, chain_apply(p)) + return (&_ProcessChain{}).new(this, chainApply(p)) } // Process instantiates a processing chain for a dedicated input @@ -138,30 +138,30 @@ func (this *_ProcessChain) step(p ProcessingResult) ProcessingResult { return this.creator(p) } -func chain_transform(t TransformFunction) step_creator { +func chainTransform(t TransformFunction) stepCreator { return func(p ProcessingResult) ProcessingResult { return p.Transform(t) } } -func chain_explode(e ExplodeFunction) step_creator { +func chainExplode(e ExplodeFunction) stepCreator { return func(p ProcessingResult) ProcessingResult { return p.Explode(e) } } -func chain_map(m MappingFunction) step_creator { +func chainMap(m MappingFunction) stepCreator { return func(p ProcessingResult) ProcessingResult { return p.Map(m) } } -func chain_filter(f FilterFunction) step_creator { +func chainFilter(f FilterFunction) stepCreator { return func(p ProcessingResult) ProcessingResult { return p.Filter(f) } } -func chain_sort(c CompareFunction) step_creator { +func chainSort(c CompareFunction) stepCreator { return func(p ProcessingResult) ProcessingResult { return p.Sort(c) } } -func chain_with_pool(pool ProcessorPool) step_creator { +func chainWithPool(pool ProcessorPool) stepCreator { return func(p ProcessingResult) ProcessingResult { return p.WithPool(pool) } } -func chain_parallel(n int) step_creator { +func chainParallel(n int) stepCreator { return func(p ProcessingResult) ProcessingResult { return p.Parallel(n) } } -func chain_unordered(p ProcessingResult) ProcessingResult { return p.Unordered() } +func chainUnordered(p ProcessingResult) ProcessingResult { return p.Unordered() } -func chain_apply(c ProcessChain) step_creator { +func chainApply(c ProcessChain) stepCreator { return func(p ProcessingResult) ProcessingResult { return p.Apply(c) } diff --git a/cmds/ocm/pkg/processing/container.go b/cmds/ocm/pkg/processing/container.go deleted file mode 100644 index ac878337c..000000000 --- a/cmds/ocm/pkg/processing/container.go +++ /dev/null @@ -1,295 +0,0 @@ -// Copyright 2022 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package processing - -/* -import ( - _ "fmt" - "sync" - - "github.com/open-component-model/ocm/cmds/ocm/pkg/data" -) - -type container_creator func() container - -type entry_iterable interface { - entry_iterator() entry_iterator - Iterator() data.Iterator -} - -type entry_iterator interface { - data.Iterator - next() entry -} - -type container interface { - Lock() - Unlock() - Broadcast() - Wait() - - add(e entry) container - len() int - get(int) entry - open() - close() - closed() bool - - entry_iterable -} - -type _container_impl interface { - _open() - _close() - _add(e entry) bool -} - -type _container struct { - self _container_impl - *sync.Cond - sync.Mutex - entries []entry - complete bool -} - -var _ container = &_container{} -var _ data.Iterable = &_container{} - -func NewContainer() container { - return (&_container{}).new() -} - -func (this *_container) new() *_container { - this.self = this - this.entries = []entry{} - this.Cond = sync.NewCond(&this.Mutex) - return this -} - -func (this *_container) _open() { - this.complete = false -} -func (this *_container) _close() { - this.complete = true -} -func (this *_container) _add(e entry) bool { - this.entries = append(this.entries, e) - return true -} - -func (this *_container) Iterator() data.Iterator { - return this.entry_iterator() -} - -func (this *_container) add(e entry) container { - this.Lock() - notify := this.self._add(e) - this.Unlock() - if notify { - this.Broadcast() - } - return this -} - -func (this *_container) open() { - this.Lock() - this.self._open() - this.Unlock() -} -func (this *_container) close() { - this.Lock() - this.self._close() - this.Unlock() - this.Broadcast() -} - -func (this *_container) len() int { - return len(this.entries) -} - -func (this *_container) get(i int) entry { - return this.entries[i] -} - -func (this *_container) closed() bool { - return this.complete -} - -func (this *_container) entry_iterator() entry_iterator { - return (&_entry_iterator{}).new(this) -} - -type _entry_iterator struct { - container container - current int -} - -var _ entry_iterator = &_entry_iterator{} -var _ data.Iterator = &_entry_iterator{} - -func (this *_entry_iterator) new(container container) entry_iterator { - this.current = -1 - this.container = container - return this -} - -func (this *_entry_iterator) HasNext() bool { - this.container.Lock() - defer this.container.Unlock() - for true { - //fmt.Printf("HasNext: %d(%d) %t\n", this.current, this.container.len(), this.container.closed()) - if this.container.len() > this.current+1 { - if this.container.get(this.current + 1).ok { - return true - } - this.current++ - continue - } - if this.container.closed() { - return false - } - this.container.Wait() - } - return false -} - -func (this *_entry_iterator) Next() interface{} { - n, ok := this._next() - if !ok { - return nil - } - return n.value -} - -func (this *_entry_iterator) next() entry { - n, ok := this._next() - if !ok { - panic("iteration beynond data structure") - } - return n -} - -func (this *_entry_iterator) _next() (entry, bool) { - var n entry - ok := true - this.container.Lock() - if this.container.len() > this.current+1 { - this.current++ - n = this.container.get(this.current) - } else { - ok = false - } - this.container.Unlock() - return n, ok - -} - -//////////////////////////////////////////////////////////////////////////// - -// a container view offering an ordered list of entries. -// the container api (besides the raw entry iterator iter()) -// features the actually valid ordered entry set. -// there ordered array may contain holes, depending on the -// processing order, therefore a dedicted valid attribute -// is maintained, indicating the actually complete part -// of the list - -type ordered_container struct { - _container - ordered []*entry - valid int -} - -func NewOrderedContainer() container { - return (&ordered_container{}).new() -} - -func (this *ordered_container) new() *ordered_container { - this._container.new() - this._container.self = this - this.ordered = []*entry{} - return this -} - -func (this *ordered_container) _add(e entry) bool { - if e.ok { - this._container._add(e) - if e.index >= len(this.ordered) { - t := make([]*entry, e.index+1) - copy(t, this.ordered) - this.ordered = t - } - this.ordered[e.index] = &e - for this.valid < len(this.ordered) && this.ordered[this.valid] != nil { - this.valid++ - } - } - return e.ok -} - -func (this *ordered_container) _close() { - this._container._close() - this.valid = len(this.ordered) -} - -func (this *ordered_container) len() int { - return this.valid -} - -func (this *ordered_container) get(i int) entry { - e := this.ordered[i] - if e != nil { - return *e - } - return entry{i, false, nil} -} - -func (this *ordered_container) Iterator() data.Iterator { - // this this is another this than this in iter() in this.container - // still inherited to offer the unordered entries for processing - return (&_entry_iterator{}).new(this) -} - -//////////////////////////////////////////////////////////////////////////// - -type entry struct { - index int - ok bool - value interface{} -} - -//////////////////////////////////////////////////////////////////////////// - -func newEntryIterableFromIterable(data data.Iterable) entry_iterable { - e, ok := data.(entry_iterable) - if ok { - return e - } - c := NewOrderedContainer() - - go func() { - - i := data.Iterator() - for idx := 0; i.HasNext(); idx++ { - c.add(entry{idx, true, i.Next()}) - } - c.close() - }() - return c -} - - - -*/ diff --git a/cmds/ocm/pkg/processing/pool.go b/cmds/ocm/pkg/processing/pool.go index a5c0cdde1..fcde8cee0 100644 --- a/cmds/ocm/pkg/processing/pool.go +++ b/cmds/ocm/pkg/processing/pool.go @@ -47,7 +47,7 @@ type _ProcessorPool struct { n int uses int lock sync.Mutex - set *processor_set + set *processorSet } func NewProcessorPool(n int) ProcessorPool { @@ -59,7 +59,7 @@ func (this *_ProcessorPool) Request() { defer this.lock.Unlock() this.uses++ if this.uses == 1 { - this.set = (&processor_set{}).new(this.n) + this.set = (&processorSet{}).new(this.n) } } @@ -86,11 +86,11 @@ func (this *_ProcessorPool) Release() { ///////////////////////////////////////////////////////////////////////////// -type processor_set struct { +type processorSet struct { request chan func() } -func (this *processor_set) new(n int) *processor_set { +func (this *processorSet) new(n int) *processorSet { this.request = make(chan func(), n*2) for i := 0; i < n; i++ { go func() { @@ -102,10 +102,10 @@ func (this *processor_set) new(n int) *processor_set { return this } -func (this *processor_set) exec(f func()) { +func (this *processorSet) exec(f func()) { this.request <- f } -func (this *processor_set) stop() { +func (this *processorSet) stop() { close(this.request) } diff --git a/cmds/ocm/pkg/processing/sequential.go b/cmds/ocm/pkg/processing/sequential.go index 3520f9f6e..1e61e9c36 100644 --- a/cmds/ocm/pkg/processing/sequential.go +++ b/cmds/ocm/pkg/processing/sequential.go @@ -20,8 +20,6 @@ import ( "github.com/open-component-model/ocm/cmds/ocm/pkg/data" ) -///////////////////////////////////////////////////////////////////////////// - type _SynchronousProcessing struct { data data.Iterable } @@ -46,7 +44,7 @@ func (this *_SynchronousProcessing) Filter(f FilterFunction) ProcessingResult { return (&_SynchronousStep{}).new(this, process(filter(f))) } func (this *_SynchronousProcessing) Sort(c CompareFunction) ProcessingResult { - return (&_SynchronousStep{}).new(this, process_sort(c)) + return (&_SynchronousStep{}).new(this, processSort(c)) } func (this *_SynchronousProcessing) WithPool(p ProcessorPool) ProcessingResult { return (&_ParallelProcessing{}).new(NewEntryIterableFromIterable(this.data), p, NewOrderedBuffer) @@ -74,8 +72,6 @@ func (this *_SynchronousProcessing) AsSlice() data.IndexedSliceAccess { return data.IndexedSliceAccess(data.Slice(this.data)) } -//////////////////////////////////////////////////////////////////////////// - type _SynchronousStep struct { _SynchronousProcessing } @@ -85,8 +81,6 @@ func (this *_SynchronousStep) new(data data.Iterable, proc processing) *_Synchro return this } -///////////////////////////////////////////////////////////////////////////// - type processing func(data.Iterable) data.Iterable type _AsynchronousProcessing struct { @@ -114,7 +108,7 @@ func (this *_AsynchronousProcessing) Filter(f FilterFunction) ProcessingResult { return (&_AsynchronousStep{}).new(this, process(filter(f))) } func (this *_AsynchronousProcessing) Sort(c CompareFunction) ProcessingResult { - return (&_AsynchronousStep{}).new(this, process_sort(c)) + return (&_AsynchronousStep{}).new(this, processSort(c)) } func (this *_AsynchronousProcessing) WithPool(p ProcessorPool) ProcessingResult { return (&_ParallelProcessing{}).new(NewEntryIterableFromIterable(this.data), p, NewOrderedBuffer) @@ -144,8 +138,6 @@ func (this *_AsynchronousProcessing) AsSlice() data.IndexedSliceAccess { return data.IndexedSliceAccess(data.Slice(this)) } -//////////////////////////////////////////////////////////////////////////// - type _AsynchronousStep struct { _AsynchronousProcessing } @@ -160,9 +152,7 @@ func (this *_AsynchronousStep) new(data data.Iterable, proc processing) *_Asynch return this } -//////////////////////////////////////////////////////////////////////////// - -func process_sort(c CompareFunction) func(data data.Iterable) data.Iterable { +func processSort(c CompareFunction) func(data data.Iterable) data.Iterable { return func(it data.Iterable) data.Iterable { slice := data.Slice(it) data.Sort(slice, c) @@ -170,31 +160,6 @@ func process_sort(c CompareFunction) func(data data.Iterable) data.Iterable { } } -/* -func process_aggregate(a AggregationFunction) func(data data.Iterable) data.Iterable { - return func(it data.Iterable) data.Iterable { - var result []interface{} - var state interface{} - i := it.Iterator() - for i.HasNext() { - s := a(i.Next(), state) - if s != nil { - if state != nil { - result = append(result, state) - } - state = s - } - } - if state != nil { - result = append(result, state) - } - return data.IndexedSliceAccess(result) - } -} -*/ - -//////////////////////////////////////////////////////////////////////////// - func process(op operation) processing { return func(it data.Iterable) data.Iterable { slice := []interface{}{} diff --git a/pkg/common/accessio/opts.go b/pkg/common/accessio/opts.go index f86802353..ef1c8948c 100644 --- a/pkg/common/accessio/opts.go +++ b/pkg/common/accessio/opts.go @@ -161,57 +161,57 @@ type Option interface { // PathFileSystem set the evaluation filesystem for the path name func PathFileSystem(fs vfs.FileSystem) Option { - return opt_PFS{fs} + return optPfs{fs} } -type opt_PFS struct { +type optPfs struct { vfs.FileSystem } // ApplyOption applies the configured path filesystem. -func (o opt_PFS) ApplyOption(options *Options) { +func (o optPfs) ApplyOption(options *Options) { options.PathFileSystem = o.FileSystem } // RepresentationFileSystem set the evaltuation filesystem for the path name func RepresentationFileSystem(fs vfs.FileSystem) Option { - return opt_RFS{fs} + return optRfs{fs} } -type opt_RFS struct { +type optRfs struct { vfs.FileSystem } // ApplyOption applies the configured path filesystem. -func (o opt_RFS) ApplyOption(options *Options) { +func (o optRfs) ApplyOption(options *Options) { options.Representation = o.FileSystem } // File set open file to use func File(file vfs.File) Option { - return opt_F{file} + return optF{file} } -type opt_F struct { +type optF struct { vfs.File } // ApplyOption applies the configured open file -func (o opt_F) ApplyOption(options *Options) { +func (o optF) ApplyOption(options *Options) { options.File = o.File } // Reader set open reader to use func Reader(reader io.ReadCloser) Option { - return opt_R{reader} + return optR{reader} } -type opt_R struct { +type optR struct { io.ReadCloser } // ApplyOption applies the configured open file -func (o opt_R) ApplyOption(options *Options) { +func (o optR) ApplyOption(options *Options) { options.Reader = o.ReadCloser } diff --git a/pkg/contexts/config/core/configtypes.go b/pkg/contexts/config/core/configtypes.go index 8d72419a0..3e3ac6ec7 100644 --- a/pkg/contexts/config/core/configtypes.go +++ b/pkg/contexts/config/core/configtypes.go @@ -68,16 +68,21 @@ func (t *configTypeScheme) GetConfigType(name string) ConfigType { func (t *configTypeScheme) RegisterByDecoder(name string, decoder runtime.TypedObjectDecoder) error { if _, ok := decoder.(ConfigType); !ok { - errors.ErrInvalid("type", reflect.TypeOf(decoder).String()) + return errors.ErrInvalid("type", reflect.TypeOf(decoder).String()) } return t.Scheme.RegisterByDecoder(name, decoder) } -func (t *configTypeScheme) AddKnownTypes(scheme runtime.Scheme) { +func (t *configTypeScheme) AddKnownTypes(scheme runtime.Scheme) error { if _, ok := scheme.(ConfigTypeScheme); !ok { - panic("can only add RepositoryTypeSchemes") + return errors.ErrInvalid("type", reflect.TypeOf(scheme).String(), "expected", "ConfigTypeScheme") } - t.Scheme.AddKnownTypes(scheme) + + if err := t.Scheme.AddKnownTypes(scheme); err != nil { + return fmt.Errorf("failed to add known type in config type scheme: %w", err) + } + + return nil } func (t *configTypeScheme) Register(name string, rtype ConfigType) { diff --git a/pkg/contexts/credentials/core/repotypes.go b/pkg/contexts/credentials/core/repotypes.go index 7ab4fa61f..e0a220484 100644 --- a/pkg/contexts/credentials/core/repotypes.go +++ b/pkg/contexts/credentials/core/repotypes.go @@ -70,16 +70,21 @@ func (t *repositoryTypeScheme) GetRepositoryType(name string) RepositoryType { func (t *repositoryTypeScheme) RegisterByDecoder(name string, decoder runtime.TypedObjectDecoder) error { if _, ok := decoder.(RepositoryType); !ok { - errors.ErrInvalid("type", reflect.TypeOf(decoder).String()) + return errors.ErrInvalid("type", reflect.TypeOf(decoder).String()) } return t.Scheme.RegisterByDecoder(name, decoder) } -func (t *repositoryTypeScheme) AddKnownTypes(scheme runtime.Scheme) { +func (t *repositoryTypeScheme) AddKnownTypes(scheme runtime.Scheme) error { if _, ok := scheme.(RepositoryTypeScheme); !ok { - panic("can only add RepositoryTypeSchemes") + return errors.ErrInvalid("type", reflect.TypeOf(scheme).String()) } - t.Scheme.AddKnownTypes(scheme) + + if err := t.Scheme.AddKnownTypes(scheme); err != nil { + return fmt.Errorf("failed to add known type: %w", err) + } + + return nil } func (t *repositoryTypeScheme) Register(name string, rtype RepositoryType) { diff --git a/pkg/contexts/oci/core/repotypes.go b/pkg/contexts/oci/core/repotypes.go index fc00ffe2a..9838973d4 100644 --- a/pkg/contexts/oci/core/repotypes.go +++ b/pkg/contexts/oci/core/repotypes.go @@ -77,16 +77,21 @@ func (t *repositoryTypeScheme) GetRepositoryType(name string) RepositoryType { func (t *repositoryTypeScheme) RegisterByDecoder(name string, decoder runtime.TypedObjectDecoder) error { if _, ok := decoder.(RepositoryType); !ok { - errors.ErrInvalid("type", reflect.TypeOf(decoder).String()) + return errors.ErrInvalid("type", reflect.TypeOf(decoder).String()) } return t.Scheme.RegisterByDecoder(name, decoder) } -func (t *repositoryTypeScheme) AddKnownTypes(scheme runtime.Scheme) { +func (t *repositoryTypeScheme) AddKnownTypes(scheme runtime.Scheme) error { if _, ok := scheme.(RepositoryTypeScheme); !ok { - panic("can only add RepositoryTypeSchemes") + return errors.ErrInvalid("type", reflect.TypeOf(scheme).String(), "expected", "RepositoryTypeScheme") } - t.Scheme.AddKnownTypes(scheme) + + if err := t.Scheme.AddKnownTypes(scheme); err != nil { + return fmt.Errorf("failed to add known type in repository type scheme: %w", err) + } + + return nil } func (t *repositoryTypeScheme) Register(name string, rtype RepositoryType) { diff --git a/pkg/contexts/ocm/compdesc/versions/ocm.gardener.cloud/v3alpha1/version.go b/pkg/contexts/ocm/compdesc/versions/ocm.gardener.cloud/v3alpha1/version.go index a18effdba..c704aebbf 100644 --- a/pkg/contexts/ocm/compdesc/versions/ocm.gardener.cloud/v3alpha1/version.go +++ b/pkg/contexts/ocm/compdesc/versions/ocm.gardener.cloud/v3alpha1/version.go @@ -90,45 +90,45 @@ func (v *DescriptorVersion) ConvertTo(obj compdesc.ComponentDescriptorVersion) ( ComponentSpec: compdesc.ComponentSpec{ ObjectMeta: *in.ObjectMeta.Copy(), RepositoryContexts: in.RepositoryContexts.Copy(), - Sources: convert_Sources_to(in.Spec.Sources), - Resources: convert_Resources_to(in.Spec.Resources), - References: convert_References_to(in.Spec.References), + Sources: convertSourcesTo(in.Spec.Sources), + Resources: convertResourcesTo(in.Spec.Resources), + References: convertReferencesTo(in.Spec.References), }, Signatures: in.Signatures.Copy(), } return out, nil } -func convert_Reference_to(in *Reference) *compdesc.ComponentReference { +func convertReferenceTo(in *Reference) *compdesc.ComponentReference { if in == nil { return nil } out := &compdesc.ComponentReference{ - ElementMeta: *convert_ElementMeta_to(&in.ElementMeta), + ElementMeta: *convertElementmetaTo(&in.ElementMeta), ComponentName: in.ComponentName, Digest: in.Digest.Copy(), } return out } -func convert_References_to(in []Reference) compdesc.References { +func convertReferencesTo(in []Reference) compdesc.References { if in == nil { return nil } out := make(compdesc.References, len(in)) for i, v := range in { - out[i] = *convert_Reference_to(&v) + out[i] = *convertReferenceTo(&v) } return out } -func convert_Source_to(in *Source) *compdesc.Source { +func convertSourceTo(in *Source) *compdesc.Source { if in == nil { return nil } out := &compdesc.Source{ SourceMeta: compdesc.SourceMeta{ - ElementMeta: *convert_ElementMeta_to(&in.ElementMeta), + ElementMeta: *convertElementmetaTo(&in.ElementMeta), Type: in.Type, }, Access: compdesc.GenericAccessSpec(in.Access.DeepCopy()), @@ -136,18 +136,18 @@ func convert_Source_to(in *Source) *compdesc.Source { return out } -func convert_Sources_to(in Sources) compdesc.Sources { +func convertSourcesTo(in Sources) compdesc.Sources { if in == nil { return nil } out := make(compdesc.Sources, len(in)) for i, v := range in { - out[i] = *convert_Source_to(&v) + out[i] = *convertSourceTo(&v) } return out } -func convert_ElementMeta_to(in *ElementMeta) *compdesc.ElementMeta { +func convertElementmetaTo(in *ElementMeta) *compdesc.ElementMeta { if in == nil { return nil } @@ -160,16 +160,16 @@ func convert_ElementMeta_to(in *ElementMeta) *compdesc.ElementMeta { return out } -func convert_Resource_to(in *Resource) *compdesc.Resource { +func convertResourceTo(in *Resource) *compdesc.Resource { if in == nil { return nil } out := &compdesc.Resource{ ResourceMeta: compdesc.ResourceMeta{ - ElementMeta: *convert_ElementMeta_to(&in.ElementMeta), + ElementMeta: *convertElementmetaTo(&in.ElementMeta), Type: in.Type, Relation: in.Relation, - SourceRef: Convert_SourceRefs_to(in.SourceRef), + SourceRef: ConvertSourcerefsTo(in.SourceRef), Digest: in.Digest.Copy(), }, Access: compdesc.GenericAccessSpec(in.Access), @@ -177,18 +177,18 @@ func convert_Resource_to(in *Resource) *compdesc.Resource { return out } -func convert_Resources_to(in Resources) compdesc.Resources { +func convertResourcesTo(in Resources) compdesc.Resources { if in == nil { return nil } out := make(compdesc.Resources, len(in)) for i, v := range in { - out[i] = *convert_Resource_to(&v) + out[i] = *convertResourceTo(&v) } return out } -func convert_SourceRef_to(in *SourceRef) *compdesc.SourceRef { +func convertSourcerefTo(in *SourceRef) *compdesc.SourceRef { if in == nil { return nil } @@ -199,13 +199,13 @@ func convert_SourceRef_to(in *SourceRef) *compdesc.SourceRef { return out } -func Convert_SourceRefs_to(in []SourceRef) []compdesc.SourceRef { +func ConvertSourcerefsTo(in []SourceRef) []compdesc.SourceRef { if in == nil { return nil } out := make([]compdesc.SourceRef, len(in)) for i, v := range in { - out[i] = *convert_SourceRef_to(&v) + out[i] = *convertSourcerefTo(&v) } return out } @@ -226,9 +226,9 @@ func (v *DescriptorVersion) ConvertFrom(in *compdesc.ComponentDescriptor) (compd ObjectMeta: *in.ObjectMeta.Copy(), RepositoryContexts: in.RepositoryContexts.Copy(), Spec: ComponentVersionSpec{ - Sources: convert_Sources_from(in.Sources), - Resources: convert_Resources_from(in.Resources), - References: convert_References_from(in.References), + Sources: convertSourcesFrom(in.Sources), + Resources: convertResourcesFrom(in.Resources), + References: convertReferencesFrom(in.References), }, Signatures: in.Signatures.Copy(), } @@ -238,30 +238,30 @@ func (v *DescriptorVersion) ConvertFrom(in *compdesc.ComponentDescriptor) (compd return out, nil } -func convert_Reference_from(in *compdesc.ComponentReference) *Reference { +func convertReferenceFrom(in *compdesc.ComponentReference) *Reference { if in == nil { return nil } out := &Reference{ - ElementMeta: *convert_ElementMeta_from(&in.ElementMeta), + ElementMeta: *convertElementmetaFrom(&in.ElementMeta), ComponentName: in.ComponentName, Digest: in.Digest.Copy(), } return out } -func convert_References_from(in []compdesc.ComponentReference) []Reference { +func convertReferencesFrom(in []compdesc.ComponentReference) []Reference { if in == nil { return nil } out := make([]Reference, len(in)) for i, v := range in { - out[i] = *convert_Reference_from(&v) + out[i] = *convertReferenceFrom(&v) } return out } -func convert_Source_from(in *compdesc.Source) *Source { +func convertSourceFrom(in *compdesc.Source) *Source { if in == nil { return nil } @@ -271,7 +271,7 @@ func convert_Source_from(in *compdesc.Source) *Source { } out := &Source{ SourceMeta: SourceMeta{ - ElementMeta: *convert_ElementMeta_from(&in.ElementMeta), + ElementMeta: *convertElementmetaFrom(&in.ElementMeta), Type: in.Type, }, Access: acc, @@ -279,18 +279,18 @@ func convert_Source_from(in *compdesc.Source) *Source { return out } -func convert_Sources_from(in compdesc.Sources) Sources { +func convertSourcesFrom(in compdesc.Sources) Sources { if in == nil { return nil } out := make(Sources, len(in)) for i, v := range in { - out[i] = *convert_Source_from(&v) + out[i] = *convertSourceFrom(&v) } return out } -func convert_ElementMeta_from(in *compdesc.ElementMeta) *ElementMeta { +func convertElementmetaFrom(in *compdesc.ElementMeta) *ElementMeta { if in == nil { return nil } @@ -303,7 +303,7 @@ func convert_ElementMeta_from(in *compdesc.ElementMeta) *ElementMeta { return out } -func convert_Resource_from(in *compdesc.Resource) *Resource { +func convertResourceFrom(in *compdesc.Resource) *Resource { if in == nil { return nil } @@ -312,28 +312,28 @@ func convert_Resource_from(in *compdesc.Resource) *Resource { compdesc.ThrowConversionError(err) } out := &Resource{ - ElementMeta: *convert_ElementMeta_from(&in.ElementMeta), + ElementMeta: *convertElementmetaFrom(&in.ElementMeta), Type: in.Type, Relation: in.Relation, - SourceRef: convert_SourceRefs_from(in.SourceRef), + SourceRef: convertSourcerefsFrom(in.SourceRef), Access: acc, Digest: in.Digest.Copy(), } return out } -func convert_Resources_from(in compdesc.Resources) Resources { +func convertResourcesFrom(in compdesc.Resources) Resources { if in == nil { return nil } out := make(Resources, len(in)) for i, v := range in { - out[i] = *convert_Resource_from(&v) + out[i] = *convertResourceFrom(&v) } return out } -func convert_SourceRef_from(in *compdesc.SourceRef) *SourceRef { +func convertSourcerefFrom(in *compdesc.SourceRef) *SourceRef { if in == nil { return nil } @@ -344,13 +344,13 @@ func convert_SourceRef_from(in *compdesc.SourceRef) *SourceRef { return out } -func convert_SourceRefs_from(in []compdesc.SourceRef) []SourceRef { +func convertSourcerefsFrom(in []compdesc.SourceRef) []SourceRef { if in == nil { return nil } out := make([]SourceRef, len(in)) for i, v := range in { - out[i] = *convert_SourceRef_from(&v) + out[i] = *convertSourcerefFrom(&v) } return out } diff --git a/pkg/contexts/ocm/compdesc/versions/v2/version.go b/pkg/contexts/ocm/compdesc/versions/v2/version.go index b05d38291..d8f023dc6 100644 --- a/pkg/contexts/ocm/compdesc/versions/v2/version.go +++ b/pkg/contexts/ocm/compdesc/versions/v2/version.go @@ -99,45 +99,45 @@ func (v *DescriptorVersion) ConvertTo(obj compdesc.ComponentDescriptorVersion) ( Provider: provider, }, RepositoryContexts: in.RepositoryContexts.Copy(), - Sources: convert_Sources_to(in.Sources), - Resources: convert_Resources_to(in.Resources), - References: convert_ComponentReferences_to(in.ComponentReferences), + Sources: convertSourcesTo(in.Sources), + Resources: convertResourcesTo(in.Resources), + References: convertComponentreferencesTo(in.ComponentReferences), }, Signatures: in.Signatures.Copy(), } return out, nil } -func convert_ComponentReference_to(in *ComponentReference) *compdesc.ComponentReference { +func convertComponentreferenceTo(in *ComponentReference) *compdesc.ComponentReference { if in == nil { return nil } out := &compdesc.ComponentReference{ - ElementMeta: *convert_ElementMeta_to(&in.ElementMeta), + ElementMeta: *convertElementmetaTo(&in.ElementMeta), ComponentName: in.ComponentName, Digest: in.Digest.Copy(), } return out } -func convert_ComponentReferences_to(in []ComponentReference) compdesc.References { +func convertComponentreferencesTo(in []ComponentReference) compdesc.References { if in == nil { return nil } out := make(compdesc.References, len(in)) for i, v := range in { - out[i] = *convert_ComponentReference_to(&v) + out[i] = *convertComponentreferenceTo(&v) } return out } -func convert_Source_to(in *Source) *compdesc.Source { +func convertSourceTo(in *Source) *compdesc.Source { if in == nil { return nil } out := &compdesc.Source{ SourceMeta: compdesc.SourceMeta{ - ElementMeta: *convert_ElementMeta_to(&in.ElementMeta), + ElementMeta: *convertElementmetaTo(&in.ElementMeta), Type: in.Type, }, Access: compdesc.GenericAccessSpec(in.Access.DeepCopy()), @@ -145,18 +145,18 @@ func convert_Source_to(in *Source) *compdesc.Source { return out } -func convert_Sources_to(in Sources) compdesc.Sources { +func convertSourcesTo(in Sources) compdesc.Sources { if in == nil { return nil } out := make(compdesc.Sources, len(in)) for i, v := range in { - out[i] = *convert_Source_to(&v) + out[i] = *convertSourceTo(&v) } return out } -func convert_ElementMeta_to(in *ElementMeta) *compdesc.ElementMeta { +func convertElementmetaTo(in *ElementMeta) *compdesc.ElementMeta { if in == nil { return nil } @@ -169,16 +169,16 @@ func convert_ElementMeta_to(in *ElementMeta) *compdesc.ElementMeta { return out } -func convert_Resource_to(in *Resource) *compdesc.Resource { +func convertResourceTo(in *Resource) *compdesc.Resource { if in == nil { return nil } out := &compdesc.Resource{ ResourceMeta: compdesc.ResourceMeta{ - ElementMeta: *convert_ElementMeta_to(&in.ElementMeta), + ElementMeta: *convertElementmetaTo(&in.ElementMeta), Type: in.Type, Relation: in.Relation, - SourceRef: Convert_SourceRefs_to(in.SourceRef), + SourceRef: ConvertSourcerefsTo(in.SourceRef), Digest: in.Digest.Copy(), }, Access: compdesc.GenericAccessSpec(in.Access), @@ -186,18 +186,18 @@ func convert_Resource_to(in *Resource) *compdesc.Resource { return out } -func convert_Resources_to(in Resources) compdesc.Resources { +func convertResourcesTo(in Resources) compdesc.Resources { if in == nil { return nil } out := make(compdesc.Resources, len(in)) for i, v := range in { - out[i] = *convert_Resource_to(&v) + out[i] = *convertResourceTo(&v) } return out } -func convert_SourceRef_to(in *SourceRef) *compdesc.SourceRef { +func convertSourcerefTo(in *SourceRef) *compdesc.SourceRef { if in == nil { return nil } @@ -208,13 +208,13 @@ func convert_SourceRef_to(in *SourceRef) *compdesc.SourceRef { return out } -func Convert_SourceRefs_to(in []SourceRef) []compdesc.SourceRef { +func ConvertSourcerefsTo(in []SourceRef) []compdesc.SourceRef { if in == nil { return nil } out := make([]compdesc.SourceRef, len(in)) for i, v := range in { - out[i] = *convert_SourceRef_to(&v) + out[i] = *convertSourcerefTo(&v) } return out } @@ -247,9 +247,9 @@ func (v *DescriptorVersion) ConvertFrom(in *compdesc.ComponentDescriptor) (compd }, RepositoryContexts: in.RepositoryContexts.Copy(), Provider: provider, - Sources: convert_Sources_from(in.Sources), - Resources: convert_Resources_from(in.Resources), - ComponentReferences: convert_ComponentReferences_from(in.References), + Sources: convertSourcesFrom(in.Sources), + Resources: convertResourcesFrom(in.Resources), + ComponentReferences: convertComponentreferencesFrom(in.References), }, Signatures: in.Signatures.Copy(), } @@ -259,30 +259,30 @@ func (v *DescriptorVersion) ConvertFrom(in *compdesc.ComponentDescriptor) (compd return out, nil } -func convert_ComponentReference_from(in *compdesc.ComponentReference) *ComponentReference { +func convertComponentreferenceFrom(in *compdesc.ComponentReference) *ComponentReference { if in == nil { return nil } out := &ComponentReference{ - ElementMeta: *convert_ElementMeta_from(&in.ElementMeta), + ElementMeta: *convertElementmetaFrom(&in.ElementMeta), ComponentName: in.ComponentName, Digest: in.Digest.Copy(), } return out } -func convert_ComponentReferences_from(in []compdesc.ComponentReference) []ComponentReference { +func convertComponentreferencesFrom(in []compdesc.ComponentReference) []ComponentReference { if in == nil { return nil } out := make([]ComponentReference, len(in)) for i, v := range in { - out[i] = *convert_ComponentReference_from(&v) + out[i] = *convertComponentreferenceFrom(&v) } return out } -func convert_Source_from(in *compdesc.Source) *Source { +func convertSourceFrom(in *compdesc.Source) *Source { if in == nil { return nil } @@ -292,7 +292,7 @@ func convert_Source_from(in *compdesc.Source) *Source { } out := &Source{ SourceMeta: SourceMeta{ - ElementMeta: *convert_ElementMeta_from(&in.ElementMeta), + ElementMeta: *convertElementmetaFrom(&in.ElementMeta), Type: in.Type, }, Access: acc, @@ -300,18 +300,18 @@ func convert_Source_from(in *compdesc.Source) *Source { return out } -func convert_Sources_from(in compdesc.Sources) Sources { +func convertSourcesFrom(in compdesc.Sources) Sources { if in == nil { return nil } out := make(Sources, len(in)) for i, v := range in { - out[i] = *convert_Source_from(&v) + out[i] = *convertSourceFrom(&v) } return out } -func convert_ElementMeta_from(in *compdesc.ElementMeta) *ElementMeta { +func convertElementmetaFrom(in *compdesc.ElementMeta) *ElementMeta { if in == nil { return nil } @@ -324,7 +324,7 @@ func convert_ElementMeta_from(in *compdesc.ElementMeta) *ElementMeta { return out } -func convert_Resource_from(in *compdesc.Resource) *Resource { +func convertResourceFrom(in *compdesc.Resource) *Resource { if in == nil { return nil } @@ -333,28 +333,28 @@ func convert_Resource_from(in *compdesc.Resource) *Resource { compdesc.ThrowConversionError(err) } out := &Resource{ - ElementMeta: *convert_ElementMeta_from(&in.ElementMeta), + ElementMeta: *convertElementmetaFrom(&in.ElementMeta), Type: in.Type, Relation: in.Relation, - SourceRef: convert_SourceRefs_from(in.SourceRef), + SourceRef: convertSourcerefsFrom(in.SourceRef), Access: acc, Digest: in.Digest.Copy(), } return out } -func convert_Resources_from(in compdesc.Resources) Resources { +func convertResourcesFrom(in compdesc.Resources) Resources { if in == nil { return nil } out := make(Resources, len(in)) for i, v := range in { - out[i] = *convert_Resource_from(&v) + out[i] = *convertResourceFrom(&v) } return out } -func convert_SourceRef_from(in *compdesc.SourceRef) *SourceRef { +func convertSourcerefFrom(in *compdesc.SourceRef) *SourceRef { if in == nil { return nil } @@ -365,13 +365,13 @@ func convert_SourceRef_from(in *compdesc.SourceRef) *SourceRef { return out } -func convert_SourceRefs_from(in []compdesc.SourceRef) []SourceRef { +func convertSourcerefsFrom(in []compdesc.SourceRef) []SourceRef { if in == nil { return nil } out := make([]SourceRef, len(in)) for i, v := range in { - out[i] = *convert_SourceRef_from(&v) + out[i] = *convertSourcerefFrom(&v) } return out } diff --git a/pkg/contexts/ocm/core/repotypes.go b/pkg/contexts/ocm/core/repotypes.go index 22e6c67c8..75d05988a 100644 --- a/pkg/contexts/ocm/core/repotypes.go +++ b/pkg/contexts/ocm/core/repotypes.go @@ -80,16 +80,21 @@ func (t *repositoryTypeScheme) GetRepositoryType(name string) RepositoryType { func (t *repositoryTypeScheme) RegisterByDecoder(name string, decoder runtime.TypedObjectDecoder) error { if _, ok := decoder.(RepositoryType); !ok { - errors.ErrInvalid("type", reflect.TypeOf(decoder).String()) + return errors.ErrInvalid("type", reflect.TypeOf(decoder).String()) } return t.Scheme.RegisterByDecoder(name, decoder) } -func (t *repositoryTypeScheme) AddKnownTypes(scheme runtime.Scheme) { +func (t *repositoryTypeScheme) AddKnownTypes(scheme runtime.Scheme) error { if _, ok := scheme.(RepositoryTypeScheme); !ok { - panic("can only add RepositoryTypeSchemes") + return errors.ErrInvalid("type", reflect.TypeOf(scheme).String(), "expected", "RepositoryTypeScheme") } - t.Scheme.AddKnownTypes(scheme) + + if err := t.Scheme.AddKnownTypes(scheme); err != nil { + return fmt.Errorf("failed to add known type in repository type scheme: %w", err) + } + + return nil } func (t *repositoryTypeScheme) Register(name string, rtype RepositoryType) { diff --git a/pkg/env/builder/oci_artefact.go b/pkg/env/builder/oci_artefact.go index d4f0ff5ec..9871a8bb4 100644 --- a/pkg/env/builder/oci_artefact.go +++ b/pkg/env/builder/oci_artefact.go @@ -25,7 +25,7 @@ const T_OCIARTEFACT = "artefact" const T_OCIINDEX = "index" const T_OCIMANIFEST = "manifest" -type oci_artefact struct { +type ociArtefact struct { base kind string artfunc func(a oci.ArtefactAccess) error @@ -34,11 +34,11 @@ type oci_artefact struct { tags []string } -func (r *oci_artefact) Type() string { +func (r *ociArtefact) Type() string { return r.kind } -func (r *oci_artefact) Set() { +func (r *ociArtefact) Set() { r.Builder.oci_nsacc = r.ns r.Builder.oci_artacc = r.ArtefactAccess r.Builder.oci_cleanuplayers = true @@ -49,7 +49,7 @@ func (r *oci_artefact) Set() { } } -func (r *oci_artefact) Close() error { +func (r *ociArtefact) Close() error { err := r.ArtefactAccess.Close() if err != nil { return err @@ -64,7 +64,7 @@ func (r *oci_artefact) Close() error { return err } -func (r *oci_artefact) addArtefact(a oci.ArtefactAccess) error { +func (r *ociArtefact) addArtefact(a oci.ArtefactAccess) error { _, err := r.ArtefactAccess.AddArtefact(a, nil) return err } @@ -93,7 +93,7 @@ func (b *Builder) artefact(tag string, ns cpi.NamespaceAccess, t func(access oci if tag != "" { tags = append(tags, tag) } - r := b.configure(&oci_artefact{ArtefactAccess: v, kind: k, tags: tags, ns: ns, artfunc: b.oci_artfunc}, f, 1) + r := b.configure(&ociArtefact{ArtefactAccess: v, kind: k, tags: tags, ns: ns, artfunc: b.oci_artfunc}, f, 1) if r == nil { return nil } diff --git a/pkg/env/builder/oci_artefactset.go b/pkg/env/builder/oci_artefactset.go index c70df898f..d1b38dc07 100644 --- a/pkg/env/builder/oci_artefactset.go +++ b/pkg/env/builder/oci_artefactset.go @@ -28,5 +28,5 @@ func (b *Builder) ArtefactSet(path string, fmt accessio.FileFormat, f ...func()) r, err := artefactset.Open(accessobj.ACC_WRITABLE|accessobj.ACC_CREATE, path, 0777, fmt, accessio.PathFileSystem(b.FileSystem())) b.failOn(err) - b.configure(&oci_namespace{NamespaceAccess: r, kind: T_OCIARTEFACTSET}, f) + b.configure(&ociNamespace{NamespaceAccess: r, kind: T_OCIARTEFACTSET}, f) } diff --git a/pkg/env/builder/oci_config.go b/pkg/env/builder/oci_config.go index 3d6307c96..aaca94ccc 100644 --- a/pkg/env/builder/oci_config.go +++ b/pkg/env/builder/oci_config.go @@ -22,20 +22,20 @@ import ( const T_OCICONFIG = "oci config" -type oci_config struct { +type ociConfig struct { base blob accessio.BlobAccess } -func (r *oci_config) Type() string { +func (r *ociConfig) Type() string { return T_OCICONFIG } -func (r *oci_config) Set() { +func (r *ociConfig) Set() { r.Builder.blob = &r.blob } -func (r *oci_config) Close() error { +func (r *ociConfig) Close() error { if r.blob == nil { return errors.Newf("config blob required") } @@ -53,5 +53,5 @@ func (r *oci_config) Close() error { func (b *Builder) Config(f ...func()) { b.expect(b.oci_artacc, T_OCIMANIFEST, func() bool { return b.oci_artacc.IsManifest() }) - b.configure(&oci_config{}, f) + b.configure(&ociConfig{}, f) } diff --git a/pkg/env/builder/oci_ctf.go b/pkg/env/builder/oci_ctf.go index 390d0b6ba..51e581190 100644 --- a/pkg/env/builder/oci_ctf.go +++ b/pkg/env/builder/oci_ctf.go @@ -25,5 +25,5 @@ const T_OCI_CTF = "oci common transport format" func (b *Builder) OCICommonTransport(path string, fmt accessio.FileFormat, f ...func()) { r, err := ctf.Open(b.OCMContext().OCIContext(), accessobj.ACC_WRITABLE|accessobj.ACC_CREATE, path, 0777, accessio.PathFileSystem(b.FileSystem())) b.failOn(err) - b.configure(&oci_repository{Repository: r, kind: T_OCI_CTF}, f) + b.configure(&ociRepository{Repository: r, kind: T_OCI_CTF}, f) } diff --git a/pkg/env/builder/oci_layer.go b/pkg/env/builder/oci_layer.go index c7f1c35da..3467bb74d 100644 --- a/pkg/env/builder/oci_layer.go +++ b/pkg/env/builder/oci_layer.go @@ -22,20 +22,20 @@ import ( const T_OCILAYER = "oci layer" -type oci_layer struct { +type ociLayer struct { base blob accessio.BlobAccess } -func (r *oci_layer) Type() string { +func (r *ociLayer) Type() string { return T_OCILAYER } -func (r *oci_layer) Set() { +func (r *ociLayer) Set() { r.Builder.blob = &r.blob } -func (r *oci_layer) Close() error { +func (r *ociLayer) Close() error { if r.blob == nil { return errors.Newf("config blob required") } @@ -56,5 +56,5 @@ func (r *oci_layer) Close() error { func (b *Builder) Layer(f ...func()) *artdesc.Descriptor { b.expect(b.oci_artacc, T_OCIMANIFEST, func() bool { return b.oci_artacc.IsManifest() }) - return b.configure(&oci_layer{}, f).(*artdesc.Descriptor) + return b.configure(&ociLayer{}, f).(*artdesc.Descriptor) } diff --git a/pkg/env/builder/oci_namespace.go b/pkg/env/builder/oci_namespace.go index 1eadb7e16..0386df3f3 100644 --- a/pkg/env/builder/oci_namespace.go +++ b/pkg/env/builder/oci_namespace.go @@ -20,20 +20,20 @@ import ( const T_OCINAMESPACE = "oci namespace" -type oci_namespace struct { +type ociNamespace struct { base kind string oci.NamespaceAccess } -func (r *oci_namespace) Type() string { +func (r *ociNamespace) Type() string { if r.kind != "" { return r.kind } return T_OCINAMESPACE } -func (r *oci_namespace) Set() { +func (r *ociNamespace) Set() { r.Builder.oci_nsacc = r.NamespaceAccess } @@ -43,5 +43,5 @@ func (b *Builder) Namespace(name string, f ...func()) { b.expect(b.oci_repo, T_OCIREPOSITORY) r, err := b.oci_repo.LookupNamespace(name) b.failOn(err) - b.configure(&oci_namespace{NamespaceAccess: r, kind: T_OCIARTEFACTSET}, f) + b.configure(&ociNamespace{NamespaceAccess: r, kind: T_OCIARTEFACTSET}, f) } diff --git a/pkg/env/builder/oci_repo.go b/pkg/env/builder/oci_repo.go index 1abdf094c..b8817a24d 100644 --- a/pkg/env/builder/oci_repo.go +++ b/pkg/env/builder/oci_repo.go @@ -20,19 +20,19 @@ import ( const T_OCIREPOSITORY = "oci repository" -type oci_repository struct { +type ociRepository struct { base kind string cpi.Repository } -func (r *oci_repository) Type() string { +func (r *ociRepository) Type() string { if r.kind != "" { return r.kind } return T_OCIREPOSITORY } -func (r *oci_repository) Set() { +func (r *ociRepository) Set() { r.Builder.oci_repo = r.Repository } diff --git a/pkg/env/builder/ocm_comparch.go b/pkg/env/builder/ocm_comparch.go index 148530f09..a6e7c576a 100644 --- a/pkg/env/builder/ocm_comparch.go +++ b/pkg/env/builder/ocm_comparch.go @@ -30,5 +30,5 @@ func (b *Builder) ComponentArchive(path string, fmt accessio.FileFormat, name, v r.SetVersion(vers) r.GetDescriptor().Provider.Name = metav1.ProviderName("ACME") - b.configure(&ocm_version{ComponentVersionAccess: r, kind: T_COMPARCH}, f) + b.configure(&ocmVersion{ComponentVersionAccess: r, kind: T_COMPARCH}, f) } diff --git a/pkg/env/builder/ocm_component.go b/pkg/env/builder/ocm_component.go index fe5b9b7e0..d8482e2b8 100644 --- a/pkg/env/builder/ocm_component.go +++ b/pkg/env/builder/ocm_component.go @@ -20,20 +20,20 @@ import ( const T_OCMCOMPONENT = "component" -type ocm_component struct { +type ocmComponent struct { base kind string cpi.ComponentAccess } -func (r *ocm_component) Type() string { +func (r *ocmComponent) Type() string { if r.kind != "" { return r.kind } return T_OCMCOMPONENT } -func (r *ocm_component) Set() { +func (r *ocmComponent) Set() { r.Builder.ocm_comp = r.ComponentAccess } @@ -43,5 +43,5 @@ func (b *Builder) Component(name string, f ...func()) { b.expect(b.ocm_repo, T_OCMREPOSITORY) c, err := b.ocm_repo.LookupComponent(name) b.failOn(err) - b.configure(&ocm_component{ComponentAccess: c}, f) + b.configure(&ocmComponent{ComponentAccess: c}, f) } diff --git a/pkg/env/builder/ocm_ctf.go b/pkg/env/builder/ocm_ctf.go index e09b0e5a7..47439c17d 100644 --- a/pkg/env/builder/ocm_ctf.go +++ b/pkg/env/builder/ocm_ctf.go @@ -25,5 +25,5 @@ const T_OCM_CTF = "ocm common transport format" func (b *Builder) OCMCommonTransport(path string, fmt accessio.FileFormat, f ...func()) { r, err := ctf.Open(b.OCMContext(), accessobj.ACC_WRITABLE|accessobj.ACC_CREATE, path, 0777, accessio.PathFileSystem(b.FileSystem())) b.failOn(err) - b.configure(&ocm_repository{Repository: r, kind: T_OCM_CTF}, f) + b.configure(&ocmRepository{Repository: r, kind: T_OCM_CTF}, f) } diff --git a/pkg/env/builder/ocm_reference.go b/pkg/env/builder/ocm_reference.go index c099cecf2..a4f4d360f 100644 --- a/pkg/env/builder/ocm_reference.go +++ b/pkg/env/builder/ocm_reference.go @@ -18,7 +18,7 @@ import ( "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" ) -type ocm_reference struct { +type ocmReference struct { base meta compdesc.ComponentReference @@ -26,15 +26,15 @@ type ocm_reference struct { const T_OCMREF = "reference" -func (r *ocm_reference) Type() string { +func (r *ocmReference) Type() string { return T_OCMREF } -func (r *ocm_reference) Set() { +func (r *ocmReference) Set() { r.Builder.ocm_meta = &r.meta.ElementMeta } -func (r *ocm_reference) Close() error { +func (r *ocmReference) Close() error { return r.ocm_vers.SetReference(&r.meta) } @@ -42,7 +42,7 @@ func (r *ocm_reference) Close() error { func (b *Builder) Reference(name, comp, vers string, f ...func()) { b.expect(b.ocm_vers, T_OCMVERSION) - r := &ocm_reference{} + r := &ocmReference{} r.meta.Name = name r.meta.Version = vers r.meta.ComponentName = comp diff --git a/pkg/env/builder/ocm_repo.go b/pkg/env/builder/ocm_repo.go index eec4fb7e8..3e353cf52 100644 --- a/pkg/env/builder/ocm_repo.go +++ b/pkg/env/builder/ocm_repo.go @@ -20,19 +20,19 @@ import ( const T_OCMREPOSITORY = "ocm repository" -type ocm_repository struct { +type ocmRepository struct { base kind string cpi.Repository } -func (r *ocm_repository) Type() string { +func (r *ocmRepository) Type() string { if r.kind != "" { return r.kind } return T_OCMREPOSITORY } -func (r *ocm_repository) Set() { +func (r *ocmRepository) Set() { r.Builder.ocm_repo = r.Repository } diff --git a/pkg/env/builder/ocm_resource.go b/pkg/env/builder/ocm_resource.go index 18c0cc03c..6d2fafdab 100644 --- a/pkg/env/builder/ocm_resource.go +++ b/pkg/env/builder/ocm_resource.go @@ -21,7 +21,7 @@ import ( "github.com/open-component-model/ocm/pkg/errors" ) -type ocm_resource struct { +type ocmResource struct { base meta compdesc.ResourceMeta @@ -31,18 +31,18 @@ type ocm_resource struct { const T_OCMRESOURCE = "resource" -func (r *ocm_resource) Type() string { +func (r *ocmResource) Type() string { return T_OCMRESOURCE } -func (r *ocm_resource) Set() { +func (r *ocmResource) Set() { r.Builder.ocm_rsc = &r.meta r.Builder.ocm_acc = &r.access r.Builder.ocm_meta = &r.meta.ElementMeta r.Builder.blob = &r.blob } -func (r *ocm_resource) Close() error { +func (r *ocmResource) Close() error { switch { case r.access != nil: return r.Builder.ocm_vers.SetResource(&r.meta, r.access) @@ -56,7 +56,7 @@ func (r *ocm_resource) Close() error { func (b *Builder) Resource(name, vers, typ string, relation metav1.ResourceRelation, f ...func()) { b.expect(b.ocm_vers, T_OCMVERSION) - r := &ocm_resource{} + r := &ocmResource{} r.meta.Name = name r.meta.Version = vers r.meta.Type = typ diff --git a/pkg/env/builder/ocm_source.go b/pkg/env/builder/ocm_source.go index a5bee1246..eac2d309a 100644 --- a/pkg/env/builder/ocm_source.go +++ b/pkg/env/builder/ocm_source.go @@ -20,7 +20,7 @@ import ( "github.com/open-component-model/ocm/pkg/errors" ) -type ocm_source struct { +type ocmSource struct { base meta compdesc.SourceMeta @@ -30,18 +30,18 @@ type ocm_source struct { const T_OCMSOURCE = "source" -func (r *ocm_source) Type() string { +func (r *ocmSource) Type() string { return T_OCMSOURCE } -func (r *ocm_source) Set() { +func (r *ocmSource) Set() { r.Builder.ocm_src = &r.meta r.Builder.ocm_acc = &r.access r.Builder.ocm_meta = &r.meta.ElementMeta r.Builder.blob = &r.blob } -func (r *ocm_source) Close() error { +func (r *ocmSource) Close() error { switch { case r.access != nil: return r.Builder.ocm_vers.SetSource(&r.meta, r.access) @@ -55,7 +55,7 @@ func (r *ocm_source) Close() error { func (b *Builder) Source(name, vers, typ string, f ...func()) { b.expect(b.ocm_vers, T_OCMVERSION) - r := &ocm_source{} + r := &ocmSource{} r.meta.Name = name r.meta.Type = typ r.meta.Version = vers diff --git a/pkg/env/builder/ocm_version.go b/pkg/env/builder/ocm_version.go index 84da44794..6d9faaac6 100644 --- a/pkg/env/builder/ocm_version.go +++ b/pkg/env/builder/ocm_version.go @@ -22,20 +22,20 @@ import ( const T_OCMVERSION = "component version" -type ocm_version struct { +type ocmVersion struct { base kind string cpi.ComponentVersionAccess } -func (r *ocm_version) Type() string { +func (r *ocmVersion) Type() string { if r.kind != "" { return r.kind } return T_OCMVERSION } -func (r *ocm_version) Set() { +func (r *ocmVersion) Set() { r.Builder.ocm_vers = r.ComponentVersionAccess } @@ -51,7 +51,7 @@ func (b *Builder) Version(name string, f ...func()) { } b.failOn(err) v.GetDescriptor().Provider.Name = metav1.ProviderName("ACME") - b.configure(&ocm_version{ComponentVersionAccess: v}, f) + b.configure(&ocmVersion{ComponentVersionAccess: v}, f) } func (b *Builder) ComponentVersion(name, version string, f ...func()) { diff --git a/pkg/env/env.go b/pkg/env/env.go index 39709acac..bd181b5e1 100644 --- a/pkg/env/env.go +++ b/pkg/env/env.go @@ -23,13 +23,11 @@ import ( "github.com/mandelsoft/vfs/pkg/readonlyfs" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" - "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/config" "github.com/open-component-model/ocm/pkg/contexts/credentials" + "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" "github.com/open-component-model/ocm/pkg/contexts/oci" - "github.com/open-component-model/ocm/pkg/contexts/ocm" ) @@ -45,8 +43,6 @@ func (dummyOption) Mount(*composefs.ComposedFileSystem) error { return nil } -//////////////////////////////////////////////////////////////////////////////// - type fsOpt struct { dummyOption path string @@ -64,8 +60,6 @@ func (o fsOpt) Mount(cfs *composefs.ComposedFileSystem) error { return cfs.Mount(o.path, o.fs) } -//////////////////////////////////////////////////////////////////////////////// - type tdOpt struct { dummyOption path string diff --git a/pkg/runtime/scheme.go b/pkg/runtime/scheme.go index 2217cb4dc..354257264 100644 --- a/pkg/runtime/scheme.go +++ b/pkg/runtime/scheme.go @@ -172,7 +172,7 @@ func (t KnownTypes) TypeNames() []string { // Scheme is the interface to describe a set of object types // that implement a dedicated interface. // As such it knows about the desired interface of the instances -// and can validate it. Additionally it provides an implementation +// and can validate it. Additionally, it provides an implementation // for generic unstructured objects that can be used to decode // any serialized from of object candidates and provide the // effective type. @@ -186,7 +186,7 @@ type Scheme interface { Decode(data []byte, unmarshaler Unmarshaler) (TypedObject, error) Encode(obj TypedObject, marshaler Marshaler) ([]byte, error) EnforceDecode(data []byte, unmarshaler Unmarshaler) (TypedObject, error) - AddKnownTypes(scheme Scheme) + AddKnownTypes(scheme Scheme) error KnownTypes() KnownTypes KnownTypeNames() []string } @@ -200,37 +200,37 @@ type defaultScheme struct { types KnownTypes } -func MustNewDefaultScheme(proto_ifce interface{}, proto_unstr Unstructured, acceptUnknown bool, defaultdecoder TypedObjectDecoder) Scheme { - s, err := NewDefaultScheme(proto_ifce, proto_unstr, acceptUnknown, defaultdecoder) +func MustNewDefaultScheme(protoIfce interface{}, protoUnstr Unstructured, acceptUnknown bool, defaultdecoder TypedObjectDecoder) Scheme { + s, err := NewDefaultScheme(protoIfce, protoUnstr, acceptUnknown, defaultdecoder) if err != nil { panic(err) } return s } -func NewDefaultScheme(proto_ifce interface{}, proto_unstr Unstructured, acceptUnknown bool, defaultdecoder TypedObjectDecoder) (Scheme, error) { - if proto_ifce == nil { +func NewDefaultScheme(protoIfce interface{}, protoUnstr Unstructured, acceptUnknown bool, defaultdecoder TypedObjectDecoder) (Scheme, error) { + if protoIfce == nil { return nil, fmt.Errorf("object interface must be given by pointer to interace (is nil)") } - it := reflect.TypeOf(proto_ifce) + it := reflect.TypeOf(protoIfce) if it.Kind() != reflect.Ptr { - return nil, fmt.Errorf("object interface %T: must be given by pointer to interace (is not pointer)", proto_ifce) + return nil, fmt.Errorf("object interface %T: must be given by pointer to interace (is not pointer)", protoIfce) } it = it.Elem() if it.Kind() != reflect.Interface { - return nil, fmt.Errorf("object interface %T: must be given by pointer to interace (does not point to interface)", proto_ifce) + return nil, fmt.Errorf("object interface %T: must be given by pointer to interace (does not point to interface)", protoIfce) } if !it.Implements(typeTypedObject) { - return nil, fmt.Errorf("object interface %T: must implement TypedObject", proto_ifce) + return nil, fmt.Errorf("object interface %T: must implement TypedObject", protoIfce) } - ut, err := ProtoType(proto_unstr) + ut, err := ProtoType(protoUnstr) if err != nil { - return nil, errors.Wrapf(err, "unstructured prototype %T", proto_unstr) + return nil, errors.Wrapf(err, "unstructured prototype %T", protoUnstr) } if acceptUnknown { if !reflect.PtrTo(ut).Implements(typeTypedObject) { - return nil, fmt.Errorf("unstructured type %T must implement TypedObject to be acceptale as unknown result", proto_unstr) + return nil, fmt.Errorf("unstructured type %T must implement TypedObject to be acceptale as unknown result", protoUnstr) } } @@ -243,12 +243,13 @@ func NewDefaultScheme(proto_ifce interface{}, proto_unstr Unstructured, acceptUn }, nil } -func (d *defaultScheme) AddKnownTypes(s Scheme) { +func (d *defaultScheme) AddKnownTypes(s Scheme) error { d.lock.Lock() defer d.lock.Unlock() for k, v := range s.KnownTypes() { d.types[k] = v } + return nil } func (d *defaultScheme) KnownTypes() KnownTypes {