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

Connect My Computer: Keeping compatibility promise #31951

Merged
merged 18 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
226 changes: 119 additions & 107 deletions gen/proto/go/teleport/lib/teleterm/v1/cluster.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions gen/proto/js/teleport/lib/teleterm/v1/cluster_pb.d.ts

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

32 changes: 31 additions & 1 deletion gen/proto/js/teleport/lib/teleterm/v1/cluster_pb.js

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

1 change: 1 addition & 0 deletions lib/teleterm/apiserver/handler/handler_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func newAPIRootClusterWithDetails(cluster *clusters.ClusterWithDetails) (*api.Cl
return nil, trace.Wrap(err)
}
apiCluster.LoggedInUser.UserType = userType
apiCluster.ServerVersion = cluster.ServerVersion

return apiCluster, nil
}
Expand Down
26 changes: 17 additions & 9 deletions lib/teleterm/clusters/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type ClusterWithDetails struct {
ACL *api.ACL
// UserType identifies whether the user is a local user or comes from an SSO provider.
UserType types.UserType
// ServerVersion is the version of Teleport that is running.
ServerVersion string
}

// Connected indicates if connection to the cluster can be established
Expand All @@ -81,14 +83,19 @@ func (c *Cluster) Connected() bool {
// and enabled enterprise features. This method requires a valid cert.
func (c *Cluster) GetWithDetails(ctx context.Context) (*ClusterWithDetails, error) {
var (
pingResponse proto.PingResponse
caps *types.AccessCapabilities
authClusterID string
acl *api.ACL
user types.User
authPingResponse proto.PingResponse
caps *types.AccessCapabilities
authClusterID string
acl *api.ACL
user types.User
)

err := AddMetadataToRetryableError(ctx, func() error {
clusterPingResponse, err := c.clusterClient.Ping(ctx)
gzdunek marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, trace.Wrap(err)
}

err = AddMetadataToRetryableError(ctx, func() error {
proxyClient, err := c.clusterClient.ConnectToProxy(ctx)
if err != nil {
return trace.Wrap(err)
Expand All @@ -101,7 +108,7 @@ func (c *Cluster) GetWithDetails(ctx context.Context) (*ClusterWithDetails, erro
}
defer authClient.Close()

pingResponse, err = authClient.Ping(ctx)
authPingResponse, err = authClient.Ping(ctx)
if err != nil {
return trace.Wrap(err)
}
Expand Down Expand Up @@ -131,7 +138,7 @@ func (c *Cluster) GetWithDetails(ctx context.Context) (*ClusterWithDetails, erro
}

roleSet := services.NewRoleSet(roles...)
userACL := services.NewUserACL(user, roleSet, *pingResponse.ServerFeatures, false)
userACL := services.NewUserACL(user, roleSet, *authPingResponse.ServerFeatures, false)

acl = &api.ACL{
RecordedSessions: convertToAPIResourceAccess(userACL.RecordedSessions),
Expand All @@ -158,10 +165,11 @@ func (c *Cluster) GetWithDetails(ctx context.Context) (*ClusterWithDetails, erro
Cluster: c,
SuggestedReviewers: caps.SuggestedReviewers,
RequestableRoles: caps.RequestableRoles,
Features: pingResponse.ServerFeatures,
Features: authPingResponse.ServerFeatures,
AuthClusterID: authClusterID,
ACL: acl,
UserType: user.GetUserType(),
ServerVersion: clusterPingResponse.ServerVersion,
}

return withDetails, nil
Expand Down
3 changes: 3 additions & 0 deletions proto/teleport/lib/teleterm/v1/cluster.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ message Cluster {
// during the first auth server startup.
// Only present when detailed information is queried from the auth server.
string auth_cluster_id = 9;
// ServerVersion is the version of Teleport that is running.
// Only present when detailed information is queried from the proxy server.
string server_version = 10;
}

// LoggedInUser describes a logged-in user
Expand Down
1 change: 1 addition & 0 deletions web/packages/teleterm/src/services/tshd/testHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const makeRootCluster = (
proxyHost: 'teleport-local:3080',
authClusterId: '73c4746b-d956-4f16-9848-4e3469f70762',
loggedInUser: makeLoggedInUser(),
serverVersion: '1.0.0',
...props,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
ClustersServiceState,
} from 'teleterm/ui/services/clusters';
import { routing } from 'teleterm/ui/uri';
import { makeRootCluster } from 'teleterm/services/tshd/testHelpers';

import * as docTypes from '../services/workspacesService/documentsService/types';

Expand All @@ -49,42 +50,43 @@ const leafClusterDoc = {

export const Online = () => {
const state = createClusterServiceState();
state.clusters.set(rootClusterDoc.clusterUri, {
uri: rootClusterDoc.clusterUri,
leaf: false,
name: 'localhost',
connected: true,
proxyHost: 'localhost:3080',
authClusterId: '73c4746b-d956-4f16-9848-4e3469f70762',
});
state.clusters.set(
rootClusterDoc.clusterUri,
makeRootCluster({
uri: rootClusterDoc.clusterUri,
name: 'localhost',
proxyHost: 'localhost:3080',
})
);

return renderState(state, rootClusterDoc);
};

export const Offline = () => {
const state = createClusterServiceState();
state.clusters.set(rootClusterDoc.clusterUri, {
uri: rootClusterDoc.clusterUri,
leaf: false,
name: 'localhost',
connected: false,
proxyHost: 'localhost:3080',
authClusterId: '73c4746b-d956-4f16-9848-4e3469f70762',
});
state.clusters.set(
rootClusterDoc.clusterUri,
makeRootCluster({
uri: rootClusterDoc.clusterUri,
name: 'localhost',
proxyHost: 'localhost:3080',
authClusterId: '73c4746b-d956-4f16-9848-4e3469f70762',
})
);

return renderState(state, rootClusterDoc);
};

export const Notfound = () => {
const state = createClusterServiceState();
state.clusters.set(rootClusterDoc.clusterUri, {
uri: rootClusterDoc.clusterUri,
leaf: false,
name: 'localhost',
connected: true,
proxyHost: 'localhost:3080',
authClusterId: '73c4746b-d956-4f16-9848-4e3469f70762',
});
state.clusters.set(
rootClusterDoc.clusterUri,
makeRootCluster({
uri: rootClusterDoc.clusterUri,
name: 'localhost',
proxyHost: 'localhost:3080',
})
);
return renderState(state, leafClusterDoc);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ const testSetup = (
leaf: false,
proxyHost: 'localhost:3080',
authClusterId: '73c4746b-d956-4f16-9848-4e3469f70762',
serverVersion: '1.0.0',
loggedInUser: makeLoggedInUser(),
};
const leafCluster: tsh.Cluster = {
Expand All @@ -592,6 +593,7 @@ const testSetup = (
leaf: true,
proxyHost: '',
authClusterId: '5408fc2f-a452-4bde-bda2-b3b918c635ad',
serverVersion: '',
loggedInUser: makeLoggedInUser(),
};
const appContext = new MockAppContext();
Expand Down
15 changes: 5 additions & 10 deletions web/packages/teleterm/src/ui/Search/pickers/results.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
makeKube,
makeServer,
makeLabelsList,
makeRootCluster,
} from 'teleterm/services/tshd/testHelpers';
import { ResourceSearchError } from 'teleterm/ui/services/resources';

Expand Down Expand Up @@ -295,27 +296,21 @@ const SearchResultItems = () => {
},
{
kind: 'cluster-filter',
resource: {
resource: makeRootCluster({
name: 'teleport-local',
uri: clusterUri,
authClusterId: '',
connected: true,
leaf: false,
proxyHost: 'teleport-local.dev:3090',
},
}),
nameMatch: '',
score: 0,
},
{
kind: 'cluster-filter',
resource: {
resource: makeRootCluster({
name: 'teleport-very-long-cluster-name-with-uuid-2f96e498-88ec-442f-a25b-569fa915041c',
uri: longClusterUri,
authClusterId: '',
connected: true,
leaf: false,
proxyHost: 'teleport-local.dev:3090',
},
}),
nameMatch: '',
score: 0,
},
Expand Down
28 changes: 8 additions & 20 deletions web/packages/teleterm/src/ui/Search/useSearch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import { MockAppContextProvider } from '../fixtures/MockAppContextProvider';
import { makeResourceResult } from './testHelpers';
import { rankResults, useFilterSearch, useResourceSearch } from './useSearch';

import type * as tsh from 'teleterm/services/tshd/types';

beforeEach(() => {
jest.restoreAllMocks();
});
Expand Down Expand Up @@ -223,14 +221,8 @@ describe('useFiltersSearch', () => {
it('does not return cluster filters if there is only one cluster', () => {
const appContext = new MockAppContext();
appContext.clustersService.setState(draftState => {
draftState.clusters.set('/clusters/teleport-local', {
connected: true,
authClusterId: '73c4746b-d956-4f16-9848-4e3469f70762',
leaf: false,
name: 'teleport-local',
proxyHost: 'localhost:3080',
uri: '/clusters/teleport-local',
});
const rootCluster = makeRootCluster();
draftState.clusters.set(rootCluster.uri, rootCluster);
});

const { result } = renderHook(() => useFilterSearch(), {
Expand All @@ -248,22 +240,18 @@ describe('useFiltersSearch', () => {

it('returns one cluster filter if the search term matches it', () => {
const appContext = new MockAppContext();
const clusterA: tsh.Cluster = {
connected: true,
authClusterId: '73c4746b-d956-4f16-9848-4e3469f70762',
leaf: false,
const clusterA = makeRootCluster({
name: 'teleport-a',
proxyHost: 'localhost:3080',
uri: '/clusters/teleport-a',
};
const clusterB: tsh.Cluster = {
connected: true,
authClusterId: '73c4746b-d956-4f16-1848-4e3469f70762',
leaf: false,
serverVersion: '1.0.0',
ravicious marked this conversation as resolved.
Show resolved Hide resolved
});
const clusterB = makeRootCluster({
name: 'teleport-b',
proxyHost: 'localhost:3080',
uri: '/clusters/teleport-b',
};
serverVersion: '1.0.0',
});
appContext.clustersService.setState(draftState => {
draftState.clusters.set(clusterA.uri, clusterA);
draftState.clusters.set(clusterB.uri, clusterB);
Expand Down
Loading