Skip to content

Commit 9c4653c

Browse files
authored
Merge pull request #728 from mrmerlin320/iacfileType
use iacFileType from core schema
2 parents 0bf035a + e18584a commit 9c4653c

File tree

5 files changed

+47
-46
lines changed

5 files changed

+47
-46
lines changed

files/error.go

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

1010
"github.com/layer5io/meshkit/errors"
11+
coreV1 "github.com/meshery/schemas/models/v1alpha1/core"
1112
)
1213

1314
var (
@@ -173,7 +174,7 @@ func ErrFailedToExtractArchive(fileName string, err error) error {
173174
return errors.New(ErrFailedToExtractTarCode, errors.Critical, sdescription, ldescription, probableCause, remedy)
174175
}
175176

176-
func ErrFailedToIdentifyFile(fileName string, fileExt string, identificationTrace map[string]error) error {
177+
func ErrFailedToIdentifyFile(fileName string, fileExt string, identificationTrace map[coreV1.IaCFileTypes]error) error {
177178

178179
validTypes := slices.Collect(maps.Keys(identificationTrace))
179180

files/identification.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/layer5io/meshkit/utils"
1515
"github.com/layer5io/meshkit/utils/kubernetes/kompose"
1616
"github.com/layer5io/meshkit/utils/walker"
17-
"github.com/meshery/schemas/models/core"
17+
coreV1 "github.com/meshery/schemas/models/v1alpha1/core"
1818
"github.com/meshery/schemas/models/v1beta1"
1919
"github.com/meshery/schemas/models/v1beta1/pattern"
2020

@@ -36,7 +36,7 @@ import (
3636
)
3737

3838
type IdentifiedFile struct {
39-
Type string
39+
Type coreV1.IaCFileTypes
4040

4141
// pattern.PatternFile (meshery-design),
4242
// []runtime.Object (k8s manifest) ,
@@ -51,52 +51,52 @@ func IdentifyFile(sanitizedFile SanitizedFile) (IdentifiedFile, error) {
5151
var parsed interface{}
5252

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

5656
// Attempt to parse the file as a Meshery design
5757
if parsed, err = ParseFileAsMesheryDesign(sanitizedFile); err == nil {
5858
return IdentifiedFile{
59-
Type: core.IacFileTypes.MESHERY_DESIGN,
59+
Type: coreV1.MesheryDesign,
6060
ParsedFile: parsed,
6161
}, nil
6262
}
63-
identificationErrorsTrace[core.IacFileTypes.MESHERY_DESIGN] = err
63+
identificationErrorsTrace[coreV1.MesheryDesign] = err
6464

6565
// Attempt to parse the file as a Kubernetes manifest
6666
if parsed, err = ParseFileAsKubernetesManifest(sanitizedFile); err == nil {
6767
return IdentifiedFile{
68-
Type: core.IacFileTypes.KUBERNETES_MANIFEST,
68+
Type: coreV1.K8sManifest,
6969
ParsedFile: parsed,
7070
}, nil
7171
}
72-
identificationErrorsTrace[core.IacFileTypes.KUBERNETES_MANIFEST] = err
72+
identificationErrorsTrace[coreV1.K8sManifest] = err
7373

7474
// Attempt to parse the file as a Helm chart
7575
if parsed, err = ParseFileAsHelmChart(sanitizedFile); err == nil {
7676
return IdentifiedFile{
77-
Type: core.IacFileTypes.HELM_CHART,
77+
Type: coreV1.HelmChart,
7878
ParsedFile: parsed,
7979
}, nil
8080
}
81-
identificationErrorsTrace[core.IacFileTypes.HELM_CHART] = err
81+
identificationErrorsTrace[coreV1.HelmChart] = err
8282

8383
// Attempt to parse the file as a Docker Compose file
8484
if parsed, err = ParseFileAsDockerCompose(sanitizedFile); err == nil {
8585
return IdentifiedFile{
86-
Type: core.IacFileTypes.DOCKER_COMPOSE,
86+
Type: coreV1.DockerCompose,
8787
ParsedFile: parsed,
8888
}, nil
8989
}
90-
identificationErrorsTrace[core.IacFileTypes.DOCKER_COMPOSE] = err
90+
identificationErrorsTrace[coreV1.DockerCompose] = err
9191

9292
// Attempt to parse the file as a Kustomization file
9393
if parsed, err = ParseFileAsKustomization(sanitizedFile); err == nil {
9494
return IdentifiedFile{
95-
Type: core.IacFileTypes.KUSTOMIZE,
95+
Type: coreV1.K8sKustomize,
9696
ParsedFile: parsed,
9797
}, nil
9898
}
99-
identificationErrorsTrace[core.IacFileTypes.KUSTOMIZE] = err
99+
identificationErrorsTrace[coreV1.K8sKustomize] = err
100100

101101
// If no file type matched, return a detailed error with the identification trace
102102
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
@@ -7,7 +7,7 @@ import (
77

88
"github.com/layer5io/meshkit/errors"
99
"github.com/layer5io/meshkit/files"
10-
"github.com/meshery/schemas/models/core"
10+
coreV1 "github.com/meshery/schemas/models/v1alpha1/core"
1111
)
1212

1313
func TestSanitizeFile(t *testing.T) {
@@ -18,7 +18,7 @@ func TestSanitizeFile(t *testing.T) {
1818
expectError bool
1919
expectedErrCode string
2020
expectedContent map[string]interface{}
21-
expectedType string
21+
expectedType coreV1.IaCFileTypes
2222
}{
2323
{
2424
name: "Valid JSON",
@@ -73,59 +73,59 @@ func TestSanitizeFile(t *testing.T) {
7373
name: "Can Identify Design",
7474
filePath: "./samples/valid_design.yml",
7575
expectedExt: ".yml",
76-
expectedType: core.IacFileTypes.MESHERY_DESIGN,
76+
expectedType: coreV1.MesheryDesign,
7777
},
7878

7979
{
8080
name: "Can Identify Designs packaged as OCI images",
8181
filePath: "./samples/valid-design-oci.tar",
8282
expectedExt: ".tar",
83-
expectedType: core.IacFileTypes.MESHERY_DESIGN,
83+
expectedType: coreV1.MesheryDesign,
8484
},
8585
{
8686
name: "Can Identify Kubernetes Manifest",
8787
filePath: "./samples/valid_manifest.yml",
8888
expectedExt: ".yml",
89-
expectedType: core.IacFileTypes.KUBERNETES_MANIFEST,
89+
expectedType: coreV1.K8sManifest,
9090
},
9191

9292
{
9393
name: "Can Identify Kubernetes Manifest With Crds",
9494
filePath: "./samples/manifest-with-crds.yml",
9595
expectedExt: ".yml",
96-
expectedType: core.IacFileTypes.KUBERNETES_MANIFEST,
96+
expectedType: coreV1.K8sManifest,
9797
},
9898

9999
{
100100
name: "Can Identify HelmChart",
101101
filePath: "./samples/valid-helm.tgz",
102102
expectedExt: ".tgz",
103-
expectedType: core.IacFileTypes.HELM_CHART,
103+
expectedType: coreV1.HelmChart,
104104
},
105105
{
106106
name: "Can Identify Kustomize archive (tar.gz)",
107107
filePath: "./samples/wordpress-kustomize.tar.gz",
108108
expectedExt: ".gz",
109-
expectedType: core.IacFileTypes.KUSTOMIZE,
109+
expectedType: coreV1.K8sKustomize,
110110
},
111111
{
112112
name: "Can Identify Kustomize archive (zip)",
113113
filePath: "./samples/wordpress-kustomize.zip",
114114
expectedExt: ".zip",
115-
expectedType: core.IacFileTypes.KUSTOMIZE,
115+
expectedType: coreV1.K8sKustomize,
116116
},
117117
{
118118
name: "Can Identify Docker Compose",
119119
filePath: "./samples/valid-docker-compose.yml",
120120
expectedExt: ".yml",
121-
expectedType: core.IacFileTypes.DOCKER_COMPOSE,
121+
expectedType: coreV1.DockerCompose,
122122
},
123123

124124
{
125125
name: "Can Identify Docker Compose v2",
126126
filePath: "./samples/valid-compose-2.yml",
127127
expectedExt: ".yml",
128-
expectedType: core.IacFileTypes.DOCKER_COMPOSE,
128+
expectedType: coreV1.DockerCompose,
129129
},
130130

131131
// {

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
github.com/google/uuid v1.6.0
2727
github.com/kubernetes/kompose v1.35.0
2828
github.com/layer5io/meshery-operator v0.8.1
29-
github.com/meshery/schemas v0.8.11
29+
github.com/meshery/schemas v0.8.14
3030
github.com/nats-io/nats.go v1.38.0
3131
github.com/open-policy-agent/opa v1.0.1
3232
github.com/opencontainers/image-spec v1.1.0
@@ -36,8 +36,8 @@ require (
3636
github.com/spf13/viper v1.19.0
3737
github.com/tidwall/sjson v1.2.5
3838
golang.org/x/oauth2 v0.25.0
39-
golang.org/x/sync v0.11.0
40-
golang.org/x/text v0.22.0
39+
golang.org/x/sync v0.12.0
40+
golang.org/x/text v0.23.0
4141
google.golang.org/api v0.218.0
4242
gopkg.in/yaml.v2 v2.4.0
4343
gopkg.in/yaml.v3 v3.0.1
@@ -252,12 +252,12 @@ require (
252252
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
253253
go.opentelemetry.io/otel/trace v1.34.0 // indirect
254254
go.uber.org/multierr v1.11.0 // indirect
255-
golang.org/x/crypto v0.35.0 // indirect
255+
golang.org/x/crypto v0.36.0 // indirect
256256
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
257257
golang.org/x/mod v0.22.0 // indirect
258-
golang.org/x/net v0.36.0 // indirect
259-
golang.org/x/sys v0.30.0 // indirect
260-
golang.org/x/term v0.29.0 // indirect
258+
golang.org/x/net v0.38.0 // indirect
259+
golang.org/x/sys v0.31.0 // indirect
260+
golang.org/x/term v0.30.0 // indirect
261261
golang.org/x/time v0.9.0 // indirect
262262
golang.org/x/tools v0.29.0 // indirect
263263
google.golang.org/genproto/googleapis/rpc v0.0.0-20250124145028-65684f501c47 // indirect

go.sum

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxU
416416
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
417417
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
418418
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
419-
github.com/meshery/schemas v0.8.11 h1:1agZYIDownq0E1q22pe8juvrr49V2SYJ/ik4p3ibO5c=
420-
github.com/meshery/schemas v0.8.11/go.mod h1:qEpf8LaRSsj6/C8iOnvFWfIwhP/H7J4V08Q0tmsB6XQ=
419+
github.com/meshery/schemas v0.8.14 h1:4f7NGVQcpZEK6e5JvKvbo5WkDchVh+MFsNyf3LvbtzQ=
420+
github.com/meshery/schemas v0.8.14/go.mod h1:oJnVQASN/0K2y7wJ2rc1odcDb/g3AGRyGzfKqsPHuqg=
421421
github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM=
422422
github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk=
423423
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
@@ -666,8 +666,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
666666
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
667667
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
668668
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
669-
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
670-
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
669+
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
670+
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
671671
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 h1:yqrTHse8TCMW1M1ZCP+VAR/l0kKxwaAIqN/il7x4voA=
672672
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU=
673673
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
@@ -681,17 +681,17 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
681681
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
682682
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
683683
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
684-
golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA=
685-
golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I=
684+
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
685+
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
686686
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
687687
golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
688688
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
689689
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
690690
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
691691
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
692692
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
693-
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
694-
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
693+
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
694+
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
695695
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
696696
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
697697
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -708,16 +708,16 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
708708
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
709709
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
710710
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
711-
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
712-
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
711+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
712+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
713713
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
714-
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
715-
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
714+
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
715+
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
716716
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
717717
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
718718
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
719-
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
720-
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
719+
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
720+
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
721721
golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY=
722722
golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
723723
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

0 commit comments

Comments
 (0)