-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Define and add IneligibleStatus fields for access list members and owners
#31857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e6bdd3a
58e9edf
da878b7
d0a3b67
b9cc5dc
1a18c5c
c022302
a306b77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,10 @@ message AccessListOwner { | |
|
|
||
| // description is the plaintext description of the owner and why they are an owner. | ||
| string description = 2; | ||
|
|
||
| // ineligible_status describes if this owner is eligible or not | ||
| // and if not, describes how they're lacking eligibility. | ||
| IneligibleStatus ineligible_status = 3; | ||
| } | ||
|
|
||
| // AccessListAudit describes the audit configuration for an access list. | ||
|
|
@@ -130,4 +134,25 @@ message MemberSpec { | |
|
|
||
| // added_by is the user that added this user to the access list. | ||
| string added_by = 6; | ||
|
|
||
| // ineligible_status describes if this member is eligible or not | ||
| // and if not, describes how they're lacking eligibility. | ||
| IneligibleStatus ineligible_status = 7; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing comment |
||
| } | ||
|
|
||
| // IneligibleStatus describes how the user is ineligible. | ||
| enum IneligibleStatus { | ||
| // INELIGIBLE_STATUS_UNSPECIFIED means eligiblity is unknown. | ||
| INELIGIBLE_STATUS_UNSPECIFIED = 0; | ||
| // INELIGIBLE_STATUS_ELIGIBLE means checks were done and user met all requirements. | ||
| INELIGIBLE_STATUS_ELIGIBLE = 1; | ||
| // INELIGIBLE_STATUS_USER_NOT_EXIST means user was not found in backend. | ||
| INELIGIBLE_STATUS_USER_NOT_EXIST = 2; | ||
| // INELIGIBLE_STATUS_MISSING_REQUIREMENTS means user is missing some requirements | ||
| // defined by AccessListRequires (fields can be either ownership_requires | ||
| // or membership_requires) | ||
| INELIGIBLE_STATUS_MISSING_REQUIREMENTS = 3; | ||
| // INELIGIBLE_STATUS_EXPIRED means user is expired. | ||
| // Only applicable to members. | ||
| INELIGIBLE_STATUS_EXPIRED = 4; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,8 +27,10 @@ import ( | |
| traitv1 "github.com/gravitational/teleport/api/types/trait/convert/v1" | ||
| ) | ||
|
|
||
| type AccessListOption func(*accesslist.AccessList) | ||
|
|
||
| // FromProto converts a v1 access list into an internal access list object. | ||
| func FromProto(msg *accesslistv1.AccessList) (*accesslist.AccessList, error) { | ||
| func FromProto(msg *accesslistv1.AccessList, opts ...AccessListOption) (*accesslist.AccessList, error) { | ||
| if msg == nil { | ||
| return nil, trace.BadParameter("access list message is nil") | ||
| } | ||
|
|
@@ -54,6 +56,9 @@ func FromProto(msg *accesslistv1.AccessList) (*accesslist.AccessList, error) { | |
| owners[i] = accesslist.Owner{ | ||
| Name: owner.Name, | ||
| Description: owner.Description, | ||
| // Set it to empty as default. | ||
| // Must provide as options to set it with the provided value. | ||
| IneligibleStatus: "", | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -79,16 +84,25 @@ func FromProto(msg *accesslistv1.AccessList) (*accesslist.AccessList, error) { | |
| }, | ||
| }) | ||
|
|
||
| for _, opt := range opts { | ||
| opt(accessList) | ||
| } | ||
|
|
||
| return accessList, trace.Wrap(err) | ||
| } | ||
|
|
||
| // ToProto converts an internal access list into a v1 access list object. | ||
| func ToProto(accessList *accesslist.AccessList) *accesslistv1.AccessList { | ||
| owners := make([]*accesslistv1.AccessListOwner, len(accessList.Spec.Owners)) | ||
| for i, owner := range accessList.Spec.Owners { | ||
| var ineligibleStatus accesslistv1.IneligibleStatus | ||
| if enumVal, ok := accesslistv1.IneligibleStatus_value[owner.IneligibleStatus]; ok { | ||
| ineligibleStatus = accesslistv1.IneligibleStatus(enumVal) | ||
| } | ||
| owners[i] = &accesslistv1.AccessListOwner{ | ||
| Name: owner.Name, | ||
| Description: owner.Description, | ||
| Name: owner.Name, | ||
| Description: owner.Description, | ||
| IneligibleStatus: ineligibleStatus, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -117,3 +131,20 @@ func ToProto(accessList *accesslist.AccessList) *accesslistv1.AccessList { | |
| }, | ||
| } | ||
| } | ||
|
|
||
| // WithOwnersIneligibleStatusField sets the "ineligibleStatus" field to the provided proto value. | ||
| func WithOwnersIneligibleStatusField(protoOwners []*accesslistv1.AccessListOwner) AccessListOption { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: godoc. |
||
| return func(a *accesslist.AccessList) { | ||
| updatedOwners := make([]accesslist.Owner, len(a.GetOwners())) | ||
| for i, owner := range a.GetOwners() { | ||
| protoIneligibleStatus := protoOwners[i].GetIneligibleStatus() | ||
| ineligibleStatus := "" | ||
| if protoIneligibleStatus != accesslistv1.IneligibleStatus_INELIGIBLE_STATUS_UNSPECIFIED { | ||
| ineligibleStatus = protoIneligibleStatus.String() | ||
| } | ||
| owner.IneligibleStatus = ineligibleStatus | ||
| updatedOwners[i] = owner | ||
| } | ||
| a.SetOwners(updatedOwners) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,8 +25,10 @@ import ( | |
| headerv1 "github.com/gravitational/teleport/api/types/header/convert/v1" | ||
| ) | ||
|
|
||
| type MemberOption func(*accesslist.AccessListMember) | ||
|
|
||
| // FromMemberProto converts a v1 access list member into an internal access list member object. | ||
| func FromMemberProto(msg *accesslistv1.Member) (*accesslist.AccessListMember, error) { | ||
| func FromMemberProto(msg *accesslistv1.Member, opts ...MemberOption) (*accesslist.AccessListMember, error) { | ||
| if msg == nil { | ||
| return nil, trace.BadParameter("access list message is nil") | ||
| } | ||
|
|
@@ -42,8 +44,15 @@ func FromMemberProto(msg *accesslistv1.Member) (*accesslist.AccessListMember, er | |
| Expires: msg.Spec.Expires.AsTime(), | ||
| Reason: msg.Spec.Reason, | ||
| AddedBy: msg.Spec.AddedBy, | ||
| // Set it to empty as default. | ||
| // Must provide as options to set it with the provided value. | ||
| IneligibleStatus: "", | ||
| }) | ||
|
|
||
| for _, opt := range opts { | ||
| opt(member) | ||
| } | ||
|
|
||
| return member, trace.Wrap(err) | ||
| } | ||
|
|
||
|
|
@@ -62,15 +71,21 @@ func FromMembersProto(msgs []*accesslistv1.Member) ([]*accesslist.AccessListMemb | |
|
|
||
| // ToMemberProto converts an internal access list member into a v1 access list member object. | ||
| func ToMemberProto(member *accesslist.AccessListMember) *accesslistv1.Member { | ||
| var ineligibleStatus accesslistv1.IneligibleStatus | ||
| if enumVal, ok := accesslistv1.IneligibleStatus_value[member.Spec.IneligibleStatus]; ok { | ||
| ineligibleStatus = accesslistv1.IneligibleStatus(enumVal) | ||
| } | ||
|
|
||
| return &accesslistv1.Member{ | ||
| Header: headerv1.ToResourceHeaderProto(member.ResourceHeader), | ||
| Spec: &accesslistv1.MemberSpec{ | ||
| AccessList: member.Spec.AccessList, | ||
| Name: member.Spec.Name, | ||
| Joined: timestamppb.New(member.Spec.Joined), | ||
| Expires: timestamppb.New(member.Spec.Expires), | ||
| Reason: member.Spec.Reason, | ||
| AddedBy: member.Spec.AddedBy, | ||
| AccessList: member.Spec.AccessList, | ||
| Name: member.Spec.Name, | ||
| Joined: timestamppb.New(member.Spec.Joined), | ||
| Expires: timestamppb.New(member.Spec.Expires), | ||
| Reason: member.Spec.Reason, | ||
| AddedBy: member.Spec.AddedBy, | ||
| IneligibleStatus: ineligibleStatus, | ||
| }, | ||
| } | ||
| } | ||
|
|
@@ -83,3 +98,15 @@ func ToMembersProto(members []*accesslist.AccessListMember) []*accesslistv1.Memb | |
| } | ||
| return out | ||
| } | ||
|
|
||
| // WithMemberIneligibleStatusField sets the "ineligibleStatus" field to the provided proto value. | ||
| func WithMemberIneligibleStatusField(protoMember *accesslistv1.Member) MemberOption { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: godoc. |
||
| return func(m *accesslist.AccessListMember) { | ||
| protoIneligibleStatus := protoMember.GetSpec().GetIneligibleStatus() | ||
| ineligibleStatus := "" | ||
| if protoIneligibleStatus != accesslistv1.IneligibleStatus_INELIGIBLE_STATUS_UNSPECIFIED { | ||
| ineligibleStatus = protoIneligibleStatus.String() | ||
| } | ||
| m.Spec.IneligibleStatus = ineligibleStatus | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing comment