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