|
| 1 | +package config |
| 2 | + |
| 3 | +import ( |
| 4 | + "ocm.software/ocm/api/config" |
| 5 | + cfgcpi "ocm.software/ocm/api/config/cpi" |
| 6 | + "ocm.software/ocm/api/ocm/extensions/attrs/preferrelativeattr" |
| 7 | + "ocm.software/ocm/api/utils/runtime" |
| 8 | +) |
| 9 | + |
| 10 | +const ( |
| 11 | + ConfigType = "local.oci.uploader" + cfgcpi.OCM_CONFIG_TYPE_SUFFIX |
| 12 | + ConfigTypeV1 = ConfigType + runtime.VersionSeparator + "v1" |
| 13 | +) |
| 14 | + |
| 15 | +func init() { |
| 16 | + cfgcpi.RegisterConfigType(cfgcpi.NewConfigType[*Config](ConfigType, usage)) |
| 17 | + cfgcpi.RegisterConfigType(cfgcpi.NewConfigType[*Config](ConfigTypeV1)) |
| 18 | +} |
| 19 | + |
| 20 | +// Config describes a memory based config interface. |
| 21 | +type Config struct { |
| 22 | + runtime.ObjectVersionedType `json:",inline"` |
| 23 | + UploadOptions |
| 24 | +} |
| 25 | + |
| 26 | +// New creates a new memory ConfigSpec. |
| 27 | +func New() *Config { |
| 28 | + return &Config{ |
| 29 | + ObjectVersionedType: runtime.NewVersionedTypedObject(ConfigType), |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +func (a *Config) ApplyTo(ctx config.Context, target interface{}) error { |
| 34 | + t, ok := target.(*UploadOptions) |
| 35 | + if !ok { |
| 36 | + return config.ErrNoContext(ConfigType) |
| 37 | + } |
| 38 | + t.Repositories = append(t.Repositories, a.Repositories...) |
| 39 | + t.PreferRelativeAccess = a.PreferRelativeAccess |
| 40 | + return nil |
| 41 | +} |
| 42 | + |
| 43 | +const usage = ` |
| 44 | +The config type <code>` + ConfigType + `</code> can be used to set some |
| 45 | +configurations for the implicit OCI artifact upload for OCI based OCM repositories. |
| 46 | +
|
| 47 | +<pre> |
| 48 | + type: ` + ConfigType + ` |
| 49 | + preferRelativeAccess: true # use relative access methods for given target repositories. |
| 50 | + repositories: |
| 51 | + - localhost:5000 |
| 52 | +</pre> |
| 53 | +
|
| 54 | +If <code>preferRelativeAccess</code> is set to <code>true</code> the |
| 55 | +OCI uploader for OCI based OCM repositories does not use the |
| 56 | +OCI repository to create absolute OCI access methods |
| 57 | +if the target repository is in the <code>repositories</code> list. |
| 58 | +Instead, a relative <code>relativeOciReference</code> access method |
| 59 | +is created. |
| 60 | +If this list is empty, all uploads are handled this way. |
| 61 | +
|
| 62 | +If the global attribute <code>` + preferrelativeattr.ATTR_SHORT + `</code> |
| 63 | +is configured, it overrides the <code>preferRelativeAccess</code> setting. |
| 64 | +` |
0 commit comments