Skip to content

feat: add component references to CLI internals#86

Merged
jakobmoellerdev merged 2 commits into
open-component-model:mainfrom
jakobmoellerdev:component-references
May 5, 2025
Merged

feat: add component references to CLI internals#86
jakobmoellerdev merged 2 commits into
open-component-model:mainfrom
jakobmoellerdev:component-references

Conversation

@jakobmoellerdev

@jakobmoellerdev jakobmoellerdev commented Apr 29, 2025

Copy link
Copy Markdown
Member

What this PR does / why we need it

reintroduces the concept of universal component references:

// Ref represents the parsed structure of an OCM component reference.
// A component reference is a string that uniquely identifies a component in a repository.
//
// The format of a component reference is:
//
//	[<type>::]<repository>/[<valid-prefix>]/<component>[:<version>][@<digest>]
//
// For valid prefixes, see ValidPrefixes.
// For valid components, see ComponentRegex.
// For valid versions, see VersionRegex.
// For valid digests, see DigestRegex.
type Ref struct {
	// Type represents the repository type (e.g., "oci", "ctf")
	Type string

	// Repository is the location of the component repository
	Repository runtime.Typed

	// Prefix is an optional path element that helps structure components within a repository
	// It can only be one of ValidPrefixes.
	Prefix string

	// Component is the name of the component.
	// Validated as per ComponentRegex.
	Component string

	// Version is the semantic version of the component. It can be specified without Digest,
	// in which case it is a "soft" version pinning in that the content behind the version
	// can change without the specification becoming invalid.
	// Validated as per VersionRegex.
	Version string

	// Digest is an optional content-addressable identifier for a pinned component version (e.g., sha256:abcd...)
	// if present, it indicates a specific version of the component MUST be present with this digest.
	// Thus, the Digest is more authoritative than the Version.
	// Validates as per DigestRegex.
	Digest string
}

that can be parsed from input strings

// Parse parses an input string into a Ref.
// Accepted inputs are of the forms
//
//   - [ctf::][<file path>/[<DefaultPrefix>]/<component id>[:<version>][@<digest>]
//   - [oci::][<registry>/<repository>/[<DefaultPrefix>]/<component id>[:<version>][@<digest>]
//   - localhost[:<port>]/[<DefaultPrefix>]/<component id>[:<version>] - localhost special cases
//
// Not accepted cases that were valid in old OCM:
//
//   - [type::][<repositorySpecJSON>/[<DefaultPrefix>]/<component id>[:<version>] - arbitrary repository definitions
//   - <repositoryAlias>//[<DefaultPrefix>]/<component id>[:<version>] - repository aliases for the ocm configuration
//
// All non-supported special cases are currently under review of being accepted forms.
func Parse(input string) (*Ref, error) { ... }

This code roughly resembles
https://github.com/open-component-model/ocm/blob/2ea69c7ecca1e8be7e9d9f94dfdcac6090f1c69d/api/oci/ref_test.go

We need this in order to supply the CLI with a possibility for a positional arg that acts like the old OCM reference.

Which issue(s) this PR fixes

fix open-component-model/ocm-project#477

needed in order to prepare for get cv command

@jakobmoellerdev jakobmoellerdev requested a review from a team as a code owner April 29, 2025 16:40
@github-actions github-actions Bot added kind/feature new feature, enhancement, improvement, extension size/l Large labels Apr 29, 2025
@jakobmoellerdev jakobmoellerdev force-pushed the component-references branch 2 times, most recently from 361d53e to dfec335 Compare April 29, 2025 16:44
```
// Parse parses an input string into a Ref.
// Accepted inputs are of the forms
//
//   - [ctf::][<file path>/[<DefaultPrefix>]/<component id>[:<version>][@<digest>]
//   - [oci::][<registry>/<repository>/[<DefaultPrefix>]/<component id>[:<version>][@<digest>]
//   - localhost[:<port>]/[<DefaultPrefix>]/<component id>[:<version>] - localhost special cases
//
// Not accepted cases that were valid in old OCM:
//
//   - [type::][<repositorySpecJSON>/[<DefaultPrefix>]/<component id>[:<version>] - arbitrary repository definitions
//   - <repositoryAlias>//[<DefaultPrefix>]/<component id>[:<version>] - repository aliases for the ocm configuration
//
// All non-supported special cases are currently under review of being accepted forms.
//
// in a much smaller scope and size and will grow over time.
func Parse(input string) (*Ref, error) { ... }
```
This code roughly resembles
https://github.com/open-component-model/ocm/blob/2ea69c7ecca1e8be7e9d9f94dfdcac6090f1c69d/api/oci/ref_test.go
@jakobmoellerdev jakobmoellerdev changed the title feat: add component references feat: add component references to CLI internals Apr 29, 2025
frewilhelm
frewilhelm previously approved these changes May 2, 2025
Comment thread cli/internal/reference/compref/compref.go
@jakobmoellerdev jakobmoellerdev merged commit 2139720 into open-component-model:main May 5, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature new feature, enhancement, improvement, extension size/l Large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Component Reference Strings

2 participants