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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v2.9.0
version: v2.15.0

check-license:
name: License scan
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
# 'latest', 'nightly', or a semver
version: v1.25.1
version: v1.26.2
args: check

test:
Expand Down Expand Up @@ -187,7 +187,7 @@ jobs:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
# 'latest', 'nightly', or a semver
version: v1.25.1
version: v1.26.2
args: release
- name: Write latest version to file
run: mkdir -p dist && printf '%s\n' "${TAG}" > dist/LATEST_VERSION
Expand Down
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ linters:
allow-unused: true
exclusions:
generated: lax
rules:
- path: '(_test|test_helper)\.go$'
linters:
- goconst
presets:
- comments
- common-false-positives
Expand Down
5 changes: 3 additions & 2 deletions cmd/context/context_save.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
)

const (
APIPathFlag = "api-path"
currentContextKey = "current-context"
APIPathFlag = "api-path"
)

type SaveArgs struct {
Expand Down Expand Up @@ -112,7 +113,7 @@ func RunContextSaveCommand(args *SaveArgs) func(cli *di.Deps, cmd *cobra.Command

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"current-context": cfg.CurrentContext,
currentContextKey: cfg.CurrentContext,
"context": namedCtx.Context,
})
} else {
Expand Down
2 changes: 1 addition & 1 deletion cmd/context/context_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func RunContextSetCommand(args *SetArgs, cli *di.Deps) func(cli *di.Deps, cmd *c

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"current-context": args.Name,
currentContextKey: args.Name,
})
} else {
cli.Printer.PrintLn(fmt.Sprintf("Current context set to %s", args.Name))
Expand Down
2 changes: 1 addition & 1 deletion cmd/context/context_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func RunContextShowCommand(cli *di.Deps, cmd *cobra.Command, cfg *config.Config)

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"current-context": ctx.Context,
currentContextKey: ctx.Context,
"name": cfg.CurrentContext,
})
} else {
Expand Down
10 changes: 7 additions & 3 deletions cmd/dashboard/dashboard_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"sigs.k8s.io/kustomize/kyaml/yaml"
)

const (
dashboardKey = "dashboard"
)

// ApplyArgs contains arguments for dashboard apply command
type ApplyArgs struct {
File string
Expand Down Expand Up @@ -93,7 +97,7 @@ func createDashboard(cli *di.Deps, api *stackstate_api.APIClient, fileBytes []by

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"dashboard": dashboard,
dashboardKey: dashboard,
})
} else {
cli.Printer.Success(fmt.Sprintf("Dashboard created successfully! ID: %d, Name: %s", dashboard.GetId(), dashboard.GetName()))
Expand All @@ -118,7 +122,7 @@ func updateDashboard(cli *di.Deps, api *stackstate_api.APIClient, dashboardId st
patchSchema.SetScope(*scope)
}
}
if dashboardContent, ok := dashboardData["dashboard"]; ok {
if dashboardContent, ok := dashboardData[dashboardKey]; ok {
// Convert dashboard content to PersesDashboard
dashboardBytes, err := yaml.Marshal(dashboardContent)
if err == nil {
Expand All @@ -137,7 +141,7 @@ func updateDashboard(cli *di.Deps, api *stackstate_api.APIClient, dashboardId st

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"dashboard": dashboard,
dashboardKey: dashboard,
})
} else {
cli.Printer.Success(fmt.Sprintf("Dashboard updated successfully! ID: %d, Name: %s", dashboard.GetId(), dashboard.GetName()))
Expand Down
2 changes: 1 addition & 1 deletion cmd/dashboard/dashboard_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func RunDashboardCloneCommand(args *CloneArgs) di.CmdWithApiFn {

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"dashboard": clonedDashboard,
dashboardKey: clonedDashboard,
})
} else {
cli.Printer.Success(fmt.Sprintf("Dashboard cloned successfully! New dashboard ID: %d, Name: %s", clonedDashboard.GetId(), clonedDashboard.GetName()))
Expand Down
4 changes: 2 additions & 2 deletions cmd/dashboard/dashboard_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func RunDashboardEditCommand(args *EditArgs) di.CmdWithApiFn {
patchSchema.SetScope(*scope)
}
}
if dashboardContent, ok := editedDashboard["dashboard"]; ok {
if dashboardContent, ok := editedDashboard[dashboardKey]; ok {
// Convert dashboard content to PersesDashboard
dashboardBytes, err := json.Marshal(dashboardContent)
if err == nil {
Expand All @@ -118,7 +118,7 @@ func RunDashboardEditCommand(args *EditArgs) di.CmdWithApiFn {

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"dashboard": updatedDashboard,
dashboardKey: updatedDashboard,
})
} else {
cli.Printer.Success(fmt.Sprintf("Dashboard updated successfully! ID: %d, Name: %s", updatedDashboard.GetId(), updatedDashboard.GetName()))
Expand Down
19 changes: 12 additions & 7 deletions cmd/health/health_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (
"github.com/stackvista/stackstate-cli/internal/printer"
)

const (
metricsKey = "metrics"
errorsKey = "errors"
)

type StatusArgs struct {
Urn string
SubStream string
Expand Down Expand Up @@ -105,8 +110,8 @@ func RunStreamStatus(cli *di.Deps, api *stackstate_api.APIClient, args *StatusAr
if cli.IsJson() {
json := map[string]interface{}{
"consistency-model": status.ConsistencyModel,
"metrics": streamMetricsToJson(status.AggregateMetrics),
"errors": streamErrorsToJson(status.GlobalErrors),
metricsKey: streamMetricsToJson(status.AggregateMetrics),
errorsKey: streamErrorsToJson(status.GlobalErrors),
}
if status.HasMainStreamStatus() {
json["main-stream"] = subStreamStatusToJson(*status.MainStreamStatus)
Expand Down Expand Up @@ -148,7 +153,7 @@ func streamMetricsToTable(metrics stackstate_api.HealthStreamMetrics) printer.Ta
printer.MetricBucketToRow("updates per seconds", metrics.UpdatesPerSecond),
printer.MetricBucketToRow("deletes per seconds", metrics.DeletesPerSecond),
},
MissingTableDataMsg: printer.NotFoundMsg{Types: "metrics"},
MissingTableDataMsg: printer.NotFoundMsg{Types: metricsKey},
}
}

Expand All @@ -174,7 +179,7 @@ func streamErrorsToTable(errors []stackstate_api.HealthStreamError) printer.Tabl
return printer.TableData{
Header: []string{"Message", "Count"},
Data: data,
MissingTableDataMsg: printer.NotFoundMsg{Types: "errors"},
MissingTableDataMsg: printer.NotFoundMsg{Types: errorsKey},
}
}

Expand Down Expand Up @@ -233,7 +238,7 @@ func streamConsistencyStateToTable(state stackstate_api.HealthSubStreamConsisten
Data: [][]interface{}{
{repeatInterval, expiryInterval, snapshotRepeatInterval, snapshotExpiryInterval, checkpointOffset, checkpointBatchIndex},
},
MissingTableDataMsg: printer.NotFoundMsg{Types: "errors"},
MissingTableDataMsg: printer.NotFoundMsg{Types: errorsKey},
}
}

Expand All @@ -251,8 +256,8 @@ func subStreamStatusToJson(status stackstate_api.HealthSubStreamStatus) map[stri
return map[string]interface{}{
"check-state-count": status.CheckStateCount,
"consistency-state": streamConsistencyStateToJson(status.SubStreamState),
"metrics": streamMetricsToJson(status.Metrics),
"errors": streamErrorsToJson(status.Errors),
metricsKey: streamMetricsToJson(status.Metrics),
errorsKey: streamErrorsToJson(status.Errors),
}
}

Expand Down
10 changes: 7 additions & 3 deletions cmd/license/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ import (
"github.com/stackvista/stackstate-cli/internal/printer"
)

const (
stateKey = "state"
)

func subscriptionAsTable(subscription *stackstate_api.SubscriptionState) printer.TableData {
var header []string
data := make([][]interface{}, 0)
switch l := subscription.GetActualInstance().(type) {
case *stackstate_api.ExpiredSubscription:
header = []string{"state", "tenant", "expiration", "plan"}
header = []string{stateKey, "tenant", "expiration", "plan"}
data = append(data, []interface{}{"expired", l.Subscription.Tenant, expiration(l.Subscription.ExpiryTimestampMs), l.Subscription.Plan})
case *stackstate_api.LicensedSubscription:
header = []string{"state", "tenant", "expiration", "plan"}
header = []string{stateKey, "tenant", "expiration", "plan"}
data = append(data, []interface{}{"valid", l.Subscription.Tenant, expiration(l.Subscription.ExpiryTimestampMs), l.Subscription.Plan})
case *stackstate_api.UnlicensedSubscription:
header = []string{"state", "reason"}
header = []string{stateKey, "reason"}
data = append(data, []interface{}{"unlicensed", l.Reason})
}

Expand Down
14 changes: 12 additions & 2 deletions cmd/monitor/monitor_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import (
"github.com/stackvista/stackstate-cli/internal/printer"
)

const (
statusColumn = "Status"
)

const (
nameKey = "Name"
nodesKey = "nodes"
identifierKey = "Identifier"
)

type ApplyArgs struct {
File string
}
Expand Down Expand Up @@ -45,7 +55,7 @@ func RunMonitorApplyCommand(args *ApplyArgs) di.CmdWithApiFn {

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"nodes": nodes,
nodesKey: nodes,
})
} else {
if len(nodes) == 0 {
Expand All @@ -61,7 +71,7 @@ func RunMonitorApplyCommand(args *ApplyArgs) di.CmdWithApiFn {
cli.Printer.Success(fmt.Sprintf("Applied <bold>%d</> monitor(s).", len(nodes)))
if len(nodes) > 0 {
cli.Printer.Table(printer.TableData{
Header: []string{"Type", "Id", "Status", "Identifier", "Name"},
Header: []string{"Type", "Id", statusColumn, identifierKey, nameKey},
Data: tableData,
})
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/monitor/monitor_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"github.com/stackvista/stackstate-cli/internal/di"
)

const (
monitorKey = "monitor"
)

type CloneArgs struct {
IdArgs
NewName string
Expand Down Expand Up @@ -53,7 +57,7 @@ func RunMonitorCloneCommand(args *CloneArgs) di.CmdWithApiFn {

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"monitor": clonedMonitor,
monitorKey: clonedMonitor,
})
} else {
cli.Printer.Success(fmt.Sprintf("Monitor %d has been created", clonedMonitor.GetId()))
Expand Down
2 changes: 1 addition & 1 deletion cmd/monitor/monitor_disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func RunMonitorDisableCommand(args *IdArgs, status *sts.MonitorStatusValue) di.C

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"monitor": monitorPatchResult,
monitorKey: monitorPatchResult,
})
} else {
cli.Printer.Success(fmt.Sprintf("Monitor %s has been disabled", identifier))
Expand Down
6 changes: 3 additions & 3 deletions cmd/monitor/monitor_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func RunMonitorEditCommand(args *EditArgs) di.CmdWithApiFn {

if strings.Compare(orig, string(c)) == 0 {
if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{"nodes": []string{}, "message": "No changes made"})
cli.Printer.PrintJson(map[string]interface{}{nodesKey: []string{}, "message": "No changes made"})
} else {
cli.Printer.PrintWarn("No changes made")
}
Expand All @@ -119,7 +119,7 @@ func RunMonitorEditCommand(args *EditArgs) di.CmdWithApiFn {

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"nodes": nodes,
nodesKey: nodes,
})
} else {
tableData := make([][]interface{}, 0)
Expand All @@ -130,7 +130,7 @@ func RunMonitorEditCommand(args *EditArgs) di.CmdWithApiFn {
cli.Printer.Success(fmt.Sprintf("Updated <bold>%d</> monitor(s).", len(nodes)))
if len(nodes) > 0 {
cli.Printer.Table(printer.TableData{
Header: []string{"Type", "Id", "Status", "Identifier", "Name"},
Header: []string{"Type", "Id", statusColumn, identifierKey, nameKey},
Data: tableData,
})
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/monitor/monitor_enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func RunMonitorEnableCommand(args *IdArgs) di.CmdWithApiFn {

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"monitor": monitorPatchResult,
monitorKey: monitorPatchResult,
})
} else {
cli.Printer.Success(fmt.Sprintf("Monitor %s has been enabled", identifier))
Expand Down
2 changes: 1 addition & 1 deletion cmd/monitor/monitor_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func RunMonitorListCommand(
tableData = append(tableData, []interface{}{monitor.Id, monitor.Status, *monitor.Identifier, monitor.Name, monitor.FunctionId, monitor.Tags})
}
cli.Printer.Table(printer.TableData{
Header: []string{"Id", "Status", "Identifier", "Name", "Function Id", "Tags"},
Header: []string{"Id", statusColumn, identifierKey, nameKey, "Function Id", "Tags"},
Data: tableData,
MissingTableDataMsg: printer.NotFoundMsg{Types: "monitors"},
})
Expand Down
14 changes: 9 additions & 5 deletions cmd/rbac/rbac_describe_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"github.com/stackvista/stackstate-cli/pkg/pflags"
)

const (
permissionsKey = "permissions"
)

type DescribePermissionsArgs struct {
Subject string
Permission string
Expand Down Expand Up @@ -69,14 +73,14 @@ func RunDescribePermissionsCommand(args *DescribePermissionsArgs) di.CmdWithApiF
if cli.IsJson() {
if sourceStrings != nil {
cli.Printer.PrintJson(map[string]interface{}{
"subject": description.SubjectHandle,
"permissions": description.Permissions,
"sources": sourceStrings,
Subject: description.SubjectHandle,
permissionsKey: description.Permissions,
"sources": sourceStrings,
})
} else {
cli.Printer.PrintJson(map[string]interface{}{
"subject": description.SubjectHandle,
"permissions": description.Permissions,
Subject: description.SubjectHandle,
permissionsKey: description.Permissions,
})
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/rbac/rbac_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func RunGrantPermissionsCommand(args *GrantPermissionsArgs) di.CmdWithApiFn {

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"subject": description.SubjectHandle,
"permissions": description.Permissions,
Subject: description.SubjectHandle,
permissionsKey: description.Permissions,
})
} else {
cli.Printer.Successf("Granted permission '%s' on '%s' to subject '%s'", args.Permission, args.Resource, args.Subject)
Expand Down
2 changes: 1 addition & 1 deletion cmd/rbac/rbac_list_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func RunListPermissionsCommand(cmd *cobra.Command, cli *di.Deps, api *stackstate

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"permissions": permissions.Permissions,
permissionsKey: permissions.Permissions,
})
} else {
cli.Printer.Successf("Available permissions: %s", strings.Join(permissions.Permissions, ", "))
Expand Down
4 changes: 2 additions & 2 deletions cmd/rbac/rbac_revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func RunRevokePermissionsCommand(args *RevokePermissionsArgs) di.CmdWithApiFn {

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"subject": description.SubjectHandle,
"permissions": description.Permissions,
Subject: description.SubjectHandle,
permissionsKey: description.Permissions,
})
} else {
cli.Printer.Successf("Revoked permission '%s' on '%s' from subject '%s'", args.Permission, args.Resource, args.Subject)
Expand Down
Loading
Loading