-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin installation and update (#187)
uploader CLI options and named uploaders
- Loading branch information
1 parent
c32a6ec
commit beb2097
Showing
123 changed files
with
3,832 additions
and
675 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
type Config struct { | ||
AccessMethods Values `json:"accessMethods"` | ||
Uploaders Values `json:"uploaders"` | ||
} | ||
|
||
type Values struct { | ||
Path string `json:"path"` | ||
} | ||
|
||
func GetConfig(raw json.RawMessage) (interface{}, error) { | ||
var cfg Config | ||
|
||
err := json.Unmarshal(raw, &cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &cfg, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
cmds/ocm/commands/ocmcmds/common/options/uploaderoption/option.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package uploaderoption | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/mandelsoft/vfs/pkg/vfs" | ||
"github.com/spf13/pflag" | ||
"sigs.k8s.io/yaml" | ||
|
||
"github.com/open-component-model/ocm/cmds/ocm/pkg/options" | ||
"github.com/open-component-model/ocm/pkg/cobrautils/flag" | ||
"github.com/open-component-model/ocm/pkg/contexts/clictx" | ||
"github.com/open-component-model/ocm/pkg/contexts/ocm" | ||
"github.com/open-component-model/ocm/pkg/contexts/ocm/registration" | ||
"github.com/open-component-model/ocm/pkg/errors" | ||
) | ||
|
||
func From(o options.OptionSetProvider) *Option { | ||
var opt *Option | ||
o.AsOptionSet().Get(&opt) | ||
return opt | ||
} | ||
|
||
type Registration struct { | ||
Name string | ||
ArtefactType string | ||
MediaType string | ||
Config json.RawMessage | ||
} | ||
|
||
func New() *Option { | ||
return &Option{} | ||
} | ||
|
||
type Option struct { | ||
spec map[string]string | ||
Registrations []*Registration | ||
} | ||
|
||
func (o *Option) AddFlags(fs *pflag.FlagSet) { | ||
flag.StringToStringVarP(fs, &o.spec, "uploader", "", nil, "repository uploader (<name>:<artefact type>:<media type>=<JSON target config)") | ||
} | ||
|
||
func (o *Option) Complete(ctx clictx.Context) error { | ||
desc := "<name>[:<artefact type>[:<media type>]]" | ||
for n, v := range o.spec { | ||
nam := n | ||
art := "" | ||
med := "" | ||
i := strings.Index(nam, ":") | ||
if i >= 0 { | ||
art = nam[i+1:] | ||
nam = nam[:i] | ||
i = strings.Index(art, ":") | ||
if i >= 0 { | ||
med = art[i+1:] | ||
art = art[:i] | ||
i = strings.Index(med, ":") | ||
if i >= 0 { | ||
return fmt.Errorf("invalid uploader registration %s must be of %s", n, desc) | ||
} | ||
} | ||
} | ||
|
||
var data json.RawMessage | ||
var err error | ||
if strings.HasPrefix(v, "@") { | ||
data, err = vfs.ReadFile(ctx.FileSystem(), v[1:]) | ||
if err != nil { | ||
return errors.Wrapf(err, "cannot read upload target specification from %q", v[1:]) | ||
} | ||
} else { | ||
var values interface{} | ||
if err = yaml.Unmarshal([]byte(v), &values); err != nil { | ||
return errors.Wrapf(err, "invalid target specification %q", v) | ||
} | ||
data, err = json.Marshal(values) | ||
if err != nil { | ||
return errors.Wrapf(err, "cannot marshal target specification") | ||
} | ||
} | ||
o.Registrations = append(o.Registrations, &Registration{ | ||
Name: nam, | ||
ArtefactType: art, | ||
MediaType: med, | ||
Config: data, | ||
}) | ||
} | ||
return nil | ||
} | ||
|
||
func (o *Option) Register(ctx ocm.ContextProvider) error { | ||
for _, s := range o.Registrations { | ||
err := registration.RegisterBlobHandlerByName(ctx.OCMContext(), s.Name, s.Config, | ||
registration.ForArtefactType(s.ArtefactType), registration.ForMimeType(s.MediaType)) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (o *Option) Usage() string { | ||
s := ` | ||
If the <code>--uploader</code> option is specified, appropriate uploaders | ||
are configured for the transport target. It has the following format | ||
<center> | ||
<pre><name>:<artefact type>:<media type>=<yaml target config></pre> | ||
</center> | ||
The uploader name may be a path expression with the following possibilities: | ||
- <code>ocm/ociRegistry</code>: oci Registry upload for local OCI artefact blobs. | ||
The media type is optional. If given ist must be an OCI artefact media type. | ||
- <code>plugin/<plugin name>[/<uploader name]</code>: uploader provided by plugin. | ||
` | ||
return s | ||
} |
17 changes: 17 additions & 0 deletions
17
cmds/ocm/commands/ocmcmds/common/options/uploaderoption/suite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package uploaderoption | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Uploader Option Suite") | ||
} |
Oops, something went wrong.