mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-23 16:20:29 +00:00
works
This commit is contained in:
@@ -20,6 +20,7 @@ type Hook struct {
|
||||
Match func(string) bool
|
||||
Decode func(name string, config any) (database.Connector, error)
|
||||
Name string
|
||||
Field configure.Updater
|
||||
}
|
||||
|
||||
var hooks = make([]Hook, 0)
|
||||
@@ -30,11 +31,13 @@ func init() {
|
||||
Match: postgres.NameMatcher,
|
||||
Decode: postgres.DecodeConfig,
|
||||
Name: postgres.Name,
|
||||
Field: postgres.Field,
|
||||
},
|
||||
Hook{
|
||||
Match: gosql.NameMatcher,
|
||||
Decode: gosql.DecodeConfig,
|
||||
Name: gosql.Name,
|
||||
Field: gosql.Field,
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -48,18 +51,17 @@ type Config struct {
|
||||
// Fields implements [configure.StructUpdater].
|
||||
func (c *Config) Fields() []configure.Updater {
|
||||
dialects := configure.OneOf{
|
||||
FieldName: "dialect",
|
||||
Description: "The database dialect Zitadel connects to",
|
||||
SubFields: []configure.Updater{},
|
||||
}
|
||||
for _, hook := range hooks {
|
||||
value := c.Dialects[hook.Name]
|
||||
dialects.SubFields = append(dialects.SubFields, &configure.Field[any]{
|
||||
if hook.Field == nil {
|
||||
panic("hook must configure its config fields")
|
||||
}
|
||||
dialects.SubFields = append(dialects.SubFields, &configure.Struct{
|
||||
FieldName: hook.Name,
|
||||
Default: nil,
|
||||
Description: fmt.Sprintf("Configuration for connection string for %s", hook.Name),
|
||||
Version: config.V3,
|
||||
Value: &value,
|
||||
Description: fmt.Sprintf("Configuration for %s", hook.Name),
|
||||
SubFields: []configure.Updater{hook.Field},
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -6,12 +6,25 @@ import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/cmd/configure"
|
||||
"github.com/zitadel/zitadel/backend/storage/database"
|
||||
)
|
||||
|
||||
var (
|
||||
_ database.Connector = (*Config)(nil)
|
||||
Name = "gosql"
|
||||
_ database.Connector = (*Config)(nil)
|
||||
|
||||
Name = "gosql"
|
||||
Field = &configure.Field[string]{
|
||||
Description: "Connection string",
|
||||
Version: semver.MustParse("v3"),
|
||||
Validate: func(s string) error {
|
||||
_, err := pgxpool.ParseConfig(s)
|
||||
return err
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
|
@@ -6,14 +6,91 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/cmd/configure"
|
||||
"github.com/zitadel/zitadel/backend/storage/database"
|
||||
)
|
||||
|
||||
var (
|
||||
_ database.Connector = (*Config)(nil)
|
||||
Name = "postgres"
|
||||
|
||||
Field = &configure.OneOf{
|
||||
Description: "Configuring postgres using one of the following options",
|
||||
SubFields: []configure.Updater{
|
||||
&configure.Field[string]{
|
||||
Description: "Connection string",
|
||||
Version: semver.MustParse("v3"),
|
||||
Validate: func(s string) error {
|
||||
_, err := pgxpool.ParseConfig(s)
|
||||
return err
|
||||
},
|
||||
},
|
||||
&configure.Struct{
|
||||
Description: "Configuration for the connection",
|
||||
SubFields: []configure.Updater{
|
||||
&configure.Field[string]{
|
||||
FieldName: "host",
|
||||
Value: "localhost",
|
||||
Description: "The host to connect to",
|
||||
Version: semver.MustParse("3"),
|
||||
},
|
||||
&configure.Field[uint32]{
|
||||
FieldName: "port",
|
||||
Value: 5432,
|
||||
Description: "The port to connect to",
|
||||
Version: semver.MustParse("3"),
|
||||
},
|
||||
&configure.Field[string]{
|
||||
FieldName: "database",
|
||||
Value: "zitadel",
|
||||
Description: "The database to connect to",
|
||||
Version: semver.MustParse("3"),
|
||||
},
|
||||
&configure.Field[string]{
|
||||
FieldName: "user",
|
||||
Description: "The user to connect as",
|
||||
Value: "zitadel",
|
||||
Version: semver.MustParse("3"),
|
||||
},
|
||||
&configure.Field[string]{
|
||||
FieldName: "password",
|
||||
Description: "The password to connect with",
|
||||
Version: semver.MustParse("3"),
|
||||
HideInput: true,
|
||||
},
|
||||
&configure.OneOf{
|
||||
FieldName: "sslMode",
|
||||
Description: "The SSL mode to use",
|
||||
SubFields: []configure.Updater{
|
||||
&configure.Constant[string]{
|
||||
Description: "Disable",
|
||||
Constant: "disable",
|
||||
Version: semver.MustParse("3"),
|
||||
},
|
||||
&configure.Constant[string]{
|
||||
Description: "Require",
|
||||
Constant: "require",
|
||||
Version: semver.MustParse("3"),
|
||||
},
|
||||
&configure.Constant[string]{
|
||||
Description: "Verify CA",
|
||||
Constant: "verify-ca",
|
||||
Version: semver.MustParse("3"),
|
||||
},
|
||||
&configure.Constant[string]{
|
||||
Description: "Verify Full",
|
||||
Constant: "verify-full",
|
||||
Version: semver.MustParse("3"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
type Config struct{ *pgxpool.Config }
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/storage/database"
|
||||
)
|
||||
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/storage/database"
|
||||
)
|
||||
|
||||
|
@@ -2,6 +2,7 @@ package postgres
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/storage/database"
|
||||
)
|
||||
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/storage/database"
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user