@serve.zone/interfaces 32.115.0 → 32.117.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/changelog.md +16 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/controlledtakeover.d.ts +125 -0
- package/dist_ts/data/controlledtakeover.js +217 -0
- package/dist_ts/data/corestorereplication.d.ts +13 -0
- package/dist_ts/data/corestorereplication.js +27 -4
- package/dist_ts/data/diskencryption.d.ts +100 -0
- package/dist_ts/data/diskencryption.js +176 -0
- package/dist_ts/data/gatewayarearows.d.ts +17 -7
- package/dist_ts/data/gatewayarearows.js +31 -14
- package/dist_ts/data/index.d.ts +3 -0
- package/dist_ts/data/index.js +4 -1
- package/dist_ts/data/locationlock.d.ts +98 -0
- package/dist_ts/data/locationlock.js +175 -0
- package/dist_ts/index.d.ts +2 -0
- package/dist_ts/index.js +3 -1
- package/dist_ts/requests/controlledtakeover.d.ts +78 -0
- package/dist_ts/requests/controlledtakeover.js +45 -0
- package/dist_ts/requests/diskencryption.d.ts +73 -0
- package/dist_ts/requests/diskencryption.js +2 -0
- package/dist_ts/requests/index.d.ts +3 -0
- package/dist_ts/requests/index.js +4 -1
- package/dist_ts/requests/locationlock.d.ts +104 -0
- package/dist_ts/requests/locationlock.js +2 -0
- package/package.json +25 -1
- package/readme.md +34 -3
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/controlledtakeover.ts +338 -0
- package/ts/data/corestorereplication.ts +37 -3
- package/ts/data/diskencryption.ts +275 -0
- package/ts/data/gatewayarearows.ts +49 -18
- package/ts/data/index.ts +3 -0
- package/ts/data/locationlock.ts +280 -0
- package/ts/index.ts +2 -0
- package/ts/requests/controlledtakeover.ts +167 -0
- package/ts/requests/diskencryption.ts +81 -0
- package/ts/requests/index.ts +3 -0
- package/ts/requests/locationlock.ts +119 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type * as plugins from '../plugins.js';
|
|
2
|
+
import type { TSha256Digest } from '../data/immutableimage.js';
|
|
3
|
+
import type { ILocationDestroyOperation, ILocationDestroyPlan, ILocationLockOperation, ILocationLockPlan, TLocationLockMode } from '../data/locationlock.js';
|
|
4
|
+
import type { IIdentityCredential } from '../data/user.js';
|
|
5
|
+
interface ILocationAdministratorRequest {
|
|
6
|
+
identity: IIdentityCredential;
|
|
7
|
+
}
|
|
8
|
+
interface ILocationTargetRequest extends ILocationAdministratorRequest {
|
|
9
|
+
locationId: string;
|
|
10
|
+
}
|
|
11
|
+
interface ILocationOperationRequest extends ILocationAdministratorRequest {
|
|
12
|
+
operationId: string;
|
|
13
|
+
}
|
|
14
|
+
interface ILocationOperationMutation extends ILocationOperationRequest {
|
|
15
|
+
expectedRevision: number;
|
|
16
|
+
}
|
|
17
|
+
export interface IReq_Admin_Cloudly_PlanLocationLock extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_PlanLocationLock> {
|
|
18
|
+
method: 'planLocationLock';
|
|
19
|
+
request: ILocationTargetRequest & {
|
|
20
|
+
mode: TLocationLockMode;
|
|
21
|
+
};
|
|
22
|
+
response: {
|
|
23
|
+
plan: ILocationLockPlan;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Fresh passkey required. Cloud access may carry Lock. An answer acknowledges the durable record. */
|
|
27
|
+
export interface IReq_Admin_Cloudly_StartLocationLock extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_StartLocationLock> {
|
|
28
|
+
method: 'startLocationLock';
|
|
29
|
+
request: IReq_Admin_Cloudly_PlanLocationLock['request'] & {
|
|
30
|
+
membershipDigest: TSha256Digest;
|
|
31
|
+
};
|
|
32
|
+
response: {
|
|
33
|
+
operation: ILocationLockOperation;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface IReq_Admin_Cloudly_GetLocationLock extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_GetLocationLock> {
|
|
37
|
+
method: 'getLocationLock';
|
|
38
|
+
request: ILocationOperationRequest;
|
|
39
|
+
response: {
|
|
40
|
+
operation: ILocationLockOperation;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface IReq_Admin_Cloudly_ListLocationLocks extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_ListLocationLocks> {
|
|
44
|
+
method: 'listLocationLocks';
|
|
45
|
+
request: ILocationAdministratorRequest & {
|
|
46
|
+
after: string | null;
|
|
47
|
+
};
|
|
48
|
+
response: {
|
|
49
|
+
/** Up to locationLockBounds.operationsPerPage entries, strictly ascending by operation ID. */
|
|
50
|
+
operations: ILocationLockOperation[];
|
|
51
|
+
/** Last returned ID if another page exists, otherwise null. */
|
|
52
|
+
nextAfter: string | null;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Fresh passkey required. Cloudly compares the observed lock revision before unlocking. */
|
|
56
|
+
export interface IReq_Admin_Cloudly_UnlockLocation extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_UnlockLocation> {
|
|
57
|
+
method: 'unlockLocation';
|
|
58
|
+
request: ILocationOperationMutation;
|
|
59
|
+
response: {
|
|
60
|
+
operation: ILocationLockOperation;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** Destroy administration is direct-only. Cloudly refuses cloud-access sessions. */
|
|
64
|
+
export interface IReq_Admin_Cloudly_PlanLocationDestroy extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_PlanLocationDestroy> {
|
|
65
|
+
method: 'planLocationDestroy';
|
|
66
|
+
request: ILocationTargetRequest;
|
|
67
|
+
response: {
|
|
68
|
+
plan: ILocationDestroyPlan;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** A fresh human administrator records a pending request over direct access. */
|
|
72
|
+
export interface IReq_Admin_Cloudly_InitiateLocationDestroy extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_InitiateLocationDestroy> {
|
|
73
|
+
method: 'initiateLocationDestroy';
|
|
74
|
+
request: ILocationTargetRequest & {
|
|
75
|
+
membershipDigest: TSha256Digest;
|
|
76
|
+
};
|
|
77
|
+
response: {
|
|
78
|
+
operation: ILocationDestroyOperation;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** A different human administrator with a fresh passkey confirms the exact pending revision over direct access. */
|
|
82
|
+
export interface IReq_Admin_Cloudly_ConfirmLocationDestroy extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_ConfirmLocationDestroy> {
|
|
83
|
+
method: 'confirmLocationDestroy';
|
|
84
|
+
request: ILocationOperationMutation;
|
|
85
|
+
response: {
|
|
86
|
+
operation: ILocationDestroyOperation;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Only a still-pending Destroy can be cancelled. Direct access and fresh passkey required. */
|
|
90
|
+
export interface IReq_Admin_Cloudly_CancelLocationDestroy extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_CancelLocationDestroy> {
|
|
91
|
+
method: 'cancelLocationDestroy';
|
|
92
|
+
request: ILocationOperationMutation;
|
|
93
|
+
response: {
|
|
94
|
+
operation: ILocationDestroyOperation;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export interface IReq_Admin_Cloudly_GetLocationDestroy extends plugins.typedrequestInterfaces.implementsTR<plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_GetLocationDestroy> {
|
|
98
|
+
method: 'getLocationDestroy';
|
|
99
|
+
request: ILocationOperationRequest;
|
|
100
|
+
response: {
|
|
101
|
+
operation: ILocationDestroyOperation;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serve.zone/interfaces",
|
|
3
|
-
"version": "32.
|
|
3
|
+
"version": "32.117.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared TypeScript interfaces and TypedRequest contracts for the serve.zone ecosystem.",
|
|
6
6
|
"exports": {
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"types": "./dist_ts/data/backup/index.d.ts",
|
|
21
21
|
"default": "./dist_ts/data/backup/index.js"
|
|
22
22
|
},
|
|
23
|
+
"./data/controlledtakeover": {
|
|
24
|
+
"types": "./dist_ts/data/controlledtakeover.d.ts",
|
|
25
|
+
"default": "./dist_ts/data/controlledtakeover.js"
|
|
26
|
+
},
|
|
23
27
|
"./data/coremail": {
|
|
24
28
|
"types": "./dist_ts/data/coremail/index.d.ts",
|
|
25
29
|
"default": "./dist_ts/data/coremail/index.js"
|
|
@@ -36,10 +40,18 @@
|
|
|
36
40
|
"types": "./dist_ts/data/dcstorage.d.ts",
|
|
37
41
|
"default": "./dist_ts/data/dcstorage.js"
|
|
38
42
|
},
|
|
43
|
+
"./data/diskencryption": {
|
|
44
|
+
"types": "./dist_ts/data/diskencryption.d.ts",
|
|
45
|
+
"default": "./dist_ts/data/diskencryption.js"
|
|
46
|
+
},
|
|
39
47
|
"./data/gateway": {
|
|
40
48
|
"types": "./dist_ts/data/gateway.d.ts",
|
|
41
49
|
"default": "./dist_ts/data/gateway.js"
|
|
42
50
|
},
|
|
51
|
+
"./data/locationlock": {
|
|
52
|
+
"types": "./dist_ts/data/locationlock.d.ts",
|
|
53
|
+
"default": "./dist_ts/data/locationlock.js"
|
|
54
|
+
},
|
|
43
55
|
"./data/mail": {
|
|
44
56
|
"types": "./dist_ts/data/mail.d.ts",
|
|
45
57
|
"default": "./dist_ts/data/mail.js"
|
|
@@ -68,6 +80,10 @@
|
|
|
68
80
|
"types": "./dist_ts/requests/backup.d.ts",
|
|
69
81
|
"default": "./dist_ts/requests/backup.js"
|
|
70
82
|
},
|
|
83
|
+
"./requests/controlledtakeover": {
|
|
84
|
+
"types": "./dist_ts/requests/controlledtakeover.d.ts",
|
|
85
|
+
"default": "./dist_ts/requests/controlledtakeover.js"
|
|
86
|
+
},
|
|
71
87
|
"./requests/coremail": {
|
|
72
88
|
"types": "./dist_ts/requests/coremail.d.ts",
|
|
73
89
|
"default": "./dist_ts/requests/coremail.js"
|
|
@@ -88,6 +104,10 @@
|
|
|
88
104
|
"types": "./dist_ts/requests/dcstorage.d.ts",
|
|
89
105
|
"default": "./dist_ts/requests/dcstorage.js"
|
|
90
106
|
},
|
|
107
|
+
"./requests/diskencryption": {
|
|
108
|
+
"types": "./dist_ts/requests/diskencryption.d.ts",
|
|
109
|
+
"default": "./dist_ts/requests/diskencryption.js"
|
|
110
|
+
},
|
|
91
111
|
"./requests/gateway": {
|
|
92
112
|
"types": "./dist_ts/requests/gateway.d.ts",
|
|
93
113
|
"default": "./dist_ts/requests/gateway.js"
|
|
@@ -104,6 +124,10 @@
|
|
|
104
124
|
"types": "./dist_ts/requests/gatewayhealth.d.ts",
|
|
105
125
|
"default": "./dist_ts/requests/gatewayhealth.js"
|
|
106
126
|
},
|
|
127
|
+
"./requests/locationlock": {
|
|
128
|
+
"types": "./dist_ts/requests/locationlock.d.ts",
|
|
129
|
+
"default": "./dist_ts/requests/locationlock.js"
|
|
130
|
+
},
|
|
107
131
|
"./requests/mail": {
|
|
108
132
|
"types": "./dist_ts/requests/mail.d.ts",
|
|
109
133
|
"default": "./dist_ts/requests/mail.js"
|
package/readme.md
CHANGED
|
@@ -20,7 +20,7 @@ The root export exposes the six area namespaces:
|
|
|
20
20
|
import { appstore, data, platform, platformservice, protocol, requests } from '@serve.zone/interfaces';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
The `corestorereplication`, `dcstorage`, and `preparedimages` request namespaces are available under `requests` and as named imports from the root.
|
|
23
|
+
The `controlledtakeover`, `corestorereplication`, `dcstorage`, and `preparedimages` request namespaces are available under `requests` and as named imports from the root.
|
|
24
24
|
|
|
25
25
|
### Package entry points
|
|
26
26
|
|
|
@@ -30,7 +30,7 @@ and provides TypeScript declarations.
|
|
|
30
30
|
|
|
31
31
|
| Path | Purpose |
|
|
32
32
|
| --- | --- |
|
|
33
|
-
| `.` | Root barrel with the area namespaces and the `corestorereplication`, `dcstorage`, and `preparedimages` request namespaces. |
|
|
33
|
+
| `.` | Root barrel with the area namespaces and the `controlledtakeover`, `corestorereplication`, `dcstorage`, and `preparedimages` request namespaces. |
|
|
34
34
|
| `/appstore` | App Store catalog, manifest, service requirement, and upgrade contracts. |
|
|
35
35
|
| `/data` | Shared platform data shapes and validators. |
|
|
36
36
|
| `/requests` | TypedRequest contracts and request namespaces for the control plane. |
|
|
@@ -38,13 +38,16 @@ and provides TypeScript declarations.
|
|
|
38
38
|
| `/platformservice` | Legacy platform-service contracts. |
|
|
39
39
|
| `/protocol` | Session offers, peer compatibility, and protocol refusals. |
|
|
40
40
|
| `/data/backup`, `/requests/backup` | Backup and restore payloads, refusal helpers, and RPC types. |
|
|
41
|
+
| `/data/controlledtakeover`, `/requests/controlledtakeover` | Controlled takeover snapshots and administrator RPCs for nupst webhook metadata and one-time HTTP credential disclosure. |
|
|
41
42
|
| `/data/coremail`, `/requests/coremail`, `/requests/coremail-admin` | CoreMail data, validators, service RPC types, and administrator RPC types. |
|
|
42
43
|
| `/data/corestore`, `/requests/corestore` | Corestore database allocation references, inventory, and control-plane RPC contracts. |
|
|
43
|
-
| `/data/corestorereplication`, `/requests/corestorereplication` | Per-binding replication roles, lag, link grants, and administrator RPC types. |
|
|
44
|
+
| `/data/corestorereplication`, `/requests/corestorereplication` | Per-binding replication roles, lag, link grants with optional transport policy, and administrator RPC types. |
|
|
44
45
|
| `/data/dcstorage`, `/requests/dcstorage` | Storage-node enrollment, pinned volume, pool membership and telemetry contracts. |
|
|
46
|
+
| `/data/diskencryption`, `/requests/diskencryption` | TPM-bound machine identities, key release challenges and outcomes, unlock approvals, and offline recovery key metadata. |
|
|
45
47
|
| `/data/gateway`, `/requests/gateway`, `/requests/gatewayconnector` | Gateway client data and validators, client RPC types, and controller connector RPC types. |
|
|
46
48
|
| `/requests/gatewaycertificatestore` | Gateway certificate store inventory, import, private export, and delete contracts. |
|
|
47
49
|
| `/requests/gatewayhealth` | Capability-gated service health snapshots and Cloudly administrator RPC contracts. |
|
|
50
|
+
| `/data/locationlock`, `/requests/locationlock` | Location Lock and direct-only, two-administrator Destroy plans, operation snapshots, and administrator RPC types. |
|
|
48
51
|
| `/data/mail`, `/requests/mail` | Service mail data and mail RPC types. |
|
|
49
52
|
| `/data/preparedimages`, `/requests/preparedimages` | Pallet prepared-image lists, observations, and pull credential RPC types. |
|
|
50
53
|
| `/runtime` | Node-only cryptographic and runtime helpers. |
|
|
@@ -2511,6 +2514,29 @@ still `retiring`. Every refusal is one of `data.nodeRuntimeRetirementRefusals`
|
|
|
2511
2514
|
retirement of a node whose last accepted report is younger than
|
|
2512
2515
|
`clusterNodeObservationFreshnessMs`) — and takes nothing away.
|
|
2513
2516
|
|
|
2517
|
+
### Controlled Takeover and nupst
|
|
2518
|
+
|
|
2519
|
+
`startControlledTakeover` takes distinct source and target clusters, the shutdown time in
|
|
2520
|
+
Unix milliseconds, a safety margin in milliseconds and one idempotency key per operator action.
|
|
2521
|
+
Cloudly derives the locations and the service plan. The response reports the stored operation
|
|
2522
|
+
at admission. For a nupst trigger, Cloudly verifies the signed delivery and records its
|
|
2523
|
+
`webhook-id` and the shutdown action's `executeAt`. Both triggers use
|
|
2524
|
+
`deadlineAt = executeAt - safetyMarginMs`.
|
|
2525
|
+
|
|
2526
|
+
`getControlledTakeoverOperation` reads the stored status. `getControlledTakeoverOperations`
|
|
2527
|
+
reads up to eight operations in ascending ID order, starting at `after: null`. Pass the
|
|
2528
|
+
returned `nextAfter` to read the next page. Each operation contains up to 1,024 services in
|
|
2529
|
+
execution order with ingress services first. `snapshotControlledTakeoverOperation` checks
|
|
2530
|
+
the schedule, phases, timestamps and service entries. `abortControlledTakeover` passes the
|
|
2531
|
+
observed revision. Cloudly checks the revision and the irreversible commit fence together
|
|
2532
|
+
before recording an abort.
|
|
2533
|
+
|
|
2534
|
+
`configureNupstWebhookEndpoint` sets the endpoint's location, cluster, enabled state and
|
|
2535
|
+
margin. `rotateNupstWebhookEndpointSecret` compares the observed secret version, with
|
|
2536
|
+
`null` for an endpoint that has never had a secret. Both return `INupstWebhookEndpointConfig`
|
|
2537
|
+
with the credential represented by `secretConfigured` and `secretVersion` only. Sender-side
|
|
2538
|
+
secret provisioning occurs separately. All six methods require administrator authorization.
|
|
2539
|
+
|
|
2514
2540
|
### Corestore Per-Binding Replication
|
|
2515
2541
|
|
|
2516
2542
|
Cloudly grants a directed link for one workload database or object-storage binding. Both Corestores
|
|
@@ -5005,6 +5031,11 @@ area name: `data.IGatewayAreaContents[area]`, also `data.TGatewayAreaContent<are
|
|
|
5005
5031
|
slot, and abort clears the slot while retaining the active secret. Each is one edges-table write.
|
|
5006
5032
|
A rotation-capable row writes `stagedSecret: null` when idle. Row reads disclose only a keep
|
|
5007
5033
|
version for each sealed credential, and row digests include versions in place of values.
|
|
5034
|
+
To commit, set `secret: { kind: 'promoteStaged', version }` to the observed staged version and
|
|
5035
|
+
state `stagedSecret: null` in the same compare-and-swap row write. Resolution moves the stored
|
|
5036
|
+
value and its version to the active slot. A missing or mismatched staged version is refused.
|
|
5037
|
+
Compute the row digest from the resolved row. Send the promotion form only to a Cloudly
|
|
5038
|
+
version that supports it.
|
|
5008
5039
|
Before Cloudly sends any row carrying `stagedSecret`, check the connected gateway's
|
|
5009
5040
|
`getGatewayCapabilities` answer with
|
|
5010
5041
|
`data.supportsGatewayRemoteIngressStagedSecretRotation(answer.capabilities)`. Until the gateway
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { compareWireTokens } from '../private/canonicaljson.js';
|
|
2
|
+
import { validateControllerIdentifier, validateControllerStrictJson } from '../private/controllercontract.js';
|
|
3
|
+
import { readDataElements, readExactDataRecord } from '../private/dataproperties.js';
|
|
4
|
+
import { isBoundedInteger } from '../private/runtimepolicy.js';
|
|
5
|
+
import { validateServiceId } from './coremail.runtime.js';
|
|
6
|
+
import { isIdempotencyKey } from './idempotencykey.js';
|
|
7
|
+
|
|
8
|
+
export const controlledTakeoverPhases = Object.freeze([
|
|
9
|
+
'pending', 'promotingController', 'drainingServices', 'completed', 'failed', 'aborted',
|
|
10
|
+
] as const);
|
|
11
|
+
export type TControlledTakeoverPhase = typeof controlledTakeoverPhases[number];
|
|
12
|
+
|
|
13
|
+
export type TControlledTakeoverTrigger = 'operator' | 'nupst';
|
|
14
|
+
|
|
15
|
+
export const controlledTakeoverServicePhases = Object.freeze([
|
|
16
|
+
'pending', 'stopping', 'syncing', 'activating', 'completed', 'skipped', 'failed',
|
|
17
|
+
] as const);
|
|
18
|
+
export type TControlledTakeoverServicePhase = typeof controlledTakeoverServicePhases[number];
|
|
19
|
+
|
|
20
|
+
export const controlledTakeoverBounds = Object.freeze({
|
|
21
|
+
maximumServices: 1024,
|
|
22
|
+
maximumServiceNameBytes: 256,
|
|
23
|
+
maximumRefusalCodeLength: 64,
|
|
24
|
+
// Each operation carries the full service plan. Keep full pages below the 16 MiB text frame.
|
|
25
|
+
operationsPerPage: 8,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export interface IControlledTakeoverServiceEntry {
|
|
29
|
+
serviceId: string;
|
|
30
|
+
serviceName: string;
|
|
31
|
+
isIngress: boolean;
|
|
32
|
+
priority: number;
|
|
33
|
+
phase: TControlledTakeoverServicePhase;
|
|
34
|
+
/** Unix milliseconds. Null until the service starts moving. */
|
|
35
|
+
startedAt: number | null;
|
|
36
|
+
/** Unix milliseconds. Null until the service reaches a terminal phase. */
|
|
37
|
+
completedAt: number | null;
|
|
38
|
+
/** A machine-readable code for a skipped or failed service. */
|
|
39
|
+
refusalCode: string | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Durable observation of one forward-only move. Timestamps are Unix milliseconds. */
|
|
43
|
+
export interface IControlledTakeoverOperation {
|
|
44
|
+
id: string;
|
|
45
|
+
sourceClusterId: string;
|
|
46
|
+
targetClusterId: string;
|
|
47
|
+
sourceLocationId: string;
|
|
48
|
+
targetLocationId: string;
|
|
49
|
+
trigger: TControlledTakeoverTrigger;
|
|
50
|
+
/** The authenticated nupst webhook-id. An operator start has no delivery ID. */
|
|
51
|
+
nupstDeliveryId: string | null;
|
|
52
|
+
executeAt: number;
|
|
53
|
+
deadlineAt: number;
|
|
54
|
+
safetyMarginMs: number;
|
|
55
|
+
phase: TControlledTakeoverPhase;
|
|
56
|
+
revision: number;
|
|
57
|
+
createdAt: number;
|
|
58
|
+
updatedAt: number;
|
|
59
|
+
completedAt: number | null;
|
|
60
|
+
/** In the controller's execution order, with ingress services first. */
|
|
61
|
+
services: IControlledTakeoverServiceEntry[];
|
|
62
|
+
/** A machine-readable code for a failed operation. */
|
|
63
|
+
failureReason: string | null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Webhook endpoint metadata. Cloudly owns secret presence, version and rotation. */
|
|
67
|
+
export interface INupstWebhookEndpointConfig {
|
|
68
|
+
id: string;
|
|
69
|
+
locationId: string;
|
|
70
|
+
clusterId: string;
|
|
71
|
+
enabled: boolean;
|
|
72
|
+
secretConfigured: boolean;
|
|
73
|
+
secretVersion: number | null;
|
|
74
|
+
safetyMarginMs: number;
|
|
75
|
+
updatedAt: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface IControlledTakeoverStartInput {
|
|
79
|
+
sourceClusterId: string;
|
|
80
|
+
targetClusterId: string;
|
|
81
|
+
/** Operator-supplied shutdown time in Unix milliseconds. */
|
|
82
|
+
executeAt: number;
|
|
83
|
+
safetyMarginMs: number;
|
|
84
|
+
/** Stable across retries of a single operator start. */
|
|
85
|
+
idempotencyKey: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface IControlledTakeoverGetInput {
|
|
89
|
+
operationId: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface IControlledTakeoverListInput {
|
|
93
|
+
/** Exclusive operation ID cursor. Null requests the first page. */
|
|
94
|
+
after: string | null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface IControlledTakeoverAbortInput extends IControlledTakeoverGetInput {
|
|
98
|
+
expectedRevision: number;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface INupstWebhookEndpointConfigureInput {
|
|
102
|
+
id: string;
|
|
103
|
+
locationId: string;
|
|
104
|
+
clusterId: string;
|
|
105
|
+
enabled: boolean;
|
|
106
|
+
safetyMarginMs: number;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface INupstWebhookEndpointRotateInput {
|
|
110
|
+
id: string;
|
|
111
|
+
/** Null requires that a secret has yet to be provisioned. */
|
|
112
|
+
expectedSecretVersion: number | null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface IControlledTakeoverOperationResponse {
|
|
116
|
+
operation: IControlledTakeoverOperation;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface IControlledTakeoverListResponse {
|
|
120
|
+
/** Strictly ascending by operation ID. */
|
|
121
|
+
operations: IControlledTakeoverOperation[];
|
|
122
|
+
/** The last returned ID if another page exists. Null at the end. */
|
|
123
|
+
nextAfter: string | null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const controlledTakeoverAbortRefusals = Object.freeze([
|
|
127
|
+
'operation-not-found', 'revision-stale', 'operation-not-abortable',
|
|
128
|
+
] as const);
|
|
129
|
+
export type TControlledTakeoverAbortRefusal = typeof controlledTakeoverAbortRefusals[number];
|
|
130
|
+
|
|
131
|
+
export type TControlledTakeoverAbortResponse =
|
|
132
|
+
| { ok: true; operation: IControlledTakeoverOperation }
|
|
133
|
+
| { ok: false; code: TControlledTakeoverAbortRefusal };
|
|
134
|
+
|
|
135
|
+
export interface INupstWebhookEndpointResponse {
|
|
136
|
+
endpoint: INupstWebhookEndpointConfig;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const invalid = (): never => { throw new Error('Controlled takeover contract rejected.'); };
|
|
140
|
+
const exact = (value: unknown, keys: readonly string[]) => readExactDataRecord(value, keys) ?? invalid();
|
|
141
|
+
const identifier = (value: unknown): string =>
|
|
142
|
+
typeof value === 'string' && validateControllerIdentifier(value, 'identifier').length === 0 ? value : invalid();
|
|
143
|
+
const integer = (value: unknown, minimum: number): number =>
|
|
144
|
+
isBoundedInteger(value, minimum, Number.MAX_SAFE_INTEGER) ? value : invalid();
|
|
145
|
+
const nullablePositive = (value: unknown): number | null => value === null ? null : integer(value, 1);
|
|
146
|
+
const boolean = (value: unknown): boolean => typeof value === 'boolean' ? value : invalid();
|
|
147
|
+
const choice = <T extends string>(value: unknown, choices: readonly T[]): T =>
|
|
148
|
+
choices.find((candidate) => candidate === value) ?? invalid();
|
|
149
|
+
|
|
150
|
+
const encoder = new TextEncoder();
|
|
151
|
+
const serviceNameOf = (value: unknown): string => {
|
|
152
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > controlledTakeoverBounds.maximumServiceNameBytes
|
|
153
|
+
|| /[\u0000-\u001f\u007f-\u009f]/u.test(value) || encoder.encode(value).byteLength > controlledTakeoverBounds.maximumServiceNameBytes
|
|
154
|
+
|| validateControllerStrictJson(value, 'serviceName').length !== 0) return invalid();
|
|
155
|
+
return value;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const reasonCodeOf = (value: unknown): string | null => {
|
|
159
|
+
if (value === null) return null;
|
|
160
|
+
if (typeof value !== 'string' || value.length > controlledTakeoverBounds.maximumRefusalCodeLength
|
|
161
|
+
|| !/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(value)) return invalid();
|
|
162
|
+
return value;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/** Capture one service observation with phase-dependent timestamps and refusal code. */
|
|
166
|
+
export const snapshotControlledTakeoverServiceEntry = (value: unknown): IControlledTakeoverServiceEntry => {
|
|
167
|
+
const entry = exact(value, ['serviceId', 'serviceName', 'isIngress', 'priority', 'phase', 'startedAt', 'completedAt', 'refusalCode']);
|
|
168
|
+
const { serviceId } = entry;
|
|
169
|
+
if (typeof serviceId !== 'string' || validateServiceId(serviceId).length !== 0) return invalid();
|
|
170
|
+
|
|
171
|
+
const phase = choice(entry.phase, controlledTakeoverServicePhases);
|
|
172
|
+
const startedAt = nullablePositive(entry.startedAt);
|
|
173
|
+
const completedAt = nullablePositive(entry.completedAt);
|
|
174
|
+
const refusalCode = reasonCodeOf(entry.refusalCode);
|
|
175
|
+
const terminal = phase === 'completed' || phase === 'failed' || phase === 'skipped';
|
|
176
|
+
const refused = phase === 'failed' || phase === 'skipped';
|
|
177
|
+
|
|
178
|
+
if (terminal !== (completedAt !== null) || refused !== (refusalCode !== null)) return invalid();
|
|
179
|
+
if (phase === 'pending' || phase === 'skipped') {
|
|
180
|
+
if (startedAt !== null) return invalid();
|
|
181
|
+
} else if (phase !== 'failed' && startedAt === null) return invalid();
|
|
182
|
+
if (startedAt !== null && completedAt !== null && startedAt > completedAt) return invalid();
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
serviceId, serviceName: serviceNameOf(entry.serviceName), isIngress: boolean(entry.isIngress),
|
|
186
|
+
priority: integer(entry.priority, Number.MIN_SAFE_INTEGER), phase, startedAt, completedAt, refusalCode,
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const scheduleOf = (record: Record<string, unknown>) => {
|
|
191
|
+
const executeAt = integer(record.executeAt, 1);
|
|
192
|
+
const safetyMarginMs = integer(record.safetyMarginMs, 0);
|
|
193
|
+
if (safetyMarginMs >= executeAt) return invalid();
|
|
194
|
+
return { executeAt, safetyMarginMs };
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const clustersOf = (record: Record<string, unknown>) => {
|
|
198
|
+
const sourceClusterId = identifier(record.sourceClusterId);
|
|
199
|
+
const targetClusterId = identifier(record.targetClusterId);
|
|
200
|
+
if (sourceClusterId === targetClusterId) return invalid();
|
|
201
|
+
return { sourceClusterId, targetClusterId };
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/** Capture a value-free operation snapshot. Fencing and transition admission belong to Cloudly. */
|
|
205
|
+
export const snapshotControlledTakeoverOperation = (value: unknown): IControlledTakeoverOperation => {
|
|
206
|
+
const operation = exact(value, [
|
|
207
|
+
'id', 'sourceClusterId', 'targetClusterId', 'sourceLocationId', 'targetLocationId', 'trigger',
|
|
208
|
+
'nupstDeliveryId', 'executeAt', 'deadlineAt', 'safetyMarginMs', 'phase', 'revision', 'createdAt',
|
|
209
|
+
'updatedAt', 'completedAt', 'services', 'failureReason',
|
|
210
|
+
]);
|
|
211
|
+
const id = identifier(operation.id);
|
|
212
|
+
const clusters = clustersOf(operation);
|
|
213
|
+
const sourceLocationId = identifier(operation.sourceLocationId);
|
|
214
|
+
const targetLocationId = identifier(operation.targetLocationId);
|
|
215
|
+
if (sourceLocationId === targetLocationId) return invalid();
|
|
216
|
+
|
|
217
|
+
const trigger = choice(operation.trigger, ['operator', 'nupst'] as const);
|
|
218
|
+
const nupstDeliveryId = operation.nupstDeliveryId === null ? null : identifier(operation.nupstDeliveryId);
|
|
219
|
+
if ((trigger === 'nupst') !== (nupstDeliveryId !== null)) return invalid();
|
|
220
|
+
|
|
221
|
+
const schedule = scheduleOf(operation);
|
|
222
|
+
const deadlineAt = integer(operation.deadlineAt, 1);
|
|
223
|
+
if (deadlineAt !== schedule.executeAt - schedule.safetyMarginMs) return invalid();
|
|
224
|
+
|
|
225
|
+
const phase = choice(operation.phase, controlledTakeoverPhases);
|
|
226
|
+
const revision = integer(operation.revision, 1);
|
|
227
|
+
const createdAt = integer(operation.createdAt, 1);
|
|
228
|
+
const updatedAt = integer(operation.updatedAt, createdAt);
|
|
229
|
+
const completedAt = nullablePositive(operation.completedAt);
|
|
230
|
+
const failureReason = reasonCodeOf(operation.failureReason);
|
|
231
|
+
const terminal = phase === 'completed' || phase === 'failed' || phase === 'aborted';
|
|
232
|
+
if (terminal !== (completedAt !== null) || (phase === 'failed') !== (failureReason !== null)) return invalid();
|
|
233
|
+
if (completedAt !== null && (completedAt < createdAt || completedAt > updatedAt)) return invalid();
|
|
234
|
+
|
|
235
|
+
const entries = readDataElements(operation.services, controlledTakeoverBounds.maximumServices) ?? invalid();
|
|
236
|
+
const services = entries.map(snapshotControlledTakeoverServiceEntry);
|
|
237
|
+
const serviceIds = new Set<string>();
|
|
238
|
+
let sawNonIngress = false;
|
|
239
|
+
for (const service of services) {
|
|
240
|
+
if (serviceIds.has(service.serviceId) || (service.isIngress && sawNonIngress)) return invalid();
|
|
241
|
+
serviceIds.add(service.serviceId);
|
|
242
|
+
sawNonIngress ||= !service.isIngress;
|
|
243
|
+
for (const time of [service.startedAt, service.completedAt]) {
|
|
244
|
+
if (time !== null && (time < createdAt || time > (completedAt ?? updatedAt))) return invalid();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
id, ...clusters, sourceLocationId, targetLocationId, trigger, nupstDeliveryId, ...schedule,
|
|
250
|
+
deadlineAt, phase, revision, createdAt, updatedAt, completedAt, services, failureReason,
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
export const snapshotNupstWebhookEndpointConfig = (value: unknown): INupstWebhookEndpointConfig => {
|
|
255
|
+
const endpoint = exact(value, [
|
|
256
|
+
'id', 'locationId', 'clusterId', 'enabled', 'secretConfigured', 'secretVersion', 'safetyMarginMs', 'updatedAt',
|
|
257
|
+
]);
|
|
258
|
+
const secretConfigured = boolean(endpoint.secretConfigured);
|
|
259
|
+
const secretVersion = nullablePositive(endpoint.secretVersion);
|
|
260
|
+
if (secretConfigured !== (secretVersion !== null)) return invalid();
|
|
261
|
+
return {
|
|
262
|
+
id: identifier(endpoint.id), locationId: identifier(endpoint.locationId), clusterId: identifier(endpoint.clusterId),
|
|
263
|
+
enabled: boolean(endpoint.enabled), secretConfigured, secretVersion,
|
|
264
|
+
safetyMarginMs: integer(endpoint.safetyMarginMs, 0), updatedAt: integer(endpoint.updatedAt, 1),
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
export const snapshotControlledTakeoverStartInput = (value: unknown): IControlledTakeoverStartInput => {
|
|
269
|
+
const input = exact(value, ['sourceClusterId', 'targetClusterId', 'executeAt', 'safetyMarginMs', 'idempotencyKey']);
|
|
270
|
+
const { idempotencyKey } = input;
|
|
271
|
+
if (!isIdempotencyKey(idempotencyKey)) return invalid();
|
|
272
|
+
return { ...clustersOf(input), ...scheduleOf(input), idempotencyKey };
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export const snapshotControlledTakeoverGetInput = (value: unknown): IControlledTakeoverGetInput => {
|
|
276
|
+
const input = exact(value, ['operationId']);
|
|
277
|
+
return { operationId: identifier(input.operationId) };
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
export const snapshotControlledTakeoverListInput = (value: unknown): IControlledTakeoverListInput => {
|
|
281
|
+
const input = exact(value, ['after']);
|
|
282
|
+
return { after: input.after === null ? null : identifier(input.after) };
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
export const snapshotControlledTakeoverAbortInput = (value: unknown): IControlledTakeoverAbortInput => {
|
|
286
|
+
const input = exact(value, ['operationId', 'expectedRevision']);
|
|
287
|
+
return { operationId: identifier(input.operationId), expectedRevision: integer(input.expectedRevision, 1) };
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
export const snapshotNupstWebhookEndpointConfigureInput = (value: unknown): INupstWebhookEndpointConfigureInput => {
|
|
291
|
+
const input = exact(value, ['id', 'locationId', 'clusterId', 'enabled', 'safetyMarginMs']);
|
|
292
|
+
return {
|
|
293
|
+
id: identifier(input.id), locationId: identifier(input.locationId), clusterId: identifier(input.clusterId),
|
|
294
|
+
enabled: boolean(input.enabled), safetyMarginMs: integer(input.safetyMarginMs, 0),
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
export const snapshotNupstWebhookEndpointRotateInput = (value: unknown): INupstWebhookEndpointRotateInput => {
|
|
299
|
+
const input = exact(value, ['id', 'expectedSecretVersion']);
|
|
300
|
+
return { id: identifier(input.id), expectedSecretVersion: nullablePositive(input.expectedSecretVersion) };
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
export const snapshotControlledTakeoverOperationResponse = (value: unknown): IControlledTakeoverOperationResponse => ({
|
|
304
|
+
operation: snapshotControlledTakeoverOperation(exact(value, ['operation']).operation),
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
export const snapshotControlledTakeoverListResponse = (
|
|
308
|
+
value: unknown, request: IControlledTakeoverListInput,
|
|
309
|
+
): IControlledTakeoverListResponse => {
|
|
310
|
+
const response = exact(value, ['operations', 'nextAfter']);
|
|
311
|
+
const entries = readDataElements(response.operations, controlledTakeoverBounds.operationsPerPage) ?? invalid();
|
|
312
|
+
const operations = entries.map(snapshotControlledTakeoverOperation);
|
|
313
|
+
let lastId = snapshotControlledTakeoverListInput(request).after;
|
|
314
|
+
for (const operation of operations) {
|
|
315
|
+
if (lastId !== null && compareWireTokens(lastId, operation.id) >= 0) return invalid();
|
|
316
|
+
lastId = operation.id;
|
|
317
|
+
}
|
|
318
|
+
const nextAfter = response.nextAfter === null ? null : identifier(response.nextAfter);
|
|
319
|
+
if (nextAfter !== null && (operations.length !== controlledTakeoverBounds.operationsPerPage
|
|
320
|
+
|| nextAfter !== lastId)) return invalid();
|
|
321
|
+
return { operations, nextAfter };
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
export const snapshotControlledTakeoverAbortResponse = (value: unknown): TControlledTakeoverAbortResponse => {
|
|
325
|
+
const success = readExactDataRecord(value, ['ok', 'operation']);
|
|
326
|
+
if (success?.ok === true) {
|
|
327
|
+
const operation = snapshotControlledTakeoverOperation(success.operation);
|
|
328
|
+
if (operation.phase !== 'aborted') return invalid();
|
|
329
|
+
return { ok: true, operation };
|
|
330
|
+
}
|
|
331
|
+
const refusal = exact(value, ['ok', 'code']);
|
|
332
|
+
if (refusal.ok !== false) return invalid();
|
|
333
|
+
return { ok: false, code: choice(refusal.code, controlledTakeoverAbortRefusals) };
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
export const snapshotNupstWebhookEndpointResponse = (value: unknown): INupstWebhookEndpointResponse => ({
|
|
337
|
+
endpoint: snapshotNupstWebhookEndpointConfig(exact(value, ['endpoint']).endpoint),
|
|
338
|
+
});
|