zitadel/internal/api/grpc/management/project_member_converter.go
Livio Amstutz 3549a8b64e
feat: port reduction (#323)
* move mgmt pkg

* begin package restructure

* rename auth package to authz

* begin start api

* move auth

* move admin

* fix merge

* configs and interceptors

* interceptor

* revert generate-grpc.sh

* some cleanups

* console

* move console

* fix tests and merging

* js linting

* merge

* merging and configs

* change k8s base to current ports

* fixes

* cleanup

* regenerate proto

* remove unnecessary whitespace

* missing param

* go mod tidy

* fix merging

* move login pkg

* cleanup

* move api pkgs again

* fix pkg naming

* fix generate-static.sh for login

* update workflow

* fixes

* logging

* remove duplicate

* comment for optional gateway interfaces

* regenerate protos

* fix proto imports for grpc web

* protos

* grpc web generate

* grpc web generate

* fix changes

* add translation interceptor

* fix merging

* regenerate mgmt proto
2020-07-08 13:56:37 +02:00

123 lines
4.1 KiB
Go

package management
import (
"github.com/caos/logging"
"github.com/golang/protobuf/ptypes"
"github.com/caos/zitadel/internal/eventstore/models"
proj_model "github.com/caos/zitadel/internal/project/model"
"github.com/caos/zitadel/pkg/grpc/management"
)
func projectMemberFromModel(member *proj_model.ProjectMember) *management.ProjectMember {
creationDate, err := ptypes.TimestampProto(member.CreationDate)
logging.Log("GRPC-kd8re").OnError(err).Debug("unable to parse timestamp")
changeDate, err := ptypes.TimestampProto(member.ChangeDate)
logging.Log("GRPC-dlei3").OnError(err).Debug("unable to parse timestamp")
return &management.ProjectMember{
CreationDate: creationDate,
ChangeDate: changeDate,
Sequence: member.Sequence,
UserId: member.UserID,
Roles: member.Roles,
}
}
func projectMemberAddToModel(member *management.ProjectMemberAdd) *proj_model.ProjectMember {
return &proj_model.ProjectMember{
ObjectRoot: models.ObjectRoot{
AggregateID: member.Id,
},
UserID: member.UserId,
Roles: member.Roles,
}
}
func projectMemberChangeToModel(member *management.ProjectMemberChange) *proj_model.ProjectMember {
return &proj_model.ProjectMember{
ObjectRoot: models.ObjectRoot{
AggregateID: member.Id,
},
UserID: member.UserId,
Roles: member.Roles,
}
}
func projectMemberSearchRequestsToModel(role *management.ProjectMemberSearchRequest) *proj_model.ProjectMemberSearchRequest {
return &proj_model.ProjectMemberSearchRequest{
Offset: role.Offset,
Limit: role.Limit,
Queries: projectMemberSearchQueriesToModel(role.Queries),
}
}
func projectMemberSearchQueriesToModel(queries []*management.ProjectMemberSearchQuery) []*proj_model.ProjectMemberSearchQuery {
converted := make([]*proj_model.ProjectMemberSearchQuery, len(queries))
for i, q := range queries {
converted[i] = projectMemberSearchQueryToModel(q)
}
return converted
}
func projectMemberSearchQueryToModel(query *management.ProjectMemberSearchQuery) *proj_model.ProjectMemberSearchQuery {
return &proj_model.ProjectMemberSearchQuery{
Key: projectMemberSearchKeyToModel(query.Key),
Method: searchMethodToModel(query.Method),
Value: query.Value,
}
}
func projectMemberSearchKeyToModel(key management.ProjectMemberSearchKey) proj_model.ProjectMemberSearchKey {
switch key {
case management.ProjectMemberSearchKey_PROJECTMEMBERSEARCHKEY_EMAIL:
return proj_model.ProjectMemberSearchKeyEmail
case management.ProjectMemberSearchKey_PROJECTMEMBERSEARCHKEY_FIRST_NAME:
return proj_model.ProjectMemberSearchKeyFirstName
case management.ProjectMemberSearchKey_PROJECTMEMBERSEARCHKEY_LAST_NAME:
return proj_model.ProjectMemberSearchKeyLastName
case management.ProjectMemberSearchKey_PROJECTMEMBERSEARCHKEY_USER_NAME:
return proj_model.ProjectMemberSearchKeyUserName
default:
return proj_model.ProjectMemberSearchKeyUnspecified
}
}
func projectMemberSearchResponseFromModel(response *proj_model.ProjectMemberSearchResponse) *management.ProjectMemberSearchResponse {
return &management.ProjectMemberSearchResponse{
Offset: response.Offset,
Limit: response.Limit,
TotalResult: response.TotalResult,
Result: projectMemberViewsFromModel(response.Result),
}
}
func projectMemberViewsFromModel(members []*proj_model.ProjectMemberView) []*management.ProjectMemberView {
converted := make([]*management.ProjectMemberView, len(members))
for i, member := range members {
converted[i] = projectMemberViewFromModel(member)
}
return converted
}
func projectMemberViewFromModel(member *proj_model.ProjectMemberView) *management.ProjectMemberView {
creationDate, err := ptypes.TimestampProto(member.CreationDate)
logging.Log("GRPC-sl9cs").OnError(err).Debug("unable to parse timestamp")
changeDate, err := ptypes.TimestampProto(member.ChangeDate)
logging.Log("GRPC-8iw2d").OnError(err).Debug("unable to parse timestamp")
return &management.ProjectMemberView{
UserId: member.UserID,
UserName: member.UserName,
Email: member.Email,
FirstName: member.FirstName,
LastName: member.LastName,
Roles: member.Roles,
CreationDate: creationDate,
ChangeDate: changeDate,
Sequence: member.Sequence,
}
}