mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix non-legacy APIs not being retrieved correctly
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
439c469ce6
commit
b14e77a616
@ -47,7 +47,7 @@ export class ExtendedMap<K, V> extends Map<K, V> {
|
||||
*/
|
||||
strictSet(key: K, val: V): this {
|
||||
if (this.has(key)) {
|
||||
throw new TypeError("Duplicate key in map");
|
||||
throw new TypeError(`Duplicate key in map: ${key}`);
|
||||
}
|
||||
|
||||
return this.set(key, val);
|
||||
@ -59,7 +59,7 @@ export class ExtendedMap<K, V> extends Map<K, V> {
|
||||
*/
|
||||
strictGet(key: K): V {
|
||||
if (!this.has(key)) {
|
||||
throw new TypeError("key not in map");
|
||||
throw new TypeError(`Key not in map: ${key}`);
|
||||
}
|
||||
|
||||
return this.get(key);
|
||||
|
||||
@ -522,19 +522,20 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
private isAllowedCheckers = new ExtendedObservableMap<string, () => Promise<Set<string>>>();
|
||||
|
||||
private async getIsAllowedResourcesInNamespace(namespace: string): Promise<Set<string>> {
|
||||
console.log("getIsAllowedResourcesInNamespace", Date.now());
|
||||
const groups = await this.getApiResourceMap();
|
||||
const isAllowed = new Set<string>();
|
||||
|
||||
for (const group of groups.values()) {
|
||||
for (const versions of group.values()) {
|
||||
for (const resource of versions.keys()) {
|
||||
for (const [group, versions] of groups) {
|
||||
for (const [version, resources] of versions) {
|
||||
for (const resource of resources.keys()) {
|
||||
const canList = await this.canI({
|
||||
resource,
|
||||
version,
|
||||
group,
|
||||
namespace,
|
||||
verb: "list",
|
||||
});
|
||||
|
||||
|
||||
if (canList) {
|
||||
isAllowed.add(resource);
|
||||
}
|
||||
|
||||
@ -45,6 +45,8 @@ type ResourceName = string;
|
||||
*/
|
||||
export type ApiResourceMap = Map<Group, Map<Version, Map<ResourceName, ApiResource>>>;
|
||||
|
||||
const groupVersionRegex = /^((?<group>.*)\/)?(?<version>.*)$/;
|
||||
|
||||
/**
|
||||
* Get the list of all resources kubernetes knows about from the current cluster of `kc`.
|
||||
* @param kc The config of the cluster to get all resources of
|
||||
@ -72,7 +74,7 @@ export async function getClusterResources(kc: KubeConfig, throttle = 10): Promis
|
||||
const res = new ExtendedMap<string, ExtendedMap<string, ExtendedMap<string, ApiResource>>>();
|
||||
|
||||
for (const apiResourceList of apiResourceLists) {
|
||||
const [group, version] = apiResourceList.groupVersion.split("/");
|
||||
const { groups: { group, version } } = apiResourceList.groupVersion.match(groupVersionRegex);
|
||||
const versions = res.getOrInsert(group, ExtendedMap.new);
|
||||
const resources = versions.getOrInsert(version, ExtendedMap.new);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user