Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Database typo #1707

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions gateway/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type DatabaseSchemas map[string]*DatabaseSchema // Key here is resource id --> c
type DatabaseRules map[string]*DatabaseRule // Key here is resource id --> clusterId--projectId--resourceType--dbAlias-tableName-rule

// DatabasePreparedQueries is a map which stores database prepared query information
type DatabasePreparedQueries map[string]*DatbasePreparedQuery // Key here is resource id --> clusterId--projectId--resourceType--dbAlias-prepareQueryId
type DatabasePreparedQueries map[string]*DatabasePreparedQuery // Key here is resource id --> clusterId--projectId--resourceType--dbAlias-prepareQueryId

// EventingSchemas is a map which stores eventing schema information
type EventingSchemas map[string]*EventingSchema // Key here is resource id --> clusterId--projectId--resourceType--schemaId
Expand Down Expand Up @@ -233,16 +233,16 @@ type CrudStub struct {
DBName string `json:"name,omitempty" yaml:"name" mapstructure:"name"` // name of the logical database or schema name according to the database type
Conn string `json:"conn,omitempty" yaml:"conn" mapstructure:"conn"`
Collections map[string]*TableRule `json:"collections,omitempty" yaml:"collections" mapstructure:"collections"` // The key here is table name
PreparedQueries map[string]*DatbasePreparedQuery `json:"preparedQueries,omitempty" yaml:"preparedQueries" mapstructure:"preparedQueries"`
PreparedQueries map[string]*DatabasePreparedQuery `json:"preparedQueries,omitempty" yaml:"preparedQueries" mapstructure:"preparedQueries"`
IsPrimary bool `json:"isPrimary" yaml:"isPrimary" mapstructure:"isPrimary"`
Enabled bool `json:"enabled" yaml:"enabled" mapstructure:"enabled"`
BatchTime int `json:"batchTime,omitempty" yaml:"batchTime" mapstructure:"batchTime"` // time in milli seconds
BatchRecords int `json:"batchRecords,omitempty" yaml:"batchRecords" mapstructure:"batchRecords"` // indicates number of records per batch
Limit int64 `json:"limit,omitempty" yaml:"limit" mapstructure:"limit"` // indicates number of records per batch
}

// DatbasePreparedQuery stores information of prepared query
type DatbasePreparedQuery struct {
// DatabasePreparedQuery stores information of prepared query
type DatabasePreparedQuery struct {
ID string `json:"id" yaml:"id" mapstructure:"id"`
SQL string `json:"sql" yaml:"sql" mapstructure:"sql"`
Rule *Rule `json:"rule" yaml:"rule" mapstructure:"rule"`
Expand Down
2 changes: 1 addition & 1 deletion gateway/config/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func GenerateEmptyProject(project *ProjectConfig) *Project {
DatabaseConfigs: make(map[string]*DatabaseConfig),
DatabaseSchemas: make(map[string]*DatabaseSchema),
DatabaseRules: make(map[string]*DatabaseRule),
DatabasePreparedQueries: make(map[string]*DatbasePreparedQuery),
DatabasePreparedQueries: make(map[string]*DatabasePreparedQuery),
EventingConfig: new(EventingConfig),
EventingSchemas: make(map[string]*EventingSchema),
EventingRules: make(map[string]*Rule),
Expand Down
6 changes: 3 additions & 3 deletions gateway/managers/syncman/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (s *Manager) validateResource(ctx context.Context, eventType string, resour
case config.ResourceDatabasePreparedQuery:
switch eventType {
case config.ResourceAddEvent, config.ResourceUpdateEvent:
value := new(config.DatbasePreparedQuery)
value := new(config.DatabasePreparedQuery)
if err := mapstructure.Decode(resource, value); err != nil {
return false, helpers.Logger.LogError(helpers.GetRequestID(ctx), fmt.Sprintf("invalid type provided for resource (%s) expecting (%v) got (%v)", resourceType, "config.Auth{}", reflect.TypeOf(resource)), nil, nil)
}
Expand Down Expand Up @@ -551,9 +551,9 @@ func updateResource(ctx context.Context, eventType string, globalConfig *config.
case config.ResourceDatabasePreparedQuery:
switch eventType {
case config.ResourceAddEvent, config.ResourceUpdateEvent:
value := new(config.DatbasePreparedQuery)
value := new(config.DatabasePreparedQuery)
if err := mapstructure.Decode(resource, value); err != nil {
return helpers.Logger.LogError(helpers.GetRequestID(ctx), fmt.Sprintf("invalid type provided for resource (%s) expecting (%v) got (%v)", resourceType, "config.DatbasePreparedQuery{}", reflect.TypeOf(resource)), nil, nil)
return helpers.Logger.LogError(helpers.GetRequestID(ctx), fmt.Sprintf("invalid type provided for resource (%s) expecting (%v) got (%v)", resourceType, "config.DatabasePreparedQuery{}", reflect.TypeOf(resource)), nil, nil)
}

if project.DatabasePreparedQueries == nil {
Expand Down
2 changes: 1 addition & 1 deletion gateway/managers/syncman/syncman_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (s *Manager) GetPreparedQuery(ctx context.Context, project, dbAlias, id str
}

// SetPreparedQueries sets database preparedqueries
func (s *Manager) SetPreparedQueries(ctx context.Context, project, dbAlias, id string, v *config.DatbasePreparedQuery, params model.RequestParams) (int, error) {
func (s *Manager) SetPreparedQueries(ctx context.Context, project, dbAlias, id string, v *config.DatabasePreparedQuery, params model.RequestParams) (int, error) {
// Check if the request has been hijacked
hookResponse := s.integrationMan.InvokeHook(ctx, params)
if hookResponse.CheckResponse() {
Expand Down
40 changes: 20 additions & 20 deletions gateway/managers/syncman/syncman_crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,33 +355,33 @@ func TestManager_GetPreparedQuery(t *testing.T) {
},
{
name: "dbAlias is empty",
s: &Manager{clusterID: "chicago", projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabasePreparedQueries: config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "id"): &config.DatbasePreparedQuery{DbAlias: "alias", ID: "id", SQL: "field"}}}}}},
s: &Manager{clusterID: "chicago", projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabasePreparedQueries: config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "id"): &config.DatabasePreparedQuery{DbAlias: "alias", ID: "id", SQL: "field"}}}}}},
args: args{ctx: context.Background(), dbAlias: "*", id: "id", project: "1"},
want: []interface{}{&config.DatbasePreparedQuery{ID: "id", DbAlias: "alias", SQL: "field"}},
want: []interface{}{&config.DatabasePreparedQuery{ID: "id", DbAlias: "alias", SQL: "field"}},
},
{
name: "dbAlias is not present in config",
s: &Manager{projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabasePreparedQueries: config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "id"): &config.DatbasePreparedQuery{DbAlias: "alias", ID: "id", SQL: "field"}}}}}},
s: &Manager{projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabasePreparedQueries: config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "id"): &config.DatabasePreparedQuery{DbAlias: "alias", ID: "id", SQL: "field"}}}}}},
args: args{ctx: context.Background(), dbAlias: "notAlias", id: "id", project: "1"},
wantErr: true,
},
{
name: "id is not empty but not present in prepared queries",
s: &Manager{projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabaseConfigs: config.DatabaseConfigs{config.GenerateResourceID("chicago", "1", config.ResourceDatabaseConfig, "alias"): &config.DatabaseConfig{DBName: "DBName", DbAlias: "alias"}}, DatabasePreparedQueries: config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "alias", "id"): &config.DatbasePreparedQuery{DbAlias: "alias", ID: "id", SQL: "field"}}}}}},
s: &Manager{projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabaseConfigs: config.DatabaseConfigs{config.GenerateResourceID("chicago", "1", config.ResourceDatabaseConfig, "alias"): &config.DatabaseConfig{DBName: "DBName", DbAlias: "alias"}}, DatabasePreparedQueries: config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "alias", "id"): &config.DatabasePreparedQuery{DbAlias: "alias", ID: "id", SQL: "field"}}}}}},
args: args{ctx: context.Background(), dbAlias: "alias", id: "notKey", project: "1"},
wantErr: true,
},
{
name: "id is not empty and present in prepared queries",
s: &Manager{clusterID: "chicago", projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabaseConfigs: config.DatabaseConfigs{config.GenerateResourceID("chicago", "1", config.ResourceDatabaseConfig, "alias"): &config.DatabaseConfig{DBName: "DBName", DbAlias: "alias"}}, DatabasePreparedQueries: config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "alias", "key"): &config.DatbasePreparedQuery{DbAlias: "alias", ID: "key", SQL: "field"}}}}}},
s: &Manager{clusterID: "chicago", projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabaseConfigs: config.DatabaseConfigs{config.GenerateResourceID("chicago", "1", config.ResourceDatabaseConfig, "alias"): &config.DatabaseConfig{DBName: "DBName", DbAlias: "alias"}}, DatabasePreparedQueries: config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "alias", "key"): &config.DatabasePreparedQuery{DbAlias: "alias", ID: "key", SQL: "field"}}}}}},
args: args{ctx: context.Background(), dbAlias: "alias", id: "key", project: "1"},
want: []interface{}{&config.DatbasePreparedQuery{ID: "key", DbAlias: "alias", SQL: "field"}},
want: []interface{}{&config.DatabasePreparedQuery{ID: "key", DbAlias: "alias", SQL: "field"}},
},
{
name: "id is empty",
s: &Manager{clusterID: "chicago", projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabaseConfigs: config.DatabaseConfigs{config.GenerateResourceID("chicago", "1", config.ResourceDatabaseConfig, "alias"): &config.DatabaseConfig{DBName: "DBName", DbAlias: "alias"}}, DatabasePreparedQueries: config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "alias", "key"): &config.DatbasePreparedQuery{DbAlias: "alias", ID: "key", SQL: "field"}}}}}},
s: &Manager{clusterID: "chicago", projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabaseConfigs: config.DatabaseConfigs{config.GenerateResourceID("chicago", "1", config.ResourceDatabaseConfig, "alias"): &config.DatabaseConfig{DBName: "DBName", DbAlias: "alias"}}, DatabasePreparedQueries: config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "alias", "key"): &config.DatabasePreparedQuery{DbAlias: "alias", ID: "key", SQL: "field"}}}}}},
args: args{ctx: context.Background(), dbAlias: "alias", id: "*", project: "1"},
want: []interface{}{&config.DatbasePreparedQuery{ID: "key", DbAlias: "alias", SQL: "field"}},
want: []interface{}{&config.DatabasePreparedQuery{ID: "key", DbAlias: "alias", SQL: "field"}},
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -411,7 +411,7 @@ func TestManager_SetPreparedQueries(t *testing.T) {
project string
dbAlias string
id string
v *config.DatbasePreparedQuery
v *config.DatabasePreparedQuery
}
tests := []struct {
name string
Expand All @@ -423,24 +423,24 @@ func TestManager_SetPreparedQueries(t *testing.T) {
}{
{
name: "unable to get project",
s: &Manager{projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabasePreparedQueries: config.DatabasePreparedQueries{"resourceId": &config.DatbasePreparedQuery{DbAlias: "alias", ID: "id", SQL: "field"}}}}}},
args: args{ctx: context.Background(), dbAlias: "alias", id: "id", project: "2", v: &config.DatbasePreparedQuery{ID: "queryID", SQL: "field"}},
s: &Manager{projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabasePreparedQueries: config.DatabasePreparedQueries{"resourceId": &config.DatabasePreparedQuery{DbAlias: "alias", ID: "id", SQL: "field"}}}}}},
args: args{ctx: context.Background(), dbAlias: "alias", id: "id", project: "2", v: &config.DatabasePreparedQuery{ID: "queryID", SQL: "field"}},
wantErr: true,
},
{
name: "database not present in config",
s: &Manager{projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabasePreparedQueries: config.DatabasePreparedQueries{"resourceId": &config.DatbasePreparedQuery{DbAlias: "alias", ID: "id", SQL: "field"}}}}}},
args: args{ctx: context.Background(), dbAlias: "notAlias", id: "id", project: "1", v: &config.DatbasePreparedQuery{ID: "queryID", SQL: "field"}},
s: &Manager{projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabasePreparedQueries: config.DatabasePreparedQueries{"resourceId": &config.DatabasePreparedQuery{DbAlias: "alias", ID: "id", SQL: "field"}}}}}},
args: args{ctx: context.Background(), dbAlias: "notAlias", id: "id", project: "1", v: &config.DatabasePreparedQuery{ID: "queryID", SQL: "field"}},
wantErr: true,
},
{
name: "unable to set crud config",
s: &Manager{clusterID: "chicago", projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{ProjectConfig: &config.ProjectConfig{ID: "1"}, DatabaseConfigs: map[string]*config.DatabaseConfig{"resourceId": {DbAlias: "alias"}}}}}},
args: args{ctx: context.Background(), dbAlias: "alias", id: "queryID", project: "1", v: &config.DatbasePreparedQuery{ID: "queryID", SQL: "field"}},
args: args{ctx: context.Background(), dbAlias: "alias", id: "queryID", project: "1", v: &config.DatabasePreparedQuery{ID: "queryID", SQL: "field"}},
modulesMockArgs: []mockArgs{
{
method: "SetDatabasePreparedQueryConfig",
args: []interface{}{mock.Anything, "1", config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "alias", "queryID"): &config.DatbasePreparedQuery{DbAlias: "alias", ID: "queryID", SQL: "field"}}},
args: []interface{}{mock.Anything, "1", config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "alias", "queryID"): &config.DatabasePreparedQuery{DbAlias: "alias", ID: "queryID", SQL: "field"}}},
paramsReturned: []interface{}{errors.New("unable to set db config")},
},
},
Expand All @@ -449,18 +449,18 @@ func TestManager_SetPreparedQueries(t *testing.T) {
{
name: "prepared queries are set",
s: &Manager{clusterID: "chicago", projectConfig: &config.Config{Projects: config.Projects{"1": &config.Project{DatabaseConfigs: config.DatabaseConfigs{config.GenerateResourceID("chicago", "1", config.ResourceDatabaseConfig, "alias"): &config.DatabaseConfig{DBName: "DBName", DbAlias: "alias"}}, ProjectConfig: &config.ProjectConfig{ID: "1"}}}}},
args: args{ctx: context.Background(), dbAlias: "alias", id: "queryID", project: "1", v: &config.DatbasePreparedQuery{ID: "queryID", SQL: "field"}},
args: args{ctx: context.Background(), dbAlias: "alias", id: "queryID", project: "1", v: &config.DatabasePreparedQuery{ID: "queryID", SQL: "field"}},
modulesMockArgs: []mockArgs{
{
method: "SetDatabasePreparedQueryConfig",
args: []interface{}{mock.Anything, "1", config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "alias", "queryID"): &config.DatbasePreparedQuery{DbAlias: "alias", ID: "queryID", SQL: "field"}}},
args: []interface{}{mock.Anything, "1", config.DatabasePreparedQueries{config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "alias", "queryID"): &config.DatabasePreparedQuery{DbAlias: "alias", ID: "queryID", SQL: "field"}}},
paramsReturned: []interface{}{nil},
},
},
storeMockArgs: []mockArgs{
{
method: "SetResource",
args: []interface{}{context.Background(), config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "alias", "queryID"), &config.DatbasePreparedQuery{DbAlias: "alias", ID: "queryID", SQL: "field"}},
args: []interface{}{context.Background(), config.GenerateResourceID("chicago", "1", config.ResourceDatabasePreparedQuery, "alias", "queryID"), &config.DatabasePreparedQuery{DbAlias: "alias", ID: "queryID", SQL: "field"}},
paramsReturned: []interface{}{nil},
},
},
Expand Down Expand Up @@ -561,7 +561,7 @@ func TestManager_RemovePreparedQueries(t *testing.T) {
},
},
DatabasePreparedQueries: config.DatabasePreparedQueries{
config.GenerateResourceID("chicago", "myproject", config.ResourceDatabasePreparedQuery, "db", "id"): &config.DatbasePreparedQuery{
config.GenerateResourceID("chicago", "myproject", config.ResourceDatabasePreparedQuery, "db", "id"): &config.DatabasePreparedQuery{
DbAlias: "db",
ID: "id",
},
Expand Down Expand Up @@ -594,7 +594,7 @@ func TestManager_RemovePreparedQueries(t *testing.T) {
},
},
DatabasePreparedQueries: config.DatabasePreparedQueries{
config.GenerateResourceID("chicago", "myproject", config.ResourceDatabasePreparedQuery, "db", "fetchInstruments"): &config.DatbasePreparedQuery{
config.GenerateResourceID("chicago", "myproject", config.ResourceDatabasePreparedQuery, "db", "fetchInstruments"): &config.DatabasePreparedQuery{
DbAlias: "db",
SQL: "select * from instruments;",
ID: "fetchInstruments",
Expand Down
Loading