@@ -11,6 +11,8 @@ import (
1111 "os"
1212 "path/filepath"
1313
14+ "gopkg.in/yaml.v3"
15+
1416 "github.com/elastic/elastic-package/internal/multierror"
1517)
1618
@@ -39,13 +41,13 @@ func newAssetTypeWithFolder(typeName AssetType, folderName string) assetTypeFold
3941var (
4042 AssetTypeElasticsearchIndexTemplate = newAssetType ("index_template" )
4143 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" )
4951)
5052
5153// Asset represents a package asset to be loaded into Kibana or Elasticsearch.
@@ -68,6 +70,12 @@ func LoadPackageAssets(pkgRootPath string) ([]Asset, error) {
6870 return nil , fmt .Errorf ("could not load kibana assets: %w" , err )
6971 }
7072
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+
7179 a , err := loadElasticsearchAssets (pkgRootPath )
7280 if err != nil {
7381 return a , fmt .Errorf ("could not load elasticsearch assets: %w" , err )
@@ -85,10 +93,11 @@ func loadKibanaAssets(pkgRootPath string) ([]Asset, error) {
8593
8694 assetTypes = []assetTypeFolder {
8795 AssetTypeKibanaDashboard ,
88- AssetTypeKibanaVisualization ,
89- AssetTypeKibanaSavedSearch ,
90- AssetTypeKibanaMap ,
9196 AssetTypeKibanaLens ,
97+ AssetTypeKibanaMap ,
98+ AssetTypeKibanaSavedSearch ,
99+ AssetTypeKibanaTag ,
100+ AssetTypeKibanaVisualization ,
92101 AssetTypeSecurityRule ,
93102 }
94103
@@ -112,6 +121,34 @@ func loadKibanaAssets(pkgRootPath string) ([]Asset, error) {
112121 return assets , nil
113122}
114123
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+
115152func loadElasticsearchAssets (pkgRootPath string ) ([]Asset , error ) {
116153 packageManifestPath := filepath .Join (pkgRootPath , PackageManifestFile )
117154 pkgManifest , err := ReadPackageManifest (packageManifestPath )
0 commit comments