Skip to content
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

Add conditional update methods for AccessList and AccessListMembers #40036

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions api/client/accesslist/accesslist.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ func (c *Client) UpsertAccessList(ctx context.Context, accessList *accesslist.Ac
return responseAccessList, trace.Wrap(err)
}

// UpdateAccessList updates an access list resource.
func (c *Client) UpdateAccessList(ctx context.Context, accessList *accesslist.AccessList) (*accesslist.AccessList, error) {
resp, err := c.grpcClient.UpdateAccessList(ctx, &accesslistv1.UpdateAccessListRequest{
AccessList: conv.ToProto(accessList),
})
if err != nil {
return nil, trace.Wrap(err)
}
responseAccessList, err := conv.FromProto(resp)
return responseAccessList, trace.Wrap(err)
}

// DeleteAccessList removes the specified access list resource.
func (c *Client) DeleteAccessList(ctx context.Context, name string) error {
_, err := c.grpcClient.DeleteAccessList(ctx, &accesslistv1.DeleteAccessListRequest{
Expand Down Expand Up @@ -219,6 +231,18 @@ func (c *Client) UpsertAccessListMember(ctx context.Context, member *accesslist.
return responseMember, trace.Wrap(err)
}

// UpdateAccessListMember updates an access list member resource using a conditional update.
func (c *Client) UpdateAccessListMember(ctx context.Context, member *accesslist.AccessListMember) (*accesslist.AccessListMember, error) {
resp, err := c.grpcClient.UpdateAccessListMember(ctx, &accesslistv1.UpdateAccessListMemberRequest{
Member: conv.ToMemberProto(member),
})
if err != nil {
return nil, trace.Wrap(err)
}
responseMember, err := conv.FromMemberProto(resp)
return responseMember, trace.Wrap(err)
}

// DeleteAccessListMember hard deletes the specified access list member resource.
func (c *Client) DeleteAccessListMember(ctx context.Context, accessList string, memberName string) error {
_, err := c.grpcClient.DeleteAccessListMember(ctx, &accesslistv1.DeleteAccessListMemberRequest{
Expand Down
1,070 changes: 613 additions & 457 deletions api/gen/proto/go/teleport/accesslist/v1/accesslist_service.pb.go

Large diffs are not rendered by default.

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

17 changes: 17 additions & 0 deletions api/proto/teleport/accesslist/v1/accesslist_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ service AccessListService {
rpc GetAccessList(GetAccessListRequest) returns (AccessList);
// UpsertAccessList creates or updates an access list resource.
rpc UpsertAccessList(UpsertAccessListRequest) returns (AccessList);
// UpdateAccessList updates an access list resource.
rpc UpdateAccessList(UpdateAccessListRequest) returns (AccessList);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between update and upsert? Those two methods sound confusing when you want to modify an access list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upsert creates or unconditionally updates the access list - i,e. it doesn't care about revision. It will just replace whatever is in backend.

Update cares about revision and forces the revision to match before doing the update. If the revision doesn't match, it returns an error trace.CompareFailed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update and Upsert are pretty standard RPCs for our resources. See RFD 153 for the semantics and expected behaviors.

// DeleteAccessList hard deletes the specified access list resource.
rpc DeleteAccessList(DeleteAccessListRequest) returns (google.protobuf.Empty);
// DeleteAllAccessLists hard deletes all access lists.
Expand All @@ -53,6 +55,8 @@ service AccessListService {
rpc GetAccessListMember(GetAccessListMemberRequest) returns (Member);
// UpsertAccessListMember creates or updates an access list member resource.
rpc UpsertAccessListMember(UpsertAccessListMemberRequest) returns (Member);
// UpdateAccessListMember conditionally updates an access list member resource.
tigrato marked this conversation as resolved.
Show resolved Hide resolved
rpc UpdateAccessListMember(UpdateAccessListMemberRequest) returns (Member);
// DeleteAccessListMember hard deletes the specified access list member
// resource.
rpc DeleteAccessListMember(DeleteAccessListMemberRequest) returns (google.protobuf.Empty);
Expand Down Expand Up @@ -125,6 +129,12 @@ message UpsertAccessListRequest {
AccessList access_list = 1;
}

// UpdateAccessListRequest is the request for updating an access list.
message UpdateAccessListRequest {
// access_list is the access list to upsert.
AccessList access_list = 1;
}

// DeleteAccessListRequest is the request for deleting an access list.
message DeleteAccessListRequest {
// name is the name of the access list to delete.
Expand Down Expand Up @@ -237,6 +247,13 @@ message UpsertAccessListMemberRequest {
Member member = 4;
}

// UpdateAccessListMemberRequest is the request for updating an access list
// member.
message UpdateAccessListMemberRequest {
// member is the access list member to upsert.
Member member = 1;
}

// DeleteAccessListMemberRequest is the request for deleting a member from an
// access list.
message DeleteAccessListMemberRequest {
Expand Down
Loading
Loading