Skip to content

Commit c99d4c0

Browse files
committed
adr
1 parent 0b5af5c commit c99d4c0

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

api/ocm/compdesc/componentdescriptor.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ func (o *SourceMeta) SetReferenceHints(hints []refhints.ReferenceHint) {
461461
o.ReferenceHints = refhints.ReferenceHints(hints).Copy()
462462
}
463463

464+
// AddReferenceHints sets the reference hints specified together with the metadata.
465+
func (o *SourceMeta) AddReferenceHints(hints ...refhints.ReferenceHint) {
466+
o.ReferenceHints.Add(hints...)
467+
}
468+
464469
// SetType sets the type of the object.
465470
func (o *SourceMeta) SetType(ttype string) {
466471
o.Type = ttype
@@ -692,6 +697,11 @@ func (o *ResourceMeta) SetReferenceHints(hints []refhints.ReferenceHint) {
692697
o.ReferenceHints = refhints.ReferenceHints(hints).Copy()
693698
}
694699

700+
// AddReferenceHints sets the reference hints specified together with the metadata.
701+
func (o *ResourceMeta) AddReferenceHints(hints ...refhints.ReferenceHint) {
702+
o.ReferenceHints.Add(hints...)
703+
}
704+
695705
// SetType sets the type of the object.
696706
func (o *ResourceMeta) SetType(ttype string) {
697707
o.Type = ttype

api/ocm/refhints/hints.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ func NewHints(f func(ref string, implicit ...bool) ReferenceHint, ref string, im
4646
return ReferenceHints{f(ref, implicit...)}
4747
}
4848

49+
func (h *ReferenceHints) Add(hints ...ReferenceHint) {
50+
*h = sliceutils.AppendUniqueFunc(*h, runtime.MatchType[ReferenceHint], hints...)
51+
}
52+
4953
func (h ReferenceHints) Copy() ReferenceHints {
5054
var result ReferenceHints
5155

docs/adrs/0003-referene-hints.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Architectural Decision Record: Rework of Referebce Hints
2+
3+
### Meaning of Reference Hints
4+
5+
During the transport of software artifacts referenced from external artifact repositories like
6+
OCI registries, they might be stored as blobs along with the component version (access method
7+
`localBlob`. If those component versions are transported again into a repository landscape they
8+
might be uploaded again to external repositories.
9+
10+
To provide useful identities for storing those artifacts hints in external repositories, again,
11+
the original identity of the external artifact must be stored along with the local blob.
12+
13+
### Current Solution
14+
15+
The access method origibally used to refernce the exterbal artfact provides a reference hint,
16+
which can later be used by the blob uploaders to reconstruct a useful identity.
17+
Therefore, the `localBlob` access method is able to keep track of this hint value.
18+
The hint is just a string, which needs to be intepreted by the uploader.
19+
20+
### Problems with Current Solution
21+
22+
The assumprion behind the current solution is that the uploader will always upload the
23+
artifactinto a similar repository, again. Therefore, there would be a one-to-one relation
24+
between access method and uploader.
25+
26+
Unfortunately this is not true in all cases:
27+
- There are access methods now (like`wget`), which are able to handle any kind of artifact blob
28+
with different natural repositoty types and identity schemes.
29+
- Therefore,
30+
- it can neither provide an implicit reference hint anymore
31+
- nor there is a one-to-one relation to a typed uploader anymore.
32+
- artifacts might be uploadable to different repository types using different
33+
identity schemes.
34+
35+
This problem is partly covered by allowing to specify a hint along with those access methods
36+
similar to the `localBlob` access method. But this can only be a workarround, because
37+
- the hint is not typed and potential target repositories might use diufferent identity schemes
38+
- it is possible to store a single hint, only.
39+
40+
### Proposed Solution
41+
42+
Hints have to be typed, to allow uploaders to know what identites are provided and how the
43+
hint string has to be interpreted. Additionally, it must be possible to store
44+
mulltiple hints for an artifact.
45+
46+
To be compatible a serialization format is defined for a list of type hints, which maps such
47+
a list to a single string.
48+
49+
The library provides a new type `ReferenceHint = map[string]string`, which provides access to
50+
a formal hint, by providing access to a set of string attributes. There are three predefined
51+
attributes:
52+
- `type` the formal type of the hint (may be empty to cover old component versions)
53+
The types are defined like the resource types. The following types are defined for now:
54+
- `oci`: OCI identity given by the attribute `reference` with the cirrently used format
55+
- `maven`: Maven identity (GAV) given by the attribute `reference` with the currently used format
56+
- `npm`: Node package identity given by the attribute `reference` with the currently used
57+
format
58+
- `reference`: the standard attribute to hold a string representation for the identity.
59+
- `implicit`: Value `true` indicated an implicit hint (as used today) provided by an accessmethods.
60+
61+
New Hint types my use other attributes.
62+
63+
An access method can provide (and store) implicit hints as before. THose hints are indicated
64+
to be implicit. When composing an access method it is only allowed to store implicit hints.
65+
This is completely compatible to the current solution.
66+
67+
Additionally, multiplehints can be stored abd delivered.
68+
69+
To support any kind of hint for any scenario, the artifact metadata (resources and sources)
70+
is extended to store explicit hints, which will be part of the normalized form.
71+
This is done by an additional attribute `referenceHints`. It is a list of string maps
72+
holding the hint attributes (including the hint type).
73+
74+
Uploaders are called with the aggrgation of explicit (from metadata) and implicit (from
75+
access methods) hints. Hereby, the explicit hints have precedence.
76+
77+
If an uploader creates a local access specification, only implicit hints may be stored, here.
78+
79+
There is a new composition option (`--refhint`) now for composing resources
80+
and sources for the CLI. It accepts an attribute setting. Multiple such options starting with the `type`attribute are used to compose a single hint.
81+
82+
### Hint Serialization Format
83+
84+
In general a hint is serialized to the following string
85+
<center>
86+
[&lt;*type*>`::]`&lt;*attribute*>`=`&lt;*value*>{`,`&lt;*attribute*>`=`&lt;*value*>}
87+
</center>
88+
89+
The type is not serilaized as attribute. The `implicit` attribute is never serialized is the string is stored in an access specification.
90+
If no type is known the type part is omiited.
91+
92+
A list of hints is serialized to
93+
94+
<center>
95+
&lt;*hint*>{`;`&lt;*hint*>}
96+
</center>
97+
98+
*Attributes* names consist of alpha numeric chaŕacters, only.
99+
If a *value*may not cotain a `::`. If it contains a `;`, `,` or `"`
100+
character it must be given in double quotes.
101+
In the double quote form any `"` or `\` character has to be escaped by
102+
a preceding `\` character.
103+
104+
To be as compatible as possible, a single attribute hint with the attribute
105+
`reference` is serialized as naked value (as before) if there are no special
106+
characters enforcing a quoted form.
107+
108+
### Incompatible Changes:
109+
110+
#### Componwnt Version Representation
111+
112+
- The new library creates always typed hints for new elements. Old hints are
113+
left as they are. This means, that old versions of the OCM tooling
114+
cannot work correctly with component versions with persisted hints in
115+
access specifications
116+
- If explicit hints are created, they are not observed by old tool versions.
117+
Those component versions cannot be verified by an older tool version.
118+
119+
#### OCM Library
120+
121+
- The `SetResourceBlob`and `SetSourceBlob` API method no accepts
122+
a hint array instead of a string-based hint.
123+
124+
- Uploaders provided by a plugin now get a serialized hint list
125+
instead of a simple untyped reference format.
126+
-
127+
- There are new options for creating resource(source access objects.
128+
129+
130+
131+

0 commit comments

Comments
 (0)