Skip to content

Commit

Permalink
Merge pull request #1442 from tailwarden/develop
Browse files Browse the repository at this point in the history
v3.1.18 release 🚀
  • Loading branch information
Azanul authored Jun 19, 2024
2 parents 3edf7c6 + 909a57b commit 61a4e4c
Show file tree
Hide file tree
Showing 17 changed files with 1,076 additions and 789 deletions.
22 changes: 8 additions & 14 deletions controller/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func (ctrl *Controller) ListAccounts(c context.Context) (accounts []models.Account, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &accounts, nil)
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &accounts, nil, "")
return
}

Expand All @@ -20,32 +20,26 @@ func (ctrl *Controller) CountResources(c context.Context, provider, name string)
if name != "" {
conditions = append(conditions, [3]string{"account", "=", name})
}
_, err = ctrl.repo.HandleQuery(c, repository.ResourceCountKey, &output, conditions)
_, err = ctrl.repo.HandleQuery(c, repository.ResourceCountKey, &output, conditions, "")
return
}

func (ctrl *Controller) InsertAccount(c context.Context, account models.Account) (lastId int64, err error) {
result, err := ctrl.repo.HandleQuery(c, repository.InsertKey, &account, nil)
if err != nil {
return
}
return result.LastInsertId()
lastId, err = ctrl.repo.HandleQuery(c, repository.InsertKey, &account, nil, "")
return
}

func (ctrl *Controller) RescanAccount(c context.Context, account *models.Account, accountId string) (rows int64, err error) {
res, err := ctrl.repo.HandleQuery(c, repository.ReScanAccountKey, account, [][3]string{{"id", "=", accountId}, {"status", "=", "CONNECTED"}})
if err != nil {
return 0, err
}
return res.RowsAffected()
rows, err = ctrl.repo.HandleQuery(c, repository.ReScanAccountKey, account, [][3]string{{"id", "=", accountId}, {"status", "=", "CONNECTED"}}, "")
return
}

func (ctrl *Controller) DeleteAccount(c context.Context, accountId string) (err error) {
_, err = ctrl.repo.HandleQuery(c, repository.DeleteKey, new(models.Account), [][3]string{{"id", "=", accountId}})
_, err = ctrl.repo.HandleQuery(c, repository.DeleteKey, new(models.Account), [][3]string{{"id", "=", accountId}}, "")
return
}

func (ctrl *Controller) UpdateAccount(c context.Context, account models.Account, accountId string) (err error) {
_, err = ctrl.repo.HandleQuery(c, repository.UpdateAccountKey, &account, [][3]string{{"id", "=", accountId}})
_, err = ctrl.repo.HandleQuery(c, repository.UpdateAccountKey, &account, [][3]string{{"id", "=", accountId}}, "")
return
}
11 changes: 4 additions & 7 deletions controller/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ import (
)

func (ctrl *Controller) InsertAlert(c context.Context, alert models.Alert) (alertId int64, err error) {
result, err := ctrl.repo.HandleQuery(c, repository.InsertKey, &alert, nil)
if err != nil {
return
}
return result.LastInsertId()
alertId, err = ctrl.repo.HandleQuery(c, repository.InsertKey, &alert, nil, "")
return
}

func (ctrl *Controller) UpdateAlert(c context.Context, alert models.Alert, alertId string) (err error) {
_, err = ctrl.repo.HandleQuery(c, repository.UpdateAlertKey, &alert, [][3]string{{"id", "=", alertId}})
_, err = ctrl.repo.HandleQuery(c, repository.UpdateAlertKey, &alert, [][3]string{{"id", "=", alertId}}, "")
return
}

func (ctrl *Controller) DeleteAlert(c context.Context, alertId string) (err error) {
_, err = ctrl.repo.HandleQuery(c, repository.DeleteKey, new(models.Alert), [][3]string{{"id", "=", alertId}})
_, err = ctrl.repo.HandleQuery(c, repository.DeleteKey, new(models.Alert), [][3]string{{"id", "=", alertId}}, "")
return
}
6 changes: 4 additions & 2 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package controller

import (
"context"
"database/sql"

"github.com/tailwarden/komiser/models"
)

type totalOutput struct {
Expand Down Expand Up @@ -30,7 +31,8 @@ type accountOutput struct {
}

type Repository interface {
HandleQuery(context.Context, string, interface{}, [][3]string) (sql.Result, error)
HandleQuery(context.Context, string, interface{}, [][3]string, string) (int64, error)
GenerateFilterQuery(view models.View, queryTitle string, arguments []int64, queryParameter string) ([]string, error)
}

type Controller struct {
Expand Down
44 changes: 38 additions & 6 deletions controller/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,63 @@ import (
)

func (ctrl *Controller) GetResource(c context.Context, resourceId string) (resource models.Resource, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &resource, [][3]string{{"resource_id", "=", resourceId}})
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &resource, [][3]string{{"resource_id", "=", resourceId}}, "")
return
}

func (ctrl *Controller) GetResources(c context.Context, idList string) (resources []models.Resource, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &resources, [][3]string{{"id", "IN", "(" + strings.Trim(idList, "[]") + ")"}})
resources = make([]models.Resource, 0)
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &resources, [][3]string{{"id", "IN", "(" + strings.Trim(idList, "[]") + ")"}}, "")
return
}

func (ctrl *Controller) ListResources(c context.Context) (resources []models.Resource, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &resources, [][3]string{})
resources = make([]models.Resource, 0)
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &resources, [][3]string{}, "")
return
}

func (ctrl *Controller) CountRegionsFromResources(c context.Context) (regions totalOutput, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.RegionResourceCountKey, &regions, [][3]string{})
_, err = ctrl.repo.HandleQuery(c, repository.RegionResourceCountKey, &regions, [][3]string{}, "")
return
}

func (ctrl *Controller) CountRegionsFromAccounts(c context.Context) (accounts totalOutput, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.AccountsResourceCountKey, &accounts, [][3]string{})
_, err = ctrl.repo.HandleQuery(c, repository.AccountsResourceCountKey, &accounts, [][3]string{}, "")
return
}

func (ctrl *Controller) SumResourceCost(c context.Context) (cost costOutput, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.ResourceCostSumKey, &cost, [][3]string{})
_, err = ctrl.repo.HandleQuery(c, repository.ResourceCostSumKey, &cost, [][3]string{}, "")
return
}

func (ctrl *Controller) ResourceWithFilter(c context.Context, view models.View, arguments []int64, queryParameter string) (resources []models.Resource, err error) {
resources = make([]models.Resource, 0)
queries, err := ctrl.repo.GenerateFilterQuery(view, repository.ListResourceWithFilter, arguments, queryParameter)
if err != nil {
return
}
for _, query := range queries {
_, err = ctrl.repo.HandleQuery(c, repository.ListResourceWithFilter, &resources, [][3]string{}, query)
if err != nil {
return
}
}
return
}

func (ctrl *Controller) RelationWithFilter(c context.Context, view models.View, arguments []int64, queryParameter string) (resources []models.Resource, err error) {
resources = make([]models.Resource, 0)
queries, err := ctrl.repo.GenerateFilterQuery(view, repository.ListRelationWithFilter, arguments, queryParameter)
if err != nil {
return
}
for _, query := range queries {
_, err = ctrl.repo.HandleQuery(c, repository.ListRelationWithFilter, &resources, [][3]string{}, query)
if err != nil {
return
}
}
return
}
34 changes: 29 additions & 5 deletions controller/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,50 @@ import (
)

func (ctrl *Controller) LocationStatsBreakdown(c context.Context) (groups []models.OutputResources, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.LocationBreakdownStatKey, &groups, [][3]string{})
_, err = ctrl.repo.HandleQuery(c, repository.LocationBreakdownStatKey, &groups, [][3]string{}, "")
return
}

func (ctrl *Controller) ListRegions(c context.Context) (regions []regionOutput, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.ListRegionsKey, &regions, nil)
_, err = ctrl.repo.HandleQuery(c, repository.ListRegionsKey, &regions, nil, "")
return
}

func (ctrl *Controller) ListProviders(c context.Context) (providers []providerOutput, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.ListProvidersKey, &providers, nil)
_, err = ctrl.repo.HandleQuery(c, repository.ListProvidersKey, &providers, nil, "")
return
}

func (ctrl *Controller) ListServices(c context.Context) (services []serviceOutput, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.ListServicesKey, &services, nil)
_, err = ctrl.repo.HandleQuery(c, repository.ListServicesKey, &services, nil, "")
return
}

func (ctrl *Controller) ListAccountNames(c context.Context) (accounts []accountOutput, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.ListAccountsKey, &accounts, nil)
_, err = ctrl.repo.HandleQuery(c, repository.ListAccountsKey, &accounts, nil, "")
return
}

func (ctrl *Controller) StatsWithFilter(c context.Context, view models.View, arguments []int64, queryParameter string) (regionCount totalOutput, resourceCount totalOutput, costCount costOutput, err error) {
queries, err := ctrl.repo.GenerateFilterQuery(view, repository.ListStatsWithFilter, arguments, queryParameter)
if err != nil {
return
}
_, err = ctrl.repo.HandleQuery(c, repository.ListStatsWithFilter, &regionCount, [][3]string{}, queries[0])
if err != nil {
return
}

// for resource count
_, err = ctrl.repo.HandleQuery(c, repository.ListStatsWithFilter, &resourceCount, [][3]string{}, queries[1])
if err != nil {
return
}

// for cost sum
_, err = ctrl.repo.HandleQuery(c, repository.ListStatsWithFilter, &costCount, [][3]string{}, queries[2])
if err != nil {
return
}
return
}
2 changes: 1 addition & 1 deletion controller/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import (

func (ctrl *Controller) UpdateTags(c context.Context, tags []models.Tag, resourceId string) (resource models.Resource, err error) {
resource.Tags = tags
_, err = ctrl.repo.HandleQuery(c, repository.UpdateTagsKey, &resource, [][3]string{{"id", "=", fmt.Sprint(resourceId)}})
_, err = ctrl.repo.HandleQuery(c, repository.UpdateTagsKey, &resource, [][3]string{{"id", "=", fmt.Sprint(resourceId)}}, "")
return
}
19 changes: 8 additions & 11 deletions controller/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,36 @@ import (
)

func (ctrl *Controller) GetView(c context.Context, viewId string) (view models.View, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &view, [][3]string{{"id", "=", viewId}})
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &view, [][3]string{{"id", "=", viewId}}, "")
return
}

func (ctrl *Controller) ListViews(c context.Context) (views []models.View, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &views, [][3]string{})
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &views, [][3]string{}, "")
return
}

func (ctrl *Controller) InsertView(c context.Context, view models.View) (viewId int64, err error) {
result, err := ctrl.repo.HandleQuery(c, repository.InsertKey, &view, nil)
if err != nil {
return
}
return result.LastInsertId()
viewId, err = ctrl.repo.HandleQuery(c, repository.InsertKey, &view, nil, "")
return
}

func (ctrl *Controller) UpdateView(c context.Context, view models.View, viewId string) (err error) {
_, err = ctrl.repo.HandleQuery(c, repository.UpdateViewKey, &view, [][3]string{{"id", "=", viewId}})
_, err = ctrl.repo.HandleQuery(c, repository.UpdateViewKey, &view, [][3]string{{"id", "=", viewId}}, "")
return
}

func (ctrl *Controller) DeleteView(c context.Context, viewId string) (err error) {
_, err = ctrl.repo.HandleQuery(c, repository.DeleteKey, new(models.View), [][3]string{{"id", "=", viewId}})
_, err = ctrl.repo.HandleQuery(c, repository.DeleteKey, new(models.View), [][3]string{{"id", "=", viewId}}, "")
return
}

func (ctrl *Controller) UpdateViewExclude(c context.Context, view models.View, viewId string) (err error) {
_, err = ctrl.repo.HandleQuery(c, repository.UpdateViewExcludeKey, &view, [][3]string{{"id", "=", viewId}})
_, err = ctrl.repo.HandleQuery(c, repository.UpdateViewExcludeKey, &view, [][3]string{{"id", "=", viewId}}, "")
return
}

func (ctrl *Controller) ListViewAlerts(c context.Context, viewId string) (alerts []models.Alert, err error) {
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &alerts, [][3]string{{"view_id", "=", viewId}})
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &alerts, [][3]string{{"view_id", "=", viewId}}, "")
return
}
3 changes: 1 addition & 2 deletions dashboard/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Sentry from '@sentry/react';
import classNames from 'classnames';
import { BrowserTracing } from '@sentry/tracing';
import { useRouter } from 'next/router';
import { ReactNode, useEffect } from 'react';
import settingsService from '@services/settingsService';
Expand Down Expand Up @@ -47,7 +46,7 @@ function Layout({ children }: LayoutProps) {
if (telemetry?.telemetry_enabled && environment.production) {
Sentry.init({
dsn: environment.SENTRY_URL,
integrations: [new BrowserTracing()],
integrations: [Sentry.browserTracingIntegration()],

// We recommend adjusting this value in production, or using tracesSampler
// for finer control
Expand Down
Loading

0 comments on commit 61a4e4c

Please sign in to comment.