Skip to content

Commit

Permalink
Merge branch 'master' into github_access_method
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Aug 2, 2022
2 parents b6bba92 + da17a48 commit c0863c2
Show file tree
Hide file tree
Showing 60 changed files with 2,016 additions and 503 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ format:
check:
@$(REPO_ROOT)/hack/check.sh --golangci-lint-config=./.golangci.yaml $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/pkg/...

.PHONY: force-test
force-test:
@go test --count=1 $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/pkg/...

.PHONY: test
test:
@echo "> Test"
@go test $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/pkg/...

.PHONY: generate
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ to embed the creation of component versions in build processes, for example in a

The OCI and OCM support can be found in packages
[`pkg/contexts/oci`](pkg/contexts/oci) and [`pkg/contexts/ocm`](pkg/contexts/ocm).


There are several specifications:
- [Naming Schemes](docs/names/README.md)
- [Element Specifications](docs/formats/README.md)
9 changes: 3 additions & 6 deletions cmds/ocm/commands/misccmds/credentials/get/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,16 @@ func NewCommand(ctx clictx.Context, names ...string) *cobra.Command {
}

func (o *Command) ForName(name string) *cobra.Command {
list := ""
for _, i := range o.CredentialsContext().ConsumerIdentityMatchers().List() {
list += " - <code>" + i.Type + "</code>: " + i.Description + "\n"
}

return &cobra.Command{
Use: "{<consumer property>=<value>}",
Short: "Get credentials for a dedicated consumer spec",
Long: `
Try to resolve a given consumer specification against the configured credential
settings and show the found credential attributes.
For the following usage contexts a standard identity matcher exists:
` + list +
For the following usage contexts with matchers and standard identity matchers exist:
` + utils.FormatListElements("", utils.IdentityMatcherList(o.CredentialsContext().ConsumerIdentityMatchers().List())) +
`
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 Down
6 changes: 3 additions & 3 deletions cmds/ocm/commands/ocmcmds/components/sign/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/datacontext"
"github.com/open-component-model/ocm/pkg/contexts/oci"
ctfoci "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/ctf"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociregistry"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociartefact"
metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
"github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/ctf"
"github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes"
Expand Down Expand Up @@ -111,13 +111,13 @@ var _ = Describe("access method", func() {
})
env.Resource("value", "", resourcetypes.OCI_IMAGE, metav1.LocalRelation, func() {
env.Access(
ociregistry.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE, OCIVERSION)),
ociartefact.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE, OCIVERSION)),
)
env.Label("transportByValue", true)
})
env.Resource("ref", "", resourcetypes.OCI_IMAGE, metav1.LocalRelation, func() {
env.Access(
ociregistry.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE2, OCIVERSION)),
ociartefact.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE2, OCIVERSION)),
)
})
})
Expand Down
6 changes: 3 additions & 3 deletions cmds/ocm/commands/ocmcmds/components/transfer/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/oci/repositories/artefactset"
ctfoci "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/ctf"
"github.com/open-component-model/ocm/pkg/contexts/ocm"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociregistry"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociartefact"
metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
ctfocm "github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/ctf"
"github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes"
Expand Down Expand Up @@ -125,13 +125,13 @@ var _ = Describe("Test Environment", func() {
})
env.Resource("value", "", resourcetypes.OCI_IMAGE, metav1.LocalRelation, func() {
env.Access(
ociregistry.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE, OCIVERSION)),
ociartefact.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE, OCIVERSION)),
)
env.Label("transportByValue", true)
})
env.Resource("ref", "", resourcetypes.OCI_IMAGE, metav1.LocalRelation, func() {
env.Access(
ociregistry.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE2, OCIVERSION)),
ociartefact.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE2, OCIVERSION)),
)
})
})
Expand Down
6 changes: 3 additions & 3 deletions cmds/ocm/commands/ocmcmds/components/verify/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociartefact"
. "github.com/open-component-model/ocm/pkg/contexts/ocm/signing"

"github.com/open-component-model/ocm/pkg/common/accessobj"
"github.com/open-component-model/ocm/pkg/contexts/datacontext"
"github.com/open-component-model/ocm/pkg/contexts/oci"
ctfoci "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/ctf"
"github.com/open-component-model/ocm/pkg/contexts/ocm"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociregistry"
"github.com/open-component-model/ocm/pkg/contexts/ocm/attrs/signingattr"
metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
"github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/ctf"
Expand Down Expand Up @@ -113,13 +113,13 @@ var _ = Describe("access method", func() {
})
env.Resource("value", "", resourcetypes.OCI_IMAGE, metav1.LocalRelation, func() {
env.Access(
ociregistry.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE, OCIVERSION)),
ociartefact.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE, OCIVERSION)),
)
env.Label("transportByValue", true)
})
env.Resource("ref", "", resourcetypes.OCI_IMAGE, metav1.LocalRelation, func() {
env.Access(
ociregistry.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE2, OCIVERSION)),
ociartefact.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE2, OCIVERSION)),
)
})
})
Expand Down
10 changes: 5 additions & 5 deletions cmds/ocm/commands/ocmcmds/ctf/transfer/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/oci"
"github.com/open-component-model/ocm/pkg/contexts/oci/artdesc"
ctfoci "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/ctf"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociregistry"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociartefact"
metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
ctfocm "github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/ctf"
"github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes"
Expand Down Expand Up @@ -87,13 +87,13 @@ var _ = Describe("Test Environment", func() {
})
env.Resource("value", "", resourcetypes.OCI_IMAGE, metav1.LocalRelation, func() {
env.Access(
ociregistry.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE, OCIVERSION)),
ociartefact.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE, OCIVERSION)),
)
env.Label("transportByValue", true)
})
env.Resource("ref", "", resourcetypes.OCI_IMAGE, metav1.LocalRelation, func() {
env.Access(
ociregistry.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE2, OCIVERSION)),
ociartefact.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE2, OCIVERSION)),
)
})
})
Expand Down Expand Up @@ -130,10 +130,10 @@ transferring component "github.com/mandelsoft/test"...

data, err := json.Marshal(comp.GetDescriptor().Resources[2].Access)
Expect(err).To(Succeed())
Expect(string(data)).To(Equal("{\"imageReference\":\"alias.alias/ocm/ref:v2.0\",\"type\":\"ociRegistry\"}"))
Expect(string(data)).To(Equal("{\"imageReference\":\"alias.alias/ocm/ref:v2.0\",\"type\":\"" + ociartefact.Type + "\"}"))

data, err = json.Marshal(comp.GetDescriptor().Resources[1].Access)
Expect(err).To(Succeed())
Expect(string(data)).To(Equal("{\"imageReference\":\"alias.alias/ocm/value:v2.0\",\"type\":\"ociRegistry\"}"))
Expect(string(data)).To(Equal("{\"imageReference\":\"alias.alias/ocm/value:v2.0\",\"type\":\"" + ociartefact.Type + "\"}"))
})
})
8 changes: 4 additions & 4 deletions cmds/ocm/commands/ocmcmds/resources/add/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import (

"github.com/open-component-model/ocm/pkg/common/accessobj"
"github.com/open-component-model/ocm/pkg/contexts/oci/repositories/artefactset"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociregistry"
"github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/comparch"
"github.com/open-component-model/ocm/pkg/mime"

. "github.com/open-component-model/ocm/cmds/ocm/testhelper"
"github.com/open-component-model/ocm/pkg/common"
"github.com/open-component-model/ocm/pkg/common/accessio"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/localblob"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociartefact"
"github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc"
metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
)
Expand Down Expand Up @@ -167,11 +167,11 @@ var _ = Describe("Add resources", func() {
Expect(r.Version).To(Equal("v0.1.0"))
Expect(r.Relation).To(Equal(metav1.ResourceRelation("external")))

Expect(r.Access.GetType()).To(Equal(ociregistry.Type))
Expect(r.Access.GetType()).To(Equal(ociartefact.Type))

acc, err := env.OCMContext().AccessSpecForSpec(r.Access)
Expect(err).To(Succeed())
Expect(reflect.TypeOf(acc)).To(Equal(reflect.TypeOf((*ociregistry.AccessSpec)(nil))))
Expect(acc.(*ociregistry.AccessSpec).ImageReference).To(Equal("ghcr.io/mandelsoft/pause:v0.1.0"))
Expect(reflect.TypeOf(acc)).To(Equal(reflect.TypeOf((*ociartefact.AccessSpec)(nil))))
Expect(acc.(*ociartefact.AccessSpec).ImageReference).To(Equal("ghcr.io/mandelsoft/pause:v0.1.0"))
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ name: image
version: v0.1.0
relation: external
access:
type: ociRegistry
type: ociArtefact
imageReference: ghcr.io/mandelsoft/pause:v0.1.0
37 changes: 34 additions & 3 deletions cmds/ocm/pkg/utils/listhelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,46 @@ package utils

import (
"fmt"

"github.com/open-component-model/ocm/pkg/contexts/credentials"
)

type StringElementList []string

func (l StringElementList) Size() int { return len(l) }
func (l StringElementList) Key(i int) string { return l[i] }
func (l StringElementList) Description(i int) string { return "" }

func FormatList(def string, elems ...string) string {
return FormatListElements(def, StringElementList(elems))
}

type ListElements interface {
Size() int
Key(i int) string
Description(i int) string
}

func FormatListElements(def string, elems ListElements) string {
names := ""
for _, n := range elems {
names = fmt.Sprintf("%s\n - <code>%s</code>", names, n)
if n == def {
size := elems.Size()

for i := 0; i < size; i++ {
key := elems.Key(i)
names = fmt.Sprintf("%s\n - <code>%s</code>", names, key)
if key == def {
names += " (default)"
}
desc := elems.Description(i)
if len(desc) > 0 {
names += ": " + desc
}
}
return names + "\n"
}

type IdentityMatcherList []credentials.IdentityMatcherInfo

func (l IdentityMatcherList) Size() int { return len(l) }
func (l IdentityMatcherList) Key(i int) string { return l[i].Type }
func (l IdentityMatcherList) Description(i int) string { return l[i].Description }
21 changes: 21 additions & 0 deletions cmds/test/play/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"crypto/x509/pkix"
"encoding/hex"
"fmt"
"regexp"
"time"

"github.com/open-component-model/ocm/pkg/errors"
Expand All @@ -33,8 +34,28 @@ func CheckErr(err error, msg string, args ...interface{}) {
}
}

var expr = regexp.MustCompile("^[a-z][-a-z0-9]*([.][a-z][-a-z0-9]*)*[.][a-z]{2,}(/[a-z][-a-z0-9_]*([.][a-z][-a-z0-9_]*)*)+$")

func Check(s string, exp bool) {
if expr.MatchString(s) != exp {
fmt.Printf("%s[%t] failed\n", s, exp)
}
}

func main() {

Check("github.wdf.sap.corp/kubernetes/landscape-setup", true)
Check("weave.works/registry/app", true)
Check("internal.github.org/registry/app", true)
Check("a.de/c", true)
Check("a.de/c/d/e-f", true)
Check("a.de/c/d/e_f", true)
Check("a.de/c/d/e", true)
Check("a.de/c/d/e.f", true)
Check("a.de/", false)
Check("a.de/a/", false)
Check("a.de//a", false)
Check("a.de/a.", false)
capriv, capub, err := rsa.Handler{}.CreateKeyPair()

CheckErr(err, "ca keypair")
Expand Down
34 changes: 34 additions & 0 deletions docs/formats/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Format Specifications

The Open Component Model (OCM) uses some dedicated formats
to represent content:

- File Formats

- Common Transport Format (CTF)

It is possible to represent OCI and OCM content as file system content.
This is used to provide a repository implementation based on a filesystem,
which can be used to transport content without direct internet access.

There are three different technical flavors:
- `directory`: the content is stored directly as a directory tree
- `tar`: the directory tree is stored in a tar archive
- `tgz`: the directory tree is stored in a zipped tar archive

All those technical representations use the same [file formats and directory
structure](../../pkg/contexts/oci/repositories/ctf/README.md).

- Raw Helm Chart Format

Helm Charts can be stored as OCI artefacts in OCI repositories. When
downloading those artefacts by default they will be transformed to the
regular helm file system representation by some download handlers.
If a raw format is chosen the
[OCI representation](../../pkg/contexts/oci/repositories/ctf/README.md#artefact-set-archive-format)
is used to represent the chart content.

- Component Descriptor

There are two [serialization versions](compdesc/README.md) to store an OCM component descriptor
as YAML
Loading

0 comments on commit c0863c2

Please sign in to comment.