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 {
|
strictSet(key: K, val: V): this {
|
||||||
if (this.has(key)) {
|
if (this.has(key)) {
|
||||||
throw new TypeError("Duplicate key in map");
|
throw new TypeError(`Duplicate key in map: ${key}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.set(key, val);
|
return this.set(key, val);
|
||||||
@ -59,7 +59,7 @@ export class ExtendedMap<K, V> extends Map<K, V> {
|
|||||||
*/
|
*/
|
||||||
strictGet(key: K): V {
|
strictGet(key: K): V {
|
||||||
if (!this.has(key)) {
|
if (!this.has(key)) {
|
||||||
throw new TypeError("key not in map");
|
throw new TypeError(`Key not in map: ${key}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.get(key);
|
return this.get(key);
|
||||||
|
|||||||
@ -522,15 +522,16 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
private isAllowedCheckers = new ExtendedObservableMap<string, () => Promise<Set<string>>>();
|
private isAllowedCheckers = new ExtendedObservableMap<string, () => Promise<Set<string>>>();
|
||||||
|
|
||||||
private async getIsAllowedResourcesInNamespace(namespace: string): Promise<Set<string>> {
|
private async getIsAllowedResourcesInNamespace(namespace: string): Promise<Set<string>> {
|
||||||
console.log("getIsAllowedResourcesInNamespace", Date.now());
|
|
||||||
const groups = await this.getApiResourceMap();
|
const groups = await this.getApiResourceMap();
|
||||||
const isAllowed = new Set<string>();
|
const isAllowed = new Set<string>();
|
||||||
|
|
||||||
for (const group of groups.values()) {
|
for (const [group, versions] of groups) {
|
||||||
for (const versions of group.values()) {
|
for (const [version, resources] of versions) {
|
||||||
for (const resource of versions.keys()) {
|
for (const resource of resources.keys()) {
|
||||||
const canList = await this.canI({
|
const canList = await this.canI({
|
||||||
resource,
|
resource,
|
||||||
|
version,
|
||||||
|
group,
|
||||||
namespace,
|
namespace,
|
||||||
verb: "list",
|
verb: "list",
|
||||||
});
|
});
|
||||||
|
|||||||
@ -45,6 +45,8 @@ type ResourceName = string;
|
|||||||
*/
|
*/
|
||||||
export type ApiResourceMap = Map<Group, Map<Version, Map<ResourceName, ApiResource>>>;
|
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`.
|
* 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
|
* @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>>>();
|
const res = new ExtendedMap<string, ExtendedMap<string, ExtendedMap<string, ApiResource>>>();
|
||||||
|
|
||||||
for (const apiResourceList of apiResourceLists) {
|
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 versions = res.getOrInsert(group, ExtendedMap.new);
|
||||||
const resources = versions.getOrInsert(version, ExtendedMap.new);
|
const resources = versions.getOrInsert(version, ExtendedMap.new);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user