Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/sigstore/co…
Browse files Browse the repository at this point in the history
…sign/v2-2.2.4
  • Loading branch information
morri-son authored Apr 18, 2024
2 parents a722e13 + 7d613d8 commit 4a33476
Show file tree
Hide file tree
Showing 34 changed files with 1,014 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push_ocm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}

- name: inject go-build-cache into docker
uses: reproducible-containers/buildkit-cache-dance@v2
uses: reproducible-containers/buildkit-cache-dance@v3
with:
cache-source: go-build-cache

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:
uses: anchore/sbom-action/download-syft@ab5d7b5f48981941c4c5d6bf33aeb98fe3bae38c # v0.15.10

- name: Setup Cosign
uses: sigstore/cosign-installer@v3.4.0
uses: sigstore/cosign-installer@v3.5.0

- name: Setup git config
run: |
Expand Down
2 changes: 2 additions & 0 deletions cmds/ocm/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/get"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/hash"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/install"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/list"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/show"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/sign"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs/transfer"
Expand Down Expand Up @@ -234,6 +235,7 @@ func newCliCommand(opts *CLIOptions, mod ...func(clictx.Context, *cobra.Command)

cmd.AddCommand(check.NewCommand(opts.Context))
cmd.AddCommand(get.NewCommand(opts.Context))
cmd.AddCommand(list.NewCommand(opts.Context))
cmd.AddCommand(create.NewCommand(opts.Context))
cmd.AddCommand(add.NewCommand(opts.Context))
cmd.AddCommand(sign.NewCommand(opts.Context))
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/common/options/keyoption/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (o *Option) AddFlags(fs *pflag.FlagSet) {
fs.StringArrayVarP(&o.publicKeys, "public-key", "k", nil, "public key setting")
fs.StringArrayVarP(&o.privateKeys, "private-key", "K", nil, "private key setting")
fs.StringArrayVarP(&o.issuers, "issuer", "I", nil, "issuer name or distinguished name (DN) (optionally for dedicated signature) ([<name>:=]<dn>")
fs.StringArrayVarP(&o.rootCAs, "ca-cert", "", nil, "additional root certificate authorities")
fs.StringArrayVarP(&o.rootCAs, "ca-cert", "", nil, "additional root certificate authorities (for signing certificates)")
}

func (o *Option) Configure(ctx clictx.Context) error {
Expand Down
28 changes: 27 additions & 1 deletion cmds/ocm/commands/misccmds/hash/sign/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package sign

import (
"crypto/x509"
"crypto/x509/pkix"
"fmt"
"strings"
Expand Down Expand Up @@ -36,6 +37,7 @@ type Command struct {

pubFile string
rootFile string
rootCAs []string

stype string
priv signutils.GenericPrivateKey
Expand Down Expand Up @@ -72,7 +74,9 @@ $ ocm sign hash key.priv SHA-256:810ff2fb242a5dee4220f2cb0e6a519891fb67f2f828a6c
func (o *Command) AddFlags(set *pflag.FlagSet) {
set.StringVarP(&o.stype, "algorithm", "S", rsa.Algorithm, "signature algorithm")
set.StringVarP(&o.pubFile, "publicKey", "", "", "public key certificate file")
set.StringVarP(&o.rootFile, "rootCerts", "", "", "root certificates file")
set.StringVarP(&o.rootFile, "rootCerts", "", "", "root certificates file (deprecated)")
set.StringArrayVarP(&o.rootCAs, "ca-cert", "", nil, "additional root certificate authorities (for signing certificates)")

}

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

if len(o.rootCAs) > 0 {
var list []*x509.Certificate
for _, r := range o.rootCAs {
data, err := utils2.ReadFile(r, o.FileSystem())
if err != nil {
return errors.Wrapf(err, "root CA")
}
certs, err := signutils.GetCertificateChain(data, false)
if err != nil {
return errors.Wrapf(err, "root CA")
}
list = append(list, certs...)
}
if o.roots != nil {
for _, c := range list {
o.roots.(*x509.CertPool).AddCert(c)
}
} else {
o.roots = list
}
}

o.priv, err = utils2.ReadFile(args[0], o.FileSystem())
if err != nil {
return err
Expand Down
11 changes: 0 additions & 11 deletions cmds/ocm/commands/ocmcmds/common/addhdlrs/rscs/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,5 @@ func (r *ResourceSpec) Validate(ctx clictx.Context, input *addhdlrs.ResourceInpu
if err := compdescv2.ValidateResource(fldPath, rsc, false); err != nil {
allErrs = append(allErrs, err...)
}

if input.Access != nil {
if r.Relation == metav1.LocalRelation {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("relation"), "access requires external relation"))
}
}
if input.Input != nil {
if r.Relation != metav1.LocalRelation {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("relation"), "input requires local relation"))
}
}
return allErrs.ToAggregate()
}
3 changes: 2 additions & 1 deletion cmds/ocm/commands/ocmcmds/common/handlers/comphdlr/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/open-component-model/ocm/cmds/ocm/pkg/processing"
"github.com/open-component-model/ocm/pkg/semverutils"
)

func Compare(a, b interface{}) int {
Expand All @@ -18,7 +19,7 @@ func Compare(a, b interface{}) int {
if c != 0 {
return c
}
return strings.Compare(aa.ComponentVersion.GetVersion(), ab.ComponentVersion.GetVersion())
return semverutils.Compare(aa.ComponentVersion.GetVersion(), ab.ComponentVersion.GetVersion())
}

// Sort is a processing chain sorting original objects provided by type handler.
Expand Down
99 changes: 99 additions & 0 deletions cmds/ocm/commands/ocmcmds/common/handlers/vershdlr/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0

package vershdlr

import (
"github.com/Masterminds/semver/v3"

"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/options/lookupoption"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/options/versionconstraintsoption"
"github.com/open-component-model/ocm/cmds/ocm/pkg/options"
"github.com/open-component-model/ocm/pkg/contexts/ocm"
"github.com/open-component-model/ocm/pkg/utils"
)

type Option interface {
ApplyToHandler(handler *TypeHandler)
}

type Options []Option

func (o Options) ApplyToHandler(handler *TypeHandler) {
for _, e := range o {
e.ApplyToHandler(handler)
}
}

func OptionsFor(o options.OptionSetProvider) Options {
var hopts []Option
if constr := versionconstraintsoption.From(o); constr != nil {
if len(constr.Constraints) > 0 {
hopts = append(hopts, WithVersionConstraints(constr.Constraints))
}
if constr.Latest {
hopts = append(hopts, LatestOnly())
}
}
if lookup := lookupoption.From(o); lookup != nil {
hopts = append(hopts, Resolver(lookup))
}
return hopts
}

////////////////////////////////////////////////////////////////////////////////

type constraints struct {
constraints []*semver.Constraints
}

func (o constraints) ApplyToHandler(handler *TypeHandler) {
handler.constraints = o.constraints
}

func WithVersionConstraints(c []*semver.Constraints) Option {
return constraints{c}
}

////////////////////////////////////////////////////////////////////////////////

type latestonly struct {
flag bool
}

func (o latestonly) ApplyToHandler(handler *TypeHandler) {
handler.latest = o.flag
}

func LatestOnly(b ...bool) Option {
return latestonly{utils.OptionalDefaultedBool(true, b...)}
}

////////////////////////////////////////////////////////////////////////////////

type resolver struct {
resolver ocm.ComponentVersionResolver
}

func (o resolver) ApplyToHandler(handler *TypeHandler) {
handler.resolver = o.resolver
}

func Resolver(r ocm.ComponentVersionResolver) Option {
return resolver{r}
}

////////////////////////////////////////////////////////////////////////////////

type repository struct {
repository ocm.Repository
}

func (o repository) ApplyToHandler(handler *TypeHandler) {
handler.repobase = o.repository
}

func Repository(r ocm.Repository) Option {
return repository{r}
}
26 changes: 26 additions & 0 deletions cmds/ocm/commands/ocmcmds/common/handlers/vershdlr/sort.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0

package vershdlr

import (
"strings"

"github.com/open-component-model/ocm/cmds/ocm/pkg/processing"
"github.com/open-component-model/ocm/pkg/semverutils"
)

func Compare(a, b interface{}) int {
aa := a.(*Object)
ab := b.(*Object)

c := strings.Compare(aa.Component, ab.Component)
if c != 0 {
return c
}
return semverutils.Compare(aa.Version, ab.Version)
}

// Sort is a processing chain sorting original objects provided by type handler.
var Sort = processing.Sort(Compare)
Loading

0 comments on commit 4a33476

Please sign in to comment.