Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple plugin concept #169

Merged
merged 6 commits into from
Nov 3, 2022
Merged

Conversation

mandelsoft
Copy link
Contributor

@mandelsoft mandelsoft commented Oct 30, 2022

Alpha version

Using plugins it is possible now to provide additional access methods by separate executables found in a ocm plugin directory.

The plugin exectutable must implement a set of commands:

  • info The info command must return a JSON object describing the the plugin and its capabilities. So far, it might only provide access methods. It is intended to extend this by downloader and uploader implementations.
  • accessmethod all access relevant commands are available as sub commands for the accessmethod command
    • validate <spec> a given access specification is validated. It returns additional derived metadata for the given specification
      • a human readable info text
      • the consumer id required to determine optional credentials.
      • the media type, either derived from the spec or a constant.
      • a hint usable as reference name for local blob to reconstruct a useful name for exploded imports.
    • get -c <creds> <spec> dump the provided content to stdout
  • upload (not yet used) all upload relevant commands are available as sub commands for the upload command
    • validate <name> <repo spec> a given target specification is validated. It returns additional derived metadata for the given specification
    • put -c <creds> -a <artifacttype> -m <mediatype> -h <hint> <name> <repo spec> intended for the uploader support It reads the data from stdin and puts a resulting access spec as JSON on stdout

The library now provides a command line frame for a plugin implementation, which must implement a plugin and accessmethod interface.

The ocm CLI now provides information about configured plugins.

The OCM context can be configured to register the capabilities of detected plugins, which make the additional extensions available for the regular API usage.

The help command also reflects extensions provided by plugins, now.

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Release note:

@mandelsoft mandelsoft requested a review from jensh007 October 30, 2022 16:26
@mandelsoft mandelsoft force-pushed the plugins branch 3 times, most recently from 547dac0 to 2dfade5 Compare October 31, 2022 14:28
@mandelsoft mandelsoft marked this pull request as ready for review November 2, 2022 08:47
jensh007
jensh007 previously approved these changes Nov 2, 2022
Makefile Outdated
go build -ldflags "-s -w \
-X github.com/open-component-model/ocm/pkg/version.gitVersion=$(EFFECTIVE_VERSION) \
-X github.com/open-component-model/ocm/pkg/version.gitTreeState=$(GIT_TREE_STATE) \
-X github.com/open-component-model/ocm/pkg/version.gitCommit=$(COMMIT) \
-X github.com/open-component-model/ocm/pkg/version.buildDate=$(shell date --rfc-3339=seconds | sed 's/ /T/')" \
-o bin/helminstaller \
./cmds/helminstaller
go build -ldflags "-s -w \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor the whole build target to be less chaotic, for example:

NOW         := $(shell date --rfc-3339=seconds | sed 's/ /T/')
BUILD_FLAGS := "-s -w \
	-X github.com/open-component-model/ocm/pkg/version.gitVersion=$(EFFECTIVE_VERSION) \
	-X github.com/open-component-model/ocm/pkg/version.gitTreeState=$(GIT_TREE_STATE) \
	-X github.com/open-component-model/ocm/pkg/version.gitCommit=$(COMMIT) \
	-X github.com/open-component-model/ocm/pkg/version.buildDate=$(NOW)"

build: ${SOURCES}
	mkdir -p bin
	go build -ldflags $(BUILD_FLAGS) -o bin/ocm ./cmds/ocm
	go build -ldflags $(BUILD_FLAGS) -o bin/helminstaller ./cmds/helminstaller
	go build -ldflags $(BUILD_FLAGS) -o bin/demo ./cmds/demoplugin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

yitsushi
yitsushi previously approved these changes Nov 2, 2022
yitsushi
yitsushi previously approved these changes Nov 2, 2022
Alpha version

Using plugins it is possible now to provide additional access methods
by separate executables found in a ocm plugin directory.

The plugin executable must implement a set of commands:
- info <spec>
  The info command must return a JSON object describing
  the plugin and its capabilities.
  So far, it might only provide access methods. It is intended
  to extend this by downloader and uploader implementations.
- accessmethod
  all access relevant capabilities are available as sub commands
  for the accessmethod command
  - validate <spec>
    a given access specification is validated. It returns
    additional derived metadata for the given specification
    - a human readable info text
    - the consumer id required to determine optional credentials.
    - the media type, either derived from the spec or a constant.
    - a hint usable as reference name for local blobs to reconstruct
      a useful name for exploded imports.
  - get -c <creds> <spec>
    dump the provided content to stdout
  - put -c <creds> -m <mediatype> -h <hint> <access type>
    not yet used, intended for the uploader support
    It reads the data from stdin and puts a resulting access spec
    as JSON on stdout

The library now provides a command line frame for a plugin implementation,
which must implement a plugin and accessmethod interface.

The ocm CLI now provides information about configured plugins.

The OCM context can be configured to register the capabilities
of detected plugins, which make the addutional extensions
available for the regular API usage.
To speed up ocm context creation with plugins, the evaluation
of a plugin dir is put into a separate cache now.
Context creation then just reuses known plugin dir setup
to create a context binding without calling all the plugins.
@mandelsoft
Copy link
Contributor Author

Unfortunately the pflag string-to-string is not compatible with my StringMap option variant. I had to fix something after the rebase.

@mandelsoft mandelsoft requested a review from jensh007 November 3, 2022 10:38
@mandelsoft mandelsoft merged commit 48789ca into open-component-model:main Nov 3, 2022
@mandelsoft mandelsoft deleted the plugins branch November 3, 2022 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants