Skip to content

Commit

Permalink
Merge pull request #302 from TencentBlueKing/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
zhu327 authored Jun 4, 2024
2 parents 2b941a2 + aecac6c commit 3a4635a
Show file tree
Hide file tree
Showing 37 changed files with 324 additions and 320 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.13
1.12.14
29 changes: 10 additions & 19 deletions pkg/abac/pap/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type GroupController interface {
ListPagingSubjectSystemGroups(
_type, id, systemID string, beforeExpiredAt, limit, offset int64,
) ([]SubjectGroup, error)
FilterGroupsHasMemberBeforeExpiredAt(subjects []Subject, expiredAt int64) ([]Subject, error)
ListGroupSubjectBeforeExpiredAtBySubjects(subjects []Subject, expiredAt int64) ([]GroupSubject, error)
CheckSubjectEffectGroups(_type, id string, groupIDs []string) (map[string]map[string]interface{}, error)

GetGroupMemberCount(_type, id string) (int64, error)
Expand Down Expand Up @@ -141,7 +141,10 @@ func (c *groupController) GetGroupSubjectCountBeforeExpiredAt(expiredAt int64) (
return c.service.GetGroupSubjectCountBeforeExpiredAt(expiredAt)
}

func (c *groupController) FilterGroupsHasMemberBeforeExpiredAt(subjects []Subject, expiredAt int64) ([]Subject, error) {
func (c *groupController) ListGroupSubjectBeforeExpiredAtBySubjects(
subjects []Subject,
expiredAt int64,
) ([]GroupSubject, error) {
errorWrapf := errorx.NewLayerFunctionErrorWrapf(GroupCTL, "FilterGroupsHasMemberBeforeExpiredAt")

svcSubjects := convertToServiceSubjects(subjects)
Expand All @@ -150,32 +153,20 @@ func (c *groupController) FilterGroupsHasMemberBeforeExpiredAt(subjects []Subjec
return nil, errorWrapf(err, "service.ListPKsBySubjects subjects=`%+v` fail", subjects)
}

existGroupPKs, err := c.service.FilterGroupPKsHasMemberBeforeExpiredAt(groupPKs, expiredAt)
svcRelations, err := c.service.ListGroupSubjectBeforeExpiredAtByGroupPKs(groupPKs, expiredAt)
if err != nil {
return nil, errorWrapf(
err, "service.FilterGroupPKsHasMemberBeforeExpiredAt groupPKs=`%+v`, expiredAt=`%d` fail",
err, "service.ListGroupSubjectBeforeExpiredAtByGroupPKs groupPKs=`%+v`, expiredAt=`%d` fail",
groupPKs, expiredAt,
)
}

existSubjects, err := cacheimpls.BatchGetSubjectByPKs(existGroupPKs)
relations, err := convertToGroupSubjects(svcRelations)
if err != nil {
return nil, errorWrapf(
err, "cacheimpls.BatchGetSubjectByPKs groupPKs=`%+v` fail",
existGroupPKs,
)
}

existGroups := make([]Subject, 0, len(existGroupPKs))
for _, subject := range existSubjects {
existGroups = append(existGroups, Subject{
Type: subject.Type,
ID: subject.ID,
Name: subject.Name,
})
return nil, errorWrapf(err, "convertToGroupSubjects svcRelations=`%+v` fail", svcRelations)
}

return existGroups, nil
return relations, nil
}

func (c *groupController) CheckSubjectEffectGroups(
Expand Down
30 changes: 15 additions & 15 deletions pkg/abac/pap/mock/group.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/api/debug/handler/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
)

type queryPolicyCacheSerializer struct {
System string `form:"system" binding:"required"`
System string `form:"system" binding:"required"`
SubjectType string `form:"subject_type" binding:"required"`
SubjectID string `form:"subject_id" binding:"required"`
SubjectID string `form:"subject_id" binding:"required"`

Action string `form:"action"`
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/api/debug/handler/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func QueryActions(c *gin.Context) {
}

type querySubjectsSerializer struct {
Type string `form:"type" binding:"required"`
ID string `form:"id" binding:"required"`
Type string `form:"type" binding:"required"`
ID string `form:"id" binding:"required"`
System string `form:"system" binding:"required"`
}

Expand Down Expand Up @@ -154,10 +154,10 @@ func QuerySubjects(c *gin.Context) {
}

type queryPoliciesSerializer struct {
System string `form:"system" binding:"required"`
System string `form:"system" binding:"required"`
SubjectType string `form:"subject_type" binding:"required"`
SubjectID string `form:"subject_id" binding:"required"`
Action string `form:"action" binding:"required"`
SubjectID string `form:"subject_id" binding:"required"`
Action string `form:"action" binding:"required"`
}

// QueryPolicies ...
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/engine/handler/credentials_slz.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
package handler

type credentialsVerifySerializer struct {
Type string `json:"type" binding:"required"`
Data appCodeAppSecretSerializer `json:"data" binding:"required"`
Type string `json:"type" binding:"required"`
Data appCodeAppSecretSerializer `json:"data" binding:"required"`
}

type appCodeAppSecretSerializer struct {
AppCode string `json:"app_code" binding:"required"`
AppSecret string `json:"app_secret" binding:"required"`
AppCode string `json:"app_code" binding:"required"`
AppSecret string `json:"app_secret" binding:"required"`
}

type credentialsVerifyResponseSerializer struct {
Expand Down
22 changes: 11 additions & 11 deletions pkg/api/engine/handler/policy_slz.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (s *listPolicySerializer) initDefault() {

type policyResponseSubject struct {
Type string `json:"type" example:"user"`
ID string `json:"id" example:"admin"`
ID string `json:"id" example:"admin"`
Name string `json:"name" example:"Administer"`
}

Expand All @@ -99,15 +99,15 @@ type policyResponseAction struct {
}

type enginePolicyResponse struct {
Version string `json:"version" example:"1"`
ID int64 `json:"id" example:"100"`
System string `json:"system" example:"bk_cmdb"`
Version string `json:"version" example:"1"`
ID int64 `json:"id" example:"100"`
System string `json:"system" example:"bk_cmdb"`
Actions []policyResponseAction `json:"actions"`
Subject policyResponseSubject `json:"subject"`
Expression map[string]interface{} `json:"expression"`
TemplateID int64 `json:"template_id"`
ExpiredAt int64 `json:"expired_at" example:"4102444800"`
UpdatedAt int64 `json:"updated_at" example:"4102444800"`
ExpiredAt int64 `json:"expired_at" example:"4102444800"`
UpdatedAt int64 `json:"updated_at" example:"4102444800"`
}

type policyListResponse struct {
Expand All @@ -118,9 +118,9 @@ type policyListResponse struct {
// -- listPolicyPKs

type listPolicyIDsSerializer struct {
BeginUpdatedAt int64 `form:"begin_updated_at" json:"begin_updated_at" binding:"min=1" example:"1592899208"`
EndUpdatedAt int64 `form:"end_updated_at" json:"end_updated_at" binding:"min=1" example:"1592899208"`
Type string `form:"type" json:"type" binding:"omitempty,oneof=abac rbac" example:"abac"`
BeginUpdatedAt int64 `form:"begin_updated_at" json:"begin_updated_at" binding:"min=1"`
EndUpdatedAt int64 `form:"end_updated_at" json:"end_updated_at" binding:"min=1"`
Type string `form:"type" json:"type" binding:"omitempty,oneof=abac rbac"`
}

func (s *listPolicyIDsSerializer) validate() (bool, string) {
Expand Down Expand Up @@ -148,8 +148,8 @@ type listPolicyIDsResponse struct {
// --a getMaxPolicyPK

type getMaxPolicyIDSerializer struct {
UpdatedAt int64 `form:"updated_at" json:"updated_at" binding:"min=1" example:"1592899208"`
Type string `form:"type" json:"type" binding:"omitempty,oneof=abac rbac" example:"abac"`
UpdatedAt int64 `form:"updated_at" json:"updated_at" binding:"min=1" example:"1592899208"`
Type string `form:"type" json:"type" binding:"omitempty,oneof=abac rbac" example:"abac"`
}

func (s *getMaxPolicyIDSerializer) initDefault() {
Expand Down
40 changes: 20 additions & 20 deletions pkg/api/model/handler/action_slz.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
)

type relatedResourceType struct {
SystemID string `json:"system_id" binding:"required" example:"bk_cmdb"`
ID string `json:"id" binding:"required,max=32" example:"host"`
SystemID string `json:"system_id" binding:"required" example:"bk_cmdb"`
ID string `json:"id" binding:"required,max=32" example:"host"`

NameAlias string `json:"name_alias" example:""`
NameAlias string `json:"name_alias" example:""`
NameAliasEn string `json:"name_alias_en" example:""`

// 实例选择方式/范围: ["all", "instance", "attribute", "instance:paste"]
Expand All @@ -45,39 +45,39 @@ type relatedEnvironment struct {
}

type actionSerializer struct {
ID string `json:"id" binding:"required,max=32" example:"biz_create"`
Name string `json:"name" binding:"required" example:"biz_create"`
NameEn string `json:"name_en" binding:"required" example:"biz_create"`
ID string `json:"id" binding:"required,max=32" example:"biz_create"`
Name string `json:"name" binding:"required" example:"biz_create"`
NameEn string `json:"name_en" binding:"required" example:"biz_create"`

Description string `json:"description" binding:"omitempty" example:"biz_create is"`
DescriptionEn string `json:"description_en" binding:"omitempty" example:"biz_create is"`
Sensitivity int64 `json:"sensitivity" binding:"omitempty,gte=0,lte=9" example:"0"`
Description string `json:"description" binding:"omitempty" example:"biz_create is"`
DescriptionEn string `json:"description_en" binding:"omitempty" example:"biz_create is"`
Sensitivity int64 `json:"sensitivity" binding:"omitempty,gte=0,lte=9" example:"0"`

AuthType string `json:"auth_type" binding:"omitempty,oneof=rbac abac" example:"abac"`
Type string `json:"type" binding:"omitempty,oneof=create edit view delete list manage execute debug use"`
Hidden bool `json:"hidden" binding:"omitempty" example:"false"`
Type string `json:"type" binding:"omitempty,oneof=create edit view delete list manage execute debug use"`
Hidden bool `json:"hidden" binding:"omitempty" example:"false"`

RelatedResourceTypes []relatedResourceType `json:"related_resource_types"`
RelatedActions []string `json:"related_actions"`
RelatedEnvironments []relatedEnvironment `json:"related_environments" binding:"omitempty"`
RelatedEnvironments []relatedEnvironment `json:"related_environments" binding:"omitempty"`

Version int64 `json:"version" binding:"omitempty,gte=1" example:"1"`
}

type actionUpdateSerializer struct {
Name string `json:"name" example:"biz_create"`
NameEn string `json:"name_en" example:"biz_create"`
Description string `json:"description" binding:"omitempty" example:"biz_create is"`
DescriptionEn string `json:"description_en" binding:"omitempty" example:"biz_create is"`
Sensitivity int64 `json:"sensitivity" binding:"omitempty,gte=0,lte=9" example:"0"`
Name string `json:"name" example:"biz_create"`
NameEn string `json:"name_en" example:"biz_create"`
Description string `json:"description" example:"biz_create is" binding:"omitempty"`
DescriptionEn string `json:"description_en" example:"biz_create is" binding:"omitempty"`
Sensitivity int64 `json:"sensitivity" example:"0" binding:"omitempty,gte=0,lte=9"`

AuthType string `json:"auth_type" binding:"omitempty,oneof=rbac abac" example:"abac"`
Type string `json:"type" binding:"omitempty,oneof=create edit view delete list manage execute debug use"`
Hidden bool `json:"hidden" binding:"omitempty" example:"false"`
Type string `json:"type" binding:"omitempty,oneof=create edit view delete list manage execute debug use"`
Hidden bool `json:"hidden" binding:"omitempty" example:"false"`

RelatedResourceTypes []relatedResourceType `json:"related_resource_types"`
RelatedActions []string `json:"related_actions"`
RelatedEnvironments []relatedEnvironment `json:"related_environments" binding:"omitempty"`
RelatedEnvironments []relatedEnvironment `json:"related_environments" binding:"omitempty"`

Version int64 `json:"version" binding:"omitempty,gte=1" example:"1"`
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/api/model/handler/instance_selection_slz.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ import (
)

type instanceSelectionSerializer struct {
ID string `json:"id" binding:"required,max=32" example:"biz_set"`
Name string `json:"name" binding:"required" example:"biz_set"`
NameEn string `json:"name_en" binding:"required" example:"biz_set"`
IsDynamic bool `json:"is_dynamic" binding:"omitempty" example:"false"`
ID string `json:"id" binding:"required,max=32" example:"biz_set"`
Name string `json:"name" binding:"required" example:"biz_set"`
NameEn string `json:"name_en" binding:"required" example:"biz_set"`
IsDynamic bool `json:"is_dynamic" binding:"omitempty" example:"false"`

ResourceTypeChain []referenceResourceType `json:"resource_type_chain" structs:"resource_type_chain" binding:"required"`
}

type instanceSelectionUpdateSerializer struct {
// ID string `json:"id" binding:"required"`
Name string `json:"name" binding:"required" example:"biz_set"`
NameEn string `json:"name_en" binding:"required" example:"biz_set"`
Name string `json:"name" binding:"required" example:"biz_set"`
NameEn string `json:"name_en" binding:"required" example:"biz_set"`
IsDynamic bool `json:"is_dynamic" binding:"omitempty" example:"false"`

ResourceTypeChain []referenceResourceType `json:"resource_type_chain" structs:"resource_type_chain" binding:"required"`
Expand Down
22 changes: 11 additions & 11 deletions pkg/api/model/handler/resource_type_slz.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ type resourceProviderConfig struct {
}

type resourceTypeSerializer struct {
ID string `json:"id" binding:"required,max=32" example:"biz_set"`
Name string `json:"name" binding:"required" example:"biz_set"`
NameEn string `json:"name_en" binding:"required" example:"biz_set"`
ID string `json:"id" binding:"required,max=32" example:"biz_set"`
Name string `json:"name" binding:"required" example:"biz_set"`
NameEn string `json:"name_en" binding:"required" example:"biz_set"`

Description string `json:"description" binding:"omitempty" example:"biz_set is a"`
DescriptionEn string `json:"description_en" binding:"omitempty" example:"biz_set is a"`
Sensitivity int64 `json:"sensitivity" binding:"omitempty,gte=0,lte=9" example:"0"`
Description string `json:"description" binding:"omitempty" example:"biz_set is a"`
DescriptionEn string `json:"description_en" binding:"omitempty" example:"biz_set is a"`
Sensitivity int64 `json:"sensitivity" binding:"omitempty,gte=0,lte=9" example:"0"`

// can be empty
Parents []referenceResourceType `json:"parents"`
Expand All @@ -42,11 +42,11 @@ type resourceTypeSerializer struct {

type resourceTypeUpdateSerializer struct {
// ID string `json:"id" binding:"required"`
Name string `json:"name" binding:"omitempty" example:"biz_set"`
NameEn string `json:"name_en" binding:"omitempty" example:"biz_set"`
Description string `json:"description" binding:"omitempty" example:"biz_set is a"`
DescriptionEn string `json:"description_en" binding:"omitempty" example:"biz_set is a"`
Sensitivity int64 `json:"sensitivity" binding:"omitempty,gte=0,lte=9" example:"0"`
Name string `json:"name" binding:"omitempty" example:"biz_set"`
NameEn string `json:"name_en" binding:"omitempty" example:"biz_set"`
Description string `json:"description" binding:"omitempty" example:"biz_set is a"`
DescriptionEn string `json:"description_en" binding:"omitempty" example:"biz_set is a"`
Sensitivity int64 `json:"sensitivity" binding:"omitempty,gte=0,lte=9" example:"0"`

// can be empty
Parents []referenceResourceType `json:"parents"`
Expand Down
Loading

0 comments on commit 3a4635a

Please sign in to comment.