chore: merge (#5773)

* feat: allow skip of success page for native apps (#5627)

add possibility to return to callback directly after login without rendering the successful login page

* build next

* fix(console): disallow inline fonts, critical styles (#5714)

fix: disallow inline

* fix(setup): step 10 for postgres (#5717)

* fix(setup): smaller transactions (#5743)

* fix: order by sequence by default

* test: add allowCreationDateFilter

* fix(step10): separate executions (#5754)

* feat: allow skip of success page for native apps (#5627)

add possibility to return to callback directly after login without rendering the successful login page

* build next

* fix(console): disallow inline fonts, critical styles (#5714)

fix: disallow inline

* fix(setup): step 10 for postgres (#5717)

* fix(setup): smaller transactions (#5743)

* fix(step10): split statements

* fix(step10): split into separate execs

* chore: prerelease

* add truncate before insert

* fix: add truncate

* Merge branch 'main' into optimise-step-10

* chore: reset release definition

---------

Co-authored-by: Livio Spring <livio.a@gmail.com>
Co-authored-by: Max Peintner <max@caos.ch>

---------

Co-authored-by: Livio Spring <livio.a@gmail.com>
Co-authored-by: Max Peintner <max@caos.ch>
This commit is contained in:
Silvan 2023-04-28 16:56:51 +02:00 committed by GitHub
parent 458a383de2
commit 39bdef35e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 66 additions and 40 deletions

View File

@ -1,7 +1,7 @@
module.exports = { module.exports = {
branches: [ branches: [
{name: 'main', channel: 'next'}, {name: 'main'},
{name: 'next', prerelease: true} {name: 'next'},
], ],
plugins: [ plugins: [
"@semantic-release/commit-analyzer" "@semantic-release/commit-analyzer"

View File

@ -398,6 +398,7 @@ Quotas:
Eventstore: Eventstore:
PushTimeout: 15s PushTimeout: 15s
AllowOrderByCreationDate: false
DefaultInstance: DefaultInstance:
InstanceName: InstanceName:

View File

@ -115,7 +115,7 @@ func startZitadel(config *Config, masterKey string) error {
return fmt.Errorf("cannot start queries: %w", err) return fmt.Errorf("cannot start queries: %w", err)
} }
authZRepo, err := authz.Start(queries, dbClient, keys.OIDC, config.ExternalSecure) authZRepo, err := authz.Start(queries, dbClient, keys.OIDC, config.ExternalSecure, config.Eventstore.AllowOrderByCreationDate)
if err != nil { if err != nil {
return fmt.Errorf("error starting authz repo: %w", err) return fmt.Errorf("error starting authz repo: %w", err)
} }
@ -229,11 +229,11 @@ func startAPIs(
if err != nil { if err != nil {
return fmt.Errorf("error creating api %w", err) return fmt.Errorf("error creating api %w", err)
} }
authRepo, err := auth_es.Start(ctx, config.Auth, config.SystemDefaults, commands, queries, dbClient, eventstore, keys.OIDC, keys.User) authRepo, err := auth_es.Start(ctx, config.Auth, config.SystemDefaults, commands, queries, dbClient, eventstore, keys.OIDC, keys.User, config.Eventstore.AllowOrderByCreationDate)
if err != nil { if err != nil {
return fmt.Errorf("error starting auth repo: %w", err) return fmt.Errorf("error starting auth repo: %w", err)
} }
adminRepo, err := admin_es.Start(ctx, config.Admin, store, dbClient, eventstore) adminRepo, err := admin_es.Start(ctx, config.Admin, store, dbClient, eventstore, config.Eventstore.AllowOrderByCreationDate)
if err != nil { if err != nil {
return fmt.Errorf("error starting admin repo: %w", err) return fmt.Errorf("error starting admin repo: %w", err)
} }

View File

@ -23,8 +23,8 @@ type EsRepository struct {
eventstore.AdministratorRepo eventstore.AdministratorRepo
} }
func Start(ctx context.Context, conf Config, static static.Storage, dbClient *database.DB, esV2 *eventstore2.Eventstore) (*EsRepository, error) { func Start(ctx context.Context, conf Config, static static.Storage, dbClient *database.DB, esV2 *eventstore2.Eventstore, allowOrderByCreationDate bool) (*EsRepository, error) {
es, err := v1.Start(dbClient) es, err := v1.Start(dbClient, allowOrderByCreationDate)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -34,8 +34,8 @@ type EsRepository struct {
eventstore.OrgRepository eventstore.OrgRepository
} }
func Start(ctx context.Context, conf Config, systemDefaults sd.SystemDefaults, command *command.Commands, queries *query.Queries, dbClient *database.DB, esV2 *eventstore2.Eventstore, oidcEncryption crypto.EncryptionAlgorithm, userEncryption crypto.EncryptionAlgorithm) (*EsRepository, error) { func Start(ctx context.Context, conf Config, systemDefaults sd.SystemDefaults, command *command.Commands, queries *query.Queries, dbClient *database.DB, esV2 *eventstore2.Eventstore, oidcEncryption crypto.EncryptionAlgorithm, userEncryption crypto.EncryptionAlgorithm, allowOrderByCreationDate bool) (*EsRepository, error) {
es, err := v1.Start(dbClient) es, err := v1.Start(dbClient, allowOrderByCreationDate)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -8,6 +8,6 @@ import (
"github.com/zitadel/zitadel/internal/query" "github.com/zitadel/zitadel/internal/query"
) )
func Start(queries *query.Queries, dbClient *database.DB, keyEncryptionAlgorithm crypto.EncryptionAlgorithm, externalSecure bool) (repository.Repository, error) { func Start(queries *query.Queries, dbClient *database.DB, keyEncryptionAlgorithm crypto.EncryptionAlgorithm, externalSecure, allowOrderByCreationDate bool) (repository.Repository, error) {
return eventsourcing.Start(queries, dbClient, keyEncryptionAlgorithm, externalSecure) return eventsourcing.Start(queries, dbClient, keyEncryptionAlgorithm, externalSecure, allowOrderByCreationDate)
} }

View File

@ -18,8 +18,8 @@ type EsRepository struct {
eventstore.TokenVerifierRepo eventstore.TokenVerifierRepo
} }
func Start(queries *query.Queries, dbClient *database.DB, keyEncryptionAlgorithm crypto.EncryptionAlgorithm, externalSecure bool) (repository.Repository, error) { func Start(queries *query.Queries, dbClient *database.DB, keyEncryptionAlgorithm crypto.EncryptionAlgorithm, externalSecure, allowOrderByCreationDate bool) (repository.Repository, error) {
es, err := v1.Start(dbClient) es, err := v1.Start(dbClient, allowOrderByCreationDate)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -9,8 +9,9 @@ import (
) )
type Config struct { type Config struct {
PushTimeout time.Duration PushTimeout time.Duration
Client *database.DB Client *database.DB
AllowOrderByCreationDate bool
repo repository.Repository repo repository.Repository
} }
@ -20,6 +21,6 @@ func TestConfig(repo repository.Repository) *Config {
} }
func Start(config *Config) (*Eventstore, error) { func Start(config *Config) (*Eventstore, error) {
config.repo = z_sql.NewCRDB(config.Client) config.repo = z_sql.NewCRDB(config.Client, config.AllowOrderByCreationDate)
return NewEventstore(config), nil return NewEventstore(config), nil
} }

View File

@ -99,10 +99,11 @@ const (
type CRDB struct { type CRDB struct {
*database.DB *database.DB
AllowOrderByCreationDate bool
} }
func NewCRDB(client *database.DB) *CRDB { func NewCRDB(client *database.DB, allowOrderByCreationDate bool) *CRDB {
return &CRDB{client} return &CRDB{client, allowOrderByCreationDate}
} }
func (db *CRDB) Health(ctx context.Context) error { return db.Ping() } func (db *CRDB) Health(ctx context.Context) error { return db.Ping() }
@ -254,11 +255,19 @@ func (db *CRDB) db() *sql.DB {
} }
func (db *CRDB) orderByEventSequence(desc bool) string { func (db *CRDB) orderByEventSequence(desc bool) string {
if desc { if db.AllowOrderByCreationDate {
return " ORDER BY creation_date DESC, event_sequence DESC" if desc {
return " ORDER BY creation_date DESC, event_sequence DESC"
}
return " ORDER BY creation_date, event_sequence"
} }
return " ORDER BY creation_date, event_sequence" if desc {
return " ORDER BY event_sequence DESC"
}
return " ORDER BY event_sequence"
} }
func (db *CRDB) eventQuery() string { func (db *CRDB) eventQuery() string {

View File

@ -542,6 +542,7 @@ func Test_query_events_with_crdb(t *testing.T) {
DB: tt.fields.client, DB: tt.fields.client,
Database: new(testDB), Database: new(testDB),
}, },
AllowOrderByCreationDate: true,
} }
// setup initial data for query // setup initial data for query
@ -820,9 +821,12 @@ func Test_query_events_mocked(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
crdb := &CRDB{DB: &database.DB{ crdb := &CRDB{
Database: new(testDB), DB: &database.DB{
}} Database: new(testDB),
},
AllowOrderByCreationDate: true,
}
if tt.fields.mock != nil { if tt.fields.mock != nil {
crdb.DB.DB = tt.fields.mock.client crdb.DB.DB = tt.fields.mock.client
} }

View File

@ -22,9 +22,9 @@ type eventstore struct {
repo repository.Repository repo repository.Repository
} }
func Start(db *database.DB) (Eventstore, error) { func Start(db *database.DB, allowOrderByCreationDate bool) (Eventstore, error) {
return &eventstore{ return &eventstore{
repo: z_sql.Start(db), repo: z_sql.Start(db, allowOrderByCreationDate),
}, nil }, nil
} }

View File

@ -4,8 +4,9 @@ import (
"github.com/zitadel/zitadel/internal/database" "github.com/zitadel/zitadel/internal/database"
) )
func Start(client *database.DB) *SQL { func Start(client *database.DB, allowOrderByCreationDate bool) *SQL {
return &SQL{ return &SQL{
client: client, client: client,
allowOrderByCreationDate: allowOrderByCreationDate,
} }
} }

View File

@ -21,11 +21,11 @@ func (db *SQL) Filter(ctx context.Context, searchQuery *es_models.SearchQueryFac
if !searchQuery.InstanceFiltered { if !searchQuery.InstanceFiltered {
logging.WithFields("stack", string(debug.Stack())).Warn("instanceid not filtered") logging.WithFields("stack", string(debug.Stack())).Warn("instanceid not filtered")
} }
return filter(ctx, db.client, searchQuery) return db.filter(ctx, db.client, searchQuery)
} }
func filter(ctx context.Context, db *database.DB, searchQuery *es_models.SearchQueryFactory) (events []*es_models.Event, err error) { func (sql *SQL) filter(ctx context.Context, db *database.DB, searchQuery *es_models.SearchQueryFactory) (events []*es_models.Event, err error) {
query, limit, values, rowScanner := buildQuery(ctx, db, searchQuery) query, limit, values, rowScanner := sql.buildQuery(ctx, db, searchQuery)
if query == "" { if query == "" {
return nil, errors.ThrowInvalidArgument(nil, "SQL-rWeBw", "invalid query factory") return nil, errors.ThrowInvalidArgument(nil, "SQL-rWeBw", "invalid query factory")
} }
@ -53,7 +53,7 @@ func filter(ctx context.Context, db *database.DB, searchQuery *es_models.SearchQ
} }
func (db *SQL) LatestSequence(ctx context.Context, queryFactory *es_models.SearchQueryFactory) (uint64, error) { func (db *SQL) LatestSequence(ctx context.Context, queryFactory *es_models.SearchQueryFactory) (uint64, error) {
query, _, values, rowScanner := buildQuery(ctx, db.client, queryFactory) query, _, values, rowScanner := db.buildQuery(ctx, db.client, queryFactory)
if query == "" { if query == "" {
return 0, errors.ThrowInvalidArgument(nil, "SQL-rWeBw", "invalid query factory") return 0, errors.ThrowInvalidArgument(nil, "SQL-rWeBw", "invalid query factory")
} }
@ -68,7 +68,7 @@ func (db *SQL) LatestSequence(ctx context.Context, queryFactory *es_models.Searc
} }
func (db *SQL) InstanceIDs(ctx context.Context, queryFactory *es_models.SearchQueryFactory) ([]string, error) { func (db *SQL) InstanceIDs(ctx context.Context, queryFactory *es_models.SearchQueryFactory) ([]string, error) {
query, _, values, rowScanner := buildQuery(ctx, db.client, queryFactory) query, _, values, rowScanner := db.buildQuery(ctx, db.client, queryFactory)
if query == "" { if query == "" {
return nil, errors.ThrowInvalidArgument(nil, "SQL-Sfwg2", "invalid query factory") return nil, errors.ThrowInvalidArgument(nil, "SQL-Sfwg2", "invalid query factory")
} }

View File

@ -123,7 +123,8 @@ func TestSQL_Filter(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
sql := &SQL{ sql := &SQL{
client: &database.DB{DB: tt.fields.client.sqlClient, Database: new(testDB)}, client: &database.DB{DB: tt.fields.client.sqlClient, Database: new(testDB)},
allowOrderByCreationDate: true,
} }
events, err := sql.Filter(context.Background(), tt.args.searchQuery) events, err := sql.Filter(context.Background(), tt.args.searchQuery)
if (err != nil) != tt.res.wantErr { if (err != nil) != tt.res.wantErr {

View File

@ -33,7 +33,7 @@ const (
" FROM eventstore.events" " FROM eventstore.events"
) )
func buildQuery(ctx context.Context, db dialect.Database, queryFactory *es_models.SearchQueryFactory) (query string, limit uint64, values []interface{}, rowScanner func(s scan, dest interface{}) error) { func (sql *SQL) buildQuery(ctx context.Context, db dialect.Database, queryFactory *es_models.SearchQueryFactory) (query string, limit uint64, values []interface{}, rowScanner func(s scan, dest interface{}) error) {
searchQuery, err := queryFactory.Build() searchQuery, err := queryFactory.Build()
if err != nil { if err != nil {
logging.New().WithError(err).Warn("search query factory invalid") logging.New().WithError(err).Warn("search query factory invalid")
@ -51,9 +51,17 @@ func buildQuery(ctx context.Context, db dialect.Database, queryFactory *es_model
query += where query += where
if searchQuery.Columns == es_models.Columns_Event { if searchQuery.Columns == es_models.Columns_Event {
order := " ORDER BY creation_date, event_sequence" var order string
if searchQuery.Desc { if sql.allowOrderByCreationDate {
order = " ORDER BY creation_date DESC, event_sequence DESC" order = " ORDER BY creation_date, event_sequence"
if searchQuery.Desc {
order = " ORDER BY creation_date DESC, event_sequence DESC"
}
} else {
order = " ORDER BY event_sequence"
if searchQuery.Desc {
order = " ORDER BY event_sequence DESC"
}
} }
query += order query += order
} }

View File

@ -470,7 +470,7 @@ func Test_buildQuery(t *testing.T) {
ctx := context.Background() ctx := context.Background()
db := new(testDB) db := new(testDB)
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
gotQuery, gotLimit, gotValues, gotRowScanner := buildQuery(ctx, db, tt.args.queryFactory) gotQuery, gotLimit, gotValues, gotRowScanner := (&SQL{allowOrderByCreationDate: true}).buildQuery(ctx, db, tt.args.queryFactory)
if gotQuery != tt.res.query { if gotQuery != tt.res.query {
t.Errorf("buildQuery() gotQuery = %v, want %v", gotQuery, tt.res.query) t.Errorf("buildQuery() gotQuery = %v, want %v", gotQuery, tt.res.query)
} }

View File

@ -7,7 +7,8 @@ import (
) )
type SQL struct { type SQL struct {
client *database.DB client *database.DB
allowOrderByCreationDate bool
} }
func (db *SQL) Health(ctx context.Context) error { func (db *SQL) Health(ctx context.Context) error {