zitadel/internal/api/grpc/admin/sms.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

75 lines
2.4 KiB
Go

package admin
import (
"context"
"github.com/caos/zitadel/internal/api/grpc/object"
admin_pb "github.com/caos/zitadel/pkg/grpc/admin"
settings_pb "github.com/caos/zitadel/pkg/grpc/settings"
)
func (s *Server) ListSMSProviders(ctx context.Context, req *admin_pb.ListSMSProvidersRequest) (*admin_pb.ListSMSProvidersResponse, error) {
queries, err := listSMSConfigsToModel(req)
if err != nil {
return nil, err
}
result, err := s.query.SearchSMSConfigs(ctx, queries)
if err != nil {
return nil, err
}
return &admin_pb.ListSMSProvidersResponse{
Details: object.ToListDetails(result.Count, result.Sequence, result.Timestamp),
}, nil
}
func (s *Server) GetSMSProvider(ctx context.Context, req *admin_pb.GetSMSProviderRequest) (*admin_pb.GetSMSProviderResponse, error) {
result, err := s.query.SMSProviderConfigByID(ctx, req.Id)
if err != nil {
return nil, err
}
return &admin_pb.GetSMSProviderResponse{
Config: &settings_pb.SMSProvider{
Details: object.ToViewDetailsPb(result.Sequence, result.CreationDate, result.ChangeDate, result.ResourceOwner),
Id: result.ID,
State: smsStateToPb(result.State),
Config: SMSConfigToPb(result),
},
}, nil
}
func (s *Server) AddSMSProviderTwilio(ctx context.Context, req *admin_pb.AddSMSProviderTwilioRequest) (*admin_pb.AddSMSProviderTwilioResponse, error) {
id, result, err := s.command.AddSMSConfigTwilio(ctx, AddSMSConfigTwilioToConfig(req))
if err != nil {
return nil, err
}
return &admin_pb.AddSMSProviderTwilioResponse{
Details: object.DomainToAddDetailsPb(result),
Id: id,
}, nil
}
func (s *Server) UpdateSMSProviderTwilio(ctx context.Context, req *admin_pb.UpdateSMSProviderTwilioRequest) (*admin_pb.UpdateSMSProviderTwilioResponse, error) {
result, err := s.command.ChangeSMSConfigTwilio(ctx, req.Id, UpdateSMSConfigTwilioToConfig(req))
if err != nil {
return nil, err
}
return &admin_pb.UpdateSMSProviderTwilioResponse{
Details: object.DomainToChangeDetailsPb(result),
}, nil
}
func (s *Server) UpdateSMSProviderTwilioToken(ctx context.Context, req *admin_pb.UpdateSMSProviderTwilioTokenRequest) (*admin_pb.UpdateSMSProviderTwilioTokenResponse, error) {
result, err := s.command.ChangeSMSConfigTwilioToken(ctx, req.Id, req.Token)
if err != nil {
return nil, err
}
return &admin_pb.UpdateSMSProviderTwilioTokenResponse{
Details: object.DomainToChangeDetailsPb(result),
}, nil
}