Skip to content

Commit

Permalink
chore: merge (#5773)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Apr 28, 2023
1 parent 458a383 commit 39bdef3
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .releaserc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
branches: [
{name: 'main', channel: 'next'},
{name: 'next', prerelease: true}
{name: 'main'},
{name: 'next'},
],
plugins: [
"@semantic-release/commit-analyzer"
Expand Down
1 change: 1 addition & 0 deletions cmd/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ Quotas:

Eventstore:
PushTimeout: 15s
AllowOrderByCreationDate: false

DefaultInstance:
InstanceName:
Expand Down
6 changes: 3 additions & 3 deletions cmd/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func startZitadel(config *Config, masterKey string) error {
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 {
return fmt.Errorf("error starting authz repo: %w", err)
}
Expand Down Expand Up @@ -229,11 +229,11 @@ func startAPIs(
if err != nil {
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 {
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 {
return fmt.Errorf("error starting admin repo: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/admin/repository/eventsourcing/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type EsRepository struct {
eventstore.AdministratorRepo
}

func Start(ctx context.Context, conf Config, static static.Storage, dbClient *database.DB, esV2 *eventstore2.Eventstore) (*EsRepository, error) {
es, err := v1.Start(dbClient)
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, allowOrderByCreationDate)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/auth/repository/eventsourcing/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type EsRepository struct {
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) {
es, err := v1.Start(dbClient)
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, allowOrderByCreationDate)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/authz/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import (
"github.com/zitadel/zitadel/internal/query"
)

func Start(queries *query.Queries, dbClient *database.DB, keyEncryptionAlgorithm crypto.EncryptionAlgorithm, externalSecure bool) (repository.Repository, error) {
return eventsourcing.Start(queries, dbClient, keyEncryptionAlgorithm, externalSecure)
func Start(queries *query.Queries, dbClient *database.DB, keyEncryptionAlgorithm crypto.EncryptionAlgorithm, externalSecure, allowOrderByCreationDate bool) (repository.Repository, error) {
return eventsourcing.Start(queries, dbClient, keyEncryptionAlgorithm, externalSecure, allowOrderByCreationDate)
}
4 changes: 2 additions & 2 deletions internal/authz/repository/eventsourcing/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type EsRepository struct {
eventstore.TokenVerifierRepo
}

func Start(queries *query.Queries, dbClient *database.DB, keyEncryptionAlgorithm crypto.EncryptionAlgorithm, externalSecure bool) (repository.Repository, error) {
es, err := v1.Start(dbClient)
func Start(queries *query.Queries, dbClient *database.DB, keyEncryptionAlgorithm crypto.EncryptionAlgorithm, externalSecure, allowOrderByCreationDate bool) (repository.Repository, error) {
es, err := v1.Start(dbClient, allowOrderByCreationDate)
if err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions internal/eventstore/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
)

type Config struct {
PushTimeout time.Duration
Client *database.DB
PushTimeout time.Duration
Client *database.DB
AllowOrderByCreationDate bool

repo repository.Repository
}
Expand All @@ -20,6 +21,6 @@ func TestConfig(repo repository.Repository) *Config {
}

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
}
17 changes: 13 additions & 4 deletions internal/eventstore/repository/sql/crdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ const (

type CRDB struct {
*database.DB
AllowOrderByCreationDate bool
}

func NewCRDB(client *database.DB) *CRDB {
return &CRDB{client}
func NewCRDB(client *database.DB, allowOrderByCreationDate bool) *CRDB {
return &CRDB{client, allowOrderByCreationDate}
}

func (db *CRDB) Health(ctx context.Context) error { return db.Ping() }
Expand Down Expand Up @@ -254,11 +255,19 @@ func (db *CRDB) db() *sql.DB {
}

func (db *CRDB) orderByEventSequence(desc bool) string {
if db.AllowOrderByCreationDate {
if desc {
return " ORDER BY creation_date DESC, event_sequence DESC"
}

return " ORDER BY creation_date, event_sequence"
}

if desc {
return " ORDER BY creation_date DESC, event_sequence DESC"
return " ORDER BY event_sequence DESC"
}

return " ORDER BY creation_date, event_sequence"
return " ORDER BY event_sequence"
}

func (db *CRDB) eventQuery() string {
Expand Down
10 changes: 7 additions & 3 deletions internal/eventstore/repository/sql/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ func Test_query_events_with_crdb(t *testing.T) {
DB: tt.fields.client,
Database: new(testDB),
},
AllowOrderByCreationDate: true,
}

// setup initial data for query
Expand Down Expand Up @@ -820,9 +821,12 @@ func Test_query_events_mocked(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
crdb := &CRDB{DB: &database.DB{
Database: new(testDB),
}}
crdb := &CRDB{
DB: &database.DB{
Database: new(testDB),
},
AllowOrderByCreationDate: true,
}
if tt.fields.mock != nil {
crdb.DB.DB = tt.fields.mock.client
}
Expand Down
4 changes: 2 additions & 2 deletions internal/eventstore/v1/eventstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type eventstore struct {
repo repository.Repository
}

func Start(db *database.DB) (Eventstore, error) {
func Start(db *database.DB, allowOrderByCreationDate bool) (Eventstore, error) {
return &eventstore{
repo: z_sql.Start(db),
repo: z_sql.Start(db, allowOrderByCreationDate),
}, nil
}

Expand Down
5 changes: 3 additions & 2 deletions internal/eventstore/v1/internal/repository/sql/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"github.com/zitadel/zitadel/internal/database"
)

func Start(client *database.DB) *SQL {
func Start(client *database.DB, allowOrderByCreationDate bool) *SQL {
return &SQL{
client: client,
client: client,
allowOrderByCreationDate: allowOrderByCreationDate,
}
}
10 changes: 5 additions & 5 deletions internal/eventstore/v1/internal/repository/sql/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func (db *SQL) Filter(ctx context.Context, searchQuery *es_models.SearchQueryFac
if !searchQuery.InstanceFiltered {
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) {
query, limit, values, rowScanner := buildQuery(ctx, db, searchQuery)
func (sql *SQL) filter(ctx context.Context, db *database.DB, searchQuery *es_models.SearchQueryFactory) (events []*es_models.Event, err error) {
query, limit, values, rowScanner := sql.buildQuery(ctx, db, searchQuery)
if query == "" {
return nil, errors.ThrowInvalidArgument(nil, "SQL-rWeBw", "invalid query factory")
}
Expand Down Expand Up @@ -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) {
query, _, values, rowScanner := buildQuery(ctx, db.client, queryFactory)
query, _, values, rowScanner := db.buildQuery(ctx, db.client, queryFactory)
if query == "" {
return 0, errors.ThrowInvalidArgument(nil, "SQL-rWeBw", "invalid query factory")
}
Expand All @@ -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) {
query, _, values, rowScanner := buildQuery(ctx, db.client, queryFactory)
query, _, values, rowScanner := db.buildQuery(ctx, db.client, queryFactory)
if query == "" {
return nil, errors.ThrowInvalidArgument(nil, "SQL-Sfwg2", "invalid query factory")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ func TestSQL_Filter(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
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)
if (err != nil) != tt.res.wantErr {
Expand Down
16 changes: 12 additions & 4 deletions internal/eventstore/v1/internal/repository/sql/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
" 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()
if err != nil {
logging.New().WithError(err).Warn("search query factory invalid")
Expand All @@ -51,9 +51,17 @@ func buildQuery(ctx context.Context, db dialect.Database, queryFactory *es_model
query += where

if searchQuery.Columns == es_models.Columns_Event {
order := " ORDER BY creation_date, event_sequence"
if searchQuery.Desc {
order = " ORDER BY creation_date DESC, event_sequence DESC"
var order string
if sql.allowOrderByCreationDate {
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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func Test_buildQuery(t *testing.T) {
ctx := context.Background()
db := new(testDB)
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 {
t.Errorf("buildQuery() gotQuery = %v, want %v", gotQuery, tt.res.query)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/eventstore/v1/internal/repository/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

type SQL struct {
client *database.DB
client *database.DB
allowOrderByCreationDate bool
}

func (db *SQL) Health(ctx context.Context) error {
Expand Down

1 comment on commit 39bdef3

@vercel
Copy link

@vercel vercel bot commented on 39bdef3 Apr 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./

zitadel-docs.vercel.app
docs-zitadel.vercel.app
docs-git-main-zitadel.vercel.app

Please sign in to comment.