@@ -11,6 +11,8 @@ import (
11
11
"os"
12
12
"path/filepath"
13
13
14
+ "gopkg.in/yaml.v3"
15
+
14
16
"github.com/elastic/elastic-package/internal/multierror"
15
17
)
16
18
@@ -39,13 +41,13 @@ func newAssetTypeWithFolder(typeName AssetType, folderName string) assetTypeFold
39
41
var (
40
42
AssetTypeElasticsearchIndexTemplate = newAssetType ("index_template" )
41
43
AssetTypeElasticsearchIngestPipeline = newAssetType ("ingest_pipeline" )
42
-
43
- AssetTypeKibanaSavedSearch = newAssetType ("search " )
44
- AssetTypeKibanaVisualization = newAssetType ("visualization " )
45
- AssetTypeKibanaDashboard = newAssetType ("dashboard " )
46
- AssetTypeKibanaMap = newAssetType ("map " )
47
- AssetTypeKibanaLens = newAssetType ("lens " )
48
- AssetTypeSecurityRule = newAssetTypeWithFolder ("security-rule" , "security_rule" )
44
+ AssetTypeKibanaDashboard = newAssetType ( "dashboard" )
45
+ AssetTypeKibanaLens = newAssetType ("lens " )
46
+ AssetTypeKibanaMap = newAssetType ("map " )
47
+ AssetTypeKibanaSavedSearch = newAssetType ("search " )
48
+ AssetTypeKibanaTag = newAssetType ("tag " )
49
+ AssetTypeKibanaVisualization = newAssetType ("visualization " )
50
+ AssetTypeSecurityRule = newAssetTypeWithFolder ("security-rule" , "security_rule" )
49
51
)
50
52
51
53
// Asset represents a package asset to be loaded into Kibana or Elasticsearch.
@@ -68,6 +70,12 @@ func LoadPackageAssets(pkgRootPath string) ([]Asset, error) {
68
70
return nil , fmt .Errorf ("could not load kibana assets: %w" , err )
69
71
}
70
72
73
+ tags , err := loadKibanaTags (pkgRootPath )
74
+ if err != nil {
75
+ return nil , fmt .Errorf ("could not load kibana tags: %w" , err )
76
+ }
77
+ assets = append (assets , tags ... )
78
+
71
79
a , err := loadElasticsearchAssets (pkgRootPath )
72
80
if err != nil {
73
81
return a , fmt .Errorf ("could not load elasticsearch assets: %w" , err )
@@ -85,10 +93,11 @@ func loadKibanaAssets(pkgRootPath string) ([]Asset, error) {
85
93
86
94
assetTypes = []assetTypeFolder {
87
95
AssetTypeKibanaDashboard ,
88
- AssetTypeKibanaVisualization ,
89
- AssetTypeKibanaSavedSearch ,
90
- AssetTypeKibanaMap ,
91
96
AssetTypeKibanaLens ,
97
+ AssetTypeKibanaMap ,
98
+ AssetTypeKibanaSavedSearch ,
99
+ AssetTypeKibanaTag ,
100
+ AssetTypeKibanaVisualization ,
92
101
AssetTypeSecurityRule ,
93
102
}
94
103
@@ -112,6 +121,34 @@ func loadKibanaAssets(pkgRootPath string) ([]Asset, error) {
112
121
return assets , nil
113
122
}
114
123
124
+ func loadKibanaTags (pkgRootPath string ) ([]Asset , error ) {
125
+ tagsFilePath := filepath .Join (pkgRootPath , "kibana" , "tags.yml" )
126
+ tagsFile , err := os .ReadFile (tagsFilePath )
127
+ if errors .Is (err , os .ErrNotExist ) {
128
+ return nil , nil
129
+ }
130
+ if err != nil {
131
+ return nil , fmt .Errorf ("reading tags file failed: %w" , err )
132
+ }
133
+
134
+ type tag struct {
135
+ Text string `yaml:"text"`
136
+ }
137
+ var tags []tag
138
+ err = yaml .Unmarshal (tagsFile , & tags )
139
+ if err != nil {
140
+ return nil , fmt .Errorf ("parsing tags file failed: %w" , err )
141
+ }
142
+
143
+ assets := make ([]Asset , len (tags ))
144
+ for i , tag := range tags {
145
+ assets [i ].ID = tag .Text
146
+ assets [i ].Type = AssetTypeKibanaTag .typeName
147
+ assets [i ].SourcePath = tagsFilePath
148
+ }
149
+ return assets , nil
150
+ }
151
+
115
152
func loadElasticsearchAssets (pkgRootPath string ) ([]Asset , error ) {
116
153
packageManifestPath := filepath .Join (pkgRootPath , PackageManifestFile )
117
154
pkgManifest , err := ReadPackageManifest (packageManifestPath )
0 commit comments