mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix: Add checks to KubeObject constructor to ensure shape
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
4634643f93
commit
bf6af58d80
2 files changed
+42
-6
No files matched your search
@@ -548,14 +548,30 @@ export class KubeObject<
|
||||
}
|
||||
|
||||
constructor(data: KubeJsonApiData<Metadata, Status, Spec>) {
|
||||
if (typeof data !== "object") {
|
||||
if (!isObject(data)) {
|
||||
throw new TypeError(`Cannot create a KubeObject from ${typeof data}`);
|
||||
}
|
||||
|
||||
if (!data.metadata || typeof data.metadata !== "object") {
|
||||
if (!isObject(data.metadata)) {
|
||||
throw new KubeCreationError(`Cannot create a KubeObject from an object without metadata`, data);
|
||||
}
|
||||
|
||||
if (!isString(data.metadata.name)) {
|
||||
throw new KubeCreationError(`Cannot create a KubeObject from an object without metadata.name being a string`, data);
|
||||
}
|
||||
|
||||
if (!isString(data.metadata.uid)) {
|
||||
throw new KubeCreationError(`Cannot create a KubeObject from an object without metadata.uid being a string`, data);
|
||||
}
|
||||
|
||||
if (!isString(data.metadata.resourceVersion)) {
|
||||
throw new KubeCreationError(`Cannot create a KubeObject from an object without metadata.resourceVersion being a string`, data);
|
||||
}
|
||||
|
||||
if (!isString(data.metadata.selfLink)) {
|
||||
throw new KubeCreationError(`Cannot create a KubeObject from an object without metadata.selfLink being a string`, data);
|
||||
}
|
||||
|
||||
Object.assign(this, data);
|
||||
autoBind(this);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user