Skip to content

Commit 550960d

Browse files
authored
Merge pull request #706 from jmpsec/skip-autocreate-tags-uuid
Ability to have custom tags
2 parents 9bcdd35 + 44ebf3e commit 550960d

File tree

19 files changed

+265
-75
lines changed

19 files changed

+265
-75
lines changed

cmd/admin/handlers/post.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,8 @@ func (h *HandlersAdmin) EnvsPOSTHandler(w http.ResponseWriter, r *http.Request)
961961
ctx[sessions.CtxUser],
962962
env.ID,
963963
false,
964-
tags.TagTypeEnv); err != nil {
964+
tags.TagTypeEnv,
965+
""); err != nil {
965966
adminErrorResponse(w, "error generating tag", http.StatusInternalServerError, err)
966967
return
967968
}
@@ -1261,7 +1262,7 @@ func (h *HandlersAdmin) TagsPOSTHandler(w http.ResponseWriter, r *http.Request)
12611262
adminErrorResponse(w, "error adding tag", http.StatusInternalServerError, fmt.Errorf("tag %s already exists", t.Name))
12621263
return
12631264
}
1264-
if err := h.Tags.NewTag(t.Name, t.Description, t.Color, t.Icon, ctx[sessions.CtxUser], env.ID, false, t.TagType); err != nil {
1265+
if err := h.Tags.NewTag(t.Name, t.Description, t.Color, t.Icon, ctx[sessions.CtxUser], env.ID, false, t.TagType, t.Custom); err != nil {
12651266
adminErrorResponse(w, "error with new tag", http.StatusInternalServerError, err)
12661267
return
12671268
}
@@ -1357,7 +1358,7 @@ func (h *HandlersAdmin) TagNodesPOSTHandler(w http.ResponseWriter, r *http.Reque
13571358
}
13581359
// Processing the list of tags to add and all nodes to tag
13591360
for _, n := range toBeProcessed {
1360-
if err := h.Tags.TagNodeMulti(t.TagsAdd, n, ctx[sessions.CtxUser], false); err != nil {
1361+
if err := h.Tags.TagNodeMulti(t.TagsAdd, n, ctx[sessions.CtxUser], false, ""); err != nil {
13611362
adminErrorResponse(w, "error with tag", http.StatusInternalServerError, err)
13621363
return
13631364
}

cmd/admin/handlers/types-requests.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ type TagsRequest struct {
137137
Icon string `json:"icon"`
138138
Environment string `json:"environment"`
139139
TagType uint `json:"tagtype"`
140+
Custom string `json:"custom"`
140141
}
141142

142143
// TagNodesRequest to receive a tag for nodes

cmd/admin/static/css/custom.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,17 @@ button {
163163
font-family: monospace;
164164
font-size: 1.3em;
165165
}
166+
167+
.badge-prefix {
168+
font-size: 0.75rem;
169+
opacity: 0.8;
170+
font-weight: 400;
171+
font-style: italic;
172+
margin-right: 2px;
173+
}
174+
175+
.badge-main {
176+
font-size: 0.95rem;
177+
font-weight: 700;
178+
letter-spacing: 0.3px;
179+
}

cmd/admin/static/js/tags.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function createTag() {
1010
$("#tag_description").val("");
1111
$("#tag_icon").val("");
1212
$("#tag_env").val("");
13+
$("#tag_custom").val("");
1314
$("#createEditTagModal").modal();
1415
}
1516

@@ -30,6 +31,9 @@ function editTag(_name) {
3031
$("#tag_type")
3132
.val($("#tag_type_" + _name).val())
3233
.change();
34+
$("#tag_custom")
35+
.val($("#tag_custom_" + _name).val())
36+
.change();
3337
$("#createEditTagModal").modal();
3438
}
3539

@@ -41,6 +45,7 @@ function confirmCreateTag() {
4145
var _color = $("#tag_color").val();
4246
var _icon = $("#tag_icon").val();
4347
var _env = $("#tag_env").val();
48+
var _custom = $("#tag_custom").val();
4449
var _tagtype = parseInt($("#tag_type").val());
4550
var data = {
4651
csrftoken: _csrftoken,
@@ -51,6 +56,7 @@ function confirmCreateTag() {
5156
icon: _icon,
5257
environment: _env,
5358
tagtype: _tagtype,
59+
custom: _custom,
5460
};
5561
sendPostRequest(data, _url, _url, false);
5662
}
@@ -64,6 +70,7 @@ function confirmEditTag() {
6470
var _icon = $("#tag_icon").val();
6571
var _env = $("#tag_env").val();
6672
var _tagtype = parseInt($("#tag_type").val());
73+
var _custom = $("#tag_custom").val();
6774
var data = {
6875
csrftoken: _csrftoken,
6976
action: "edit",
@@ -73,6 +80,7 @@ function confirmEditTag() {
7380
icon: _icon,
7481
environment: _env,
7582
tagtype: _tagtype,
83+
custom: _custom,
7684
};
7785
sendPostRequest(data, _url, _url, false);
7886
}

cmd/admin/templates/node.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<i class="nav-icon fas fa-tachometer-alt"></i>
3030
<strong> Dashboard for node {{ .Hostname }} </strong>
3131
{{ range $i, $t := $template.NodeTags }}
32-
<span style="background-color: {{ $t.Color }};" class="badge"><i class="{{ $t.Icon }}"></i> {{ $t.Name }}</span>
32+
<span style="background-color: {{ $t.Color }};" class="badge"><i class="{{ $t.Icon }}"></i> {{ $t.CustomTag }}:{{ $t.Name }}</span>
3333
{{ end }}
3434
</div>
3535
<div class="card-body">
@@ -91,7 +91,11 @@
9191
<i class="nav-icon fas fa-info-circle"></i>
9292
<strong> Details of node {{ .Hostname }} </strong>
9393
{{ range $i, $t := $template.NodeTags }}
94-
<span style="background-color: {{ $t.Color }};" class="badge"><i class="{{ $t.Icon }}"></i> {{ $t.Name }}</span>
94+
<span style="background-color: {{ $t.Color }};" class="badge">
95+
<i class="{{ $t.Icon }}"></i>
96+
<span class="badge-prefix">{{ $t.CustomTag }}:</span>
97+
<span class="badge-main">{{ $t.Name }}</span>
98+
</span>
9599
{{ end }}
96100
</div>
97101
<div class="card-body">

cmd/admin/templates/tags.html

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
<div class="card mt-2">
2424
<div class="card-header">
25-
<i class="fas fa-tag"></i> All Tags</b>
25+
<i class="fas fa-tag"></i><b>All Tags</b>
2626

2727
<div class="card-header-actions">
2828
<div class="row">
@@ -42,7 +42,7 @@
4242
<table class="table table-responsive-sm table-bordered table-striped text-center">
4343
<thead>
4444
<tr>
45-
<th>Name</th>
45+
<th>Tag</th>
4646
<th>Type</th>
4747
<th>Description</th>
4848
<th>Color</th>
@@ -54,16 +54,21 @@
5454
<tbody>
5555
{{range $i, $t := $.Tags}}
5656
<tr>
57-
<td><b>{{ $t.Name }}</b><input type="hidden" value="{{ $t.Name }}" id="tag_name_{{ $t.Name }}"></td>
57+
<td>
58+
{{ $t.CustomTag }}<input type="hidden" value="{{ $t.CustomTag }}" id="tag_custom_{{ $t.Name }}">:
59+
<b>{{ $t.Name }}</b><input type="hidden" value="{{ $t.Name }}" id="tag_name_{{ $t.Name }}">
60+
</td>
5861
<td>{{ tagTypeDecorator $t.TagType }}<input type="hidden" value="{{ $t.TagType }}" id="tag_type_{{ $t.Name }}">
5962
<td>{{ $t.Description }}<input type="hidden" value="{{ $t.Description }}" id="tag_desc_{{ $t.Name }}"></td>
6063
<td>{{ $t.Color }}<input type="hidden" value="{{ $t.Color }}" id="tag_color_{{ $t.Name }}">
6164
<span style="color: {{ $t.Color }}; background-color: {{ $t.Color }};">##</span>
6265
</td>
63-
<td>{{ $t.Icon }} <i class="{{ $t.Icon }}"></i><input type="hidden" value="{{ $t.Icon }}" id="tag_icon_{{ $t.Name }}"></td>
66+
<td>{{ $t.Icon }} <i class="{{ $t.Icon }}"></i><input type="hidden" value="{{ $t.Icon }}" id="tag_icon_{{ $t.Name }}">
67+
</td>
6468
<td>
6569
<b>{{ environmentFinder $t.EnvironmentID $.Environments false }}</b>
66-
<input type="hidden" value="{{ environmentFinder $t.EnvironmentID $.Environments true }}" id="tag_env_{{ $t.Name }}"></td>
70+
<input type="hidden" value="{{ environmentFinder $t.EnvironmentID $.Environments true }}" id="tag_env_{{ $t.Name }}">
71+
</td>
6772
<td>
6873
<button type="button" class="btn btn-sm btn-ghost-danger" onclick="confirmDeleteTag('{{ $t.Name }}');">
6974
<i class="far fa-trash-alt"></i>
@@ -136,9 +141,18 @@ <h4 id="modal_title_tag" class="modal-title"></h4>
136141
<option value="2">Platform</option>
137142
<option value="3">Localname</option>
138143
<option value="4">Custom</option>
144+
<option value="5">Unknown</option>
145+
<option value="6">Tag</option>
146+
<option value="7">Hostname</option>
139147
</select>
140148
</div>
141149
</div>
150+
<div class="form-group row">
151+
<label class="col-md-2 col-form-label" for="tag_custom">Custom Tag: </label>
152+
<div class="col-md-4">
153+
<input class="form-control" name="tag_custom" id="tag_custom" type="text" autocomplete="off">
154+
</div>
155+
</div>
142156
</div>
143157
<div class="modal-footer">
144158
<button id="modal_button_tag" type="button" class="btn btn-primary" data-dismiss="modal">Create</button>

cmd/api/handlers/nodes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func (h *HandlersApi) TagNodeHandler(w http.ResponseWriter, r *http.Request) {
258258
}
259259
return
260260
}
261-
if err := h.Tags.TagNode(t.Tag, n, ctx[ctxUser], false, t.Type); err != nil {
261+
if err := h.Tags.TagNode(t.Tag, n, ctx[ctxUser], false, t.Type, t.Custom); err != nil {
262262
apiErrorResponse(w, "error tagging node", http.StatusInternalServerError, err)
263263
return
264264
}

cmd/api/handlers/tags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (h *HandlersApi) TagsActionHandler(w http.ResponseWriter, r *http.Request)
166166
apiErrorResponse(w, "error adding tag", http.StatusInternalServerError, fmt.Errorf("tag %s already exists", t.Name))
167167
return
168168
}
169-
if err := h.Tags.NewTag(t.Name, t.Description, t.Color, t.Icon, ctx[ctxUser], env.ID, false, t.TagType); err != nil {
169+
if err := h.Tags.NewTag(t.Name, t.Description, t.Color, t.Icon, ctx[ctxUser], env.ID, false, t.TagType, t.Custom); err != nil {
170170
apiErrorResponse(w, "error with new tag", http.StatusInternalServerError, err)
171171
return
172172
}

cmd/cli/api-node.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ func (api *OsctrlAPI) DeleteNode(env, identifier string) error {
6161
}
6262

6363
// TagNode to tag node in osctrl
64-
func (api *OsctrlAPI) TagNode(env, identifier, tag string, tagType uint) error {
64+
func (api *OsctrlAPI) TagNode(env, identifier, tag string, tagType uint, custom string) error {
6565
t := types.ApiNodeTagRequest{
66-
UUID: identifier,
67-
Tag: tag,
68-
Type: tagType,
66+
UUID: identifier,
67+
Tag: tag,
68+
Type: tagType,
69+
Custom: custom,
6970
}
7071
var r types.ApiGenericResponse
7172
reqURL := fmt.Sprintf("%s%s", api.Configuration.URL, path.Join(APIPath, APINodes, env, "tag"))

cmd/cli/api-tag.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ func (api *OsctrlAPI) GetTag(env, name string) (tags.AdminTag, error) {
5353
}
5454

5555
// AddTag to add a tag to osctrl
56-
func (api *OsctrlAPI) AddTag(envUUID, name, color, icon, description string, tagType uint) (types.ApiGenericResponse, error) {
56+
func (api *OsctrlAPI) AddTag(env, name, color, icon, description string, tagType uint, custom string) (types.ApiGenericResponse, error) {
5757
var r types.ApiGenericResponse
5858
t := types.ApiTagsRequest{
5959
Name: name,
6060
Description: description,
6161
Color: color,
6262
Icon: icon,
63-
EnvUUID: envUUID,
63+
Env: env,
6464
TagType: tagType,
6565
}
66-
reqURL := fmt.Sprintf("%s%s", api.Configuration.URL, path.Join(APIPath, APITags, envUUID, tags.ActionAdd))
66+
reqURL := fmt.Sprintf("%s%s", api.Configuration.URL, path.Join(APIPath, APITags, env, tags.ActionAdd))
6767
jsonMessage, err := json.Marshal(t)
6868
if err != nil {
6969
return r, fmt.Errorf("error marshaling data - %w", err)
@@ -80,13 +80,13 @@ func (api *OsctrlAPI) AddTag(envUUID, name, color, icon, description string, tag
8080
}
8181

8282
// DeleteTag to delete a tag from osctrl
83-
func (api *OsctrlAPI) DeleteTag(envUUID, name string) (types.ApiGenericResponse, error) {
83+
func (api *OsctrlAPI) DeleteTag(env, name string) (types.ApiGenericResponse, error) {
8484
var r types.ApiGenericResponse
8585
t := types.ApiTagsRequest{
86-
Name: name,
87-
EnvUUID: envUUID,
86+
Name: name,
87+
Env: env,
8888
}
89-
reqURL := fmt.Sprintf("%s%s", api.Configuration.URL, path.Join(APIPath, APITags, envUUID, tags.ActionRemove))
89+
reqURL := fmt.Sprintf("%s%s", api.Configuration.URL, path.Join(APIPath, APITags, env, tags.ActionRemove))
9090
jsonMessage, err := json.Marshal(t)
9191
if err != nil {
9292
return r, fmt.Errorf("error marshaling data - %w", err)
@@ -103,17 +103,18 @@ func (api *OsctrlAPI) DeleteTag(envUUID, name string) (types.ApiGenericResponse,
103103
}
104104

105105
// EditTag to edit a tag from osctrl
106-
func (api *OsctrlAPI) EditTag(envUUID, name, color, icon, description string, tagType uint) (types.ApiGenericResponse, error) {
106+
func (api *OsctrlAPI) EditTag(env, name, color, icon, description string, tagType uint, custom string) (types.ApiGenericResponse, error) {
107107
var r types.ApiGenericResponse
108108
t := types.ApiTagsRequest{
109109
Name: name,
110110
Description: description,
111111
Color: color,
112112
Icon: icon,
113-
EnvUUID: envUUID,
113+
Env: env,
114114
TagType: tagType,
115+
Custom: custom,
115116
}
116-
reqURL := fmt.Sprintf("%s%s", api.Configuration.URL, path.Join(APIPath, APITags, envUUID, tags.ActionEdit))
117+
reqURL := fmt.Sprintf("%s%s", api.Configuration.URL, path.Join(APIPath, APITags, env, tags.ActionEdit))
117118
jsonMessage, err := json.Marshal(t)
118119
if err != nil {
119120
return r, fmt.Errorf("error marshaling data - %w", err)

0 commit comments

Comments
 (0)