Skip to content

Commit 0dd21c3

Browse files
authored
Merge pull request #977 from meshery/fix/standardize-core-import
Standardize schemas/models/core import to bare core alias
2 parents 384145f + f62a0cf commit 0dd21c3

4 files changed

Lines changed: 28 additions & 28 deletions

File tree

files/error.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99

1010
"github.com/meshery/meshkit/errors"
11-
coreV1 "github.com/meshery/schemas/models/core"
11+
"github.com/meshery/schemas/models/core"
1212
)
1313

1414
var (
@@ -175,7 +175,7 @@ func ErrFailedToExtractArchive(fileName string, err error) error {
175175
return errors.New(ErrFailedToExtractTarCode, errors.Critical, sdescription, ldescription, probableCause, remedy)
176176
}
177177

178-
func ErrFailedToIdentifyFile(fileName string, fileExt string, identificationTrace map[coreV1.IaCFileTypes]error) error {
178+
func ErrFailedToIdentifyFile(fileName string, fileExt string, identificationTrace map[core.IaCFileTypes]error) error {
179179

180180
validTypes := slices.Collect(maps.Keys(identificationTrace))
181181

files/identification.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/meshery/meshkit/utils"
1717
"github.com/meshery/meshkit/utils/kubernetes/kompose"
1818
"github.com/meshery/meshkit/utils/walker"
19-
coreV1 "github.com/meshery/schemas/models/core"
19+
"github.com/meshery/schemas/models/core"
2020
"github.com/meshery/schemas/models/v1beta1"
2121
"github.com/meshery/schemas/models/v1beta1/pattern"
2222

@@ -38,7 +38,7 @@ import (
3838
)
3939

4040
type IdentifiedFile struct {
41-
Type coreV1.IaCFileTypes
41+
Type core.IaCFileTypes
4242

4343
// pattern.PatternFile (meshery-design),
4444
// []runtime.Object (k8s manifest) ,
@@ -53,52 +53,52 @@ func IdentifyFile(sanitizedFile SanitizedFile) (IdentifiedFile, error) {
5353
var parsed interface{}
5454

5555
// Map to store identification errors for each file type
56-
identificationErrorsTrace := map[coreV1.IaCFileTypes]error{}
56+
identificationErrorsTrace := map[core.IaCFileTypes]error{}
5757

5858
// Attempt to parse the file as a Meshery design
5959
if parsed, err = ParseFileAsMesheryDesign(sanitizedFile); err == nil {
6060
return IdentifiedFile{
61-
Type: coreV1.MesheryDesign,
61+
Type: core.MesheryDesign,
6262
ParsedFile: parsed,
6363
}, nil
6464
}
65-
identificationErrorsTrace[coreV1.MesheryDesign] = err
65+
identificationErrorsTrace[core.MesheryDesign] = err
6666

6767
// Attempt to parse the file as a Kubernetes manifest
6868
if parsed, err = ParseFileAsKubernetesManifest(sanitizedFile); err == nil {
6969
return IdentifiedFile{
70-
Type: coreV1.K8sManifest,
70+
Type: core.K8sManifest,
7171
ParsedFile: parsed,
7272
}, nil
7373
}
74-
identificationErrorsTrace[coreV1.K8sManifest] = err
74+
identificationErrorsTrace[core.K8sManifest] = err
7575

7676
// Attempt to parse the file as a Helm chart
7777
if parsed, err = ParseFileAsHelmChart(sanitizedFile); err == nil {
7878
return IdentifiedFile{
79-
Type: coreV1.HelmChart,
79+
Type: core.HelmChart,
8080
ParsedFile: parsed,
8181
}, nil
8282
}
83-
identificationErrorsTrace[coreV1.HelmChart] = err
83+
identificationErrorsTrace[core.HelmChart] = err
8484

8585
// Attempt to parse the file as a Docker Compose file
8686
if parsed, err = ParseFileAsDockerCompose(sanitizedFile); err == nil {
8787
return IdentifiedFile{
88-
Type: coreV1.DockerCompose,
88+
Type: core.DockerCompose,
8989
ParsedFile: parsed,
9090
}, nil
9191
}
92-
identificationErrorsTrace[coreV1.DockerCompose] = err
92+
identificationErrorsTrace[core.DockerCompose] = err
9393

9494
// Attempt to parse the file as a Kustomization file
9595
if parsed, err = ParseFileAsKustomization(sanitizedFile); err == nil {
9696
return IdentifiedFile{
97-
Type: coreV1.K8sKustomize,
97+
Type: core.K8sKustomize,
9898
ParsedFile: parsed,
9999
}, nil
100100
}
101-
identificationErrorsTrace[coreV1.K8sKustomize] = err
101+
identificationErrorsTrace[core.K8sKustomize] = err
102102

103103
// If no file type matched, return a detailed error with the identification trace
104104
return IdentifiedFile{}, ErrFailedToIdentifyFile(sanitizedFile.FileName, sanitizedFile.FileExt, identificationErrorsTrace)

files/tests/sanitization_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"archive/zip"
1111
"github.com/meshery/meshkit/errors"
1212
"github.com/meshery/meshkit/files"
13-
coreV1 "github.com/meshery/schemas/models/core"
13+
"github.com/meshery/schemas/models/core"
1414
"github.com/stretchr/testify/assert"
1515
)
1616

@@ -22,7 +22,7 @@ func TestSanitizeFile(t *testing.T) {
2222
expectError bool
2323
expectedErrCode string
2424
expectedContent map[string]interface{}
25-
expectedType coreV1.IaCFileTypes
25+
expectedType core.IaCFileTypes
2626
}{
2727
{
2828
name: "Valid JSON",
@@ -77,59 +77,59 @@ func TestSanitizeFile(t *testing.T) {
7777
name: "Can Identify Design",
7878
filePath: "./samples/valid_design.yml",
7979
expectedExt: ".yml",
80-
expectedType: coreV1.MesheryDesign,
80+
expectedType: core.MesheryDesign,
8181
},
8282

8383
{
8484
name: "Can Identify Designs packaged as OCI images",
8585
filePath: "./samples/valid-design-oci.tar",
8686
expectedExt: ".tar",
87-
expectedType: coreV1.MesheryDesign,
87+
expectedType: core.MesheryDesign,
8888
},
8989
{
9090
name: "Can Identify Kubernetes Manifest",
9191
filePath: "./samples/valid_manifest.yml",
9292
expectedExt: ".yml",
93-
expectedType: coreV1.K8sManifest,
93+
expectedType: core.K8sManifest,
9494
},
9595

9696
{
9797
name: "Can Identify Kubernetes Manifest With Crds",
9898
filePath: "./samples/manifest-with-crds.yml",
9999
expectedExt: ".yml",
100-
expectedType: coreV1.K8sManifest,
100+
expectedType: core.K8sManifest,
101101
},
102102

103103
{
104104
name: "Can Identify HelmChart",
105105
filePath: "./samples/valid-helm.tgz",
106106
expectedExt: ".tgz",
107-
expectedType: coreV1.HelmChart,
107+
expectedType: core.HelmChart,
108108
},
109109
{
110110
name: "Can Identify Kustomize archive (tar.gz)",
111111
filePath: "./samples/wordpress-kustomize.tar.gz",
112112
expectedExt: ".gz",
113-
expectedType: coreV1.K8sKustomize,
113+
expectedType: core.K8sKustomize,
114114
},
115115
{
116116
name: "Can Identify Kustomize archive (zip)",
117117
filePath: "./samples/wordpress-kustomize.zip",
118118
expectedExt: ".zip",
119-
expectedType: coreV1.K8sKustomize,
119+
expectedType: core.K8sKustomize,
120120
},
121121
{
122122
name: "Can Identify Docker Compose",
123123
filePath: "./samples/valid-docker-compose.yml",
124124
expectedExt: ".yml",
125-
expectedType: coreV1.DockerCompose,
125+
expectedType: core.DockerCompose,
126126
},
127127

128128
{
129129
name: "Can Identify Docker Compose v2",
130130
filePath: "./samples/valid-compose-2.yml",
131131
expectedExt: ".yml",
132-
expectedType: coreV1.DockerCompose,
132+
expectedType: core.DockerCompose,
133133
},
134134

135135
// {

registry/component.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/meshery/meshkit/utils/csv"
1616
"github.com/meshery/meshkit/utils/manifests"
1717
"github.com/meshery/schemas"
18-
corev1alpha1 "github.com/meshery/schemas/models/core"
18+
"github.com/meshery/schemas/models/core"
1919
schmeaVersion "github.com/meshery/schemas/models/v1beta1"
2020
"github.com/meshery/schemas/models/v1beta1/capability"
2121
"github.com/meshery/schemas/models/v1beta1/component"
@@ -181,7 +181,7 @@ func (c *ComponentCSV) UpdateCompDefinition(compDef *component.ComponentDefiniti
181181
for _, key := range compStyleValues {
182182
if c.Shape != "" {
183183
shape := c.Shape
184-
compDefStyles.Shape = (*corev1alpha1.Shape)(&shape)
184+
compDefStyles.Shape = (*core.Shape)(&shape)
185185
}
186186
if c.PrimaryColor != "" {
187187

0 commit comments

Comments
 (0)