Skip to content

Commit

Permalink
helm repository access method (#354)
Browse files Browse the repository at this point in the history
* helm chart acess

* input type and access type for helm repo

* docu

* support helm types fo oci:

* align matchers

* align consumer package structure and help

* fix typos
  • Loading branch information
mandelsoft authored May 5, 2023
1 parent 5fe5aa6 commit 3e14523
Show file tree
Hide file tree
Showing 114 changed files with 2,623 additions and 533 deletions.
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ linters:


# Disabled with reason
- dogsled
- exhaustruct # Doesn't really make sense.
- exhaustive # Doesn't really make sense.
- logrlint # Doesn't really make sense.
Expand Down
3 changes: 2 additions & 1 deletion cmds/demoplugin/accessmethods/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/open-component-model/ocm/cmds/demoplugin/config"
"github.com/open-component-model/ocm/pkg/cobrautils/flagsets"
"github.com/open-component-model/ocm/pkg/contexts/credentials"
"github.com/open-component-model/ocm/pkg/contexts/credentials/cpi"
"github.com/open-component-model/ocm/pkg/contexts/oci/identity"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/options"
"github.com/open-component-model/ocm/pkg/contexts/ocm/plugin/ppi"
Expand Down Expand Up @@ -89,7 +90,7 @@ func (a *AccessMethod) ValidateSpecification(p ppi.Plugin, spec ppi.AccessSpec)
}
info.MediaType = my.MediaType
info.ConsumerId = credentials.ConsumerIdentity{
identity.ID_TYPE: common.CONSUMER_TYPE,
cpi.ID_TYPE: common.CONSUMER_TYPE,
identity.ID_HOSTNAME: "localhost",
identity.ID_PATHPREFIX: my.Path,
}
Expand Down
3 changes: 2 additions & 1 deletion cmds/demoplugin/uploaders/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/open-component-model/ocm/cmds/demoplugin/common"
"github.com/open-component-model/ocm/cmds/demoplugin/config"
"github.com/open-component-model/ocm/pkg/contexts/credentials"
"github.com/open-component-model/ocm/pkg/contexts/credentials/cpi"
"github.com/open-component-model/ocm/pkg/contexts/oci/identity"
"github.com/open-component-model/ocm/pkg/contexts/ocm/plugin/ppi"
"github.com/open-component-model/ocm/pkg/errors"
Expand Down Expand Up @@ -68,7 +69,7 @@ func (a *Uploader) ValidateSpecification(p ppi.Plugin, spec ppi.UploadTargetSpec
}

info.ConsumerId = credentials.ConsumerIdentity{
identity.ID_TYPE: common.CONSUMER_TYPE,
cpi.ID_TYPE: common.CONSUMER_TYPE,
identity.ID_HOSTNAME: "localhost",
identity.ID_PATHPREFIX: my.Path,
}
Expand Down
7 changes: 4 additions & 3 deletions cmds/ecrplugin/actions/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

ocmcreds "github.com/open-component-model/ocm/pkg/contexts/credentials"
oci_repository_prepare "github.com/open-component-model/ocm/pkg/contexts/datacontext/action/types/oci-repository-prepare"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/s3/identity"
"github.com/open-component-model/ocm/pkg/contexts/ocm/plugin/ppi"
"github.com/open-component-model/ocm/pkg/errors"
)
Expand Down Expand Up @@ -59,9 +60,9 @@ func (a Action) Execute(p ppi.Plugin, spec ppi.ActionSpec, creds ocmcreds.Direct
var awsCred aws.CredentialsProvider = aws.AnonymousCredentials{}

if creds != nil {
accessKeyID := creds.GetProperty(ocmcreds.ATTR_AWS_ACCESS_KEY_ID)
accessSecret := creds.GetProperty(ocmcreds.ATTR_AWS_SECRET_ACCESS_KEY)
accessToken := creds.GetProperty(ocmcreds.ATTR_TOKEN)
accessKeyID := creds.GetProperty(identity.ATTR_AWS_ACCESS_KEY_ID)
accessSecret := creds.GetProperty(identity.ATTR_AWS_SECRET_ACCESS_KEY)
accessToken := creds.GetProperty(identity.ATTR_TOKEN)
awsCred = credentials.NewStaticCredentialsProvider(accessKeyID, accessSecret, accessToken)
}

Expand Down
2 changes: 1 addition & 1 deletion cmds/helminstaller/app/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
"github.com/open-component-model/ocm/cmds/helminstaller/app/driver"
"github.com/open-component-model/ocm/pkg/common"
"github.com/open-component-model/ocm/pkg/common/compression"
"github.com/open-component-model/ocm/pkg/contexts/oci/ociutils/helm/loader"
v1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
"github.com/open-component-model/ocm/pkg/contexts/ocm/download"
"github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes"
"github.com/open-component-model/ocm/pkg/contexts/ocm/utils"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/helm/loader"
"github.com/open-component-model/ocm/pkg/out"
"github.com/open-component-model/ocm/pkg/runtime"
"github.com/open-component-model/ocm/pkg/toi/support"
Expand Down
7 changes: 6 additions & 1 deletion cmds/ocm/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
cmdutils "github.com/open-component-model/ocm/cmds/ocm/pkg/utils"
"github.com/open-component-model/ocm/cmds/ocm/topics/common/attributes"
topicconfig "github.com/open-component-model/ocm/cmds/ocm/topics/common/config"
topiccredentials "github.com/open-component-model/ocm/cmds/ocm/topics/common/credentials"
topiclogging "github.com/open-component-model/ocm/cmds/ocm/topics/common/logging"
topicocirefs "github.com/open-component-model/ocm/cmds/ocm/topics/oci/refs"
topicocmaccessmethods "github.com/open-component-model/ocm/cmds/ocm/topics/ocm/accessmethods"
Expand Down Expand Up @@ -223,18 +224,22 @@ func newCliCommand(opts *CLIOptions, mod ...func(clictx.Context, *cobra.Command)
}
// help.Use="help <topic>"
help.DisableFlagsInUseLine = true
cmd.AddCommand(topiclogging.New(ctx))
cmd.AddCommand(topicconfig.New(ctx))
cmd.AddCommand(topiccredentials.New(ctx))
cmd.AddCommand(topiclogging.New(ctx))
cmd.AddCommand(topicocirefs.New(ctx))
cmd.AddCommand(topicocmrefs.New(ctx))
cmd.AddCommand(topicocmaccessmethods.New(ctx))
cmd.AddCommand(attributes.New(ctx))
cmd.AddCommand(topicbootstrap.New(ctx, "toi-bootstrapping"))

help.AddCommand(topicconfig.New(ctx))
help.AddCommand(topiccredentials.New(ctx))
help.AddCommand(topiclogging.New(ctx))
help.AddCommand(topicocirefs.New(ctx))
help.AddCommand(topicocmrefs.New(ctx))
help.AddCommand(topicocmaccessmethods.New(ctx))
help.AddCommand(attributes.New(ctx))
help.AddCommand(topicbootstrap.New(ctx, "toi-bootstrapping"))

for _, m := range mod {
Expand Down
4 changes: 2 additions & 2 deletions cmds/ocm/commands/misccmds/action/execute/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (o *Command) Complete(args []string) error {
o.Spec, err = action.DecodeActionSpec(data)

if o.MatcherType != "" {
m, _ := o.CredentialsContext().ConsumerIdentityMatchers().Get(o.MatcherType)
m := o.CredentialsContext().ConsumerIdentityMatchers().Get(o.MatcherType)
if m == nil {
return errors.ErrUnknown("identity matcher", o.MatcherType)
}
Expand All @@ -129,7 +129,7 @@ func (o *Command) Complete(args []string) error {
o.Consumer[name] = value
}
if t, ok := o.Consumer[credentials.ID_TYPE]; ok {
m, _ := o.CredentialsContext().ConsumerIdentityMatchers().Get(t)
m := o.CredentialsContext().ConsumerIdentityMatchers().Get(t)
if m != nil {
o.Matcher = m
}
Expand Down
31 changes: 17 additions & 14 deletions cmds/ocm/commands/misccmds/credentials/get/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ package get
import (
"sort"
"strings"
"unicode"
"unicode/utf8"

"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/listformat"
"github.com/open-component-model/ocm/cmds/ocm/pkg/output"
"github.com/open-component-model/ocm/cmds/ocm/pkg/utils"
"github.com/open-component-model/ocm/pkg/contexts/clictx"
Expand Down Expand Up @@ -45,17 +44,12 @@ func NewCommand(ctx clictx.Context, names ...string) *cobra.Command {

func (o *Command) ForName(name string) *cobra.Command {
var standard credentials.IdentityMatcherInfos
var context credentials.IdentityMatcherInfos
var consumer credentials.IdentityMatcherInfos
for _, e := range o.CredentialsContext().ConsumerIdentityMatchers().List() {
if e.Type != "" {
r, _ := utf8.DecodeRuneInString(e.Type)
if unicode.IsLower(r) {
standard = append(standard, e)
} else {
context = append(context, e)
}
if e.IsConsumerType() {
consumer = append(consumer, e)
} else {
context = append(context, e)
standard = append(standard, e)
}
}

Expand All @@ -67,10 +61,10 @@ Try to resolve a given consumer specification against the configured credential
settings and show the found credential attributes.
Matchers exist for the following usage contexts or consumer types:
` + utils.FormatListElements("", context) +
` + listformat.FormatListElements("", consumer) +
`
The following standard identity matchers are supported:
` + utils.FormatListElements("partial", standard) +
` + listformat.FormatListElements("partial", standard) +
`
The used matcher is derived from the consumer attribute <code>type</code>.
For all other consumer types a matcher matching all attributes will be used.
Expand All @@ -85,7 +79,7 @@ func (o *Command) AddFlags(set *pflag.FlagSet) {

func (o *Command) Complete(args []string) error {
if o.Type != "" {
m, _ := o.CredentialsContext().ConsumerIdentityMatchers().Get(o.Type)
m := o.CredentialsContext().ConsumerIdentityMatchers().Get(o.Type)
if m == nil {
return errors.ErrUnknown("identity matcher", o.Type)
}
Expand All @@ -104,6 +98,15 @@ func (o *Command) Complete(args []string) error {
}
o.Consumer[name] = value
}
if t, ok := o.Consumer[credentials.ID_TYPE]; ok {
m := o.CredentialsContext().ConsumerIdentityMatchers().Get(t)
if m != nil {
o.Matcher = m
}
}
if o.Matcher == nil {
o.Matcher = credentials.PartialMatch
}
return nil
}

Expand Down
22 changes: 10 additions & 12 deletions cmds/ocm/commands/misccmds/credentials/get/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (

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

. "github.com/open-component-model/ocm/cmds/ocm/testhelper"
"github.com/open-component-model/ocm/pkg/contexts/credentials/cpi"
. "github.com/open-component-model/ocm/pkg/testutils"

"github.com/open-component-model/ocm/pkg/contexts/credentials"
Expand All @@ -23,22 +25,18 @@ var _ = Describe("Test Environment", func() {
env = NewTestEnv()
cctx := env.CLI.CredentialsContext()

ids := credentials.ConsumerIdentity{
identity.ID_TYPE: "test",
identity.ID_HOSTNAME: "ghcr.io",
}
ids := credentials.NewConsumerIdentity("test", identity.ID_HOSTNAME, "ghcr.io")
creds := credentials.DirectCredentials{
"user": "testuser",
"pass": "testpass",
}

cctx.SetCredentialsForConsumer(ids, creds)

ids = credentials.ConsumerIdentity{
identity.ID_TYPE: identity.CONSUMER_TYPE,
identity.ID_HOSTNAME: "ghcr.io",
identity.ID_PATHPREFIX: "a",
}
ids = credentials.NewConsumerIdentity(identity.CONSUMER_TYPE,
identity.ID_HOSTNAME, "ghcr.io",
identity.ID_PATHPREFIX, "a",
)
creds = credentials.DirectCredentials{
"username": "testuser",
"password": "testpass",
Expand All @@ -53,7 +51,7 @@ var _ = Describe("Test Environment", func() {

It("get unknown type with partial matcher", func() {
buf := bytes.NewBuffer(nil)
Expect(env.CatchOutput(buf).Execute("get", "credentials", identity.ID_TYPE+"=test", identity.ID_HOSTNAME+"=ghcr.io")).To(Succeed())
Expect(env.CatchOutput(buf).Execute("get", "credentials", cpi.ID_TYPE+"=test", identity.ID_HOSTNAME+"=ghcr.io")).To(Succeed())
Expect(buf.String()).To(StringEqualTrimmedWithContext(`
ATTRIBUTE VALUE
pass testpass
Expand All @@ -62,14 +60,14 @@ user testuser
})
It("fail with partial matcher", func() {
buf := bytes.NewBuffer(nil)
err := env.CatchOutput(buf).Execute("get", "credentials", identity.ID_TYPE+"=test", identity.ID_HOSTNAME+"=gcr.io")
err := env.CatchOutput(buf).Execute("get", "credentials", cpi.ID_TYPE+"=test", identity.ID_HOSTNAME+"=gcr.io")
Expect(err).NotTo(BeNil())
Expect(err.Error()).To(Equal("consumer \"{\"hostname\":\"gcr.io\",\"type\":\"test\"}\" is unknown"))
})

It("get oci type with oci matcher", func() {
buf := bytes.NewBuffer(nil)
Expect(env.CatchOutput(buf).Execute("get", "credentials", identity.ID_TYPE+"="+identity.CONSUMER_TYPE, identity.ID_HOSTNAME+"=ghcr.io", identity.ID_PATHPREFIX+"=a/b")).To(Succeed())
Expect(env.CatchOutput(buf).Execute("get", "credentials", cpi.ID_TYPE+"="+identity.CONSUMER_TYPE, identity.ID_HOSTNAME+"=ghcr.io", identity.ID_PATHPREFIX+"=a/b")).To(Succeed())
Expect(buf.String()).To(StringEqualTrimmedWithContext(`
ATTRIBUTE VALUE
password testpass
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/ocmcmds/common/addhdlrs/comp/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

const (
ComponentVersionTag = "<componentversion>"
ComponentVersionTag = common.ComponentVersionTag
)

type ResourceSpecHandler struct {
Expand Down
2 changes: 2 additions & 0 deletions cmds/ocm/commands/ocmcmds/common/addhdlrs/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func (s *sourceInfo) Id() string {

type ElementSpec interface {
GetName() string
GetVersion() string
SetVersion(string)
Info() string
Validate(ctx clictx.Context, input *ResourceInput) error
}
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/ocmcmds/common/addhdlrs/rscs/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

const (
ComponentVersionTag = "<componentversion>"
ComponentVersionTag = common.ComponentVersionTag
)

type ResourceSpecHandler struct{}
Expand Down
8 changes: 5 additions & 3 deletions cmds/ocm/commands/ocmcmds/common/inputs/cpi/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ import (
)

type PathSpec struct {
runtime.ObjectVersionedType `json:",inline"`
inputs.InputSpecBase `json:",inline"`

// Path is a file or repository path
Path string `json:"path"`
}

func NewPathSpec(typ, path string) PathSpec {
return PathSpec{
ObjectVersionedType: runtime.ObjectVersionedType{
Type: typ,
InputSpecBase: inputs.InputSpecBase{
ObjectVersionedType: runtime.ObjectVersionedType{
Type: typ,
},
},
Path: path,
}
Expand Down
24 changes: 24 additions & 0 deletions cmds/ocm/commands/ocmcmds/common/inputs/inputtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ type InputSpec interface {
runtime.VersionedTypedObject
Validate(fldPath *field.Path, ctx Context, inputFilePath string) field.ErrorList
GetBlob(ctx Context, info InputResourceInfo) (accessio.TemporaryBlobAccess, string, error)
GetInputVersion(ctx Context) string
}

type InputSpecBase struct {
runtime.ObjectVersionedType `json:",inline"`
}

func (*InputSpecBase) GetInputVersion(ctx Context) string {
return ""
}

type InputType interface {
Expand Down Expand Up @@ -283,6 +292,10 @@ func (r *UnknownInputSpec) GetBlob(ctx Context, info InputResourceInfo) (accessi
return nil, "", errors.ErrUnknown("input type", r.GetType())
}

func (s *UnknownInputSpec) GetInputVersion(ctx Context) string {
return ""
}

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

type GenericInputSpec struct {
Expand Down Expand Up @@ -343,6 +356,17 @@ func (s *GenericInputSpec) GetBlob(ctx Context, info InputResourceInfo) (accessi
return s.effective.GetBlob(ctx, info)
}

func (s *GenericInputSpec) GetInputVersion(ctx Context) string {
if s.effective == nil {
var err error
s.effective, err = s.Evaluate(For(ctx))
if err != nil {
return ""
}
}
return s.effective.GetInputVersion(ctx)
}

func (s *GenericInputSpec) Evaluate(scheme InputTypeScheme) (InputSpec, error) {
var err error
if s == nil {
Expand Down
10 changes: 6 additions & 4 deletions cmds/ocm/commands/ocmcmds/common/inputs/types/binary/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
)

type Spec struct {
runtime.ObjectVersionedType `json:",inline"`
cpi.ProcessSpec `json:",inline"`
inputs.InputSpecBase `json:",inline"`
cpi.ProcessSpec `json:",inline"`

// Data is plain inline data as byte array
Data runtime.Binary `json:"data,omitempty"` // json rejects to unmarshal some !string into []byte
Expand All @@ -25,8 +25,10 @@ var _ inputs.InputSpec = (*Spec)(nil)

func New(data []byte, mediatype string, compress bool) *Spec {
return &Spec{
ObjectVersionedType: runtime.ObjectVersionedType{
Type: TYPE,
InputSpecBase: inputs.InputSpecBase{
ObjectVersionedType: runtime.ObjectVersionedType{
Type: TYPE,
},
},
ProcessSpec: cpi.NewProcessSpec(mediatype, compress),
Data: (data), // see above
Expand Down
Loading

0 comments on commit 3e14523

Please sign in to comment.