Skip to content

Commit

Permalink
Load data in rules tables
Browse files Browse the repository at this point in the history
  • Loading branch information
michellescripts committed Dec 9, 2024
1 parent dd7e49f commit ee4fd76
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import { useAwsOidcStatus } from 'teleport/Integrations/status/AwsOidc/useAwsOid
import { AwsResource } from 'teleport/Integrations/status/AwsOidc/StatCard';
import { IntegrationKind } from 'teleport/services/integrations';
import { Rds } from 'teleport/Integrations/status/AwsOidc/Details/Rds';
import { Ec2 } from 'teleport/Integrations/status/AwsOidc/Details/Ec2';
import { Eks } from 'teleport/Integrations/status/AwsOidc/Details/Eks';
import { Rules } from 'teleport/Integrations/status/AwsOidc/Details/Rules';

export function Details() {
const { resourceKind } = useParams<{
Expand All @@ -43,8 +42,8 @@ export function Details() {
{integration && (
<AwsOidcHeader integration={integration} resource={resourceKind} />
)}
{resourceKind == AwsResource.ec2 && <Ec2 />}
{resourceKind == AwsResource.eks && <Eks />}
{resourceKind == AwsResource.ec2 && <Rules />}
{resourceKind == AwsResource.eks && <Rules />}
{resourceKind == AwsResource.rds && <Rds />}
</FeatureBox>
);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,65 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React from 'react';
import React, { useEffect } from 'react';

import Table, { LabelCell } from 'design/DataTable';

import { useParams } from 'react-router';

import { useAsync } from 'shared/hooks/useAsync';
import { Indicator } from 'design';
import { Danger } from 'design/Alert';

import {
IntegrationKind,
integrationService,
} from 'teleport/services/integrations';
import { AwsResource } from 'teleport/Integrations/status/AwsOidc/StatCard';

export function Rules() {
const { name, resourceKind } = useParams<{
type: IntegrationKind;
name: string;
resourceKind: AwsResource;
}>();

const [attempt, fetchRules] = useAsync(() =>
integrationService.fetchIntegrationRules(name, resourceKind)
);

useEffect(() => {
fetchRules();
}, []);

if (attempt.status == 'processing') {
return <Indicator />;
}

if (attempt.status == 'error') {
return <Danger>{attempt.statusText}</Danger>;
}

if (!attempt.data) {
return null;
}

return (
<Table
data={[]}
data={attempt.data.rules}
columns={[
{
key: 'name',
headerText: 'Integration Name',
isSortable: true,
},
{
key: 'region',
headerText: 'Region',
isSortable: true,
},
{
key: 'tags',
headerText: 'Tags',
key: 'labelMatcher',
headerText: getResourceTerm(resourceKind),
isSortable: true,
onSort: (a, b) => {
const aStr = a.tags.toString();
const bStr = b.tags.toString();
const aStr = a.labelMatcher.toString();
const bStr = b.labelMatcher.toString();

if (aStr < bStr) {
return -1;
Expand All @@ -52,11 +85,22 @@ export function Rules() {

return 0;
},
render: ({ tags }) => <LabelCell data={tags} />,
render: ({ labelMatcher }) => (
<LabelCell data={labelMatcher.map(l => `${l.value}:${l.name}`)} />
),
},
]}
emptyText="Rules details coming soon"
emptyText={`No ${resourceKind} data`}
isSearchable
/>
);
}

function getResourceTerm(resource: AwsResource): string {
switch (resource) {
case AwsResource.rds:
return 'Tags';
default:
return 'Labels';
}
}
12 changes: 12 additions & 0 deletions web/packages/teleport/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ const cfg = {
integrationsPath: '/v1/webapi/sites/:clusterId/integrations/:name?',
integrationStatsPath:
'/v1/webapi/sites/:clusterId/integrations/:name/stats',
integrationRulesPath:
'/v1/webapi/sites/:clusterId/integrations/:name/discoveryrules?resourceType=:resourceType',

thumbprintPath: '/v1/webapi/thumbprint',
pingAwsOidcIntegrationPath:
'/v1/webapi/sites/:clusterId/integrations/aws-oidc/:name/ping',
Expand Down Expand Up @@ -994,6 +997,15 @@ const cfg = {
});
},

getIntegrationRulesUrl(name: string, resourceType: AwsResource) {
const clusterId = cfg.proxyCluster;
return generatePath(cfg.api.integrationRulesPath, {
clusterId,
name,
resourceType,
});
},

getPingAwsOidcIntegrationUrl({
integrationName,
clusterId,
Expand Down
14 changes: 14 additions & 0 deletions web/packages/teleport/src/services/integrations/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import api from 'teleport/services/api';
import cfg from 'teleport/config';

import { AwsResource } from 'teleport/Integrations/status/AwsOidc/StatCard';

import makeNode from '../nodes/makeNode';
import auth from '../auth/auth';
import { App } from '../apps';
Expand Down Expand Up @@ -60,6 +62,7 @@ import {
AwsOidcPingResponse,
AwsOidcPingRequest,
IntegrationWithSummary,
IntegrationDiscoveryRules,
} from './types';

export const integrationService = {
Expand Down Expand Up @@ -420,6 +423,17 @@ export const integrationService = {
return resp;
});
},

fetchIntegrationRules(
name: string,
resourceType: AwsResource
): Promise<IntegrationDiscoveryRules> {
return api
.get(cfg.getIntegrationRulesUrl(name, resourceType))
.then(resp => {
return resp;
});
},
};

export function makeIntegrations(json: any): Integration[] {
Expand Down
25 changes: 25 additions & 0 deletions web/packages/teleport/src/services/integrations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,31 @@ export type IntegrationWithSummary = {
awseks: ResourceTypeSummary;
};

// IntegrationDiscoveryRules contains the list of discovery rules for a given Integration.
export type IntegrationDiscoveryRules = {
// rules is the list of integration rules.
rules: IntegrationDiscoveryRule[];
// nextKey is the position to resume listing rules.
nextKey: string;
};

// IntegrationDiscoveryRule describes a discovery rule associated with an integration.
export type IntegrationDiscoveryRule = {
// resourceType indicates the type of resource that this rule targets.
// This is the same value that is set in DiscoveryConfig.AWS.<Matcher>.Types
// Example: ec2, rds, eks
resourceType: string;
// region where this rule applies to.
region: string;
// labelMatcher is the set of labels that are used to filter the resources before trying to auto-enroll them.
labelMatcher: Label[];
// discoveryConfig is the name of the DiscoveryConfig that created this rule.
discoveryConfig: string;
// lastSync contains the time when this rule was used.
// If empty, it indicates that the rule is not being used.
lastSync: number;
};

// ResourceTypeSummary contains the summary of the enrollment rules and found resources by the integration.
export type ResourceTypeSummary = {
// rulesCount is the number of enrollment rules that are using this integration.
Expand Down

0 comments on commit ee4fd76

Please sign in to comment.