zitadel/internal/api/grpc/admin/sms_converter.go
Fabi 7d235e3eed
feat: Default configs sms provider (#3187)
* feat: sms config

* feat: twilio as sms provider

* feat:sms projection

* feat: sms queries

* feat: sms queries test

* feat: sms configs

* feat: sms configs sql file

* fix merge

* fix: rename from to sendername

* fix: proto comments

* fix: token as crypto

* fix: tests

* fix: sms config sender name to sender number

* fix: sms config sender name to sender number

* Update email.go

* Update channel.go

* Update V1.111__settings.sql

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-02-21 12:22:20 +00:00

64 lines
1.8 KiB
Go

package admin
import (
"github.com/caos/zitadel/internal/api/grpc/object"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/notification/channels/twilio"
"github.com/caos/zitadel/internal/query"
admin_pb "github.com/caos/zitadel/pkg/grpc/admin"
settings_pb "github.com/caos/zitadel/pkg/grpc/settings"
)
func listSMSConfigsToModel(req *admin_pb.ListSMSProvidersRequest) (*query.SMSConfigsSearchQueries, error) {
offset, limit, asc := object.ListQueryToModel(req.Query)
return &query.SMSConfigsSearchQueries{
SearchRequest: query.SearchRequest{
Offset: offset,
Limit: limit,
Asc: asc,
},
}, nil
}
func SMSConfigToPb(app *query.SMSConfig) settings_pb.SMSConfig {
if app.TwilioConfig != nil {
return TwilioConfigToPb(app.TwilioConfig)
}
return nil
}
func TwilioConfigToPb(twilio *query.Twilio) *settings_pb.SMSProvider_Twilio {
return &settings_pb.SMSProvider_Twilio{
Twilio: &settings_pb.TwilioConfig{
Sid: twilio.SID,
SenderNumber: twilio.SenderNumber,
},
}
}
func smsStateToPb(state domain.SMSConfigState) settings_pb.SMSProviderConfigState {
switch state {
case domain.SMSConfigStateInactive:
return settings_pb.SMSProviderConfigState_SMS_PROVIDER_CONFIG_INACTIVE
case domain.SMSConfigStateActive:
return settings_pb.SMSProviderConfigState_SMS_PROVIDER_CONFIG_ACTIVE
default:
return settings_pb.SMSProviderConfigState_SMS_PROVIDER_CONFIG_INACTIVE
}
}
func AddSMSConfigTwilioToConfig(req *admin_pb.AddSMSProviderTwilioRequest) *twilio.TwilioConfig {
return &twilio.TwilioConfig{
SID: req.Sid,
SenderNumber: req.SenderNumber,
Token: req.Token,
}
}
func UpdateSMSConfigTwilioToConfig(req *admin_pb.UpdateSMSProviderTwilioRequest) *twilio.TwilioConfig {
return &twilio.TwilioConfig{
SID: req.Sid,
SenderNumber: req.SenderNumber,
}
}