Skip to content

Commit

Permalink
Address CRs
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlisa committed Oct 23, 2024
1 parent efa1921 commit 939680d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test('fetching requestable roles for servers uses UUID, not hostname', async ()
);
});

test('fetching requestable roles kube_cluster resource without namespace request', async () => {
test('fetching requestable roles for a kube_cluster resource without specifying a namespace', async () => {
const kube = makeKube();
const cluster = makeRootCluster();
const appContext = new MockAppContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ export default function useAccessRequestCheckout() {
/**
*
* @param pendingRequest holds a list or map of resources to process
* @param excludeSubResourceParentResource when true, resources that have
* subresources, will be excluded from the returned list. eg:
* if a kube_cluster resource has a list of namespaces (subresources),
* then if this flag is true, kube_cluster will be excluded from the result.
*/
function getPendingAccessRequestsPerResource(
pendingRequest: PendingAccessRequest
Expand Down Expand Up @@ -293,19 +289,11 @@ export default function useAccessRequestCheckout() {
resourceIds: pendingAccessRequestsWithoutParentResource
.filter(d => d.kind !== 'role')
.map(d => {
if (d.kind === 'namespace') {
return {
name: d.id,
kind: d.kind,
clusterName: d.clusterName,
subResourceName: d.subResourceName,
};
}
return {
name: d.id,
clusterName: d.clusterName,
kind: d.kind,
subResourceName: '',
subResourceName: d.subResourceName || '',
};
}),
roles: pendingAccessRequestsWithoutParentResource
Expand Down Expand Up @@ -345,19 +333,19 @@ export default function useAccessRequestCheckout() {
async function performDryRun() {
let teletermAccessRequest: TeletermAccessRequest;

// reset any create attempts between dry runs.
setCreateRequestAttempt({ status: '' });

try {
const { accessRequest } = await prepareAndCreateRequest({
dryRun: true,
maxDuration: getDryRunMaxDuration(),
});
teletermAccessRequest = accessRequest;
} catch {
setCreateRequestAttempt({ status: '' });
return;
}

setCreateRequestAttempt({ status: '' });

const accessRequest = makeUiAccessRequest(teletermAccessRequest);
onDryRunChange(accessRequest);
}
Expand Down Expand Up @@ -440,7 +428,7 @@ export default function useAccessRequestCheckout() {
isCollapsed,
assumedRequests: getAssumedRequests(),
toggleResource,
data: pendingAccessRequests,
pendingAccessRequests,
shouldShowClusterNameColumn,
createRequest,
reset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,14 @@ export default function useNewRequest(rootCluster: Cluster) {
return;
}

/**
* This should never happen but just a safeguard.
* This function is used in the "unified resources" view,
* where a user can click on a "request access" button.
* Selecting kube_cluster's namespace is not available in this view
* (instead it is rendered in the "request checkout" view).
*/
if (kind === 'namespace') {
// It is not possible to request a kube namespace through this function.
// The type should be corrected.
return;
}

Expand Down

0 comments on commit 939680d

Please sign in to comment.