diff --git a/core/controllers/database_v2.go b/core/controllers/database_v2.go index b23eaf09..771cee8d 100644 --- a/core/controllers/database_v2.go +++ b/core/controllers/database_v2.go @@ -12,20 +12,19 @@ import ( func PostDatabase(c *gin.Context) { // data source var payload struct { - Name string `json:"name"` - Type string `json:"type"` - Description string `json:"description"` - Host string `json:"host"` - Port int `json:"port"` - Url string `json:"url"` - Hosts []string `json:"hosts"` - Database string `json:"database"` - Username string `json:"username"` - Password string `json:"-,omitempty"` - ConnectType string `json:"connect_type"` - Status string `json:"status"` - Error string `json:"error"` - Extra map[string]string `json:"extra,omitempty"` + Name string `json:"name"` + Type string `json:"type"` + Description string `json:"description"` + Host string `json:"host"` + Port int `json:"port"` + Url string `json:"url"` + Hosts []string `json:"hosts"` + Database string `json:"database"` + Username string `json:"username"` + Password string `json:"-,omitempty"` + ConnectType string `json:"connect_type"` + Status string `json:"status"` + Error string `json:"error"` } if err := c.ShouldBindJSON(&payload); err != nil { HandleErrorBadRequest(c, err) @@ -41,14 +40,13 @@ func PostDatabase(c *gin.Context) { Description: payload.Description, Host: payload.Host, Port: payload.Port, - Url: payload.Url, + URI: payload.Url, Database: payload.Database, Username: payload.Username, Password: payload.Password, ConnectType: payload.ConnectType, Status: payload.Status, Error: payload.Error, - Extra: payload.Extra, } dataSource.SetCreated(u.Id) dataSource.SetUpdated(u.Id) diff --git a/core/models/models/v2/database_v2.go b/core/models/models/v2/database_v2.go index f990d00c..673bd92a 100644 --- a/core/models/models/v2/database_v2.go +++ b/core/models/models/v2/database_v2.go @@ -1,25 +1,46 @@ package models +import "time" + type DatabaseV2 struct { any `collection:"databases"` BaseModelV2[DatabaseV2] `bson:",inline"` - Name string `json:"name" bson:"name"` - DataSource string `json:"data_source" bson:"data_source"` - Type string `json:"type" bson:"type"` - Description string `json:"description" bson:"description"` - Host string `json:"host" bson:"host"` - Port int `json:"port" bson:"port"` - Url string `json:"url" bson:"url"` - Database string `json:"database" bson:"database"` - Username string `json:"username" bson:"username"` - Password string `json:"-,omitempty" bson:"password"` - ConnectType string `json:"connect_type" bson:"connect_type"` - Status string `json:"status" bson:"status"` - Error string `json:"error" bson:"error"` - Extra map[string]string `json:"extra,omitempty" bson:"extra,omitempty"` + Name string `json:"name" bson:"name"` + DataSource string `json:"data_source" bson:"data_source"` + Type string `json:"type" bson:"type"` + Description string `json:"description" bson:"description"` + Host string `json:"host" bson:"host"` + Port int `json:"port" bson:"port"` + URI string `json:"uri,omitempty" bson:"uri,omitempty"` + Database string `json:"database,omitempty" bson:"database,omitempty"` + Username string `json:"username,omitempty" bson:"username,omitempty"` + Password string `json:"-,omitempty" bson:"password,omitempty"` + ConnectType string `json:"connect_type,omitempty" bson:"connect_type,omitempty"` + Status string `json:"status" bson:"status"` + Error string `json:"error" bson:"error"` + Active bool `json:"active" bson:"active"` + ActiveAt time.Time `json:"active_ts" bson:"active_ts"` MongoParams *struct { AuthSource string `json:"auth_source,omitempty" bson:"auth_source,omitempty"` AuthMechanism string `json:"auth_mechanism,omitempty" bson:"auth_mechanism,omitempty"` } `json:"mongo_params,omitempty" bson:"mongo_params,omitempty"` + PostgresParams *struct { + SSLMode string `json:"ssl_mode,omitempty" bson:"ssl_mode,omitempty"` + } `json:"postgres_params,omitempty" bson:"postgres_params,omitempty"` + SnowflakeParams *struct { + Account string `json:"account,omitempty" bson:"account,omitempty"` + Schema string `json:"schema,omitempty" bson:"schema,omitempty"` + Warehouse string `json:"warehouse,omitempty" bson:"warehouse,omitempty"` + Role string `json:"role,omitempty" bson:"role,omitempty"` + } `json:"snowflake_params,omitempty" bson:"snowflake_params,omitempty"` + CassandraParams *struct { + Keyspace string `json:"keyspace,omitempty" bson:"keyspace,omitempty"` + } + HiveParams *struct { + Auth string `json:"auth,omitempty" bson:"auth,omitempty"` + } + RedisParams *struct { + DB int `json:"db,omitempty" bson:"db,omitempty"` + } } diff --git a/core/utils/mongo.go b/core/utils/mongo.go index 16070671..f576cec5 100644 --- a/core/utils/mongo.go +++ b/core/utils/mongo.go @@ -111,28 +111,13 @@ func getMongoClientV2(ctx context.Context, ds *models2.DatabaseV2) (c *mongo2.Cl // options var opts []mongo.ClientOption opts = append(opts, mongo.WithContext(ctx)) - opts = append(opts, mongo.WithUri(ds.Url)) + opts = append(opts, mongo.WithUri(ds.URI)) opts = append(opts, mongo.WithHost(ds.Host)) opts = append(opts, mongo.WithPort(ds.Port)) opts = append(opts, mongo.WithDb(ds.Database)) opts = append(opts, mongo.WithUsername(ds.Username)) opts = append(opts, mongo.WithPassword(ds.Password)) - // extra - if ds.Extra != nil { - // auth source - authSource, ok := ds.Extra["auth_source"] - if ok { - opts = append(opts, mongo.WithAuthSource(authSource)) - } - - // auth mechanism - authMechanism, ok := ds.Extra["auth_mechanism"] - if ok { - opts = append(opts, mongo.WithAuthMechanism(authMechanism)) - } - } - // client return mongo.GetMongoClient(opts...) }