Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions admin/handlers/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/jmpsec/osctrl/nodes"
"github.com/jmpsec/osctrl/queries"
"github.com/jmpsec/osctrl/settings"
"github.com/jmpsec/osctrl/tags"
"github.com/jmpsec/osctrl/users"
"github.com/jmpsec/osctrl/utils"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -1089,7 +1090,15 @@ func (h *HandlersAdmin) EnvsPOSTHandler(w http.ResponseWriter, r *http.Request)
return
}
// Create a tag for this new environment
if err := h.Tags.NewTag(env.Name, "Tag for environment "+env.Name, "", env.Icon, ctx[sessions.CtxUser], env.ID, false); err != nil {
if err := h.Tags.NewTag(
env.Name,
"Tag for environment "+env.Name,
"",
env.Icon,
ctx[sessions.CtxUser],
env.ID,
false,
tags.TagTypeEnv); err != nil {
adminErrorResponse(w, "error generating tag", http.StatusInternalServerError, err)
h.Inc(metricAdminErr)
return
Expand Down Expand Up @@ -1439,7 +1448,7 @@ func (h *HandlersAdmin) TagsPOSTHandler(w http.ResponseWriter, r *http.Request)
return
}
// Prepare user to create
if err := h.Tags.NewTag(t.Name, t.Description, t.Color, t.Icon, ctx[sessions.CtxUser], env.ID, false); err != nil {
if err := h.Tags.NewTag(t.Name, t.Description, t.Color, t.Icon, ctx[sessions.CtxUser], env.ID, false, t.TagType); err != nil {
adminErrorResponse(w, "error with new tag", http.StatusInternalServerError, err)
h.Inc(metricAdminErr)
return
Expand Down
4 changes: 3 additions & 1 deletion admin/handlers/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/jmpsec/osctrl/environments"
"github.com/jmpsec/osctrl/nodes"
"github.com/jmpsec/osctrl/settings"
"github.com/jmpsec/osctrl/tags"
"github.com/jmpsec/osctrl/users"
"github.com/jmpsec/osctrl/utils"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -783,7 +784,7 @@ func (h *HandlersAdmin) CarvesDetailsHandler(w http.ResponseWriter, r *http.Requ
}
// Custom functions to handle formatting
funcMap := template.FuncMap{
"inFutureTime": utils.InFutureTime,
"inFutureTime": utils.InFutureTime,
}
// Prepare template
tempateFiles := h.NewTemplateFiles(h.TemplatesFolder, "carves-details.html").filepaths
Expand Down Expand Up @@ -1452,6 +1453,7 @@ func (h *HandlersAdmin) TagsGETHandler(w http.ResponseWriter, r *http.Request) {
"pastFutureTimes": utils.PastFutureTimes,
"inFutureTime": utils.InFutureTime,
"environmentFinder": environments.EnvironmentFinder,
"tagTypeDecorator": tags.TagTypeDecorator,
}
// Prepare template
tempateFiles := h.NewTemplateFiles(h.TemplatesFolder, "tags.html").filepaths
Expand Down
1 change: 1 addition & 0 deletions admin/handlers/types-requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ type TagsRequest struct {
Color string `json:"color"`
Icon string `json:"icon"`
Environment string `json:"environment"`
TagType uint `json:"tagtype"`
}

// TagNodesRequest to receive a tag for nodes
Expand Down
11 changes: 10 additions & 1 deletion admin/static/js/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ function editTag(_name) {
$("#tag_description").val($("#tag_desc_" + _name).val());
$("#tag_color").val($("#tag_color_" + _name).val());
$("#tag_icon").val($("#tag_icon_" + _name).val());
$("#tag_env").val($("#tag_env_" + _name).val());
$("#tag_env")
.val($("#tag_env_" + _name).val())
.change();
$("#tag_type")
.val($("#tag_type_" + _name).val())
.change();
$("#createEditTagModal").modal();
}

Expand All @@ -36,6 +41,7 @@ function confirmCreateTag() {
var _color = $("#tag_color").val();
var _icon = $("#tag_icon").val();
var _env = $("#tag_env").val();
var _tagtype = parseInt($("#tag_type").val());
var data = {
csrftoken: _csrftoken,
action: "add",
Expand All @@ -44,6 +50,7 @@ function confirmCreateTag() {
color: _color,
icon: _icon,
environment: _env,
tagtype: _tagtype,
};
sendPostRequest(data, _url, _url, false);
}
Expand All @@ -56,6 +63,7 @@ function confirmEditTag() {
var _color = $("#tag_color").val();
var _icon = $("#tag_icon").val();
var _env = $("#tag_env").val();
var _tagtype = parseInt($("#tag_type").val());
var data = {
csrftoken: _csrftoken,
action: "edit",
Expand All @@ -64,6 +72,7 @@ function confirmEditTag() {
color: _color,
icon: _icon,
environment: _env,
tagtype: _tagtype,
};
sendPostRequest(data, _url, _url, false);
}
Expand Down
21 changes: 19 additions & 2 deletions admin/templates/tags.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Color</th>
<th>Icon</th>
Expand All @@ -54,14 +55,15 @@
{{range $i, $t := $.Tags}}
<tr>
<td><b>{{ $t.Name }}</b><input type="hidden" value="{{ $t.Name }}" id="tag_name_{{ $t.Name }}"></td>
<td>{{ tagTypeDecorator $t.TagType }}<input type="hidden" value="{{ $t.TagType }}" id="tag_type_{{ $t.Name }}">
<td>{{ $t.Description }}<input type="hidden" value="{{ $t.Description }}" id="tag_desc_{{ $t.Name }}"></td>
<td>{{ $t.Color }}<input type="hidden" value="{{ $t.Color }}" id="tag_color_{{ $t.Name }}">
<span style="color: {{ $t.Color }}; background-color: {{ $t.Color }};">##</span>
</td>
<td>{{ $t.Icon }} <i class="{{ $t.Icon }}"></i><input type="hidden" value="{{ $t.Icon }}" id="tag_icon_{{ $t.Name }}"></td>
<td>
<b>{{ environmentFinder $t.EnvironmentID $.Environments }}</b>
<input type="hidden" value="{{ environmentFinder $t.EnvironmentID $.Environments }}" id="tag_env_{{ $t.Name }}"></td>
<b>{{ environmentFinder $t.EnvironmentID $.Environments false }}</b>
<input type="hidden" value="{{ environmentFinder $t.EnvironmentID $.Environments true }}" id="tag_env_{{ $t.Name }}"></td>
<td>
<button type="button" class="btn btn-sm btn-ghost-danger" onclick="confirmDeleteTag('{{ $t.Name }}');">
<i class="far fa-trash-alt"></i>
Expand Down Expand Up @@ -125,6 +127,17 @@ <h4 id="modal_title_tag" class="modal-title"></h4>
{{ end }}
</select>
</div>
<label class="col-md-2 col-form-label" for="tag_type">Tag Type: </label>
<div class="col-md-4">
<select class="form-control" name="tag_type" id="tag_type">
<option value=""></option>
<option value="0">Environment</option>
<option value="1">UUID</option>
<option value="2">Platform</option>
<option value="3">Localname</option>
<option value="4">Custom</option>
</select>
</div>
</div>
</div>
<div class="modal-footer">
Expand Down Expand Up @@ -167,6 +180,10 @@ <h4 id="modal_title_tag" class="modal-title"></h4>
theme: "classic",
width: '100%'
});
$('#tag_type').select2({
theme: "classic",
width: '100%'
});

// Enable all tooltips
$('[data-tooltip="true"]').tooltip({trigger : 'hover'});
Expand Down
10 changes: 9 additions & 1 deletion cli/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ func addEnvironment(c *cli.Context) error {
return err
}
// Create a tag for this new environment
if err := tagsmgr.NewTag(newEnv.Name, "Tag for environment "+newEnv.Name, tags.RandomColor(), newEnv.Icon, appName, newEnv.ID, false); err != nil {
if err := tagsmgr.NewTag(
newEnv.Name,
"Tag for environment "+newEnv.Name,
tags.RandomColor(),
newEnv.Icon,
appName,
newEnv.ID,
false,
tags.TagTypeEnv); err != nil {
return err
}
// Generate flags
Expand Down
8 changes: 7 additions & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ func init() {
Usage: "Tag an existing node",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "uuid, u",
Name: "uuid",
Aliases: []string{"u"},
Usage: "Node UUID to be tagged",
},
Expand All @@ -1159,6 +1159,12 @@ func init() {
Aliases: []string{"T"},
Usage: "Tag value to be used. It will be created if does not exist",
},
&cli.StringFlag{
Name: "tag-type",
Aliases: []string{"type"},
Value: "custom",
Usage: "Tag type to be used. It can be 'env', 'uuid', 'localname' and 'custom'",
},
},
Action: cliWrapper(tagNode),
},
Expand Down
15 changes: 13 additions & 2 deletions cli/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/jmpsec/osctrl/nodes"
"github.com/jmpsec/osctrl/settings"
"github.com/jmpsec/osctrl/tags"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -152,6 +153,16 @@ func tagNode(c *cli.Context) error {
fmt.Println("❌ tag is required")
os.Exit(1)
}
tagType := c.String("tag-type")
tagTypeInt := tags.TagTypeCustom
switch tagType {
case "env":
tagTypeInt = tags.TagTypeEnv
case "uuid":
tagTypeInt = tags.TagTypeUUID
case "localname":
tagTypeInt = tags.TagTypeLocalname
}
if dbFlag {
e, err := envs.Get(env)
if err != nil {
Expand All @@ -162,7 +173,7 @@ func tagNode(c *cli.Context) error {
return fmt.Errorf("error get uuid - %s", err)
}
if tagsmgr.Exists(tag) {
if err := tagsmgr.TagNode(tag, n, appName, false); err != nil {
if err := tagsmgr.TagNode(tag, n, appName, false, tagTypeInt); err != nil {
return fmt.Errorf("error tagging - %s", err)
}
}
Expand All @@ -172,7 +183,7 @@ func tagNode(c *cli.Context) error {
}
}
if !silentFlag {
fmt.Println("✅ node was deleted successfully")
fmt.Println("✅ node was tagged successfully")
}
return nil
}
Expand Down
5 changes: 4 additions & 1 deletion environments/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ func PackageDownloadURL(env TLSEnvironment, pkg string) string {
}

// EnvironmentFinder to find the environment and return its name based on the environment ID
func EnvironmentFinder(envID uint, envs []TLSEnvironment) string {
func EnvironmentFinder(envID uint, envs []TLSEnvironment, uuid bool) string {
for _, env := range envs {
if env.ID == envID {
if uuid {
return env.UUID
}
return env.Name
}
}
Expand Down
2 changes: 1 addition & 1 deletion settings/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
require (
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/sys v0.30.0 // indirect
)

require (
Expand Down
29 changes: 6 additions & 23 deletions settings/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -29,31 +29,14 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg=
gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
gorm.io/driver/sqlite v1.5.6 h1:fO/X46qn5NUEEOZtnjJRWRzZMe8nqJiQ9E+0hi+hKQE=
gorm.io/driver/sqlite v1.5.6/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
Loading