Skip to content

Commit

Permalink
Rename ResourceKind to RequestableResourceKind, add namespace object …
Browse files Browse the repository at this point in the history
…where approp
  • Loading branch information
kimlisa committed Oct 9, 2024
1 parent 9f285c2 commit 1f71f86
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Select, {
} from 'shared/components/Select';
import { ToolTipInfo } from 'shared/components/ToolTip';

import { ResourceMap, ResourceKind } from '../resource';
import { ResourceMap, RequestableResourceKind } from '../resource';

import { ListProps, StyledTable } from './ResourceList';

Expand Down Expand Up @@ -125,7 +125,7 @@ function ActionCell({
agent: App;
addedResources: ResourceMap;
addOrRemoveResource: (
kind: ResourceKind,
kind: RequestableResourceKind,
resourceId: string,
resourceName?: string
) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { CustomSort } from 'design/DataTable/types';

import { ResourceLabel, UnifiedResource } from 'teleport/services/agents';

import { ResourceMap, ResourceKind } from '../resource';
import { ResourceMap, RequestableResourceKind } from '../resource';

import { Apps } from './Apps';
import { Databases } from './Databases';
Expand Down Expand Up @@ -126,7 +126,7 @@ export type ListProps = {
onLabelClick: (label: ResourceLabel) => void;
addedResources: ResourceMap;
addOrRemoveResource: (
kind: ResourceKind,
kind: RequestableResourceKind,
resourceId: string,
resourceName?: string
) => void;
Expand All @@ -135,7 +135,7 @@ export type ListProps = {

export type ResourceListProps = {
agents: UnifiedResource[];
selectedResource: ResourceKind;
selectedResource: RequestableResourceKind;
// disableRows disable clicking on any buttons (when fetching).
disableRows: boolean;
} & ListProps;
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

export * from './RequestCheckout';
export * from './ResourceList';
export type { ResourceMap, ResourceKind } from './resource';
export type { ResourceMap, RequestableResourceKind } from './resource';
export { getEmptyResourceState } from './resource';
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@
*/

import { ResourceIdKind } from 'teleport/services/agents';
import { KubeResourceKind } from 'teleport/services/kube';

/** Available request kinds for resource-based and role-based access requests. */
export type ResourceKind = ResourceIdKind | 'role' | 'resource';
export type RequestableResourceKind =
| ResourceIdKind
| 'role'
| 'resource'
| Exclude<KubeResourceKind, '*'>;

/**
* Maps a resource ID (usually agent name) to resource description (usually the
* same, but not necessarily).
*/
export type ResourceMap = {
[K in ResourceIdKind | 'role']: Record<string, string>;
[K in Exclude<RequestableResourceKind, 'resource'>]: Record<string, string>;
};

export function getEmptyResourceState(): ResourceMap {
Expand All @@ -39,5 +44,6 @@ export function getEmptyResourceState(): ResourceMap {
windows_desktop: {},
role: {},
saml_idp_service_provider: {},
namespace: {},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function getNumAddedResources(addedResources: ResourceMap) {
Object.keys(addedResources.kube_cluster).length +
Object.keys(addedResources.user_group).length +
Object.keys(addedResources.windows_desktop).length +
Object.keys(addedResources.saml_idp_service_provider).length
Object.keys(addedResources.saml_idp_service_provider).length +
Object.keys(addedResources.namespace).length
);
}
4 changes: 2 additions & 2 deletions web/packages/shared/services/accessRequests/accessRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { ResourceIdKind } from 'teleport/services/agents';
import { RequestableResourceKind } from 'shared/components/AccessRequests/NewRequest/resource';

export type RequestState =
| 'NONE'
Expand Down Expand Up @@ -76,7 +76,7 @@ export type Resource = {
// ResourceID is a unique identifier for a teleport resource.
export type ResourceId = {
// kind is the resource (agent) kind.
kind: ResourceIdKind;
kind: RequestableResourceKind;
// name is the name of the specific resource.
name: string;
// clusterName is the name of cluster.
Expand Down
5 changes: 3 additions & 2 deletions web/packages/teleport/src/AccessRequests/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

import { formatDuration } from 'date-fns';

import { ResourceIdKind } from 'teleport/services/agents';
import { RequestableResourceKind } from 'shared/components/AccessRequests/NewRequest/resource';

import api from 'teleport/services/api';
import cfg from 'teleport/config';
import {
Expand All @@ -41,7 +42,7 @@ export async function createAccessRequest(
reason,
roles,
resourceIds: resources.map(item => ({
kind: item.type as ResourceIdKind,
kind: item.type as RequestableResourceKind,
name: item.id,
clusterName: clusterId,
})),
Expand Down
8 changes: 4 additions & 4 deletions web/packages/teleport/src/AccessRequests/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import type { Option } from 'shared/components/Select';
import { RequestableResourceKind } from 'shared/components/AccessRequests/NewRequest/resource';

import type { ResourceIdKind } from 'teleport/services/agents';
import type { Option } from 'shared/components/Select';

export type DurationOption = Option<number>;

export interface Resource {
id: {
kind: ResourceIdKind;
kind: RequestableResourceKind;
name: string;
clusterName: string;
subResourceName?: string;
Expand All @@ -38,7 +38,7 @@ export interface Resource {
type RequestState = 'NONE' | 'PENDING' | 'APPROVED' | 'DENIED' | 'APPLIED' | '';

export interface ResourceId {
kind: ResourceIdKind;
kind: RequestableResourceKind;
name: string;
clusterName: string;
subResourceName?: string;
Expand Down
2 changes: 1 addition & 1 deletion web/packages/teleport/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ export interface UrlKubeResourcesParams {
searchAsRoles?: 'yes' | '';
kubeNamespace?: string;
kubeCluster: string;
kind: KubeResourceKind;
kind: Omit<KubeResourceKind, '*'>;
}

export interface UrlDeployServiceIamConfigureScriptParams {
Expand Down

0 comments on commit 1f71f86

Please sign in to comment.