From d1095d86dba98077e46bfc70c8a83569286984a0 Mon Sep 17 00:00:00 2001 From: Pawel Kopiczko Date: Wed, 5 Feb 2025 15:42:23 +0000 Subject: [PATCH] Set reason for each dry run Access List requests --- .../teleport/src/AccessRequests/service.ts | 97 ------------------- .../useAccessRequestCheckout.ts | 1 + 2 files changed, 1 insertion(+), 97 deletions(-) delete mode 100644 web/packages/teleport/src/AccessRequests/service.ts diff --git a/web/packages/teleport/src/AccessRequests/service.ts b/web/packages/teleport/src/AccessRequests/service.ts deleted file mode 100644 index b221d6ddaa51a..0000000000000 --- a/web/packages/teleport/src/AccessRequests/service.ts +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Teleport - * Copyright (C) 2023 Gravitational, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import { formatDuration } from 'date-fns'; - -import { RequestableResourceKind } from 'shared/components/AccessRequests/NewRequest/resource'; - -import { - AccessRequest, - AccessRequestResource, - CreateAccessRequest, - DurationOption, -} from 'teleport/AccessRequests/types'; -import { middleValues } from 'teleport/AccessRequests/utils'; -import cfg from 'teleport/config'; -import api from 'teleport/services/api'; - -export async function createAccessRequest( - clusterId: string, - roles: string[], - resources: AccessRequestResource[], - reason: string, - dryRun: boolean, - maxDuration?: Date -): Promise { - const request: CreateAccessRequest = { - reason, - roles, - resourceIds: resources.map(item => ({ - kind: item.type as RequestableResourceKind, - name: item.id, - clusterName: clusterId, - })), - suggestedReviewers: [], - maxDuration, - dryRun, - }; - - const accessRequest = await api.post(cfg.getAccessRequestUrl(), request); - - return { - id: accessRequest.id, - created: new Date(accessRequest.created), - expires: new Date(accessRequest.expires), - requestReason: accessRequest.requestReason, - resolveReason: accessRequest.resolveReason, - resources: accessRequest.resources, - reviews: accessRequest.reviews, - roles: accessRequest.roles, - state: accessRequest.state, - suggestedReviewers: accessRequest.suggestedReviewers, - thresholdNames: accessRequest.thresholdNames, - user: accessRequest.user, - }; -} - -export async function getDurationOptions( - clusterId: string, - roles: string[], - resources: AccessRequestResource[] -): Promise { - const accessRequest = await createAccessRequest( - clusterId, - roles, - resources, - '', - true - ); - - if (!accessRequest.sessionTTL || !accessRequest.maxDuration) { - return []; - } - - return middleValues( - accessRequest.created, - accessRequest.sessionTTL, - accessRequest.maxDuration - ).map(duration => ({ - value: duration.timestamp, - label: formatDuration(duration.duration), - })); -} diff --git a/web/packages/teleterm/src/ui/AccessRequestCheckout/useAccessRequestCheckout.ts b/web/packages/teleterm/src/ui/AccessRequestCheckout/useAccessRequestCheckout.ts index 521002a1f222e..d65421adeea37 100644 --- a/web/packages/teleterm/src/ui/AccessRequestCheckout/useAccessRequestCheckout.ts +++ b/web/packages/teleterm/src/ui/AccessRequestCheckout/useAccessRequestCheckout.ts @@ -338,6 +338,7 @@ export default function useAccessRequestCheckout() { try { const { accessRequest } = await prepareAndCreateRequest({ + reason: 'placeholder-reason', dryRun: true, maxDuration: getDryRunMaxDuration(), });