2020-07-08 11:56:37 +00:00
|
|
|
package admin
|
2020-03-24 06:09:28 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-07-08 11:56:37 +00:00
|
|
|
|
2020-06-16 09:40:18 +00:00
|
|
|
"github.com/golang/protobuf/ptypes/empty"
|
2020-07-08 11:56:37 +00:00
|
|
|
|
|
|
|
"github.com/caos/zitadel/pkg/grpc/admin"
|
2020-03-24 06:09:28 +00:00
|
|
|
)
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) GetOrgByID(ctx context.Context, orgID *admin.OrgID) (_ *admin.Org, err error) {
|
2020-05-13 12:22:29 +00:00
|
|
|
org, err := s.org.OrgByID(ctx, orgID.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return orgFromModel(org), nil
|
2020-03-24 06:09:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) SearchOrgs(ctx context.Context, request *admin.OrgSearchRequest) (_ *admin.OrgSearchResponse, err error) {
|
2020-05-26 14:46:16 +00:00
|
|
|
result, err := s.org.SearchOrgs(ctx, orgSearchRequestToModel(request))
|
2020-05-13 12:22:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
return &admin.OrgSearchResponse{
|
2020-05-26 14:46:16 +00:00
|
|
|
Result: orgViewsFromModel(result.Result),
|
|
|
|
Limit: request.Limit,
|
|
|
|
Offset: request.Offset,
|
|
|
|
TotalResult: result.TotalResult,
|
2020-05-13 12:22:29 +00:00
|
|
|
}, nil
|
2020-03-24 06:09:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) IsOrgUnique(ctx context.Context, request *admin.UniqueOrgRequest) (org *admin.UniqueOrgResponse, err error) {
|
2020-05-13 12:22:29 +00:00
|
|
|
isUnique, err := s.org.IsOrgUnique(ctx, request.Name, request.Domain)
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
return &admin.UniqueOrgResponse{IsUnique: isUnique}, err
|
2020-03-24 06:09:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) SetUpOrg(ctx context.Context, orgSetUp *admin.OrgSetUpRequest) (_ *admin.OrgSetUpResponse, err error) {
|
2020-05-13 12:22:29 +00:00
|
|
|
setUp, err := s.org.SetUpOrg(ctx, setUpRequestToModel(orgSetUp))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return setUpOrgResponseFromModel(setUp), err
|
2020-03-24 06:09:28 +00:00
|
|
|
}
|
2020-05-26 14:46:16 +00:00
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) GetOrgIamPolicy(ctx context.Context, in *admin.OrgIamPolicyID) (_ *admin.OrgIamPolicy, err error) {
|
2020-06-16 09:40:18 +00:00
|
|
|
policy, err := s.org.GetOrgIamPolicyByID(ctx, in.OrgId)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-05-26 14:46:16 +00:00
|
|
|
}
|
2020-06-16 09:40:18 +00:00
|
|
|
return orgIamPolicyFromModel(policy), err
|
2020-05-26 14:46:16 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) CreateOrgIamPolicy(ctx context.Context, in *admin.OrgIamPolicyRequest) (_ *admin.OrgIamPolicy, err error) {
|
2020-06-16 09:40:18 +00:00
|
|
|
policy, err := s.org.CreateOrgIamPolicy(ctx, orgIamPolicyRequestToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-05-26 14:46:16 +00:00
|
|
|
}
|
2020-06-16 09:40:18 +00:00
|
|
|
return orgIamPolicyFromModel(policy), err
|
2020-05-26 14:46:16 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) UpdateOrgIamPolicy(ctx context.Context, in *admin.OrgIamPolicyRequest) (_ *admin.OrgIamPolicy, err error) {
|
2020-06-16 09:40:18 +00:00
|
|
|
policy, err := s.org.ChangeOrgIamPolicy(ctx, orgIamPolicyRequestToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-05-26 14:46:16 +00:00
|
|
|
}
|
2020-06-16 09:40:18 +00:00
|
|
|
return orgIamPolicyFromModel(policy), err
|
2020-05-26 14:46:16 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) DeleteOrgIamPolicy(ctx context.Context, in *admin.OrgIamPolicyID) (_ *empty.Empty, err error) {
|
2020-06-16 09:40:18 +00:00
|
|
|
err = s.org.RemoveOrgIamPolicy(ctx, in.OrgId)
|
|
|
|
return &empty.Empty{}, err
|
2020-05-26 14:46:16 +00:00
|
|
|
}
|