-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathapi-resource.ts
547 lines (474 loc) · 13.2 KB
/
api-resource.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
/**
* Represents a resource or collection of resources.
*/
export interface IApiResource {
/**
* The group portion of the API version (e.g. `authorization.k8s.io`).
*/
readonly apiGroup: string;
/**
* The name of a resource type as it appears in the relevant API endpoint.
* @example - "pods" or "pods/log"
* @see https://kubernetes.io/docs/reference/access-authn-authz/rbac/#referring-to-resources
*/
readonly resourceType: string;
/**
* The unique, namespace-global, name of an object inside the Kubernetes cluster.
*
* If this is omitted, the ApiResource should represent all objects of the given type.
*/
readonly resourceName?: string;
}
/**
* An API Endpoint can either be a resource descriptor (e.g /pods)
* or a non resource url (e.g /healthz). It must be one or the other, and not both.
*/
export interface IApiEndpoint {
/**
* Return the IApiResource this object represents.
*/
asApiResource(): IApiResource | undefined;
/**
* Return the non resource url this object represents.
*/
asNonApiResource(): string | undefined;
}
/**
* Options for `ApiResource`.
*/
export interface ApiResourceOptions {
/**
* The group portion of the API version (e.g. `authorization.k8s.io`).
*/
readonly apiGroup: string;
/**
* The name of the resource type as it appears in the relevant API endpoint.
* @example - "pods" or "pods/log"
* @see https://kubernetes.io/docs/reference/access-authn-authz/rbac/#referring-to-resources
*/
readonly resourceType: string;
}
/**
* Represents information about an API resource type.
*/
export class ApiResource implements IApiResource, IApiEndpoint {
/**
* API resource information for Binding.
*/
public static readonly BINDINGS = new ApiResource({
apiGroup: '',
resourceType: 'bindings',
});
/**
* API resource information for ComponentStatus.
*/
public static readonly COMPONENT_STATUSES = new ApiResource({
apiGroup: '',
resourceType: 'componentstatuses',
});
/**
* API resource information for ConfigMap.
*/
public static readonly CONFIG_MAPS = new ApiResource({
apiGroup: '',
resourceType: 'configmaps',
});
/**
* API resource information for Endpoints.
*/
public static readonly ENDPOINTS = new ApiResource({
apiGroup: '',
resourceType: 'endpoints',
});
/**
* API resource information for Event.
*/
public static readonly EVENTS = new ApiResource({
apiGroup: '',
resourceType: 'events',
});
/**
* API resource information for LimitRange.
*/
public static readonly LIMIT_RANGES = new ApiResource({
apiGroup: '',
resourceType: 'limitranges',
});
/**
* API resource information for Namespace.
*/
public static readonly NAMESPACES = new ApiResource({
apiGroup: '',
resourceType: 'namespaces',
});
/**
* API resource information for Node.
*/
public static readonly NODES = new ApiResource({
apiGroup: '',
resourceType: 'nodes',
});
/**
* API resource information for PersistentVolumeClaim.
*/
public static readonly PERSISTENT_VOLUME_CLAIMS = new ApiResource({
apiGroup: '',
resourceType: 'persistentvolumeclaims',
});
/**
* API resource information for PersistentVolume.
*/
public static readonly PERSISTENT_VOLUMES = new ApiResource({
apiGroup: '',
resourceType: 'persistentvolumes',
});
/**
* API resource information for Pod.
*/
public static readonly PODS = new ApiResource({
apiGroup: '',
resourceType: 'pods',
});
/**
* API resource information for PodTemplate.
*/
public static readonly POD_TEMPLATES = new ApiResource({
apiGroup: '',
resourceType: 'podtemplates',
});
/**
* API resource information for ReplicationController.
*/
public static readonly REPLICATION_CONTROLLERS = new ApiResource({
apiGroup: '',
resourceType: 'replicationcontrollers',
});
/**
* API resource information for ResourceQuota.
*/
public static readonly RESOURCE_QUOTAS = new ApiResource({
apiGroup: '',
resourceType: 'resourcequotas',
});
/**
* API resource information for Secret.
*/
public static readonly SECRETS = new ApiResource({
apiGroup: '',
resourceType: 'secrets',
});
/**
* API resource information for ServiceAccount.
*/
public static readonly SERVICE_ACCOUNTS = new ApiResource({
apiGroup: '',
resourceType: 'serviceaccounts',
});
/**
* API resource information for Service.
*/
public static readonly SERVICES = new ApiResource({
apiGroup: '',
resourceType: 'services',
});
/**
* API resource information for MutatingWebhookConfiguration.
*/
public static readonly MUTATING_WEBHOOK_CONFIGURATIONS = new ApiResource({
apiGroup: 'admissionregistration.k8s.io',
resourceType: 'mutatingwebhookconfigurations',
});
/**
* API resource information for ValidatingWebhookConfiguration.
*/
public static readonly VALIDATING_WEBHOOK_CONFIGURATIONS = new ApiResource({
apiGroup: 'admissionregistration.k8s.io',
resourceType: 'validatingwebhookconfigurations',
});
/**
* API resource information for CustomResourceDefinition.
*/
public static readonly CUSTOM_RESOURCE_DEFINITIONS = new ApiResource({
apiGroup: 'apiextensions.k8s.io',
resourceType: 'customresourcedefinitions',
});
/**
* API resource information for APIService.
*/
public static readonly API_SERVICES = new ApiResource({
apiGroup: 'apiregistration.k8s.io',
resourceType: 'apiservices',
});
/**
* API resource information for ControllerRevision.
*/
public static readonly CONTROLLER_REVISIONS = new ApiResource({
apiGroup: 'apps',
resourceType: 'controllerrevisions',
});
/**
* API resource information for DaemonSet.
*/
public static readonly DAEMON_SETS = new ApiResource({
apiGroup: 'apps',
resourceType: 'daemonsets',
});
/**
* API resource information for Deployment.
*/
public static readonly DEPLOYMENTS = new ApiResource({
apiGroup: 'apps',
resourceType: 'deployments',
});
/**
* API resource information for ReplicaSet.
*/
public static readonly REPLICA_SETS = new ApiResource({
apiGroup: 'apps',
resourceType: 'replicasets',
});
/**
* API resource information for StatefulSet.
*/
public static readonly STATEFUL_SETS = new ApiResource({
apiGroup: 'apps',
resourceType: 'statefulsets',
});
/**
* API resource information for TokenReview.
*/
public static readonly TOKEN_REVIEWS = new ApiResource({
apiGroup: 'authentication.k8s.io',
resourceType: 'tokenreviews',
});
/**
* API resource information for LocalSubjectAccessReview.
*/
public static readonly LOCAL_SUBJECT_ACCESS_REVIEWS = new ApiResource({
apiGroup: 'authorization.k8s.io',
resourceType: 'localsubjectaccessreviews',
});
/**
* API resource information for SelfSubjectAccessReview.
*/
public static readonly SELF_SUBJECT_ACCESS_REVIEWS = new ApiResource({
apiGroup: 'authorization.k8s.io',
resourceType: 'selfsubjectaccessreviews',
});
/**
* API resource information for SelfSubjectRulesReview.
*/
public static readonly SELF_SUBJECT_RULES_REVIEWS = new ApiResource({
apiGroup: 'authorization.k8s.io',
resourceType: 'selfsubjectrulesreviews',
});
/**
* API resource information for SubjectAccessReview.
*/
public static readonly SUBJECT_ACCESS_REVIEWS = new ApiResource({
apiGroup: 'authorization.k8s.io',
resourceType: 'subjectaccessreviews',
});
/**
* API resource information for HorizontalPodAutoscaler.
*/
public static readonly HORIZONTAL_POD_AUTOSCALERS = new ApiResource({
apiGroup: 'autoscaling',
resourceType: 'horizontalpodautoscalers',
});
/**
* API resource information for CronJob.
*/
public static readonly CRON_JOBS = new ApiResource({
apiGroup: 'batch',
resourceType: 'cronjobs',
});
/**
* API resource information for Job.
*/
public static readonly JOBS = new ApiResource({
apiGroup: 'batch',
resourceType: 'jobs',
});
/**
* API resource information for CertificateSigningRequest.
*/
public static readonly CERTIFICATE_SIGNING_REQUESTS = new ApiResource({
apiGroup: 'certificates.k8s.io',
resourceType: 'certificatesigningrequests',
});
/**
* API resource information for Lease.
*/
public static readonly LEASES = new ApiResource({
apiGroup: 'coordination.k8s.io',
resourceType: 'leases',
});
/**
* API resource information for EndpointSlice.
*/
public static readonly ENDPOINT_SLICES = new ApiResource({
apiGroup: 'discovery.k8s.io',
resourceType: 'endpointslices',
});
/**
* API resource information for FlowSchema.
*/
public static readonly FLOW_SCHEMAS = new ApiResource({
apiGroup: 'flowcontrol.apiserver.k8s.io',
resourceType: 'flowschemas',
});
/**
* API resource information for PriorityLevelConfiguration.
*/
public static readonly PRIORITY_LEVEL_CONFIGURATIONS = new ApiResource({
apiGroup: 'flowcontrol.apiserver.k8s.io',
resourceType: 'prioritylevelconfigurations',
});
/**
* API resource information for IngressClass.
*/
public static readonly INGRESS_CLASSES = new ApiResource({
apiGroup: 'networking.k8s.io',
resourceType: 'ingressclasses',
});
/**
* API resource information for Ingress.
*/
public static readonly INGRESSES = new ApiResource({
apiGroup: 'networking.k8s.io',
resourceType: 'ingresses',
});
/**
* API resource information for NetworkPolicy.
*/
public static readonly NETWORK_POLICIES = new ApiResource({
apiGroup: 'networking.k8s.io',
resourceType: 'networkpolicies',
});
/**
* API resource information for RuntimeClass.
*/
public static readonly RUNTIME_CLASSES = new ApiResource({
apiGroup: 'node.k8s.io',
resourceType: 'runtimeclasses',
});
/**
* API resource information for PodDisruptionBudget.
*/
public static readonly POD_DISRUPTION_BUDGETS = new ApiResource({
apiGroup: 'policy',
resourceType: 'poddisruptionbudgets',
});
/**
* API resource information for ClusterRoleBinding.
*/
public static readonly CLUSTER_ROLE_BINDINGS = new ApiResource({
apiGroup: 'rbac.authorization.k8s.io',
resourceType: 'clusterrolebindings',
});
/**
* API resource information for ClusterRole.
*/
public static readonly CLUSTER_ROLES = new ApiResource({
apiGroup: 'rbac.authorization.k8s.io',
resourceType: 'clusterroles',
});
/**
* API resource information for RoleBinding.
*/
public static readonly ROLE_BINDINGS = new ApiResource({
apiGroup: 'rbac.authorization.k8s.io',
resourceType: 'rolebindings',
});
/**
* API resource information for Role.
*/
public static readonly ROLES = new ApiResource({
apiGroup: 'rbac.authorization.k8s.io',
resourceType: 'roles',
});
/**
* API resource information for PriorityClass.
*/
public static readonly PRIORITY_CLASSES = new ApiResource({
apiGroup: 'scheduling.k8s.io',
resourceType: 'priorityclasses',
});
/**
* API resource information for CSIDriver.
*/
public static readonly CSI_DRIVERS = new ApiResource({
apiGroup: 'storage.k8s.io',
resourceType: 'csidrivers',
});
/**
* API resource information for CSINode.
*/
public static readonly CSI_NODES = new ApiResource({
apiGroup: 'storage.k8s.io',
resourceType: 'csinodes',
});
/**
* API resource information for CSIStorageCapacity.
*/
public static readonly CSI_STORAGE_CAPACITIES = new ApiResource({
apiGroup: 'storage.k8s.io',
resourceType: 'csistoragecapacities',
});
/**
* API resource information for StorageClass.
*/
public static readonly STORAGE_CLASSES = new ApiResource({
apiGroup: 'storage.k8s.io',
resourceType: 'storageclasses',
});
/**
* API resource information for VolumeAttachment.
*/
public static readonly VOLUME_ATTACHMENTS = new ApiResource({
apiGroup: 'storage.k8s.io',
resourceType: 'volumeattachments',
});
/**
* API resource information for a custom resource type.
*/
public static custom(options: ApiResourceOptions): ApiResource {
return new ApiResource(options);
};
/**
* The group portion of the API version (e.g. `authorization.k8s.io`).
*/
public readonly apiGroup: string;
/**
* The name of the resource type as it appears in the relevant API endpoint.
* @example - "pods" or "pods/log"
* @see https://kubernetes.io/docs/reference/access-authn-authz/rbac/#referring-to-resources
*/
public readonly resourceType: string;
private constructor(options: ApiResourceOptions) {
this.apiGroup = options.apiGroup;
this.resourceType = options.resourceType;
}
public asApiResource(): IApiResource | undefined {
return this;
}
public asNonApiResource(): string | undefined {
return undefined;
}
}
/**
* Factory for creating non api resources.
*/
export class NonApiResource implements IApiEndpoint {
public static of(url: string): NonApiResource {
return new NonApiResource(url);
}
private constructor(private readonly nonResourceUrl: string) {};
public asApiResource(): IApiResource | undefined {
return undefined;
}
public asNonApiResource(): string | undefined {
return this.nonResourceUrl;
}
}