2020-04-07 11:23:04 +00:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/logging"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
|
|
|
proj_model "github.com/caos/zitadel/internal/project/model"
|
|
|
|
"github.com/golang/protobuf/ptypes"
|
|
|
|
)
|
|
|
|
|
|
|
|
func projectFromModel(project *proj_model.Project) *Project {
|
|
|
|
creationDate, err := ptypes.TimestampProto(project.CreationDate)
|
|
|
|
logging.Log("GRPC-iejs3").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(project.ChangeDate)
|
|
|
|
logging.Log("GRPC-di7rw").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &Project{
|
2020-04-21 15:00:32 +00:00
|
|
|
Id: project.AggregateID,
|
2020-04-07 11:23:04 +00:00
|
|
|
State: projectStateFromModel(project.State),
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Name: project.Name,
|
|
|
|
Sequence: project.Sequence,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func projectSearchResponseFromModel(response *proj_model.ProjectViewSearchResponse) *ProjectSearchResponse {
|
|
|
|
return &ProjectSearchResponse{
|
2020-05-11 10:16:29 +00:00
|
|
|
Offset: response.Offset,
|
|
|
|
Limit: response.Limit,
|
|
|
|
TotalResult: response.TotalResult,
|
2020-06-15 12:50:39 +00:00
|
|
|
Result: projectViewsFromModel(response.Result),
|
2020-05-11 10:16:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func projectViewsFromModel(projects []*proj_model.ProjectView) []*ProjectView {
|
|
|
|
converted := make([]*ProjectView, len(projects))
|
2020-05-11 10:16:29 +00:00
|
|
|
for i, project := range projects {
|
2020-06-15 12:50:39 +00:00
|
|
|
converted[i] = projectViewFromModel(project)
|
2020-05-11 10:16:29 +00:00
|
|
|
}
|
|
|
|
return converted
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func projectViewFromModel(project *proj_model.ProjectView) *ProjectView {
|
2020-05-11 10:16:29 +00:00
|
|
|
creationDate, err := ptypes.TimestampProto(project.CreationDate)
|
|
|
|
logging.Log("GRPC-dlso3").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(project.ChangeDate)
|
|
|
|
logging.Log("GRPC-sope3").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
return &ProjectView{
|
|
|
|
ProjectId: project.ProjectID,
|
2020-05-11 10:16:29 +00:00
|
|
|
State: projectStateFromModel(project.State),
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Name: project.Name,
|
|
|
|
Sequence: project.Sequence,
|
|
|
|
ResourceOwner: project.ResourceOwner,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectRoleSearchResponseFromModel(response *proj_model.ProjectRoleSearchResponse) *ProjectRoleSearchResponse {
|
|
|
|
return &ProjectRoleSearchResponse{
|
|
|
|
Offset: response.Offset,
|
|
|
|
Limit: response.Limit,
|
|
|
|
TotalResult: response.TotalResult,
|
|
|
|
Result: projectRoleViewsFromModel(response.Result),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectRoleViewsFromModel(roles []*proj_model.ProjectRoleView) []*ProjectRoleView {
|
|
|
|
converted := make([]*ProjectRoleView, len(roles))
|
|
|
|
for i, role := range roles {
|
|
|
|
converted[i] = projectRoleViewFromModel(role)
|
|
|
|
}
|
|
|
|
return converted
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectRoleViewFromModel(role *proj_model.ProjectRoleView) *ProjectRoleView {
|
|
|
|
creationDate, err := ptypes.TimestampProto(role.CreationDate)
|
|
|
|
logging.Log("GRPC-dlso3").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &ProjectRoleView{
|
|
|
|
ProjectId: role.ProjectID,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
Key: role.Key,
|
|
|
|
Group: role.Group,
|
|
|
|
DisplayName: role.DisplayName,
|
|
|
|
Sequence: role.Sequence,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-07 11:23:04 +00:00
|
|
|
func projectStateFromModel(state proj_model.ProjectState) ProjectState {
|
|
|
|
switch state {
|
2020-04-21 15:00:32 +00:00
|
|
|
case proj_model.PROJECTSTATE_ACTIVE:
|
2020-04-07 11:23:04 +00:00
|
|
|
return ProjectState_PROJECTSTATE_ACTIVE
|
2020-04-21 15:00:32 +00:00
|
|
|
case proj_model.PROJECTSTATE_INACTIVE:
|
2020-04-07 11:23:04 +00:00
|
|
|
return ProjectState_PROJECTSTATE_INACTIVE
|
|
|
|
default:
|
|
|
|
return ProjectState_PROJECTSTATE_UNSPECIFIED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectUpdateToModel(project *ProjectUpdateRequest) *proj_model.Project {
|
|
|
|
return &proj_model.Project{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
2020-04-21 15:00:32 +00:00
|
|
|
AggregateID: project.Id,
|
2020-04-07 11:23:04 +00:00
|
|
|
},
|
|
|
|
Name: project.Name,
|
|
|
|
}
|
|
|
|
}
|
2020-04-21 15:00:32 +00:00
|
|
|
|
|
|
|
func projectRoleFromModel(role *proj_model.ProjectRole) *ProjectRole {
|
|
|
|
creationDate, err := ptypes.TimestampProto(role.CreationDate)
|
|
|
|
logging.Log("GRPC-due83").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(role.ChangeDate)
|
|
|
|
logging.Log("GRPC-id93s").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &ProjectRole{
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: role.Sequence,
|
|
|
|
Key: role.Key,
|
|
|
|
DisplayName: role.DisplayName,
|
|
|
|
Group: role.Group,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectRoleAddToModel(role *ProjectRoleAdd) *proj_model.ProjectRole {
|
|
|
|
return &proj_model.ProjectRole{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: role.Id,
|
|
|
|
},
|
|
|
|
Key: role.Key,
|
|
|
|
DisplayName: role.DisplayName,
|
|
|
|
Group: role.Group,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectRoleChangeToModel(role *ProjectRoleChange) *proj_model.ProjectRole {
|
|
|
|
return &proj_model.ProjectRole{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: role.Id,
|
|
|
|
},
|
|
|
|
Key: role.Key,
|
|
|
|
DisplayName: role.DisplayName,
|
|
|
|
Group: role.Group,
|
|
|
|
}
|
|
|
|
}
|
2020-05-11 10:16:29 +00:00
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func projectSearchRequestsToModel(project *ProjectSearchRequest) *proj_model.ProjectViewSearchRequest {
|
|
|
|
return &proj_model.ProjectViewSearchRequest{
|
2020-05-11 10:16:29 +00:00
|
|
|
Offset: project.Offset,
|
|
|
|
Limit: project.Limit,
|
2020-06-15 12:50:39 +00:00
|
|
|
Queries: projectSearchQueriesToModel(project.Queries),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func grantedProjectSearchRequestsToModel(request *GrantedProjectSearchRequest) *proj_model.ProjectGrantViewSearchRequest {
|
|
|
|
return &proj_model.ProjectGrantViewSearchRequest{
|
|
|
|
Offset: request.Offset,
|
|
|
|
Limit: request.Limit,
|
|
|
|
Queries: grantedPRojectSearchQueriesToModel(request.Queries),
|
2020-05-11 10:16:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func projectSearchQueriesToModel(queries []*ProjectSearchQuery) []*proj_model.ProjectViewSearchQuery {
|
|
|
|
converted := make([]*proj_model.ProjectViewSearchQuery, len(queries))
|
2020-05-11 10:16:29 +00:00
|
|
|
for i, q := range queries {
|
2020-06-15 12:50:39 +00:00
|
|
|
converted[i] = projectSearchQueryToModel(q)
|
2020-05-11 10:16:29 +00:00
|
|
|
}
|
|
|
|
return converted
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func projectSearchQueryToModel(query *ProjectSearchQuery) *proj_model.ProjectViewSearchQuery {
|
|
|
|
return &proj_model.ProjectViewSearchQuery{
|
2020-05-11 10:16:29 +00:00
|
|
|
Key: projectSearchKeyToModel(query.Key),
|
|
|
|
Method: searchMethodToModel(query.Method),
|
|
|
|
Value: query.Value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func projectSearchKeyToModel(key ProjectSearchKey) proj_model.ProjectViewSearchKey {
|
|
|
|
switch key {
|
|
|
|
case ProjectSearchKey_PROJECTSEARCHKEY_PROJECT_NAME:
|
|
|
|
return proj_model.PROJECTSEARCHKEY_NAME
|
|
|
|
default:
|
|
|
|
return proj_model.PROJECTSEARCHKEY_UNSPECIFIED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func grantedPRojectSearchQueriesToModel(queries []*ProjectSearchQuery) []*proj_model.ProjectGrantViewSearchQuery {
|
|
|
|
converted := make([]*proj_model.ProjectGrantViewSearchQuery, len(queries))
|
|
|
|
for i, q := range queries {
|
|
|
|
converted[i] = grantedProjectSearchQueryToModel(q)
|
|
|
|
}
|
|
|
|
return converted
|
|
|
|
}
|
|
|
|
|
|
|
|
func grantedProjectSearchQueryToModel(query *ProjectSearchQuery) *proj_model.ProjectGrantViewSearchQuery {
|
|
|
|
return &proj_model.ProjectGrantViewSearchQuery{
|
|
|
|
Key: projectGrantSearchKeyToModel(query.Key),
|
|
|
|
Method: searchMethodToModel(query.Method),
|
|
|
|
Value: query.Value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectGrantSearchKeyToModel(key ProjectSearchKey) proj_model.ProjectGrantViewSearchKey {
|
2020-05-11 10:16:29 +00:00
|
|
|
switch key {
|
2020-06-15 12:50:39 +00:00
|
|
|
case ProjectSearchKey_PROJECTSEARCHKEY_PROJECT_NAME:
|
2020-05-11 10:16:29 +00:00
|
|
|
return proj_model.GRANTEDPROJECTSEARCHKEY_NAME
|
|
|
|
default:
|
|
|
|
return proj_model.GRANTEDPROJECTSEARCHKEY_UNSPECIFIED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectRoleSearchRequestsToModel(role *ProjectRoleSearchRequest) *proj_model.ProjectRoleSearchRequest {
|
|
|
|
return &proj_model.ProjectRoleSearchRequest{
|
|
|
|
Offset: role.Offset,
|
|
|
|
Limit: role.Limit,
|
|
|
|
Queries: projectRoleSearchQueriesToModel(role.Queries),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectRoleSearchQueriesToModel(queries []*ProjectRoleSearchQuery) []*proj_model.ProjectRoleSearchQuery {
|
|
|
|
converted := make([]*proj_model.ProjectRoleSearchQuery, len(queries))
|
|
|
|
for i, q := range queries {
|
|
|
|
converted[i] = projectRoleSearchQueryToModel(q)
|
|
|
|
}
|
|
|
|
return converted
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectRoleSearchQueryToModel(query *ProjectRoleSearchQuery) *proj_model.ProjectRoleSearchQuery {
|
|
|
|
return &proj_model.ProjectRoleSearchQuery{
|
|
|
|
Key: projectRoleSearchKeyToModel(query.Key),
|
|
|
|
Method: searchMethodToModel(query.Method),
|
|
|
|
Value: query.Value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectRoleSearchKeyToModel(key ProjectRoleSearchKey) proj_model.ProjectRoleSearchKey {
|
|
|
|
switch key {
|
|
|
|
case ProjectRoleSearchKey_PROJECTROLESEARCHKEY_KEY:
|
|
|
|
return proj_model.PROJECTROLESEARCHKEY_KEY
|
|
|
|
case ProjectRoleSearchKey_PROJECTROLESEARCHKEY_DISPLAY_NAME:
|
|
|
|
return proj_model.PROJECTROLESEARCHKEY_DISPLAY_NAME
|
|
|
|
default:
|
|
|
|
return proj_model.PROJECTROLESEARCHKEY_UNSPECIFIED
|
|
|
|
}
|
|
|
|
}
|