11import * as React from 'react' ;
2- import {
3- deleteData ,
4- fetchData ,
5- fetchUiProxy ,
6- handleApiJSONResponse ,
7- patchData ,
8- postData ,
9- putData ,
10- uiProxy ,
11- wsEndpoint ,
12- } from '../utils/apiCalls' ;
2+ import { deleteData , fetchData , fetchUiProxy , patchData , postData , putData , wsEndpoint } from '../utils/apiCalls' ;
133import { PatchRequest } from '@flightctl/types' ;
14- import { K8sVerb , checkAccess } from '@openshift-console/dynamic-plugin-sdk' ;
15-
16- type OcpConfig = {
17- rbacNs : string ;
18- } ;
19-
20- const useOcpConfig = ( ) => {
21- const [ config , setConfig ] = React . useState < OcpConfig > ( ) ;
22-
23- React . useEffect ( ( ) => {
24- const doItAsync = async ( ) => {
25- try {
26- const response = await fetch ( `${ uiProxy } /api/config` ) ;
27- const cfg = await handleApiJSONResponse < OcpConfig > ( response ) ;
28- setConfig ( cfg ) ;
29- } catch ( error ) {
30- // eslint-disable-next-line
31- console . error ( 'Error making request:' , error ) ;
32- }
33- } ;
34- doItAsync ( ) ;
35- } , [ ] ) ;
36-
37- return config ;
38- } ;
394
405export const useFetch = ( ) => {
416 const get = React . useCallback (
@@ -67,21 +32,6 @@ export const useFetch = () => {
6732
6833 const getWsEndpoint = React . useCallback ( ( deviceId : string ) => `${ wsEndpoint } /api/terminal/${ deviceId } ` , [ ] ) ;
6934
70- const ocpConfig = useOcpConfig ( ) ;
71-
72- const checkPermissions = React . useCallback (
73- async ( resource : string , op : string ) => {
74- const ssar = await checkAccess ( {
75- group : 'flightctl.io' ,
76- resource,
77- verb : op as K8sVerb ,
78- namespace : ocpConfig ?. rbacNs ,
79- } ) ;
80- return ! ! ssar . status ?. allowed ;
81- } ,
82- [ ocpConfig ] ,
83- ) ;
84-
8535 const proxyFetch = React . useCallback ( async ( endpoint : string , requestInit : RequestInit ) : Promise < Response > => {
8636 return fetchUiProxy ( endpoint , requestInit ) ;
8737 } , [ ] ) ;
@@ -93,7 +43,6 @@ export const useFetch = () => {
9343 put,
9444 remove,
9545 patch,
96- checkPermissions,
9746 proxyFetch,
9847 } ;
9948} ;
0 commit comments