Skip to content

Commit

Permalink
Add UpsertTrustedClusterV2 RPC (#49789)
Browse files Browse the repository at this point in the history
* Add UpsertTrustedClusterV2 rpc

This supersedes UpsertTrustedCluster rpc. V2 performs resource name
validation.

* Replace confusing UpsertValidationTrustedCluster name

* Use UpsertTrustedClusterV2 in tests

* Address feedback

- Remove unnecessary ping
- Update error messages
- Use skipNameValidation consts
- Validate cluster name before establishing trust
- Do not reveal cluster name in error message
- Use BadParameter instead of CompareFailed

* Use webclient.Find

* Fix test/lint

* Allow label updates

* Fix test

* Fix error handling

* Implement CreateTrustedClusterV2 and UpdateTrustedClusterV2

* Address feedback

* Minor fixes

* Move V2 RPCs to the trust service

* Update comment

* Drop V2 suffix

* Require matching revision

* Fix upsert/update revision

* Drop V2 from Create and Update APIs

* Lint: Fix typo
  • Loading branch information
bernardjkim authored Dec 21, 2024
1 parent bbf7c1a commit a221604
Show file tree
Hide file tree
Showing 23 changed files with 1,809 additions and 535 deletions.
52 changes: 48 additions & 4 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2286,12 +2286,56 @@ func (c *Client) GetTrustedClusters(ctx context.Context) ([]types.TrustedCluster
}

// UpsertTrustedCluster creates or updates a Trusted Cluster.
func (c *Client) UpsertTrustedCluster(ctx context.Context, trusedCluster types.TrustedCluster) (types.TrustedCluster, error) {
trustedCluster, ok := trusedCluster.(*types.TrustedClusterV2)
//
// Deprecated: Use [Client.UpsertTrustedClusterV2] instead.
func (c *Client) UpsertTrustedCluster(ctx context.Context, trustedCluster types.TrustedCluster) (types.TrustedCluster, error) {
trustedClusterV2, ok := trustedCluster.(*types.TrustedClusterV2)
if !ok {
return nil, trace.BadParameter("invalid type %T", trustedCluster)
}
resp, err := c.grpc.UpsertTrustedCluster(ctx, trustedClusterV2)
if err != nil {
return nil, trace.Wrap(err)
}
return resp, nil
}

// UpsertTrustedClusterV2 creates or updates a Trusted Cluster.
func (c *Client) UpsertTrustedClusterV2(ctx context.Context, trustedCluster types.TrustedCluster) (types.TrustedCluster, error) {
trustedClusterV2, ok := trustedCluster.(*types.TrustedClusterV2)
if !ok {
return nil, trace.BadParameter("invalid type %T", trustedCluster)
}
req := &trustpb.UpsertTrustedClusterRequest{TrustedCluster: trustedClusterV2}
resp, err := c.TrustClient().UpsertTrustedCluster(ctx, req)
if err != nil {
return nil, trace.Wrap(err)
}
return resp, nil
}

// CreateTrustedCluster creates a Trusted Cluster.
func (c *Client) CreateTrustedCluster(ctx context.Context, trustedCluster types.TrustedCluster) (types.TrustedCluster, error) {
trustedClusterV2, ok := trustedCluster.(*types.TrustedClusterV2)
if !ok {
return nil, trace.BadParameter("invalid type %T", trustedCluster)
}
req := &trustpb.CreateTrustedClusterRequest{TrustedCluster: trustedClusterV2}
resp, err := c.TrustClient().CreateTrustedCluster(ctx, req)
if err != nil {
return nil, trace.Wrap(err)
}
return resp, nil
}

// UpdateTrustedCluster updates a Trusted Cluster.
func (c *Client) UpdateTrustedCluster(ctx context.Context, trustedCluster types.TrustedCluster) (types.TrustedCluster, error) {
trustedClusterV2, ok := trustedCluster.(*types.TrustedClusterV2)
if !ok {
return nil, trace.BadParameter("invalid type %T", trusedCluster)
return nil, trace.BadParameter("invalid type %T", trustedCluster)
}
resp, err := c.grpc.UpsertTrustedCluster(ctx, trustedCluster)
req := &trustpb.UpdateTrustedClusterRequest{TrustedCluster: trustedClusterV2}
resp, err := c.TrustClient().UpdateTrustedCluster(ctx, req)
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down
449 changes: 227 additions & 222 deletions api/client/proto/authservice.pb.go

Large diffs are not rendered by default.

Loading

0 comments on commit a221604

Please sign in to comment.