Skip to content

Commit

Permalink
Merge branch 'bl-nero/role-editor-8' into bl-nero/role-editor-9
Browse files Browse the repository at this point in the history
  • Loading branch information
bl-nero committed Dec 6, 2024
2 parents 1bf29a4 + 4d4eaa6 commit 7b4bd84
Show file tree
Hide file tree
Showing 161 changed files with 13,942 additions and 6,521 deletions.
2 changes: 1 addition & 1 deletion api/accessrequest/access_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func GetResourceDetails(ctx context.Context, clusterName string, lister client.L
// We're interested in hostname or friendly name details. These apply to
// nodes, app servers, and user groups.
switch resourceID.Kind {
case types.KindNode, types.KindApp, types.KindUserGroup:
case types.KindNode, types.KindApp, types.KindUserGroup, types.KindIdentityCenterAccount:
resourceIDs = append(resourceIDs, resourceID)
}
}
Expand Down
11 changes: 8 additions & 3 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
"github.com/gravitational/teleport/api/client/discoveryconfig"
"github.com/gravitational/teleport/api/client/dynamicwindows"
"github.com/gravitational/teleport/api/client/externalauditstorage"
gitserverclient "github.com/gravitational/teleport/api/client/gitserver"
kubewaitingcontainerclient "github.com/gravitational/teleport/api/client/kubewaitingcontainer"
"github.com/gravitational/teleport/api/client/okta"
"github.com/gravitational/teleport/api/client/proto"
Expand All @@ -77,7 +78,7 @@ import (
discoveryconfigv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/discoveryconfig/v1"
dynamicwindowsv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/dynamicwindows/v1"
externalauditstoragev1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/externalauditstorage/v1"
gitserverv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/gitserver/v1"
gitserverpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/gitserver/v1"
identitycenterv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/identitycenter/v1"
integrationpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/integration/v1"
kubeproto "github.com/gravitational/teleport/api/gen/proto/go/teleport/kube/v1"
Expand Down Expand Up @@ -3807,6 +3808,8 @@ func (c *Client) ListResources(ctx context.Context, req proto.ListResourcesReque
resources[i] = respResource.GetAppServerOrSAMLIdPServiceProvider()
case types.KindSAMLIdPServiceProvider:
resources[i] = respResource.GetSAMLIdPServiceProvider()
case types.KindIdentityCenterAccount:
resources[i] = respResource.GetAppServer()
default:
return nil, trace.NotImplemented("resource type %s does not support pagination", req.ResourceType)
}
Expand Down Expand Up @@ -3896,6 +3899,8 @@ func convertEnrichedResource(resource *proto.PaginatedResource) (*types.Enriched
return &types.EnrichedResource{ResourceWithLabels: r, Logins: resource.Logins, RequiresRequest: resource.RequiresRequest}, nil
} else if r := resource.GetSAMLIdPServiceProvider(); r != nil {
return &types.EnrichedResource{ResourceWithLabels: r, RequiresRequest: resource.RequiresRequest}, nil
} else if r := resource.GetGitServer(); r != nil {
return &types.EnrichedResource{ResourceWithLabels: r, RequiresRequest: resource.RequiresRequest}, nil
} else {
return nil, trace.BadParameter("received unsupported resource %T", resource.Resource)
}
Expand Down Expand Up @@ -4876,8 +4881,8 @@ func (c *Client) UserTasksServiceClient() *usertaskapi.Client {
}

// GitServerClient returns a client for managing git servers
func (c *Client) GitServerClient() gitserverv1.GitServerServiceClient {
return gitserverv1.NewGitServerServiceClient(c.conn)
func (c *Client) GitServerClient() *gitserverclient.Client {
return gitserverclient.NewClient(gitserverpb.NewGitServerServiceClient(c.conn))
}

// GetCertAuthority retrieves a CA by type and domain.
Expand Down
125 changes: 125 additions & 0 deletions api/client/gitserver/gitserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Copyright 2024 Gravitational, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gitserver

import (
"context"

"github.com/gravitational/trace"

gitserverv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/gitserver/v1"
"github.com/gravitational/teleport/api/types"
)

// Client is an Git servers client.
type Client struct {
grpcClient gitserverv1.GitServerServiceClient
}

// NewClient creates a new Git servers client.
func NewClient(grpcClient gitserverv1.GitServerServiceClient) *Client {
return &Client{
grpcClient: grpcClient,
}
}

// GetGitServer returns Git servers by name.
func (c *Client) GetGitServer(ctx context.Context, name string) (types.Server, error) {
server, err := c.grpcClient.GetGitServer(ctx, &gitserverv1.GetGitServerRequest{Name: name})
if err != nil {
return nil, trace.Wrap(err)
}
return server, nil
}

// ListGitServers returns all Git servers matching filter.
func (c *Client) ListGitServers(ctx context.Context, pageSize int, pageToken string) ([]types.Server, string, error) {
resp, err := c.grpcClient.ListGitServers(ctx, &gitserverv1.ListGitServersRequest{
PageSize: int32(pageSize),
PageToken: pageToken,
})
if err != nil {
return nil, "", trace.Wrap(err)
}

servers := make([]types.Server, 0, len(resp.Servers))
for _, server := range resp.Servers {
servers = append(servers, server)
}
return servers, resp.NextPageToken, nil
}

func toServerV2(server types.Server) (*types.ServerV2, error) {
serverV2, ok := server.(*types.ServerV2)
if !ok {
return nil, trace.Errorf("encountered unexpected server type: %T", serverV2)
}
return serverV2, nil
}

// CreateGitServer creates a Git server resource.
func (c *Client) CreateGitServer(ctx context.Context, item types.Server) (types.Server, error) {
serverV2, err := toServerV2(item)
if err != nil {
return nil, trace.Wrap(err)
}
resp, err := c.grpcClient.CreateGitServer(ctx, &gitserverv1.CreateGitServerRequest{
Server: serverV2,
})
if err != nil {
return nil, trace.Wrap(err)
}
return resp, nil
}

// UpdateGitServer updates a Git server resource.
func (c *Client) UpdateGitServer(ctx context.Context, item types.Server) (types.Server, error) {
serverV2, err := toServerV2(item)
if err != nil {
return nil, trace.Wrap(err)
}
resp, err := c.grpcClient.UpdateGitServer(ctx, &gitserverv1.UpdateGitServerRequest{
Server: serverV2,
})
if err != nil {
return nil, trace.Wrap(err)
}
return resp, nil
}

// UpsertGitServer updates a Git server resource, creating it if it doesn't exist.
func (c *Client) UpsertGitServer(ctx context.Context, item types.Server) (types.Server, error) {
serverV2, err := toServerV2(item)
if err != nil {
return nil, trace.Wrap(err)
}
resp, err := c.grpcClient.UpsertGitServer(ctx, &gitserverv1.UpsertGitServerRequest{
Server: serverV2,
})
if err != nil {
return nil, trace.Wrap(err)
}
return resp, nil
}

// DeleteGitServer removes the specified Git server resource.
func (c *Client) DeleteGitServer(ctx context.Context, name string) error {
_, err := c.grpcClient.DeleteGitServer(ctx, &gitserverv1.DeleteGitServerRequest{Name: name})
return trace.Wrap(err)
}

// DeleteAllGitServers removes all Git server resources.
func (c *Client) DeleteAllGitServers(ctx context.Context) error {
return trace.NotImplemented("DeleteAllGitServers servers not implemented")
}
Loading

0 comments on commit 7b4bd84

Please sign in to comment.