Skip to content

Commit

Permalink
chore: remove all things related to config query (#680)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored Apr 19, 2024
1 parent d76e4a9 commit 9cff987
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 320 deletions.
15 changes: 0 additions & 15 deletions config/config.go

This file was deleted.

1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ require (
github.com/spf13/pflag v1.0.5
github.com/timberio/go-datemath v0.1.0
github.com/xeipuuv/gojsonschema v1.2.0
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
github.com/zclconf/go-cty v1.14.1
go.opentelemetry.io/otel v1.22.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.22.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1430,8 +1430,6 @@ github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMx
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 h1:zzrxE1FKn5ryBNl9eKOeqQ58Y/Qpo3Q9QNxKHX5uzzQ=
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2/go.mod h1:hzfGeIUDq/j97IG+FhNqkowIyEcD88LrW6fyU3K3WqY=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
1 change: 0 additions & 1 deletion hack/migrate/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 // indirect
github.com/yuin/gopher-lua v1.1.0 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
go.opencensus.io v0.24.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions hack/migrate/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1402,8 +1402,6 @@ github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 h1:zzrxE1FKn5ryBNl9eKOeqQ58Y/Qpo3Q9QNxKHX5uzzQ=
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2/go.mod h1:hzfGeIUDq/j97IG+FhNqkowIyEcD88LrW6fyU3K3WqY=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
65 changes: 0 additions & 65 deletions query/config.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package query

import (
gocontext "context"
"database/sql"
"fmt"

"github.com/flanksource/duty/context"
"github.com/flanksource/duty/models"
"github.com/flanksource/duty/types"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
)

func GetConfigsByIDs(ctx context.Context, ids []uuid.UUID) ([]models.ConfigItem, error) {
Expand Down Expand Up @@ -72,67 +68,6 @@ func FindConfigIDsByResourceSelector(ctx context.Context, resourceSelectors ...t
return allConfigs, nil
}

// Query executes a SQL query against the "config_" tables in the database.
func Config(ctx context.Context, sqlQuery string) ([]map[string]any, error) {
if isValid, err := validateTablesInQuery(sqlQuery, "config_"); err != nil {
return nil, err
} else if !isValid {
return nil, fmt.Errorf("query references restricted tables: %w", err)
}

return query(ctx, ctx.Pool(), sqlQuery)
}

// query runs the given SQL query against the provided db connection.
// The rows are returned as a map of columnName=>columnValue.
func query(ctx context.Context, conn *pgxpool.Pool, query string) ([]map[string]any, error) {
if _, ok := ctx.Deadline(); !ok {
var cancel gocontext.CancelFunc
ctx, cancel = ctx.WithTimeout(DefaultQueryTimeout)
defer cancel()
}

tx, err := conn.BeginTx(ctx, pgx.TxOptions{AccessMode: pgx.ReadOnly})
if err != nil {
return nil, fmt.Errorf("failed to begin db transaction: %w", err)
}
defer tx.Rollback(ctx) //nolint:errcheck

rows, err := tx.Query(ctx, query)
if err != nil {
return nil, fmt.Errorf("failed to query: %w", err)
}
defer rows.Close()

columns := rows.FieldDescriptions()
results := make([]map[string]any, 0)
for rows.Next() {
values := make([]any, len(columns))
valuePtrs := make([]any, len(columns))
for i := range columns {
valuePtrs[i] = &values[i]
}

if err := rows.Scan(valuePtrs...); err != nil {
return nil, fmt.Errorf("error scaning row: %w", err)
}

row := make(map[string]any)
for i, col := range columns {
row[col.Name] = values[i]
}

results = append(results, row)
}

err = rows.Err()
if err != nil {
return nil, err
}

return results, nil
}

func FindConfigForComponent(ctx context.Context, componentID, configType string) ([]models.ConfigItem, error) {
db := ctx.DB()
relationshipQuery := db.Table("config_component_relationships").
Expand Down
90 changes: 0 additions & 90 deletions query/config_query_validate.go

This file was deleted.

111 changes: 0 additions & 111 deletions query/config_test.go

This file was deleted.

33 changes: 0 additions & 33 deletions tests/pkg_config_test.go

This file was deleted.

0 comments on commit 9cff987

Please sign in to comment.