@gojsop/types 0.0.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/index.d.ts +104 -0
- package/package.json +14 -4
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
# @gojsop/types
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Types for [gojsop](https://github.com/efuturetoday/gojsop) scripts:
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import type { Request, Response } from "@gojsop/types";
|
|
7
|
+
|
|
8
|
+
export function validate(req: Request): Response {
|
|
9
|
+
return { allowed: true };
|
|
10
|
+
}
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Importing the package also declares the global `kube`.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Types for gojsop scripts. A policy exports validate(req) or mutate(req), a
|
|
2
|
+
// hook exports handle(event); the global kube reaches the cluster with the
|
|
3
|
+
// rights in spec.permissions.
|
|
4
|
+
|
|
5
|
+
/** A Kubernetes object; only what every object has is typed. */
|
|
6
|
+
export interface KubeObject {
|
|
7
|
+
apiVersion: string;
|
|
8
|
+
kind: string;
|
|
9
|
+
metadata?: {
|
|
10
|
+
name?: string;
|
|
11
|
+
namespace?: string;
|
|
12
|
+
labels?: Record<string, string>;
|
|
13
|
+
annotations?: Record<string, string>;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
// Loose on purpose: a script handles any kind of object.
|
|
17
|
+
// biome-ignore lint/suspicious/noExplicitAny: spec differs per kind; any keeps scripts short
|
|
18
|
+
spec?: any;
|
|
19
|
+
// biome-ignore lint/suspicious/noExplicitAny: status differs per kind
|
|
20
|
+
status?: any;
|
|
21
|
+
data?: Record<string, string>;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** What a policy's validate(req) or mutate(req) gets. */
|
|
26
|
+
export interface Request {
|
|
27
|
+
uid: string;
|
|
28
|
+
kind: { group: string; version: string; kind: string };
|
|
29
|
+
resource: { group: string; version: string; resource: string };
|
|
30
|
+
subResource?: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
namespace?: string;
|
|
33
|
+
operation: "CREATE" | "UPDATE" | "DELETE" | "CONNECT";
|
|
34
|
+
userInfo: { username?: string; uid?: string; groups?: string[]; extra?: Record<string, string[]> };
|
|
35
|
+
/** Missing on DELETE. */
|
|
36
|
+
object?: KubeObject;
|
|
37
|
+
/** Missing on CREATE. */
|
|
38
|
+
oldObject?: KubeObject;
|
|
39
|
+
dryRun: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** What validate or mutate returns. A result without allowed denies. */
|
|
43
|
+
export interface Response {
|
|
44
|
+
allowed: boolean;
|
|
45
|
+
message?: string;
|
|
46
|
+
/** HTTP status code of a denial, e.g. 403. */
|
|
47
|
+
code?: number;
|
|
48
|
+
warnings?: string[];
|
|
49
|
+
/** mutate only: the changed object; gojsop sends the difference as a JSON patch. */
|
|
50
|
+
modifiedObject?: KubeObject;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** What a hook's handle(event) gets. */
|
|
54
|
+
export interface Event {
|
|
55
|
+
type: "Added" | "Modified" | "Deleted";
|
|
56
|
+
/** For Deleted, its last state. */
|
|
57
|
+
object: KubeObject;
|
|
58
|
+
/** The name of the binding that saw the change. */
|
|
59
|
+
binding: string;
|
|
60
|
+
/** true for an object that existed when the hook started watching. */
|
|
61
|
+
initial: boolean;
|
|
62
|
+
/** Every object the binding watches right now. */
|
|
63
|
+
all(): KubeObject[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ObjectRef {
|
|
67
|
+
apiVersion: string;
|
|
68
|
+
kind: string;
|
|
69
|
+
name: string;
|
|
70
|
+
namespace?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface ListOptions {
|
|
74
|
+
apiVersion: string;
|
|
75
|
+
kind: string;
|
|
76
|
+
/** Empty or missing: all namespaces. */
|
|
77
|
+
namespace?: string;
|
|
78
|
+
labelSelector?: string;
|
|
79
|
+
fieldSelector?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The cluster, with the rights in spec.permissions. A failed call throws. */
|
|
83
|
+
export interface Kube {
|
|
84
|
+
/** The object, or null when it is missing. */
|
|
85
|
+
get(ref: ObjectRef): KubeObject | null;
|
|
86
|
+
list(options: ListOptions): KubeObject[];
|
|
87
|
+
/** Hooks only: creates the object or merges it into the existing one; returns what was stored. */
|
|
88
|
+
apply(object: KubeObject): KubeObject;
|
|
89
|
+
/** Hooks only: a missing object is no error. */
|
|
90
|
+
delete(ref: ObjectRef): boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare global {
|
|
94
|
+
const kube: Kube;
|
|
95
|
+
// gojsop's console; merges with the DOM's or Node's when those are loaded.
|
|
96
|
+
interface Console {
|
|
97
|
+
log(...data: unknown[]): void;
|
|
98
|
+
info(...data: unknown[]): void;
|
|
99
|
+
debug(...data: unknown[]): void;
|
|
100
|
+
warn(...data: unknown[]): void;
|
|
101
|
+
error(...data: unknown[]): void;
|
|
102
|
+
}
|
|
103
|
+
var console: Console;
|
|
104
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gojsop/types",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Types for gojsop scripts: the request a policy gets, the event a hook gets, and the global kube.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/efuturetoday/gojsop.git",
|
|
9
|
-
"directory": "sdk"
|
|
10
|
-
}
|
|
9
|
+
"directory": "sdk/types"
|
|
10
|
+
},
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"index.d.ts",
|
|
19
|
+
"README.md"
|
|
20
|
+
]
|
|
11
21
|
}
|