@@ -16,6 +16,16 @@ const (
1616 DefaultAutoTagUser uint = 0
1717 // DefaultAutocreated as default username and description for tags
1818 DefaultAutocreated = "Autocreated"
19+ // TagTypeEnv as tag type for environment name
20+ TagTypeEnv uint = 0
21+ // TagTypeUUID as tag type for node UUID
22+ TagTypeUUID uint = 1
23+ // TagTypePlatform as tag type for node platform
24+ TagTypePlatform uint = 2
25+ // TagTypeLocalname as tag type for node localname
26+ TagTypeLocalname uint = 3
27+ // TagTypeCustom as tag type for custom tags
28+ TagTypeCustom uint = 4
1929)
2030
2131// AdminTag to hold all tags
@@ -28,6 +38,7 @@ type AdminTag struct {
2838 CreatedBy string
2939 AutoTag bool
3040 EnvironmentID uint
41+ TagType uint
3142}
3243
3344// AdminTagForNode to check if this tag is used for an specific node
@@ -91,7 +102,7 @@ func (m *TagManager) Create(tag *AdminTag) error {
91102}
92103
93104// New empty tag
94- func (m * TagManager ) New (name , description , color , icon , user string , envID uint , auto bool ) (AdminTag , error ) {
105+ func (m * TagManager ) New (name , description , color , icon , user string , envID uint , auto bool , tagType uint ) (AdminTag , error ) {
95106 tagColor := color
96107 tagIcon := icon
97108 if tagColor == "" {
@@ -109,14 +120,15 @@ func (m *TagManager) New(name, description, color, icon, user string, envID uint
109120 CreatedBy : user ,
110121 EnvironmentID : envID ,
111122 AutoTag : auto ,
123+ TagType : tagType ,
112124 }, nil
113125 }
114126 return AdminTag {}, fmt .Errorf ("%s already exists" , name )
115127}
116128
117129// NewTag to create a tag and creates it without returning it
118- func (m * TagManager ) NewTag (name , description , color , icon , user string , envID uint , auto bool ) error {
119- tag , err := m .New (name , description , color , icon , user , envID , auto )
130+ func (m * TagManager ) NewTag (name , description , color , icon , user string , envID uint , auto bool , tagType uint ) error {
131+ tag , err := m .New (name , description , color , icon , user , envID , auto , tagType )
120132 if err != nil {
121133 return err
122134 }
@@ -220,8 +232,8 @@ func (m *TagManager) AutoTagNode(env string, node nodes.OsqueryNode, user string
220232// TagNodeMulti to tag a node with multiple tags
221233// TODO use the correct user_id
222234func (m * TagManager ) TagNodeMulti (tags []string , node nodes.OsqueryNode , user string , auto bool ) error {
223- for _ , t := range tags {
224- if err := m .TagNode (t , node , user , auto ); err != nil {
235+ for i , t := range tags {
236+ if err := m .TagNode (t , node , user , auto , uint ( i ) ); err != nil {
225237 return err
226238 }
227239 }
@@ -230,7 +242,7 @@ func (m *TagManager) TagNodeMulti(tags []string, node nodes.OsqueryNode, user st
230242
231243// TagNode to tag a node
232244// TODO use the correct user_id
233- func (m * TagManager ) TagNode (name string , node nodes.OsqueryNode , user string , auto bool ) error {
245+ func (m * TagManager ) TagNode (name string , node nodes.OsqueryNode , user string , auto bool , tagType uint ) error {
234246 if len (name ) == 0 {
235247 return fmt .Errorf ("empty tag" )
236248 }
@@ -244,6 +256,7 @@ func (m *TagManager) TagNode(name string, node nodes.OsqueryNode, user string, a
244256 CreatedBy : user ,
245257 AutoTag : auto ,
246258 EnvironmentID : node .EnvironmentID ,
259+ TagType : tagType ,
247260 }
248261 if err := m .Create (& newTag ); err != nil {
249262 return fmt .Errorf ("error creating tag %v" , err )
0 commit comments