mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-17 10:55:12 +00:00
feat: added xoauth for smtp (#11239)
# Which Problems Are Solved - Some mail providers (e.g.: MS Exchange) have deprecated plain auth # How the Problems Are Solved Adds XOauth2 auth option to SMPT - SMTP config now can contain XOAuth2 auth config - Proto files are updated to have a oneof for configuration selection. Old fields for configuring plain auth are still available not to create a breaking change. These can be removed in the future. - Columns are added to the database to persist the config # Additional Changes none # Additional Context Replace this example with links to related issues, discussions, discord threads, or other sources with more context. Use the Closing #issue syntax for issues that are resolved with this PR. - Closes #8042 --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Tim Möhlmann <[email protected]>
This commit is contained in:
co-authored by
Copilot
Tim Möhlmann
parent
96bbd6a65c
commit
3fc0ef2506
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
SMTPConfigProjectionTable = "projections.smtp_configs5"
|
||||
SMTPConfigProjectionTable = "projections.smtp_configs6"
|
||||
SMTPConfigTable = SMTPConfigProjectionTable + "_" + smtpConfigSMTPTableSuffix
|
||||
SMTPConfigHTTPTable = SMTPConfigProjectionTable + "_" + smtpConfigHTTPTableSuffix
|
||||
|
||||
@@ -25,16 +25,20 @@ const (
|
||||
SMTPConfigColumnState = "state"
|
||||
SMTPConfigColumnDescription = "description"
|
||||
|
||||
smtpConfigSMTPTableSuffix = "smtp"
|
||||
SMTPConfigSMTPColumnInstanceID = "instance_id"
|
||||
SMTPConfigSMTPColumnID = "id"
|
||||
SMTPConfigSMTPColumnTLS = "tls"
|
||||
SMTPConfigSMTPColumnSenderAddress = "sender_address"
|
||||
SMTPConfigSMTPColumnSenderName = "sender_name"
|
||||
SMTPConfigSMTPColumnReplyToAddress = "reply_to_address"
|
||||
SMTPConfigSMTPColumnHost = "host"
|
||||
SMTPConfigSMTPColumnUser = "username"
|
||||
SMTPConfigSMTPColumnPassword = "password"
|
||||
smtpConfigSMTPTableSuffix = "smtp"
|
||||
SMTPConfigSMTPColumnInstanceID = "instance_id"
|
||||
SMTPConfigSMTPColumnID = "id"
|
||||
SMTPConfigSMTPColumnTLS = "tls"
|
||||
SMTPConfigSMTPColumnSenderAddress = "sender_address"
|
||||
SMTPConfigSMTPColumnSenderName = "sender_name"
|
||||
SMTPConfigSMTPColumnReplyToAddress = "reply_to_address"
|
||||
SMTPConfigSMTPColumnHost = "host"
|
||||
SMTPConfigSMTPColumnUser = "username"
|
||||
SMTPConfigSMTPColumnPlainAuthPassword = "password"
|
||||
SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientId = "xoauth2auth_client_credentials_client_id"
|
||||
SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientSecret = "xoauth2auth_client_credentials_client_secret"
|
||||
SMTPConfigSMTPColumnXOAuth2AuthTokenEndpoint = "xoauth2auth_token_endpoint"
|
||||
SMTPConfigSMTPColumnXOAuth2AuthScope = "xoauth2auth_scope"
|
||||
|
||||
smtpConfigHTTPTableSuffix = "http"
|
||||
SMTPConfigHTTPColumnInstanceID = "instance_id"
|
||||
@@ -77,7 +81,11 @@ func (*smtpConfigProjection) Init() *old_handler.Check {
|
||||
handler.NewColumn(SMTPConfigSMTPColumnReplyToAddress, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigSMTPColumnHost, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigSMTPColumnUser, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigSMTPColumnPassword, handler.ColumnTypeJSONB, handler.Nullable()),
|
||||
handler.NewColumn(SMTPConfigSMTPColumnPlainAuthPassword, handler.ColumnTypeJSONB, handler.Nullable()),
|
||||
handler.NewColumn(SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientId, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientSecret, handler.ColumnTypeJSONB, handler.Nullable()),
|
||||
handler.NewColumn(SMTPConfigSMTPColumnXOAuth2AuthTokenEndpoint, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(SMTPConfigSMTPColumnXOAuth2AuthScope, handler.ColumnTypeTextArray, handler.Nullable()),
|
||||
},
|
||||
handler.NewPrimaryKey(SMTPConfigSMTPColumnInstanceID, SMTPConfigSMTPColumnID),
|
||||
smtpConfigSMTPTableSuffix,
|
||||
@@ -155,6 +163,39 @@ func (p *smtpConfigProjection) reduceSMTPConfigAdded(event eventstore.Event) (*h
|
||||
state = domain.SMTPConfigStateActive
|
||||
}
|
||||
|
||||
columns := []handler.Column{
|
||||
handler.NewCol(SMTPConfigSMTPColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(SMTPConfigSMTPColumnID, getSMTPConfigID(e.ID, e.Aggregate())),
|
||||
handler.NewCol(SMTPConfigSMTPColumnTLS, e.TLS),
|
||||
handler.NewCol(SMTPConfigSMTPColumnSenderAddress, e.SenderAddress),
|
||||
handler.NewCol(SMTPConfigSMTPColumnSenderName, e.SenderName),
|
||||
handler.NewCol(SMTPConfigSMTPColumnReplyToAddress, e.ReplyToAddress),
|
||||
handler.NewCol(SMTPConfigSMTPColumnHost, e.Host),
|
||||
handler.NewCol(SMTPConfigSMTPColumnUser, e.User),
|
||||
}
|
||||
|
||||
if e.PlainAuth != nil {
|
||||
columns = append(columns, removeXoauth()...)
|
||||
columns = append(columns, handler.NewCol(SMTPConfigSMTPColumnPlainAuthPassword, e.PlainAuth.Password))
|
||||
} else if e.Password != nil {
|
||||
columns = append(columns, removeXoauth()...)
|
||||
columns = append(columns, handler.NewCol(SMTPConfigSMTPColumnPlainAuthPassword, e.Password))
|
||||
}
|
||||
if e.XOAuth2Auth != nil {
|
||||
columns = append(columns, removePlainAuth()...)
|
||||
columns = append(columns,
|
||||
handler.NewCol(SMTPConfigSMTPColumnXOAuth2AuthTokenEndpoint, e.XOAuth2Auth.TokenEndpoint),
|
||||
handler.NewCol(SMTPConfigSMTPColumnXOAuth2AuthScope, e.XOAuth2Auth.Scopes),
|
||||
)
|
||||
|
||||
if e.XOAuth2Auth.ClientCredentials != nil {
|
||||
columns = append(columns,
|
||||
handler.NewCol(SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientId, e.XOAuth2Auth.ClientCredentials.ClientId),
|
||||
handler.NewCol(SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientSecret, e.XOAuth2Auth.ClientCredentials.ClientSecret),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
handler.AddCreateStatement(
|
||||
@@ -171,22 +212,24 @@ func (p *smtpConfigProjection) reduceSMTPConfigAdded(event eventstore.Event) (*h
|
||||
},
|
||||
),
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(SMTPConfigSMTPColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(SMTPConfigSMTPColumnID, getSMTPConfigID(e.ID, e.Aggregate())),
|
||||
handler.NewCol(SMTPConfigSMTPColumnTLS, e.TLS),
|
||||
handler.NewCol(SMTPConfigSMTPColumnSenderAddress, e.SenderAddress),
|
||||
handler.NewCol(SMTPConfigSMTPColumnSenderName, e.SenderName),
|
||||
handler.NewCol(SMTPConfigSMTPColumnReplyToAddress, e.ReplyToAddress),
|
||||
handler.NewCol(SMTPConfigSMTPColumnHost, e.Host),
|
||||
handler.NewCol(SMTPConfigSMTPColumnUser, e.User),
|
||||
handler.NewCol(SMTPConfigSMTPColumnPassword, e.Password),
|
||||
},
|
||||
columns,
|
||||
handler.WithTableSuffix(smtpConfigSMTPTableSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
|
||||
func removeXoauth() []handler.Column {
|
||||
return []handler.Column{
|
||||
handler.NewCol(SMTPConfigSMTPColumnXOAuth2AuthTokenEndpoint, nil),
|
||||
handler.NewCol(SMTPConfigSMTPColumnXOAuth2AuthScope, nil),
|
||||
handler.NewCol(SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientId, nil),
|
||||
handler.NewCol(SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientSecret, nil),
|
||||
}
|
||||
}
|
||||
func removePlainAuth() []handler.Column {
|
||||
return []handler.Column{handler.NewCol(SMTPConfigSMTPColumnPlainAuthPassword, nil)}
|
||||
}
|
||||
|
||||
func (p *smtpConfigProjection) reduceSMTPConfigHTTPAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, err := assertEvent[*instance.SMTPConfigHTTPAddedEvent](event)
|
||||
if err != nil {
|
||||
@@ -307,7 +350,27 @@ func (p *smtpConfigProjection) reduceSMTPConfigChanged(event eventstore.Event) (
|
||||
smtpColumns = append(smtpColumns, handler.NewCol(SMTPConfigSMTPColumnUser, *e.User))
|
||||
}
|
||||
if e.Password != nil {
|
||||
smtpColumns = append(smtpColumns, handler.NewCol(SMTPConfigSMTPColumnPassword, *e.Password))
|
||||
smtpColumns = append(smtpColumns, handler.NewCol(SMTPConfigSMTPColumnPlainAuthPassword, *e.Password))
|
||||
}
|
||||
|
||||
if !e.PlainAuth.IsEmpty() {
|
||||
smtpColumns = append(smtpColumns,
|
||||
handler.NewCol(SMTPConfigSMTPColumnPlainAuthPassword, e.PlainAuth.Password),
|
||||
)
|
||||
}
|
||||
|
||||
if !e.XOAuth2Auth.IsEmpty() {
|
||||
smtpColumns = append(smtpColumns,
|
||||
handler.NewCol(SMTPConfigSMTPColumnXOAuth2AuthTokenEndpoint, e.XOAuth2Auth.TokenEndpoint),
|
||||
handler.NewCol(SMTPConfigSMTPColumnXOAuth2AuthScope, e.XOAuth2Auth.Scopes),
|
||||
)
|
||||
|
||||
if !e.XOAuth2Auth.ClientCredentials.IsEmpty() {
|
||||
smtpColumns = append(smtpColumns,
|
||||
handler.NewCol(SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientId, e.XOAuth2Auth.ClientCredentials.ClientId),
|
||||
handler.NewCol(SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientSecret, e.XOAuth2Auth.ClientCredentials.ClientSecret),
|
||||
)
|
||||
}
|
||||
}
|
||||
if len(smtpColumns) > 0 {
|
||||
stmts = append(stmts, handler.AddUpdateStatement(
|
||||
@@ -333,7 +396,7 @@ func (p *smtpConfigProjection) reduceSMTPConfigPasswordChanged(event eventstore.
|
||||
e,
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(SMTPConfigSMTPColumnPassword, e.Password),
|
||||
handler.NewCol(SMTPConfigSMTPColumnPlainAuthPassword, e.Password),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(SMTPConfigSMTPColumnID, getSMTPConfigID(e.ID, e.Aggregate())),
|
||||
|
||||
@@ -49,7 +49,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -59,7 +59,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5_smtp SET (tls, sender_address, sender_name, reply_to_address, host, username) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6_smtp SET (tls, sender_address, sender_name, reply_to_address, host, username) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
"sender",
|
||||
@@ -105,7 +105,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -115,7 +115,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5_smtp SET (tls, sender_address, sender_name, reply_to_address, host, username) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6_smtp SET (tls, sender_address, sender_name, reply_to_address, host, username) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
"sender",
|
||||
@@ -155,7 +155,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -192,7 +192,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -201,7 +201,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5_smtp SET sender_address = $1 WHERE (id = $2) AND (instance_id = $3)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6_smtp SET sender_address = $1 WHERE (id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"sender",
|
||||
"config-id",
|
||||
@@ -238,7 +238,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -248,7 +248,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5_http SET (endpoint, signing_key) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6_http SET (endpoint, signing_key) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"endpoint",
|
||||
anyArg{},
|
||||
@@ -284,7 +284,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -321,7 +321,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -330,7 +330,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5_http SET endpoint = $1 WHERE (id = $2) AND (instance_id = $3)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6_http SET endpoint = $1 WHERE (id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"endpoint",
|
||||
"config-id",
|
||||
@@ -340,7 +340,8 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
name: "reduceSMTPConfigHTTPChanged, signing key",
|
||||
args: args{
|
||||
event: getEvent(
|
||||
@@ -364,7 +365,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -373,7 +374,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5_http SET signing_key = $1 WHERE (id = $2) AND (instance_id = $3)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6_http SET signing_key = $1 WHERE (id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
"config-id",
|
||||
@@ -416,7 +417,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs5 (creation_date, change_date, instance_id, resource_owner, aggregate_id, id, sequence, state, description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs6 (creation_date, change_date, instance_id, resource_owner, aggregate_id, id, sequence, state, description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
@@ -430,7 +431,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs5_smtp (instance_id, id, tls, sender_address, sender_name, reply_to_address, host, username, password) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs6_smtp (instance_id, id, tls, sender_address, sender_name, reply_to_address, host, username, xoauth2auth_token_endpoint, xoauth2auth_scope, xoauth2auth_client_credentials_client_id, xoauth2auth_client_credentials_client_secret, password) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)",
|
||||
expectedArgs: []interface{}{
|
||||
"instance-id",
|
||||
"ro-id",
|
||||
@@ -440,6 +441,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
"reply-to",
|
||||
"host",
|
||||
"user",
|
||||
nil, nil, nil, nil,
|
||||
anyArg{},
|
||||
},
|
||||
},
|
||||
@@ -481,7 +483,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs5 (creation_date, change_date, instance_id, resource_owner, aggregate_id, id, sequence, state, description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs6 (creation_date, change_date, instance_id, resource_owner, aggregate_id, id, sequence, state, description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
@@ -495,7 +497,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs5_smtp (instance_id, id, tls, sender_address, sender_name, reply_to_address, host, username, password) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs6_smtp (instance_id, id, tls, sender_address, sender_name, reply_to_address, host, username, xoauth2auth_token_endpoint, xoauth2auth_scope, xoauth2auth_client_credentials_client_id, xoauth2auth_client_credentials_client_secret, password) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)",
|
||||
expectedArgs: []interface{}{
|
||||
"instance-id",
|
||||
"config-id",
|
||||
@@ -505,6 +507,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
"reply-to",
|
||||
"host",
|
||||
"user",
|
||||
nil, nil, nil, nil,
|
||||
anyArg{},
|
||||
},
|
||||
},
|
||||
@@ -538,7 +541,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs5 (creation_date, change_date, instance_id, resource_owner, aggregate_id, id, sequence, state, description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs6 (creation_date, change_date, instance_id, resource_owner, aggregate_id, id, sequence, state, description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
@@ -552,7 +555,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs5_http (instance_id, id, endpoint, signing_key) VALUES ($1, $2, $3, $4)",
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs6_http (instance_id, id, endpoint, signing_key) VALUES ($1, $2, $3, $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"instance-id",
|
||||
"config-id",
|
||||
@@ -585,7 +588,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (NOT (id = $4)) AND (state = $5) AND (instance_id = $6)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (NOT (id = $4)) AND (state = $5) AND (instance_id = $6)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -596,7 +599,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -629,7 +632,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (NOT (id = $4)) AND (state = $5) AND (instance_id = $6)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (NOT (id = $4)) AND (state = $5) AND (instance_id = $6)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -640,7 +643,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -674,7 +677,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -707,7 +710,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -747,7 +750,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5_smtp SET password = $1 WHERE (id = $2) AND (instance_id = $3)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6_smtp SET password = $1 WHERE (id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
"config-id",
|
||||
@@ -755,7 +758,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs6 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -788,7 +791,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM projections.smtp_configs5 WHERE (id = $1) AND (instance_id = $2)",
|
||||
expectedStmt: "DELETE FROM projections.smtp_configs6 WHERE (id = $1) AND (instance_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"config-id",
|
||||
"instance-id",
|
||||
@@ -818,7 +821,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM projections.smtp_configs5 WHERE (id = $1) AND (instance_id = $2)",
|
||||
expectedStmt: "DELETE FROM projections.smtp_configs6 WHERE (id = $1) AND (instance_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
@@ -845,7 +848,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM projections.smtp_configs5 WHERE (instance_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.smtp_configs6 WHERE (instance_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
|
||||
+109
-16
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
@@ -100,8 +101,24 @@ var (
|
||||
name: projection.SMTPConfigSMTPColumnUser,
|
||||
table: smtpConfigsSMTPTable,
|
||||
}
|
||||
SMTPConfigSMTPColumnPassword = Column{
|
||||
name: projection.SMTPConfigSMTPColumnPassword,
|
||||
SMTPConfigSMTPColumnPlainAuthPassword = Column{
|
||||
name: projection.SMTPConfigSMTPColumnPlainAuthPassword,
|
||||
table: smtpConfigsSMTPTable,
|
||||
}
|
||||
SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientId = Column{
|
||||
name: projection.SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientId,
|
||||
table: smtpConfigsSMTPTable,
|
||||
}
|
||||
SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientSecret = Column{
|
||||
name: projection.SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientSecret,
|
||||
table: smtpConfigsSMTPTable,
|
||||
}
|
||||
SMTPConfigSMTPColumnXOAuth2AuthTokenEndpoint = Column{
|
||||
name: projection.SMTPConfigSMTPColumnXOAuth2AuthTokenEndpoint,
|
||||
table: smtpConfigsSMTPTable,
|
||||
}
|
||||
SMTPConfigSMTPColumnXOAuth2AuthScope = Column{
|
||||
name: projection.SMTPConfigSMTPColumnXOAuth2AuthScope,
|
||||
table: smtpConfigsSMTPTable,
|
||||
}
|
||||
|
||||
@@ -156,7 +173,35 @@ type SMTP struct {
|
||||
ReplyToAddress string
|
||||
Host string
|
||||
User string
|
||||
Password *crypto.CryptoValue
|
||||
PlainAuth *PlainAuth
|
||||
XOAuth2Auth *XOAuth2Auth
|
||||
}
|
||||
|
||||
type PlainAuth struct {
|
||||
Password *crypto.CryptoValue
|
||||
}
|
||||
|
||||
func (a PlainAuth) isEmpty() bool {
|
||||
return a.Password == nil
|
||||
}
|
||||
|
||||
type XOAuth2Auth struct {
|
||||
TokenEndpoint string
|
||||
Scopes []string
|
||||
ClientCredentials *XOAuthClientCredentials
|
||||
}
|
||||
|
||||
func (a XOAuth2Auth) isEmpty() bool {
|
||||
return a.ClientCredentials == nil && a.TokenEndpoint == "" && len(a.Scopes) == 0
|
||||
}
|
||||
|
||||
type XOAuthClientCredentials struct {
|
||||
ClientId string
|
||||
ClientSecret *crypto.CryptoValue
|
||||
}
|
||||
|
||||
func (a XOAuthClientCredentials) isEmpty() bool {
|
||||
return a.ClientId == "" && a.ClientSecret == nil
|
||||
}
|
||||
|
||||
func (q *Queries) SMTPConfigActive(ctx context.Context, resourceOwner string) (config *SMTPConfig, err error) {
|
||||
@@ -229,7 +274,11 @@ func prepareSMTPConfigQuery() (sq.SelectBuilder, func(*sql.Row) (*SMTPConfig, er
|
||||
SMTPConfigSMTPColumnReplyToAddress.identifier(),
|
||||
SMTPConfigSMTPColumnHost.identifier(),
|
||||
SMTPConfigSMTPColumnUser.identifier(),
|
||||
SMTPConfigSMTPColumnPassword.identifier(),
|
||||
SMTPConfigSMTPColumnPlainAuthPassword.identifier(),
|
||||
SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientId.identifier(),
|
||||
SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientSecret.identifier(),
|
||||
SMTPConfigSMTPColumnXOAuth2AuthTokenEndpoint.identifier(),
|
||||
SMTPConfigSMTPColumnXOAuth2AuthScope.identifier(),
|
||||
|
||||
SMTPConfigHTTPColumnID.identifier(),
|
||||
SMTPConfigHTTPColumnEndpoint.identifier(),
|
||||
@@ -260,7 +309,11 @@ func prepareSMTPConfigQuery() (sq.SelectBuilder, func(*sql.Row) (*SMTPConfig, er
|
||||
&smtpConfig.replyToAddress,
|
||||
&smtpConfig.host,
|
||||
&smtpConfig.user,
|
||||
&smtpConfig.password,
|
||||
&smtpConfig.plainAuthPassword,
|
||||
&smtpConfig.xoauth2AuthClientCredentialsClientId,
|
||||
&smtpConfig.xoauth2AuthClientClientCredentialsSecret,
|
||||
&smtpConfig.xoauth2AuthTokenEndpoint,
|
||||
&smtpConfig.xoauth2AuthScope,
|
||||
&httpConfig.id,
|
||||
&httpConfig.endpoint,
|
||||
&httpConfig.signingKey,
|
||||
@@ -296,7 +349,11 @@ func prepareSMTPConfigsQuery() (sq.SelectBuilder, func(*sql.Rows) (*SMTPConfigs,
|
||||
SMTPConfigSMTPColumnReplyToAddress.identifier(),
|
||||
SMTPConfigSMTPColumnHost.identifier(),
|
||||
SMTPConfigSMTPColumnUser.identifier(),
|
||||
SMTPConfigSMTPColumnPassword.identifier(),
|
||||
SMTPConfigSMTPColumnPlainAuthPassword.identifier(),
|
||||
SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientId.identifier(),
|
||||
SMTPConfigSMTPColumnXOAuth2AuthClientCredentialsClientSecret.identifier(),
|
||||
SMTPConfigSMTPColumnXOAuth2AuthTokenEndpoint.identifier(),
|
||||
SMTPConfigSMTPColumnXOAuth2AuthScope.identifier(),
|
||||
|
||||
SMTPConfigHTTPColumnID.identifier(),
|
||||
SMTPConfigHTTPColumnEndpoint.identifier(),
|
||||
@@ -330,7 +387,11 @@ func prepareSMTPConfigsQuery() (sq.SelectBuilder, func(*sql.Rows) (*SMTPConfigs,
|
||||
&smtpConfig.replyToAddress,
|
||||
&smtpConfig.host,
|
||||
&smtpConfig.user,
|
||||
&smtpConfig.password,
|
||||
&smtpConfig.plainAuthPassword,
|
||||
&smtpConfig.xoauth2AuthClientCredentialsClientId,
|
||||
&smtpConfig.xoauth2AuthClientClientCredentialsSecret,
|
||||
&smtpConfig.xoauth2AuthTokenEndpoint,
|
||||
&smtpConfig.xoauth2AuthScope,
|
||||
&httpConfig.id,
|
||||
&httpConfig.endpoint,
|
||||
&httpConfig.signingKey,
|
||||
@@ -379,20 +440,51 @@ func (q *Queries) SearchSMTPConfigs(ctx context.Context, queries *SMTPConfigsSea
|
||||
}
|
||||
|
||||
type sqlSmtpConfig struct {
|
||||
id sql.NullString
|
||||
tls sql.NullBool
|
||||
senderAddress sql.NullString
|
||||
senderName sql.NullString
|
||||
replyToAddress sql.NullString
|
||||
host sql.NullString
|
||||
user sql.NullString
|
||||
password *crypto.CryptoValue
|
||||
id sql.NullString
|
||||
tls sql.NullBool
|
||||
senderAddress sql.NullString
|
||||
senderName sql.NullString
|
||||
replyToAddress sql.NullString
|
||||
host sql.NullString
|
||||
user sql.NullString
|
||||
plainAuthPassword *crypto.CryptoValue
|
||||
xoauth2AuthClientCredentialsClientId sql.NullString
|
||||
xoauth2AuthClientClientCredentialsSecret *crypto.CryptoValue
|
||||
xoauth2AuthTokenEndpoint sql.NullString
|
||||
xoauth2AuthScope sql.NullString
|
||||
}
|
||||
|
||||
func (c sqlSmtpConfig) set(smtpConfig *SMTPConfig) {
|
||||
if !c.id.Valid {
|
||||
return
|
||||
}
|
||||
|
||||
plainAuth := &PlainAuth{
|
||||
Password: c.plainAuthPassword,
|
||||
}
|
||||
if plainAuth.isEmpty() {
|
||||
plainAuth = nil
|
||||
}
|
||||
|
||||
scopes := strings.Split(c.xoauth2AuthScope.String, " ")
|
||||
if len(scopes) == 1 && scopes[0] == "" {
|
||||
scopes = nil
|
||||
}
|
||||
xoauth2Auth := &XOAuth2Auth{
|
||||
TokenEndpoint: c.xoauth2AuthTokenEndpoint.String,
|
||||
Scopes: scopes,
|
||||
ClientCredentials: &XOAuthClientCredentials{
|
||||
ClientId: c.xoauth2AuthClientCredentialsClientId.String,
|
||||
ClientSecret: c.xoauth2AuthClientClientCredentialsSecret,
|
||||
},
|
||||
}
|
||||
if xoauth2Auth.ClientCredentials.isEmpty() {
|
||||
xoauth2Auth.ClientCredentials = nil
|
||||
}
|
||||
if xoauth2Auth.isEmpty() {
|
||||
xoauth2Auth = nil
|
||||
}
|
||||
|
||||
smtpConfig.SMTPConfig = &SMTP{
|
||||
TLS: c.tls.Bool,
|
||||
SenderAddress: c.senderAddress.String,
|
||||
@@ -400,7 +492,8 @@ func (c sqlSmtpConfig) set(smtpConfig *SMTPConfig) {
|
||||
ReplyToAddress: c.replyToAddress.String,
|
||||
Host: c.host.String,
|
||||
User: c.user.String,
|
||||
Password: c.password,
|
||||
PlainAuth: plainAuth,
|
||||
XOAuth2Auth: xoauth2Auth,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+104
-48
@@ -14,49 +14,57 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
prepareSMTPConfigStmt = `SELECT projections.smtp_configs5.creation_date,` +
|
||||
` projections.smtp_configs5.change_date,` +
|
||||
` projections.smtp_configs5.resource_owner,` +
|
||||
` projections.smtp_configs5.sequence,` +
|
||||
` projections.smtp_configs5.id,` +
|
||||
` projections.smtp_configs5.state,` +
|
||||
` projections.smtp_configs5.description,` +
|
||||
` projections.smtp_configs5_smtp.id,` +
|
||||
` projections.smtp_configs5_smtp.tls,` +
|
||||
` projections.smtp_configs5_smtp.sender_address,` +
|
||||
` projections.smtp_configs5_smtp.sender_name,` +
|
||||
` projections.smtp_configs5_smtp.reply_to_address,` +
|
||||
` projections.smtp_configs5_smtp.host,` +
|
||||
` projections.smtp_configs5_smtp.username,` +
|
||||
` projections.smtp_configs5_smtp.password,` +
|
||||
` projections.smtp_configs5_http.id,` +
|
||||
` projections.smtp_configs5_http.endpoint,` +
|
||||
` projections.smtp_configs5_http.signing_key` +
|
||||
` FROM projections.smtp_configs5` +
|
||||
` LEFT JOIN projections.smtp_configs5_smtp ON projections.smtp_configs5.id = projections.smtp_configs5_smtp.id AND projections.smtp_configs5.instance_id = projections.smtp_configs5_smtp.instance_id` +
|
||||
` LEFT JOIN projections.smtp_configs5_http ON projections.smtp_configs5.id = projections.smtp_configs5_http.id AND projections.smtp_configs5.instance_id = projections.smtp_configs5_http.instance_id`
|
||||
prepareSMTPConfigsStmt = `SELECT projections.smtp_configs5.creation_date,` +
|
||||
` projections.smtp_configs5.change_date,` +
|
||||
` projections.smtp_configs5.resource_owner,` +
|
||||
` projections.smtp_configs5.sequence,` +
|
||||
` projections.smtp_configs5.id,` +
|
||||
` projections.smtp_configs5.state,` +
|
||||
` projections.smtp_configs5.description,` +
|
||||
` projections.smtp_configs5_smtp.id,` +
|
||||
` projections.smtp_configs5_smtp.tls,` +
|
||||
` projections.smtp_configs5_smtp.sender_address,` +
|
||||
` projections.smtp_configs5_smtp.sender_name,` +
|
||||
` projections.smtp_configs5_smtp.reply_to_address,` +
|
||||
` projections.smtp_configs5_smtp.host,` +
|
||||
` projections.smtp_configs5_smtp.username,` +
|
||||
` projections.smtp_configs5_smtp.password,` +
|
||||
` projections.smtp_configs5_http.id,` +
|
||||
` projections.smtp_configs5_http.endpoint,` +
|
||||
` projections.smtp_configs5_http.signing_key,` +
|
||||
prepareSMTPConfigStmt = `SELECT projections.smtp_configs6.creation_date,` +
|
||||
` projections.smtp_configs6.change_date,` +
|
||||
` projections.smtp_configs6.resource_owner,` +
|
||||
` projections.smtp_configs6.sequence,` +
|
||||
` projections.smtp_configs6.id,` +
|
||||
` projections.smtp_configs6.state,` +
|
||||
` projections.smtp_configs6.description,` +
|
||||
` projections.smtp_configs6_smtp.id,` +
|
||||
` projections.smtp_configs6_smtp.tls,` +
|
||||
` projections.smtp_configs6_smtp.sender_address,` +
|
||||
` projections.smtp_configs6_smtp.sender_name,` +
|
||||
` projections.smtp_configs6_smtp.reply_to_address,` +
|
||||
` projections.smtp_configs6_smtp.host,` +
|
||||
` projections.smtp_configs6_smtp.username,` +
|
||||
` projections.smtp_configs6_smtp.password,` +
|
||||
` projections.smtp_configs6_smtp.xoauth2auth_client_credentials_client_id,` +
|
||||
` projections.smtp_configs6_smtp.xoauth2auth_client_credentials_client_secret,` +
|
||||
` projections.smtp_configs6_smtp.xoauth2auth_token_endpoint,` +
|
||||
` projections.smtp_configs6_smtp.xoauth2auth_scope,` +
|
||||
` projections.smtp_configs6_http.id,` +
|
||||
` projections.smtp_configs6_http.endpoint,` +
|
||||
` projections.smtp_configs6_http.signing_key` +
|
||||
` FROM projections.smtp_configs6` +
|
||||
` LEFT JOIN projections.smtp_configs6_smtp ON projections.smtp_configs6.id = projections.smtp_configs6_smtp.id AND projections.smtp_configs6.instance_id = projections.smtp_configs6_smtp.instance_id` +
|
||||
` LEFT JOIN projections.smtp_configs6_http ON projections.smtp_configs6.id = projections.smtp_configs6_http.id AND projections.smtp_configs6.instance_id = projections.smtp_configs6_http.instance_id`
|
||||
prepareSMTPConfigsStmt = `SELECT projections.smtp_configs6.creation_date,` +
|
||||
` projections.smtp_configs6.change_date,` +
|
||||
` projections.smtp_configs6.resource_owner,` +
|
||||
` projections.smtp_configs6.sequence,` +
|
||||
` projections.smtp_configs6.id,` +
|
||||
` projections.smtp_configs6.state,` +
|
||||
` projections.smtp_configs6.description,` +
|
||||
` projections.smtp_configs6_smtp.id,` +
|
||||
` projections.smtp_configs6_smtp.tls,` +
|
||||
` projections.smtp_configs6_smtp.sender_address,` +
|
||||
` projections.smtp_configs6_smtp.sender_name,` +
|
||||
` projections.smtp_configs6_smtp.reply_to_address,` +
|
||||
` projections.smtp_configs6_smtp.host,` +
|
||||
` projections.smtp_configs6_smtp.username,` +
|
||||
` projections.smtp_configs6_smtp.password,` +
|
||||
` projections.smtp_configs6_smtp.xoauth2auth_client_credentials_client_id,` +
|
||||
` projections.smtp_configs6_smtp.xoauth2auth_client_credentials_client_secret,` +
|
||||
` projections.smtp_configs6_smtp.xoauth2auth_token_endpoint,` +
|
||||
` projections.smtp_configs6_smtp.xoauth2auth_scope,` +
|
||||
` projections.smtp_configs6_http.id,` +
|
||||
` projections.smtp_configs6_http.endpoint,` +
|
||||
` projections.smtp_configs6_http.signing_key,` +
|
||||
` COUNT(*) OVER ()` +
|
||||
` FROM projections.smtp_configs5` +
|
||||
` LEFT JOIN projections.smtp_configs5_smtp ON projections.smtp_configs5.id = projections.smtp_configs5_smtp.id AND projections.smtp_configs5.instance_id = projections.smtp_configs5_smtp.instance_id` +
|
||||
` LEFT JOIN projections.smtp_configs5_http ON projections.smtp_configs5.id = projections.smtp_configs5_http.id AND projections.smtp_configs5.instance_id = projections.smtp_configs5_http.instance_id`
|
||||
` FROM projections.smtp_configs6` +
|
||||
` LEFT JOIN projections.smtp_configs6_smtp ON projections.smtp_configs6.id = projections.smtp_configs6_smtp.id AND projections.smtp_configs6.instance_id = projections.smtp_configs6_smtp.instance_id` +
|
||||
` LEFT JOIN projections.smtp_configs6_http ON projections.smtp_configs6.id = projections.smtp_configs6_http.id AND projections.smtp_configs6.instance_id = projections.smtp_configs6_http.instance_id`
|
||||
|
||||
prepareSMTPConfigCols = []string{
|
||||
"creation_date",
|
||||
@@ -74,6 +82,10 @@ var (
|
||||
"smtp_host",
|
||||
"smtp_user",
|
||||
"smtp_password",
|
||||
"xoauth2auth_client_credentials_client_id",
|
||||
"xoauth2auth_client_credentials_client_secret",
|
||||
"xoauth2auth_token_endpoint",
|
||||
"xoauth2auth_scope",
|
||||
"id",
|
||||
"endpoint",
|
||||
"signing_key",
|
||||
@@ -136,6 +148,10 @@ func Test_SMTPConfigPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
),
|
||||
},
|
||||
@@ -151,7 +167,9 @@ func Test_SMTPConfigPrepares(t *testing.T) {
|
||||
ReplyToAddress: "reply-to",
|
||||
Host: "host",
|
||||
User: "user",
|
||||
Password: &crypto.CryptoValue{},
|
||||
PlainAuth: &PlainAuth{
|
||||
Password: &crypto.CryptoValue{},
|
||||
},
|
||||
},
|
||||
ID: "2232323",
|
||||
State: domain.SMTPConfigStateActive,
|
||||
@@ -181,6 +199,10 @@ func Test_SMTPConfigPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
"2232323",
|
||||
"endpoint",
|
||||
&crypto.CryptoValue{
|
||||
@@ -237,6 +259,10 @@ func Test_SMTPConfigPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
),
|
||||
},
|
||||
@@ -252,7 +278,9 @@ func Test_SMTPConfigPrepares(t *testing.T) {
|
||||
ReplyToAddress: "reply-to2",
|
||||
Host: "host2",
|
||||
User: "user2",
|
||||
Password: &crypto.CryptoValue{},
|
||||
PlainAuth: &PlainAuth{
|
||||
Password: &crypto.CryptoValue{},
|
||||
},
|
||||
},
|
||||
ID: "44442323",
|
||||
State: domain.SMTPConfigStateInactive,
|
||||
@@ -285,6 +313,10 @@ func Test_SMTPConfigPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
),
|
||||
},
|
||||
@@ -300,7 +332,9 @@ func Test_SMTPConfigPrepares(t *testing.T) {
|
||||
ReplyToAddress: "reply-to3",
|
||||
Host: "host3",
|
||||
User: "user3",
|
||||
Password: &crypto.CryptoValue{},
|
||||
PlainAuth: &PlainAuth{
|
||||
Password: &crypto.CryptoValue{},
|
||||
},
|
||||
},
|
||||
ID: "23234444",
|
||||
State: domain.SMTPConfigStateInactive,
|
||||
@@ -383,6 +417,10 @@ func Test_SMTPConfigsPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
},
|
||||
),
|
||||
@@ -404,7 +442,9 @@ func Test_SMTPConfigsPrepares(t *testing.T) {
|
||||
ReplyToAddress: "reply-to",
|
||||
Host: "host",
|
||||
User: "user",
|
||||
Password: &crypto.CryptoValue{},
|
||||
PlainAuth: &PlainAuth{
|
||||
Password: &crypto.CryptoValue{},
|
||||
},
|
||||
},
|
||||
ID: "2232323",
|
||||
State: domain.SMTPConfigStateActive,
|
||||
@@ -437,6 +477,10 @@ func Test_SMTPConfigsPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
"2232323",
|
||||
"endpoint",
|
||||
&crypto.CryptoValue{
|
||||
@@ -465,6 +509,10 @@ func Test_SMTPConfigsPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
testNow,
|
||||
@@ -485,6 +533,10 @@ func Test_SMTPConfigsPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
},
|
||||
),
|
||||
@@ -524,7 +576,9 @@ func Test_SMTPConfigsPrepares(t *testing.T) {
|
||||
ReplyToAddress: "reply-to2",
|
||||
Host: "host2",
|
||||
User: "user2",
|
||||
Password: &crypto.CryptoValue{},
|
||||
PlainAuth: &PlainAuth{
|
||||
Password: &crypto.CryptoValue{},
|
||||
},
|
||||
},
|
||||
ID: "44442323",
|
||||
State: domain.SMTPConfigStateInactive,
|
||||
@@ -542,7 +596,9 @@ func Test_SMTPConfigsPrepares(t *testing.T) {
|
||||
ReplyToAddress: "reply-to3",
|
||||
Host: "host3",
|
||||
User: "user3",
|
||||
Password: &crypto.CryptoValue{},
|
||||
PlainAuth: &PlainAuth{
|
||||
Password: &crypto.CryptoValue{},
|
||||
},
|
||||
},
|
||||
ID: "23234444",
|
||||
State: domain.SMTPConfigStateInactive,
|
||||
|
||||
Reference in New Issue
Block a user