forked from canonical/lxd-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: restricted permissions for storage pool [WD-19339] (canonical#1111
- Loading branch information
Showing
38 changed files
with
343 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { queryKeys } from "util/queryKeys"; | ||
import { UseQueryResult } from "@tanstack/react-query"; | ||
import { useAuth } from "./auth"; | ||
import { LxdStoragePool, LXDStoragePoolOnClusterMember } from "types/storage"; | ||
import { | ||
fetchPoolFromClusterMembers, | ||
fetchStoragePool, | ||
fetchStoragePools, | ||
} from "api/storage-pools"; | ||
import { useClusterMembers } from "./useClusterMembers"; | ||
|
||
export const useStoragePool = ( | ||
pool: string, | ||
target?: string, | ||
enabled?: boolean, | ||
): UseQueryResult<LxdStoragePool> => { | ||
const { isFineGrained } = useAuth(); | ||
return useQuery({ | ||
queryKey: [queryKeys.storage, pool, target], | ||
queryFn: () => fetchStoragePool(pool, isFineGrained, target), | ||
enabled: (enabled ?? true) && isFineGrained !== null, | ||
}); | ||
}; | ||
|
||
export const useStoragePools = ( | ||
enabled?: boolean, | ||
): UseQueryResult<LxdStoragePool[]> => { | ||
const { isFineGrained } = useAuth(); | ||
return useQuery({ | ||
queryKey: [queryKeys.storage], | ||
queryFn: () => fetchStoragePools(isFineGrained), | ||
enabled: (enabled ?? true) && isFineGrained !== null, | ||
}); | ||
}; | ||
|
||
export const usePoolFromClusterMembers = ( | ||
pool: string, | ||
): UseQueryResult<LXDStoragePoolOnClusterMember[]> => { | ||
const { isFineGrained } = useAuth(); | ||
const { data: clusterMembers = [] } = useClusterMembers(); | ||
return useQuery({ | ||
queryKey: [queryKeys.storage, pool, queryKeys.cluster], | ||
queryFn: () => | ||
fetchPoolFromClusterMembers(pool, clusterMembers, isFineGrained), | ||
enabled: isFineGrained !== null && clusterMembers.length > 0, | ||
}); | ||
}; |
Oops, something went wrong.