Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import React, { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import {
Box,
ButtonLink,
ButtonText,
Text,
ButtonPrimary,
Indicator,
Expand All @@ -42,12 +42,23 @@ import useTeleport from 'teleport/useTeleport';

import { ActionButtons, HeaderSubtitle, HeaderWithBackBtn } from '../../Shared';

import { DbMeta, useDiscover } from '../../useDiscover';
import {
DbMeta,
DiscoverUrlLocationState,
useDiscover,
} from '../../useDiscover';

export function ConnectAwsAccount() {
const { storeUser } = useTeleport();
const { prevStep, nextStep, agentMeta, updateAgentMeta, eventState } =
useDiscover();
const {
prevStep,
nextStep,
agentMeta,
updateAgentMeta,
eventState,
resourceSpec,
currentStep,
} = useDiscover();

const integrationAccess = storeUser.getIntegrationsAccess();
const databaseAccess = storeUser.getDatabaseAccess();
Expand Down Expand Up @@ -140,14 +151,24 @@ export function ConnectAwsAccount() {
integrationName: selectedAwsIntegration.value,
});

// TODO(lisa): Need to add a new event to emit for this screen.
nextStep();
}

const hasAwsIntegrations = awsIntegrations.length > 0;

// When a user clicks to create a new AWS integration, we
// define location state to preserve all the states required
// to resume from this step when the user comes back to discover route
// after successfully finishing enrolling integration.
const locationState = {
pathname: cfg.getIntegrationEnrollRoute(IntegrationKind.AwsOidc),
state: { discoverEventId: eventState?.id },
state: {
discover: {
eventState,
resourceSpec,
currentStep,
},
} as DiscoverUrlLocationState,
};
return (
<Box maxWidth="700px">
Expand All @@ -174,9 +195,9 @@ export function ConnectAwsAccount() {
options={awsIntegrations}
/>
</Box>
<ButtonLink as={Link} to={locationState} pl={0}>
<ButtonText as={Link} to={locationState} pl={0}>
Or click here to set up a different AWS account
</ButtonLink>
</ButtonText>
</>
) : (
<ButtonPrimary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ export function CreateDatabaseDialog({
if (attempt.status === 'failed') {
content = (
<>
<Text bold caps mb={3}>
Database Register Failed
</Text>
<Text mb={5}>
<Icons.Warning ml={1} mr={2} color="error.main" />
Error: {attempt.statusText}
Register Failed: {attempt.statusText}
</Text>
<Flex>
<ButtonPrimary mr={3} width="50%" onClick={retry}>
Expand All @@ -70,11 +67,9 @@ export function CreateDatabaseDialog({
} else if (attempt.status === 'processing') {
content = (
<>
<Text bold caps mb={4}>
Registering Database
</Text>
<AnimatedProgressBar />
<AnimatedProgressBar mb={1} />
<TextIcon
mb={3}
css={`
white-space: pre;
`}
Expand All @@ -86,20 +81,20 @@ export function CreateDatabaseDialog({
tailMessage={' seconds left'}
/>
</TextIcon>
<ButtonPrimary width="100%" disabled>
Next
</ButtonPrimary>
</>
);
} else {
// success
content = (
<>
<Text bold caps mb={4}>
Successfully Registered Database
</Text>
<Text mb={5}>
<Icons.Check ml={1} mr={2} color="success" />
Database "{dbName}" successfully registered
</Text>
<ButtonPrimary mr={2} width="100%" onClick={next}>
<ButtonPrimary width="100%" onClick={next}>
Next
</ButtonPrimary>
</>
Expand All @@ -114,6 +109,9 @@ export function CreateDatabaseDialog({
mb={0}
textAlign="center"
>
<Text bold caps mb={4}>
Database Register
</Text>
{content}
</DialogContent>
</Dialog>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,19 @@ const services = [

const testCases = [
{
name: 'match in multiple services',
name: 'match with a service',
newLabels: dbLabels,
services: [
{
name: 'svc4',
matcherLabels: { env: ['prod'] },
awsIdentity: emptyAwsIdentity,
},
],
expectedMatch: 'svc4',
},
{
name: 'match among multple service',
newLabels: dbLabels,
services,
expectedMatch: 'svc2',
Expand All @@ -96,26 +108,14 @@ const testCases = [
name: 'no match despite matching all labels when a svc has a non-matching label',
newLabels: dbLabels,
services: [
{
name: 'svc1',
matcherLabels: { os: ['windows', 'mac'], env: ['staging'] },
awsIdentity: emptyAwsIdentity,
},
{
name: 'svc2',
matcherLabels: {
os: ['windows', 'mac', 'linux'],
tag: ['v11.0.0'],
env: ['staging', 'prod'],
fruit: ['apple', '*'], // the non-matching label
},
awsIdentity: emptyAwsIdentity,
},
{
name: 'svc3',
matcherLabels: { env: ['prod'], fruit: ['orange'] },
awsIdentity: emptyAwsIdentity,
},
],
expectedMatch: undefined,
},
Expand Down Expand Up @@ -161,7 +161,7 @@ const testCases = [
name: 'svc2',
matcherLabels: {
os: ['linux', 'mac'],
'*': ['prod', 'apple', 'v11.0.0'],
'*': ['prod', 'apple'],
},
awsIdentity: emptyAwsIdentity,
},
Expand All @@ -174,7 +174,7 @@ const testCases = [
services: [
{
name: 'svc1',
matcherLabels: { '*': ['windows', 'mac'] },
matcherLabels: { '*': ['windows'] },
awsIdentity: emptyAwsIdentity,
},
],
Expand Down Expand Up @@ -204,7 +204,7 @@ const testCases = [
name: 'svc1',
matcherLabels: {
fruit: ['*'],
os: ['mac'],
os: ['windows'],
},
awsIdentity: emptyAwsIdentity,
},
Expand Down Expand Up @@ -239,9 +239,11 @@ const testCases = [
},
];

test.each(testCases)('$name', ({ newLabels, services, expectedMatch }) => {
const foundSvc = findActiveDatabaseSvc(newLabels, services);
expect(foundSvc?.name).toEqual(expectedMatch);
describe('findActiveDatabaseSvc()', () => {
test.each(testCases)('$name', ({ newLabels, services, expectedMatch }) => {
const foundSvc = findActiveDatabaseSvc(newLabels, services);
expect(foundSvc?.name).toEqual(expectedMatch);
});
});

const newDatabaseReq: CreateDatabaseRequest = {
Expand Down Expand Up @@ -284,9 +286,9 @@ describe('registering new databases, mainly error checking', () => {
jest
.spyOn(userEventService, 'captureDiscoverEvent')
.mockResolvedValue(null as never); // return value does not matter but required by ts
jest
.spyOn(teleCtx.databaseService, 'fetchDatabases')
.mockResolvedValue({ agents: [{ name: 'new-db' } as any] });
jest.spyOn(teleCtx.databaseService, 'fetchDatabases').mockResolvedValue({
agents: [{ name: 'new-db', labels: dbLabels } as any],
});
jest
.spyOn(teleCtx.databaseService, 'createDatabase')
.mockResolvedValue(null); // ret val not used
Expand Down Expand Up @@ -339,7 +341,7 @@ describe('registering new databases, mainly error checking', () => {
expect(discoverCtx.updateAgentMeta).toHaveBeenCalledWith({
resourceName: 'db-name',
agentMatcherLabels: dbLabels,
db: { name: 'new-db' },
db: { name: 'new-db', labels: dbLabels },
});

// Test the dynamic definition of nextStep is called with a number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useDiscover } from 'teleport/Discover/useDiscover';
import { usePoll } from 'teleport/Discover/Shared/usePoll';
import { compareByString } from 'teleport/lib/util';

import { matchLabels, makeLabelMaps } from '../util';
import { matchLabels } from '../util';

import type {
CreateDatabaseRequest,
Expand Down Expand Up @@ -111,7 +111,7 @@ export function useCreateDatabase() {
updateAgentMeta({
...(agentMeta as DbMeta),
resourceName: createdDb.name,
agentMatcherLabels: createdDb.labels,
agentMatcherLabels: dbPollingResult.labels,
db: dbPollingResult,
});

Expand Down Expand Up @@ -257,21 +257,10 @@ export function findActiveDatabaseSvc(
return null;
}

// Create maps for easy lookup and matching.
const { labelKeysToMatchMap, labelValsToMatchMap, labelToMatchSeenMap } =
makeLabelMaps(newDbLabels);

const hasLabelsToMatch = newDbLabels.length > 0;
for (let i = 0; i < dbServices.length; i++) {
// Loop through the current service label keys and its value set.
const currService = dbServices[i];
const match = matchLabels({
hasLabelsToMatch,
labelKeysToMatchMap,
labelValsToMatchMap,
labelToMatchSeenMap,
matcherLabels: currService.matcherLabels,
});
const match = matchLabels(newDbLabels, currService.matcherLabels);

if (match) {
return currService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export const InitWithLabels = () => {
{...props}
agentMeta={{
...props.agentMeta,
agentMatcherLabels: [{ name: 'env', value: 'prod' }],
agentMatcherLabels: [
{ name: 'env', value: 'staging' },
{ name: 'os', value: 'windows' },
],
}}
/>
</Provider>
Expand Down
Loading