-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1426 from tailwarden/develop
v3.1.17 release 🚀
- Loading branch information
Showing
32 changed files
with
3,055 additions
and
2,263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/tailwarden/komiser/models" | ||
"github.com/tailwarden/komiser/repository" | ||
) | ||
|
||
func (ctrl *Controller) ListAccounts(c context.Context) (accounts []models.Account, err error) { | ||
_, err = ctrl.repo.HandleQuery(c, repository.ListKey, &accounts, nil) | ||
return | ||
} | ||
|
||
func (ctrl *Controller) CountResources(c context.Context, provider, name string) (output totalOutput, err error) { | ||
conditions := [][3]string{} | ||
if provider != "" { | ||
conditions = append(conditions, [3]string{"provider", "=", provider}) | ||
} | ||
if name != "" { | ||
conditions = append(conditions, [3]string{"account", "=", name}) | ||
} | ||
_, 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() | ||
} | ||
|
||
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() | ||
} | ||
|
||
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}}) | ||
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}}) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/tailwarden/komiser/models" | ||
"github.com/tailwarden/komiser/repository" | ||
) | ||
|
||
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() | ||
} | ||
|
||
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}}) | ||
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}}) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
) | ||
|
||
type totalOutput struct { | ||
Total int `bun:"total" json:"total"` | ||
} | ||
|
||
type costOutput struct { | ||
Total float64 `bun:"sum" json:"total"` | ||
} | ||
|
||
type regionOutput struct { | ||
Region string `bun:"region" json:"region"` | ||
} | ||
|
||
type providerOutput struct { | ||
Provider string `bun:"provider" json:"provider"` | ||
} | ||
|
||
type serviceOutput struct { | ||
Service string `bun:"service" json:"service"` | ||
} | ||
|
||
type accountOutput struct { | ||
Account string `bun:"account" json:"account"` | ||
} | ||
|
||
type Repository interface { | ||
HandleQuery(context.Context, string, interface{}, [][3]string) (sql.Result, error) | ||
} | ||
|
||
type Controller struct { | ||
repo Repository | ||
} | ||
|
||
func New(repo Repository) *Controller { | ||
return &Controller{repo} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/tailwarden/komiser/models" | ||
"github.com/tailwarden/komiser/repository" | ||
) | ||
|
||
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}}) | ||
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, "[]") + ")"}}) | ||
return | ||
} | ||
|
||
func (ctrl *Controller) ListResources(c context.Context) (resources []models.Resource, err error) { | ||
_, 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, ®ions, [][3]string{}) | ||
return | ||
} | ||
|
||
func (ctrl *Controller) CountRegionsFromAccounts(c context.Context) (accounts totalOutput, err error) { | ||
_, 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{}) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/tailwarden/komiser/models" | ||
"github.com/tailwarden/komiser/repository" | ||
) | ||
|
||
func (ctrl *Controller) LocationStatsBreakdown(c context.Context) (groups []models.OutputResources, err error) { | ||
_, 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, ®ions, nil) | ||
return | ||
} | ||
|
||
func (ctrl *Controller) ListProviders(c context.Context) (providers []providerOutput, err error) { | ||
_, 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) | ||
return | ||
} | ||
|
||
func (ctrl *Controller) ListAccountNames(c context.Context) (accounts []accountOutput, err error) { | ||
_, err = ctrl.repo.HandleQuery(c, repository.ListAccountsKey, &accounts, nil) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/tailwarden/komiser/models" | ||
"github.com/tailwarden/komiser/repository" | ||
) | ||
|
||
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)}}) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/tailwarden/komiser/models" | ||
"github.com/tailwarden/komiser/repository" | ||
) | ||
|
||
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}}) | ||
return | ||
} | ||
|
||
func (ctrl *Controller) ListViews(c context.Context) (views []models.View, err error) { | ||
_, 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() | ||
} | ||
|
||
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}}) | ||
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}}) | ||
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}}) | ||
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}}) | ||
return | ||
} |
Oops, something went wrong.