Skip to content

Commit 3a57106

Browse files
authored
chore(deps): upgrade cli to central config (#463)
<!-- markdownlint-disable MD041 --> #### What this PR does / why we need it upgrade follow up 3 for #455 #### Which issue(s) this PR fixes <!-- Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. --> --------- Signed-off-by: Fabian Burth <fabian.burth@sap.com>
1 parent 7b5e3ab commit 3a57106

16 files changed

Lines changed: 106 additions & 106 deletions

File tree

cli/cmd/configuration/ocm_config.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/spf13/cobra"
1111

12-
v1 "ocm.software/open-component-model/bindings/go/configuration/v1"
12+
genericv1 "ocm.software/open-component-model/bindings/go/configuration/generic/v1/spec"
1313
)
1414

1515
// OCM Configuration file and directory constants
@@ -41,15 +41,15 @@ By default (without specifying custom locations with this flag), the file will b
4141
Using the option, this configuration file be used instead of the lookup above.`)
4242
}
4343

44-
func GetFlattenedOCMConfigForCommand(cmd *cobra.Command) (*v1.Config, error) {
44+
func GetFlattenedOCMConfigForCommand(cmd *cobra.Command) (*genericv1.Config, error) {
4545
cfg, err := GetOCMConfigForCommand(cmd)
4646
if err != nil {
4747
return nil, err
4848
}
49-
return v1.FlatMap(cfg), nil
49+
return genericv1.FlatMap(cfg), nil
5050
}
5151

52-
func GetOCMConfigForCommand(cmd *cobra.Command) (*v1.Config, error) {
52+
func GetOCMConfigForCommand(cmd *cobra.Command) (*genericv1.Config, error) {
5353
path, _ := cmd.Flags().GetString(OCMConfigCommandArgument)
5454
if path != "" {
5555
return GetConfigFromPath(path)
@@ -67,13 +67,13 @@ func GetOCMConfigForCommand(cmd *cobra.Command) (*v1.Config, error) {
6767
// Returns:
6868
// - *v1.Config: The parsed configuration file.
6969
// - error: An error if no valid configuration file is found or if decoding fails.
70-
func GetOCMConfig(additional ...string) (*v1.Config, error) {
70+
func GetOCMConfig(additional ...string) (*genericv1.Config, error) {
7171
paths, err := GetOCMConfigPaths()
7272
paths = append(paths, additional...)
7373
if err != nil && len(additional) == 0 {
7474
return nil, err
7575
}
76-
cfgs := make([]*v1.Config, 0, len(paths))
76+
cfgs := make([]*genericv1.Config, 0, len(paths))
7777
for _, path := range paths {
7878
cfg, err := GetConfigFromPath(path)
7979
if err != nil {
@@ -86,7 +86,7 @@ func GetOCMConfig(additional ...string) (*v1.Config, error) {
8686
slog.Debug("ocm config was loaded successfully", slog.String("path", path))
8787
cfgs = append(cfgs, cfg)
8888
}
89-
return v1.FlatMap(cfgs...), nil
89+
return genericv1.FlatMap(cfgs...), nil
9090
}
9191

9292
// GetConfigFromPath reads and decodes the YAML configuration file from the specified path.
@@ -97,7 +97,7 @@ func GetOCMConfig(additional ...string) (*v1.Config, error) {
9797
// Returns:
9898
// - *v1.Config: The decoded configuration struct.
9999
// - error: An error if the file cannot be opened or decoded.
100-
func GetConfigFromPath(path string) (_ *v1.Config, err error) {
100+
func GetConfigFromPath(path string) (_ *genericv1.Config, err error) {
101101
file, err := os.Open(path)
102102
if err != nil {
103103
return nil, err
@@ -106,8 +106,8 @@ func GetConfigFromPath(path string) (_ *v1.Config, err error) {
106106
err = errors.Join(err, file.Close())
107107
}()
108108

109-
var instance v1.Config
110-
if err := v1.Scheme.Decode(file, &instance); err != nil {
109+
var instance genericv1.Config
110+
if err := genericv1.Scheme.Decode(file, &instance); err != nil {
111111
return nil, err
112112
}
113113
return &instance, nil

cli/cmd/configuration/ocm_config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/stretchr/testify/assert"
77

8-
v1 "ocm.software/open-component-model/bindings/go/configuration/v1"
8+
genericv1 "ocm.software/open-component-model/bindings/go/configuration/generic/v1/spec"
99
"ocm.software/open-component-model/bindings/go/runtime"
1010
)
1111

@@ -16,15 +16,15 @@ func TestGetFlattenedGetConfigFromPath(t *testing.T) {
1616
tests := []struct {
1717
name string
1818
args args
19-
want *v1.Config
19+
want *genericv1.Config
2020
wantErr bool
2121
}{
2222
{
2323
name: "parse config from file",
2424
args: args{
2525
path: "testdata/.ocmconfig-1",
2626
},
27-
want: &v1.Config{
27+
want: &genericv1.Config{
2828
Type: runtime.Type{
2929
Version: "v1",
3030
Name: "generic.config.ocm.software",

cli/cmd/setup_filesystem_config.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66

77
"github.com/spf13/cobra"
88

9-
"ocm.software/open-component-model/bindings/go/configuration/filesystem/v1alpha1"
10-
v1 "ocm.software/open-component-model/bindings/go/configuration/v1"
9+
filesystemv1alpha1 "ocm.software/open-component-model/bindings/go/configuration/filesystem/v1alpha1/spec"
10+
genericv1 "ocm.software/open-component-model/bindings/go/configuration/generic/v1/spec"
1111
"ocm.software/open-component-model/bindings/go/runtime"
1212
ocmctx "ocm.software/open-component-model/cli/internal/context"
1313
)
@@ -27,15 +27,15 @@ func setupFilesystemConfig(cmd *cobra.Command) {
2727

2828
ocmCtx := ocmctx.FromContext(cmd.Context())
2929
cfg := ocmCtx.Configuration()
30-
var fsCfg *v1alpha1.Config
30+
var fsCfg *filesystemv1alpha1.Config
3131
if cfg == nil {
3232
slog.WarnContext(cmd.Context(), "could not get configuration to initialize filesystem config")
33-
fsCfg = &v1alpha1.Config{}
33+
fsCfg = &filesystemv1alpha1.Config{}
3434
} else {
35-
fsCfg, err = v1alpha1.LookupConfig(cfg)
35+
fsCfg, err = filesystemv1alpha1.LookupConfig(cfg)
3636
if err != nil {
3737
slog.DebugContext(cmd.Context(), "could not get filesystem configuration", slog.String("error", err.Error()))
38-
fsCfg = &v1alpha1.Config{}
38+
fsCfg = &filesystemv1alpha1.Config{}
3939
}
4040
}
4141

@@ -62,17 +62,17 @@ func setupFilesystemConfig(cmd *cobra.Command) {
6262

6363
// hasFilesystemConfig checks if the central configuration already contains filesystem configuration
6464
// It uses the Config Filter function to handle versioned configurations properly
65-
func hasFilesystemConfig(cfg *v1.Config) bool {
65+
func hasFilesystemConfig(cfg *genericv1.Config) bool {
6666
if cfg == nil {
6767
return false
6868
}
6969

7070
// Use the Config Filter function to find filesystem configurations
7171
// This handles both versioned and unversioned configurations
72-
filtered, err := v1.Filter(cfg, &v1.FilterOptions{
72+
filtered, err := genericv1.Filter(cfg, &genericv1.FilterOptions{
7373
ConfigTypes: []runtime.Type{
74-
runtime.NewVersionedType(v1alpha1.ConfigType, v1alpha1.Version),
75-
runtime.NewUnversionedType(v1alpha1.ConfigType),
74+
runtime.NewVersionedType(filesystemv1alpha1.ConfigType, filesystemv1alpha1.Version),
75+
runtime.NewUnversionedType(filesystemv1alpha1.ConfigType),
7676
},
7777
})
7878
if err != nil {
@@ -83,15 +83,15 @@ func hasFilesystemConfig(cfg *v1.Config) bool {
8383
}
8484

8585
// addFilesystemConfigToCentralConfig adds the filesystem configuration to the central configuration
86-
func addFilesystemConfigToCentralConfig(cmd *cobra.Command, fsCfg *v1alpha1.Config) error {
86+
func addFilesystemConfigToCentralConfig(cmd *cobra.Command, fsCfg *filesystemv1alpha1.Config) error {
8787
ocmCtx := ocmctx.FromContext(cmd.Context())
8888
cfg := ocmCtx.Configuration()
8989
if cfg == nil {
9090
return fmt.Errorf("no central configuration available")
9191
}
9292

9393
raw := &runtime.Raw{}
94-
if err := v1.Scheme.Convert(fsCfg, raw); err != nil {
94+
if err := genericv1.Scheme.Convert(fsCfg, raw); err != nil {
9595
return fmt.Errorf("failed to convert filesystem config to raw: %w", err)
9696
}
9797
cfg.Configurations = append(cfg.Configurations, raw)

cli/cmd/setup_test.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ import (
1010
"github.com/spf13/cobra"
1111
"github.com/stretchr/testify/require"
1212

13-
"ocm.software/open-component-model/bindings/go/configuration/filesystem/v1alpha1"
14-
"ocm.software/open-component-model/bindings/go/configuration/v1"
13+
filesystemv1alpha1 "ocm.software/open-component-model/bindings/go/configuration/filesystem/v1alpha1/spec"
14+
genericv1 "ocm.software/open-component-model/bindings/go/configuration/generic/v1/spec"
1515
"ocm.software/open-component-model/bindings/go/runtime"
1616
ocmctx "ocm.software/open-component-model/cli/internal/context"
1717
)
1818

1919
func init() {
20-
v1.Scheme.MustRegisterWithAlias(&v1alpha1.Config{}, runtime.NewVersionedType(v1alpha1.ConfigType, v1alpha1.Version))
20+
genericv1.Scheme.MustRegisterWithAlias(&filesystemv1alpha1.Config{}, runtime.NewVersionedType(filesystemv1alpha1.ConfigType, filesystemv1alpha1.Version))
2121
}
2222

2323
// createConfigWithFilesystemConfig creates a v1.Config with filesystem configuration from JSON
24-
func createConfigWithFilesystemConfig(tempFolder string) *v1.Config {
24+
func createConfigWithFilesystemConfig(tempFolder string) *genericv1.Config {
2525
configJSON := `{
2626
"configurations": [
2727
{
@@ -31,7 +31,7 @@ func createConfigWithFilesystemConfig(tempFolder string) *v1.Config {
3131
]
3232
}`
3333

34-
config := &v1.Config{}
34+
config := &genericv1.Config{}
3535
if err := json.Unmarshal([]byte(configJSON), config); err != nil {
3636
panic(err)
3737
}
@@ -42,7 +42,7 @@ func TestSetupFilesystemConfig(t *testing.T) {
4242
tests := []struct {
4343
name string
4444
cliFlag string
45-
existingConfig *v1.Config
45+
existingConfig *genericv1.Config
4646
expectedTempFolder string
4747
expectedConfigMerge bool
4848
}{
@@ -56,7 +56,7 @@ func TestSetupFilesystemConfig(t *testing.T) {
5656
{
5757
name: "CLI flag with empty central config",
5858
cliFlag: "/tmp/custom",
59-
existingConfig: &v1.Config{},
59+
existingConfig: &genericv1.Config{},
6060
expectedTempFolder: "/tmp/custom",
6161
expectedConfigMerge: false, // Config merge fails due to scheme registration issue
6262
},
@@ -77,7 +77,7 @@ func TestSetupFilesystemConfig(t *testing.T) {
7777
{
7878
name: "No CLI flag and no existing config",
7979
cliFlag: "",
80-
existingConfig: &v1.Config{},
80+
existingConfig: &genericv1.Config{},
8181
expectedTempFolder: os.TempDir(), // filesystem config defaults to os.TempDir()
8282
expectedConfigMerge: false,
8383
},
@@ -130,10 +130,10 @@ func TestSetupFilesystemConfig(t *testing.T) {
130130
// Verify the filesystem config was added correctly
131131
found := false
132132
for _, cfg := range centralCfg.Configurations {
133-
if cfg.Type.Name == v1alpha1.ConfigType {
133+
if cfg.Type.Name == filesystemv1alpha1.ConfigType {
134134
found = true
135-
fsConfig := &v1alpha1.Config{}
136-
err := v1.Scheme.Convert(cfg, fsConfig)
135+
fsConfig := &filesystemv1alpha1.Config{}
136+
err := genericv1.Scheme.Convert(cfg, fsConfig)
137137
r.NoError(err, "should convert to filesystem config")
138138
r.Equal(tt.expectedTempFolder, fsConfig.TempFolder, "merged config should have correct temp folder")
139139
break
@@ -148,7 +148,7 @@ func TestSetupFilesystemConfig(t *testing.T) {
148148
func TestHasFilesystemConfig(t *testing.T) {
149149
tests := []struct {
150150
name string
151-
config *v1.Config
151+
config *genericv1.Config
152152
expected bool
153153
}{
154154
{
@@ -158,7 +158,7 @@ func TestHasFilesystemConfig(t *testing.T) {
158158
},
159159
{
160160
name: "empty config",
161-
config: &v1.Config{},
161+
config: &genericv1.Config{},
162162
expected: false,
163163
},
164164
{
@@ -168,15 +168,15 @@ func TestHasFilesystemConfig(t *testing.T) {
168168
},
169169
{
170170
name: "config with other types",
171-
config: func() *v1.Config {
171+
config: func() *genericv1.Config {
172172
configJSON := `{
173173
"configurations": [
174174
{
175175
"type": "other.type/v1"
176176
}
177177
]
178178
}`
179-
config := &v1.Config{}
179+
config := &genericv1.Config{}
180180
if err := json.Unmarshal([]byte(configJSON), config); err != nil {
181181
panic(err)
182182
}
@@ -186,7 +186,7 @@ func TestHasFilesystemConfig(t *testing.T) {
186186
},
187187
{
188188
name: "config with mixed types including filesystem",
189-
config: func() *v1.Config {
189+
config: func() *genericv1.Config {
190190
configJSON := `{
191191
"configurations": [
192192
{
@@ -198,7 +198,7 @@ func TestHasFilesystemConfig(t *testing.T) {
198198
}
199199
]
200200
}`
201-
config := &v1.Config{}
201+
config := &genericv1.Config{}
202202
if err := json.Unmarshal([]byte(configJSON), config); err != nil {
203203
panic(err)
204204
}
@@ -208,7 +208,7 @@ func TestHasFilesystemConfig(t *testing.T) {
208208
},
209209
{
210210
name: "config with unversioned filesystem config",
211-
config: func() *v1.Config {
211+
config: func() *genericv1.Config {
212212
configJSON := `{
213213
"configurations": [
214214
{
@@ -217,7 +217,7 @@ func TestHasFilesystemConfig(t *testing.T) {
217217
}
218218
]
219219
}`
220-
config := &v1.Config{}
220+
config := &genericv1.Config{}
221221
if err := json.Unmarshal([]byte(configJSON), config); err != nil {
222222
panic(err)
223223
}
@@ -238,37 +238,37 @@ func TestHasFilesystemConfig(t *testing.T) {
238238
func TestAddFilesystemConfigToCentralConfig(t *testing.T) {
239239
tests := []struct {
240240
name string
241-
initialConfig *v1.Config
242-
fsCfg *v1alpha1.Config
241+
initialConfig *genericv1.Config
242+
fsCfg *filesystemv1alpha1.Config
243243
expectedError bool
244244
expectedCount int
245245
}{
246246
{
247247
name: "add to empty config",
248-
initialConfig: &v1.Config{},
249-
fsCfg: &v1alpha1.Config{
248+
initialConfig: &genericv1.Config{},
249+
fsCfg: &filesystemv1alpha1.Config{
250250
TempFolder: "/tmp/test",
251251
},
252252
expectedError: false,
253253
expectedCount: 1,
254254
},
255255
{
256256
name: "add to existing config",
257-
initialConfig: func() *v1.Config {
257+
initialConfig: func() *genericv1.Config {
258258
configJSON := `{
259259
"configurations": [
260260
{
261261
"type": "other.type/v1"
262262
}
263263
]
264264
}`
265-
config := &v1.Config{}
265+
config := &genericv1.Config{}
266266
if err := json.Unmarshal([]byte(configJSON), config); err != nil {
267267
panic(err)
268268
}
269269
return config
270270
}(),
271-
fsCfg: &v1alpha1.Config{
271+
fsCfg: &filesystemv1alpha1.Config{
272272
TempFolder: "/tmp/test",
273273
},
274274
expectedError: false,
@@ -277,7 +277,7 @@ func TestAddFilesystemConfigToCentralConfig(t *testing.T) {
277277
{
278278
name: "nil central config",
279279
initialConfig: nil,
280-
fsCfg: &v1alpha1.Config{
280+
fsCfg: &filesystemv1alpha1.Config{
281281
TempFolder: "/tmp/test",
282282
},
283283
expectedError: true,
@@ -319,10 +319,10 @@ func TestAddFilesystemConfigToCentralConfig(t *testing.T) {
319319
// Verify the filesystem config was added correctly
320320
found := false
321321
for _, cfg := range centralCfg.Configurations {
322-
if cfg.Type.Name == v1alpha1.ConfigType {
322+
if cfg.Type.Name == filesystemv1alpha1.ConfigType {
323323
found = true
324-
fsConfig := &v1alpha1.Config{}
325-
err := v1.Scheme.Convert(cfg, fsConfig)
324+
fsConfig := &filesystemv1alpha1.Config{}
325+
err := genericv1.Scheme.Convert(cfg, fsConfig)
326326
r.NoError(err, "should convert to filesystem config")
327327
r.Equal(tt.fsCfg.TempFolder, fsConfig.TempFolder, "should have correct temp folder")
328328
break

0 commit comments

Comments
 (0)