mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:57:33 +00:00
feat: protos refactoring
* start with user * user first try done in all services * user, org, idp for discussion * remove unused stuff * bla * dockerbuild * rename search, get multiple to list... * add annotation * update proto dependencies * update proto dependencies * change proto imports * replace all old imports * fix go out * remove unused lines * correct protoc flags * grpc and openapi flags * go out source path relative * -p * remove dead code * sourcepath relative * ls * is onenapi the problem? * hobla * authoption output * wrong field name * gopf * correct option, add correct flags * small improvments * SIMPLYFY * relative path * gopf bin ich en tubel * correct path * default policies in admin * grpc generation in one file * remove non ascii * metadata on manipulations * correct auth_option import * fixes * larry * idp provider to idp * fix generate * admin and auth nearly done * admin and auth nearly done * gen * healthz * imports * deleted too much imports * fix org * add import * imports * import * naming * auth_opt * gopf * management * imports * _TYPE_UNSPECIFIED * improts * auth opts * management policies * imports * passwordlessType to MFAType * auth_opt * add user grant calls * add missing messages * result * fix option * improvements * ids * fix http * imports * fixes * fields * body * add fields * remove wrong member query * fix request response * fixes * add copy files * variable versions * generate all files * improvements * add dependencies * factors * user session * oidc information, iam * remove unused file * changes * enums * dockerfile * fix build * remove unused folder * update readme for build * move old server impl * add event type to change * some changes * start admin * remove wrong field * admin only list calls missing * fix proto numbers * surprisingly it compiles * service ts changes * admin mgmt * mgmt * auth manipulation and gets done, lists missing * validations and some field changes * validations * enum validations * remove todo * move proto files to proto/zitadel * change proto path in dockerfile * it compiles! * add validate import * remove duplicate import * fix protos * fix import * tests * cleanup * remove unimplemented methods * iam member multiple queries * all auth and admin calls * add initial password on crate human * message names * management user server * machine done * fix: todos (#1346) * fix: pub sub in new eventstore * fix: todos * fix: todos * fix: todos * fix: todos * fix: todos * fix tests * fix: search method domain * admin service, user import type typescript * admin changes * admin changes * fix: search method domain * more user grpc and begin org, fix configs * fix: return object details * org grpc * remove creation date add details * app * fix: return object details * fix: return object details * mgmt service, project members * app * fix: convert policies * project, members, granted projects, searches * fix: convert usergrants * fix: convert usergrants * auth user detail, user detail, mfa, second factor, auth * fix: convert usergrants * mfa, memberships, password, owned proj detail * fix: convert usergrants * project grant * missing details * changes, userview * idp table, keys * org list and user table filter * unify rest paths (#1381) * unify rest paths * post for all searches, mfa to multi_factor, secondfactor to second_factor * remove v1 * fix tests * rename api client key to app key * machine keys, age policy * user list, machine keys, changes * fix: org states * add default flag to policy * second factor to type * idp id * app type * unify ListQuery, ListDetails, ObjectDetails field names * user grants, apps, memberships * fix type params * metadata to detail, linke idps * api create, membership, app detail, create * idp, app, policy * queries, multi -> auth factors and missing fields * update converters * provider to user, remove old mgmt refs * temp remove authfactor dialog, build finish Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com>
This commit is contained in:
@@ -1,189 +1,84 @@
|
||||
package management
|
||||
|
||||
import (
|
||||
"github.com/caos/logging"
|
||||
member_grpc "github.com/caos/zitadel/internal/api/grpc/member"
|
||||
proj_grpc "github.com/caos/zitadel/internal/api/grpc/project"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
proj_model "github.com/caos/zitadel/internal/project/model"
|
||||
"github.com/caos/zitadel/pkg/grpc/management"
|
||||
mgmt_pb "github.com/caos/zitadel/pkg/grpc/management"
|
||||
)
|
||||
|
||||
func projectGrantFromDomain(grant *domain.ProjectGrant) *management.ProjectGrant {
|
||||
return &management.ProjectGrant{
|
||||
Id: grant.GrantID,
|
||||
State: projectGrantStateFromDomain(grant.State),
|
||||
CreationDate: timestamppb.New(grant.CreationDate),
|
||||
ChangeDate: timestamppb.New(grant.ChangeDate),
|
||||
GrantedOrgId: grant.GrantedOrgID,
|
||||
RoleKeys: grant.RoleKeys,
|
||||
Sequence: grant.Sequence,
|
||||
ProjectId: grant.AggregateID,
|
||||
}
|
||||
}
|
||||
|
||||
func projectGrantFromModel(grant *proj_model.ProjectGrant) *management.ProjectGrant {
|
||||
creationDate, err := ptypes.TimestampProto(grant.CreationDate)
|
||||
logging.Log("GRPC-8d73s").OnError(err).Debug("unable to parse timestamp")
|
||||
|
||||
changeDate, err := ptypes.TimestampProto(grant.ChangeDate)
|
||||
logging.Log("GRPC-dlso3").OnError(err).Debug("unable to parse timestamp")
|
||||
|
||||
return &management.ProjectGrant{
|
||||
Id: grant.GrantID,
|
||||
State: projectGrantStateFromModel(grant.State),
|
||||
CreationDate: creationDate,
|
||||
ChangeDate: changeDate,
|
||||
GrantedOrgId: grant.GrantedOrgID,
|
||||
RoleKeys: grant.RoleKeys,
|
||||
Sequence: grant.Sequence,
|
||||
ProjectId: grant.AggregateID,
|
||||
}
|
||||
}
|
||||
|
||||
func projectGrantCreateToDomain(grant *management.ProjectGrantCreate) *domain.ProjectGrant {
|
||||
return &domain.ProjectGrant{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: grant.ProjectId,
|
||||
},
|
||||
GrantedOrgID: grant.GrantedOrgId,
|
||||
RoleKeys: grant.RoleKeys,
|
||||
}
|
||||
}
|
||||
|
||||
func projectGrantUpdateToDomain(grant *management.ProjectGrantUpdate) *domain.ProjectGrant {
|
||||
return &domain.ProjectGrant{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: grant.ProjectId,
|
||||
},
|
||||
GrantID: grant.Id,
|
||||
RoleKeys: grant.RoleKeys,
|
||||
}
|
||||
}
|
||||
|
||||
func projectGrantSearchRequestsToModel(request *management.ProjectGrantSearchRequest) *proj_model.ProjectGrantViewSearchRequest {
|
||||
return &proj_model.ProjectGrantViewSearchRequest{
|
||||
Offset: request.Offset,
|
||||
Limit: request.Limit,
|
||||
Queries: projectGrantSearchQueriesToModel(request.ProjectId, request.Queries),
|
||||
}
|
||||
}
|
||||
|
||||
func projectGrantSearchQueriesToModel(projectId string, queries []*management.ProjectGrantSearchQuery) []*proj_model.ProjectGrantViewSearchQuery {
|
||||
converted := make([]*proj_model.ProjectGrantViewSearchQuery, 0)
|
||||
converted = append(converted, &proj_model.ProjectGrantViewSearchQuery{
|
||||
func ListProjectGrantsRequestToModel(req *mgmt_pb.ListProjectGrantsRequest) (*proj_model.ProjectGrantViewSearchRequest, error) {
|
||||
queries := proj_grpc.ProjectGrantQueriesToModel(req.Queries)
|
||||
queries = append(queries, &proj_model.ProjectGrantViewSearchQuery{
|
||||
Key: proj_model.GrantedProjectSearchKeyProjectID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
Value: projectId,
|
||||
Value: req.ProjectId,
|
||||
})
|
||||
for i, query := range queries {
|
||||
converted[i] = projectGrantSearchQueryToModel(query)
|
||||
}
|
||||
return converted
|
||||
return &proj_model.ProjectGrantViewSearchRequest{
|
||||
Offset: req.Query.Offset,
|
||||
Limit: uint64(req.Query.Limit),
|
||||
Asc: req.Query.Asc,
|
||||
//SortingColumn: //TODO: sorting
|
||||
Queries: queries,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func projectGrantSearchQueryToModel(query *management.ProjectGrantSearchQuery) *proj_model.ProjectGrantViewSearchQuery {
|
||||
return &proj_model.ProjectGrantViewSearchQuery{
|
||||
Key: projectGrantViewSearchKeyToModel(query.Key),
|
||||
Method: searchMethodToModel(query.Method),
|
||||
Value: query.Value,
|
||||
func AddProjectGrantRequestToDomain(req *mgmt_pb.AddProjectGrantRequest) *domain.ProjectGrant {
|
||||
return &domain.ProjectGrant{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: req.ProjectId,
|
||||
},
|
||||
GrantedOrgID: req.GrantedOrgId,
|
||||
RoleKeys: req.RoleKeys,
|
||||
}
|
||||
}
|
||||
|
||||
func projectGrantViewSearchKeyToModel(key management.ProjectGrantSearchKey) proj_model.ProjectGrantViewSearchKey {
|
||||
switch key {
|
||||
case management.ProjectGrantSearchKey_PROJECTGRANTSEARCHKEY_PROJECT_NAME:
|
||||
return proj_model.GrantedProjectSearchKeyProjectID
|
||||
case management.ProjectGrantSearchKey_PROJECTGRANTSEARCHKEY_ROLE_KEY:
|
||||
return proj_model.GrantedProjectSearchKeyRoleKeys
|
||||
default:
|
||||
return proj_model.GrantedProjectSearchKeyUnspecified
|
||||
func UpdateProjectGrantRequestToDomain(req *mgmt_pb.UpdateProjectGrantRequest) *domain.ProjectGrant {
|
||||
return &domain.ProjectGrant{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: req.ProjectId,
|
||||
},
|
||||
GrantID: req.GrantId,
|
||||
RoleKeys: req.RoleKeys,
|
||||
}
|
||||
}
|
||||
|
||||
func projectGrantSearchResponseFromModel(response *proj_model.ProjectGrantViewSearchResponse) *management.ProjectGrantSearchResponse {
|
||||
timestamp, err := ptypes.TimestampProto(response.Timestamp)
|
||||
logging.Log("GRPC-MCjs7").OnError(err).Debug("unable to parse timestamp")
|
||||
return &management.ProjectGrantSearchResponse{
|
||||
Offset: response.Offset,
|
||||
Limit: response.Limit,
|
||||
TotalResult: response.TotalResult,
|
||||
Result: projectGrantsFromGrantedProjectModel(response.Result),
|
||||
ViewTimestamp: timestamp,
|
||||
ProcessedSequence: response.Sequence,
|
||||
func ListProjectGrantMembersRequestToModel(req *mgmt_pb.ListProjectGrantMembersRequest) *proj_model.ProjectGrantMemberSearchRequest {
|
||||
queries := member_grpc.MemberQueriesToProjectGrantMember(req.Queries)
|
||||
queries = append(queries, &proj_model.ProjectGrantMemberSearchQuery{
|
||||
Key: proj_model.ProjectGrantMemberSearchKeyProjectID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
Value: req.ProjectId,
|
||||
})
|
||||
return &proj_model.ProjectGrantMemberSearchRequest{
|
||||
Offset: req.Query.Offset,
|
||||
Limit: uint64(req.Query.Limit),
|
||||
Asc: req.Query.Asc,
|
||||
//SortingColumn: //TODO: sorting
|
||||
Queries: queries,
|
||||
}
|
||||
}
|
||||
|
||||
func projectGrantsFromGrantedProjectModel(projects []*proj_model.ProjectGrantView) []*management.ProjectGrantView {
|
||||
converted := make([]*management.ProjectGrantView, len(projects))
|
||||
for i, project := range projects {
|
||||
converted[i] = projectGrantFromGrantedProjectModel(project)
|
||||
}
|
||||
return converted
|
||||
}
|
||||
|
||||
func projectGrantFromGrantedProjectModel(project *proj_model.ProjectGrantView) *management.ProjectGrantView {
|
||||
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")
|
||||
|
||||
return &management.ProjectGrantView{
|
||||
ProjectId: project.ProjectID,
|
||||
State: projectGrantStateFromProjectStateModel(project.State),
|
||||
CreationDate: creationDate,
|
||||
ChangeDate: changeDate,
|
||||
ProjectName: project.Name,
|
||||
Sequence: project.Sequence,
|
||||
GrantedOrgId: project.OrgID,
|
||||
GrantedOrgName: project.OrgName,
|
||||
Id: project.GrantID,
|
||||
RoleKeys: project.GrantedRoleKeys,
|
||||
ResourceOwner: project.ResourceOwner,
|
||||
ResourceOwnerName: project.ResourceOwnerName,
|
||||
func AddProjectGrantMemberRequestToDomain(req *mgmt_pb.AddProjectGrantMemberRequest) *domain.ProjectGrantMember {
|
||||
return &domain.ProjectGrantMember{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: req.ProjectId,
|
||||
},
|
||||
GrantID: req.GrantId,
|
||||
UserID: req.UserId,
|
||||
Roles: req.Roles,
|
||||
}
|
||||
}
|
||||
|
||||
func projectGrantStateFromDomain(state domain.ProjectGrantState) management.ProjectGrantState {
|
||||
switch state {
|
||||
case domain.ProjectGrantStateActive:
|
||||
return management.ProjectGrantState_PROJECTGRANTSTATE_ACTIVE
|
||||
case domain.ProjectGrantStateInactive:
|
||||
return management.ProjectGrantState_PROJECTGRANTSTATE_INACTIVE
|
||||
default:
|
||||
return management.ProjectGrantState_PROJECTGRANTSTATE_UNSPECIFIED
|
||||
func UpdateProjectGrantMemberRequestToDomain(req *mgmt_pb.UpdateProjectGrantMemberRequest) *domain.ProjectGrantMember {
|
||||
return &domain.ProjectGrantMember{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: req.ProjectId,
|
||||
},
|
||||
GrantID: req.GrantId,
|
||||
UserID: req.UserId,
|
||||
Roles: req.Roles,
|
||||
}
|
||||
}
|
||||
func projectGrantStateFromModel(state proj_model.ProjectGrantState) management.ProjectGrantState {
|
||||
switch state {
|
||||
case proj_model.ProjectGrantStateActive:
|
||||
return management.ProjectGrantState_PROJECTGRANTSTATE_ACTIVE
|
||||
case proj_model.ProjectGrantStateInactive:
|
||||
return management.ProjectGrantState_PROJECTGRANTSTATE_INACTIVE
|
||||
default:
|
||||
return management.ProjectGrantState_PROJECTGRANTSTATE_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
|
||||
func projectGrantStateFromProjectStateModel(state proj_model.ProjectState) management.ProjectGrantState {
|
||||
switch state {
|
||||
case proj_model.ProjectStateActive:
|
||||
return management.ProjectGrantState_PROJECTGRANTSTATE_ACTIVE
|
||||
case proj_model.ProjectStateInactive:
|
||||
return management.ProjectGrantState_PROJECTGRANTSTATE_INACTIVE
|
||||
default:
|
||||
return management.ProjectGrantState_PROJECTGRANTSTATE_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
|
||||
func projectGrantsToIDs(projectGrants []*proj_model.ProjectGrantView) []string {
|
||||
converted := make([]string, len(projectGrants))
|
||||
for i, grant := range projectGrants {
|
||||
converted[i] = grant.GrantID
|
||||
}
|
||||
return converted
|
||||
}
|
||||
|
Reference in New Issue
Block a user