2020-07-08 11:56:37 +00:00
|
|
|
package management
|
2020-03-24 09:14:39 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-06-15 14:50:09 +00:00
|
|
|
|
2020-04-21 15:00:32 +00:00
|
|
|
"github.com/golang/protobuf/ptypes/empty"
|
2020-07-08 11:56:37 +00:00
|
|
|
|
|
|
|
"github.com/caos/zitadel/pkg/grpc/management"
|
2020-03-24 09:14:39 +00:00
|
|
|
)
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) SearchApplications(ctx context.Context, in *management.ApplicationSearchRequest) (*management.ApplicationSearchResponse, error) {
|
2020-05-11 10:16:29 +00:00
|
|
|
response, err := s.project.SearchApplications(ctx, applicationSearchRequestsToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return applicationSearchResponseFromModel(response), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ApplicationByID(ctx context.Context, in *management.ApplicationID) (*management.ApplicationView, error) {
|
2020-08-10 07:34:56 +00:00
|
|
|
app, err := s.project.ApplicationByID(ctx, in.ProjectId, in.Id)
|
2020-04-21 15:00:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-06-23 05:06:07 +00:00
|
|
|
return applicationViewFromModel(app), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) CreateOIDCApplication(ctx context.Context, in *management.OIDCApplicationCreate) (*management.Application, error) {
|
2020-04-21 15:00:32 +00:00
|
|
|
app, err := s.project.AddApplication(ctx, oidcAppCreateToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return appFromModel(app), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) UpdateApplication(ctx context.Context, in *management.ApplicationUpdate) (*management.Application, error) {
|
2020-04-21 15:00:32 +00:00
|
|
|
app, err := s.project.ChangeApplication(ctx, appUpdateToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return appFromModel(app), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) DeactivateApplication(ctx context.Context, in *management.ApplicationID) (*management.Application, error) {
|
2020-04-21 15:00:32 +00:00
|
|
|
app, err := s.project.DeactivateApplication(ctx, in.ProjectId, in.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return appFromModel(app), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ReactivateApplication(ctx context.Context, in *management.ApplicationID) (*management.Application, error) {
|
2020-04-21 15:00:32 +00:00
|
|
|
app, err := s.project.ReactivateApplication(ctx, in.ProjectId, in.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return appFromModel(app), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-04-21 15:00:32 +00:00
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) RemoveApplication(ctx context.Context, in *management.ApplicationID) (*empty.Empty, error) {
|
2020-04-21 15:00:32 +00:00
|
|
|
err := s.project.RemoveApplication(ctx, in.ProjectId, in.Id)
|
|
|
|
return &empty.Empty{}, err
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) UpdateApplicationOIDCConfig(ctx context.Context, in *management.OIDCConfigUpdate) (*management.OIDCConfig, error) {
|
2020-04-21 15:00:32 +00:00
|
|
|
config, err := s.project.ChangeOIDCConfig(ctx, oidcConfigUpdateToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return oidcConfigFromModel(config), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-04-21 15:00:32 +00:00
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) RegenerateOIDCClientSecret(ctx context.Context, in *management.ApplicationID) (*management.ClientSecret, error) {
|
2020-04-21 15:00:32 +00:00
|
|
|
config, err := s.project.ChangeOIDConfigSecret(ctx, in.ProjectId, in.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
return &management.ClientSecret{ClientSecret: config.ClientSecretString}, nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ApplicationChanges(ctx context.Context, changesRequest *management.ChangeRequest) (*management.Changes, error) {
|
2020-06-25 09:25:38 +00:00
|
|
|
response, err := s.project.ApplicationChanges(ctx, changesRequest.Id, changesRequest.SecId, changesRequest.SequenceOffset, changesRequest.Limit, changesRequest.Asc)
|
2020-06-15 14:50:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return appChangesToResponse(response, changesRequest.GetSequenceOffset(), changesRequest.GetLimit()), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|