@homeflare/distilled-proxmox 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/LICENSE +201 -0
- package/README.md +87 -0
- package/dist/credentials.d.ts +41 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +67 -0
- package/dist/credentials.js.map +1 -0
- package/dist/errors.d.ts +128 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +91 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +18 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +167 -0
- package/dist/protocol.js.map +1 -0
- package/dist/protocol.test.d.ts +2 -0
- package/dist/protocol.test.d.ts.map +1 -0
- package/dist/protocol.test.js +64 -0
- package/dist/protocol.test.js.map +1 -0
- package/dist/retry.d.ts +50 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +43 -0
- package/dist/retry.js.map +1 -0
- package/dist/services/access.d.ts +975 -0
- package/dist/services/access.d.ts.map +1 -0
- package/dist/services/access.js +1208 -0
- package/dist/services/access.js.map +1 -0
- package/dist/services/cluster.d.ts +5940 -0
- package/dist/services/cluster.d.ts.map +1 -0
- package/dist/services/cluster.js +7405 -0
- package/dist/services/cluster.js.map +1 -0
- package/dist/services/index.d.ts +7 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +8 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/nodes.d.ts +7887 -0
- package/dist/services/nodes.d.ts.map +1 -0
- package/dist/services/nodes.js +10253 -0
- package/dist/services/nodes.js.map +1 -0
- package/dist/services/pools.d.ts +133 -0
- package/dist/services/pools.d.ts.map +1 -0
- package/dist/services/pools.js +183 -0
- package/dist/services/pools.js.map +1 -0
- package/dist/services/storage.d.ts +317 -0
- package/dist/services/storage.d.ts.map +1 -0
- package/dist/services/storage.js +239 -0
- package/dist/services/storage.js.map +1 -0
- package/dist/services/version.d.ts +20 -0
- package/dist/services/version.d.ts.map +1 -0
- package/dist/services/version.js +27 -0
- package/dist/services/version.js.map +1 -0
- package/dist/task.d.ts +51 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/task.js +60 -0
- package/dist/task.js.map +1 -0
- package/dist/traits.d.ts +12 -0
- package/dist/traits.d.ts.map +1 -0
- package/dist/traits.js +14 -0
- package/dist/traits.js.map +1 -0
- package/package.json +81 -0
- package/src/credentials.ts +101 -0
- package/src/errors.ts +152 -0
- package/src/index.ts +33 -0
- package/src/protocol.test.ts +101 -0
- package/src/protocol.ts +204 -0
- package/src/retry.ts +74 -0
- package/src/services/access.ts +2722 -0
- package/src/services/cluster.ts +18550 -0
- package/src/services/index.ts +7 -0
- package/src/services/nodes.ts +25537 -0
- package/src/services/pools.ts +397 -0
- package/src/services/storage.ts +711 -0
- package/src/services/version.ts +54 -0
- package/src/task.ts +87 -0
- package/src/traits.ts +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @homeflare/distilled-proxmox
|
|
2
|
+
|
|
3
|
+
This package is **not a HomeFlare SDK**. It is an unmodified copy of
|
|
4
|
+
`@distilled.cloud/proxmox`, generated by the [distilled](https://github.com/alchemy-run/distilled)
|
|
5
|
+
pipeline from Proxmox VE's own `apidata.js` (the api-viewer's schema — PVE
|
|
6
|
+
publishes no OpenAPI document, so this is a hand-written converter over the
|
|
7
|
+
vendor's own tree, not the shared OpenAPI dialect every other distilled
|
|
8
|
+
package uses), pinned to the vendor's GitHub mirror commit matching this
|
|
9
|
+
estate's `pve-manager` 9.2.11, published here under its own name only
|
|
10
|
+
because `@distilled.cloud/proxmox` does not exist on npm yet — the kit
|
|
11
|
+
builds it in a local clone of `alchemy-run/distilled` but, per house policy,
|
|
12
|
+
never pushes to that upstream. See
|
|
13
|
+
[`../alchemy/docs/distilled-interim.md`](../alchemy/docs/distilled-interim.md)
|
|
14
|
+
for the full route every distilled-sourced vendor package follows, and why
|
|
15
|
+
this one exists at all.
|
|
16
|
+
|
|
17
|
+
⛔ **Do not hand-edit anything under `src/`.** The whole point of the route
|
|
18
|
+
above is that this directory is _copied_, not written — a fix belongs in the
|
|
19
|
+
distilled clone's `packages/proxmox/`, regenerated, then copied back here.
|
|
20
|
+
|
|
21
|
+
⚠️ **License.** Apache-2.0, not the kit's usual MIT — this content is a
|
|
22
|
+
redistribution of `alchemy-run/distilled`'s own Apache-2.0-licensed output,
|
|
23
|
+
and relicensing a copy would misstate what it is. See `LICENSE`.
|
|
24
|
+
|
|
25
|
+
## What's in it
|
|
26
|
+
|
|
27
|
+
6 service modules, one per PVE top-level path segment — `access`,
|
|
28
|
+
`cluster`, `nodes`, `pools`, `storage`, `version` — an Effect-typed
|
|
29
|
+
operation per PVE REST endpoint (680 total, 0 skipped), with `catchTag`-able
|
|
30
|
+
errors: the shared HTTP status classes, PVE's global
|
|
31
|
+
`ParameterVerificationFailed` (the `{"errors": {field: message}}` envelope
|
|
32
|
+
every failed write can carry) and non-retryable `BadRequest` fallback, and
|
|
33
|
+
`ClusterNodeUnreachable` (PVE's non-standard 595 for a cluster-forwarded
|
|
34
|
+
request that couldn't reach its target node) on the task-management
|
|
35
|
+
operations the vendor schema itself marks `proxyto: "node"`.
|
|
36
|
+
|
|
37
|
+
Also ships `awaitTask` (`./Task`), because a PVE POST/PUT/DELETE that
|
|
38
|
+
queues a long-running action answers 200 with a bare task id the moment it
|
|
39
|
+
is QUEUED, not once it finishes — `awaitTask` polls the generated
|
|
40
|
+
`getNodeTaskStatus` operation until an `exitstatus` appears, and fails
|
|
41
|
+
unless it is EXACTLY `"OK"` (PVE also answers `"OK (warnings)"`, which is
|
|
42
|
+
not success).
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import * as Proxmox from '@distilled.cloud/proxmox'; // aliased onto this package — see docs/distilled-interim.md
|
|
46
|
+
import * as Effect from 'effect/Effect';
|
|
47
|
+
|
|
48
|
+
const program = Proxmox.Services.version.getVersion({}).pipe(
|
|
49
|
+
Effect.provide(Proxmox.ProxmoxProtocol),
|
|
50
|
+
Effect.provide(
|
|
51
|
+
Proxmox.credentials({
|
|
52
|
+
tokenId: 'root@pam!terraform',
|
|
53
|
+
secret: '...',
|
|
54
|
+
baseUrl: 'https://pve1.example.com:8006',
|
|
55
|
+
}),
|
|
56
|
+
),
|
|
57
|
+
);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Kit code never imports `@homeflare/distilled-proxmox` directly — always
|
|
61
|
+
`@distilled.cloud/proxmox`, aliased in the consuming package's `package.json`
|
|
62
|
+
(`"@distilled.cloud/proxmox": "npm:@homeflare/distilled-proxmox@<version>"`),
|
|
63
|
+
so the eventual cutover to the real published package is a one-line alias
|
|
64
|
+
swap with no import changes anywhere in the kit.
|
|
65
|
+
|
|
66
|
+
## Updating it
|
|
67
|
+
|
|
68
|
+
From the distilled clone's `homeflare/proxmox` worktree:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
DISTILLED_SPECS_LOCAL=1 pnpm --filter @distilled.cloud/proxmox run convert
|
|
72
|
+
DISTILLED_SPECS_LOCAL=1 pnpm --filter @distilled.cloud/proxmox run generate
|
|
73
|
+
pnpm --filter @distilled.cloud/proxmox run typecheck
|
|
74
|
+
pnpm format && pnpm specs:check
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Then copy `src/` here verbatim, bump this package's own `version` (a patch
|
|
78
|
+
release — the generated content changed, not this package's own shape), add
|
|
79
|
+
a changeset, and let the kit's normal release flow publish it.
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
Apache-2.0 (see `LICENSE`) — not the kit's usual MIT. `src/` is an
|
|
84
|
+
unmodified copy of `@distilled.cloud/proxmox`'s own output from
|
|
85
|
+
`alchemy-run/distilled`, which is itself Apache-2.0; this package's own
|
|
86
|
+
files (`package.json`, `tsconfig.json`, `scripts/smoke.ts`, this README)
|
|
87
|
+
are offered under the same terms.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Redacted from "effect/Redacted";
|
|
5
|
+
/** PVE's own API root, relative to the node origin. Always port 8006, always `/api2/json`. */
|
|
6
|
+
export declare const API_PATH = "/api2/json";
|
|
7
|
+
/**
|
|
8
|
+
* Normalize a node origin (or an already-complete API root) into the API
|
|
9
|
+
* base URL: trailing slashes dropped, {@link API_PATH} appended exactly
|
|
10
|
+
* once. Does NOT default the port — `https://pve.example.com:8006` (or a
|
|
11
|
+
* bare host, which the caller must have already put a scheme+port on) is
|
|
12
|
+
* expected, matching how the kit's own `PveTarget` is built per node/vip.
|
|
13
|
+
*
|
|
14
|
+
* ⛔ THE TRIM IS A LOOP, NEVER `/\/+$/`. That regex backtracks
|
|
15
|
+
* polynomially on a long run of trailing `/` (CodeQL `js/polynomial-
|
|
16
|
+
* redos`) — caller input, so a real DoS surface, not a hypothetical one.
|
|
17
|
+
* Measured the same fix already landed in `@homeflare/distilled-netbox`'s
|
|
18
|
+
* identical trim (`taslabs-net/homeflare-kit` PR 184): 0 mismatches
|
|
19
|
+
* against the old regex over 13 edge cases and 20,000 random inputs, a
|
|
20
|
+
* 100,000-slash input in 0.01ms linear.
|
|
21
|
+
*/
|
|
22
|
+
export declare const normalizeBaseUrl: (baseUrl: string) => string;
|
|
23
|
+
export interface Config {
|
|
24
|
+
/** The full `<user>@<realm>!<tokenid>` string, e.g. `root@pam!terraform`. */
|
|
25
|
+
readonly tokenId: string;
|
|
26
|
+
readonly secret: Redacted.Redacted<string>;
|
|
27
|
+
/** Fully-qualified API root, e.g. `https://pve1.example.com:8006/api2/json`. */
|
|
28
|
+
readonly apiBaseUrl: string;
|
|
29
|
+
}
|
|
30
|
+
declare const Credentials_base: Context.ServiceClass<Credentials, "ProxmoxCredentials", Effect.Effect<Config, never, never>>;
|
|
31
|
+
export declare class Credentials extends Credentials_base {
|
|
32
|
+
}
|
|
33
|
+
export declare const CredentialsFromEnv: Layer.Layer<Credentials, never, never>;
|
|
34
|
+
/** Convenience layer from a plain token and the node origin (or API root). */
|
|
35
|
+
export declare const credentials: (config: {
|
|
36
|
+
readonly tokenId: string;
|
|
37
|
+
readonly secret: string | Redacted.Redacted<string>;
|
|
38
|
+
readonly baseUrl: string;
|
|
39
|
+
}) => Layer.Layer<Credentials>;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAG5C,8FAA8F;AAC9F,eAAO,MAAM,QAAQ,eAAe,CAAC;AAErC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,YAAa,MAAM,KAAG,MAKlD,CAAC;AAEF,MAAM,WAAW,MAAM;IACrB,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3C,gFAAgF;IAChF,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;;AAED,qBAAa,WAAY,SAAQ,gBAGR;CAAG;AAQ5B,eAAO,MAAM,kBAAkB,wCAiB9B,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,WAAW,WAAY;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,KAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAWxB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxmox VE credentials — hand-written.
|
|
3
|
+
*
|
|
4
|
+
* The `Credentials` service resolves `{ tokenId, secret, apiBaseUrl }` per
|
|
5
|
+
* request; the protocol layer formats the `Authorization:
|
|
6
|
+
* PVEAPIToken=<tokenId>=<secret>` header from it.
|
|
7
|
+
*
|
|
8
|
+
* PVE is self-hosted (a cluster node, not a single-tenant SaaS), so — like
|
|
9
|
+
* `@distilled.cloud/forgejo` — there is no default API root: the instance
|
|
10
|
+
* URL is part of the credential. `tokenId` is the FULL
|
|
11
|
+
* `<user>@<realm>!<tokenid>` string PVE prints when an API token is
|
|
12
|
+
* created (`pveum user token add …`); `secret` is the value shown exactly
|
|
13
|
+
* once at creation time.
|
|
14
|
+
*/
|
|
15
|
+
import * as EffectConfig from "effect/Config";
|
|
16
|
+
import * as Context from "effect/Context";
|
|
17
|
+
import * as Effect from "effect/Effect";
|
|
18
|
+
import * as Layer from "effect/Layer";
|
|
19
|
+
import * as Redacted from "effect/Redacted";
|
|
20
|
+
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
21
|
+
/** PVE's own API root, relative to the node origin. Always port 8006, always `/api2/json`. */
|
|
22
|
+
export const API_PATH = "/api2/json";
|
|
23
|
+
/**
|
|
24
|
+
* Normalize a node origin (or an already-complete API root) into the API
|
|
25
|
+
* base URL: trailing slashes dropped, {@link API_PATH} appended exactly
|
|
26
|
+
* once. Does NOT default the port — `https://pve.example.com:8006` (or a
|
|
27
|
+
* bare host, which the caller must have already put a scheme+port on) is
|
|
28
|
+
* expected, matching how the kit's own `PveTarget` is built per node/vip.
|
|
29
|
+
*
|
|
30
|
+
* ⛔ THE TRIM IS A LOOP, NEVER `/\/+$/`. That regex backtracks
|
|
31
|
+
* polynomially on a long run of trailing `/` (CodeQL `js/polynomial-
|
|
32
|
+
* redos`) — caller input, so a real DoS surface, not a hypothetical one.
|
|
33
|
+
* Measured the same fix already landed in `@homeflare/distilled-netbox`'s
|
|
34
|
+
* identical trim (`taslabs-net/homeflare-kit` PR 184): 0 mismatches
|
|
35
|
+
* against the old regex over 13 edge cases and 20,000 random inputs, a
|
|
36
|
+
* 100,000-slash input in 0.01ms linear.
|
|
37
|
+
*/
|
|
38
|
+
export const normalizeBaseUrl = (baseUrl) => {
|
|
39
|
+
let end = baseUrl.length;
|
|
40
|
+
while (end > 0 && baseUrl.charCodeAt(end - 1) === 47 /* "/" */)
|
|
41
|
+
end--;
|
|
42
|
+
const trimmed = baseUrl.slice(0, end);
|
|
43
|
+
return trimmed.endsWith(API_PATH) ? trimmed : `${trimmed}${API_PATH}`;
|
|
44
|
+
};
|
|
45
|
+
export class Credentials extends Context.Service()("ProxmoxCredentials") {
|
|
46
|
+
}
|
|
47
|
+
const envConfig = EffectConfig.all({
|
|
48
|
+
tokenId: EffectConfig.String("PROXMOX_TOKEN_ID"),
|
|
49
|
+
secret: EffectConfig.Redacted("PROXMOX_TOKEN_SECRET"),
|
|
50
|
+
baseUrl: EffectConfig.String("PROXMOX_URL"),
|
|
51
|
+
});
|
|
52
|
+
export const CredentialsFromEnv = Layer.succeed(Credentials, envConfig.pipe(Effect.mapError(() => new ConfigError({
|
|
53
|
+
message: "PROXMOX_URL, PROXMOX_TOKEN_ID and PROXMOX_TOKEN_SECRET environment variables are required",
|
|
54
|
+
})), Effect.map(({ tokenId, secret, baseUrl }) => ({
|
|
55
|
+
tokenId,
|
|
56
|
+
secret,
|
|
57
|
+
apiBaseUrl: normalizeBaseUrl(baseUrl),
|
|
58
|
+
})), Effect.orDie));
|
|
59
|
+
/** Convenience layer from a plain token and the node origin (or API root). */
|
|
60
|
+
export const credentials = (config) => Layer.succeed(Credentials, Effect.succeed({
|
|
61
|
+
tokenId: config.tokenId,
|
|
62
|
+
secret: typeof config.secret === "string"
|
|
63
|
+
? Redacted.make(config.secret)
|
|
64
|
+
: config.secret,
|
|
65
|
+
apiBaseUrl: normalizeBaseUrl(config.baseUrl),
|
|
66
|
+
}));
|
|
67
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,YAAY,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,8FAA8F;AAC9F,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC;AAErC;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAU,EAAE;IAC1D,IAAI,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IACzB,OAAO,GAAG,GAAG,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,SAAS;QAAE,GAAG,EAAE,CAAC;IACtE,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACtC,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,QAAQ,EAAE,CAAC;AACxE,CAAC,CAAC;AAUF,MAAM,OAAO,WAAY,SAAQ,OAAO,CAAC,OAAO,EAG7C,CAAC,oBAAoB,CAAC;CAAG;AAE5B,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC;IACjC,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC;IAChD,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,sBAAsB,CAAC;IACrD,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC;CAC5C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAC7C,WAAW,EACX,SAAS,CAAC,IAAI,CACZ,MAAM,CAAC,QAAQ,CACb,GAAG,EAAE,CACH,IAAI,WAAW,CAAC;IACd,OAAO,EACL,2FAA2F;CAC9F,CAAC,CACL,EACD,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5C,OAAO;IACP,MAAM;IACN,UAAU,EAAE,gBAAgB,CAAC,OAAO,CAAC;CACtC,CAAC,CAAC,EACH,MAAM,CAAC,KAAK,CACb,CACF,CAAC;AAEF,8EAA8E;AAC9E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAI3B,EAA4B,EAAE,CAC7B,KAAK,CAAC,OAAO,CACX,WAAW,EACX,MAAM,CAAC,OAAO,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,OAAO;IACvB,MAAM,EACJ,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;QAC/B,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAC9B,CAAC,CAAC,MAAM,CAAC,MAAM;IACnB,UAAU,EAAE,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC;CAC7C,CAAC,CACH,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxmox VE-specific error types.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the common HTTP errors from core and adds PVE's own failure
|
|
5
|
+
* shapes — see `src/protocol.ts` for how each is recognized on the wire.
|
|
6
|
+
*
|
|
7
|
+
* ★ TWO DIFFERENT WIRING STYLES, ON PURPOSE:
|
|
8
|
+
* - `ParameterVerificationFailed` (and the plain `BadRequest` fallback
|
|
9
|
+
* for a 400 PVE didn't attach an `errors` object to) is GLOBAL
|
|
10
|
+
* (`commonErrorClasses`) — recognized generically in `protocol.ts`'s
|
|
11
|
+
* `unknownError`, which core's `makeRestProtocol` reaches LAST, after
|
|
12
|
+
* per-op `matchTypedError` and the status map both miss (never
|
|
13
|
+
* "before per-op matching runs" — 400 is deliberately absent from
|
|
14
|
+
* `PROXMOX_STATUS_MAP` so it always lands there). ANY write can fail
|
|
15
|
+
* parameter verification, so patching all 680 generated operations
|
|
16
|
+
* with the same error shape would be the RFC-6902 equivalent of
|
|
17
|
+
* copy-pasting one line 680 times for no additional truth. `BadRequest`
|
|
18
|
+
* matters here specifically because it is NOT retryable
|
|
19
|
+
* (`Category.withBadRequestError`) where `UnknownProxmoxError`'s
|
|
20
|
+
* `Category.withServerError` IS (core's default retry policy treats
|
|
21
|
+
* `ServerError` as transient) — see `protocol.ts`'s `unknownError` for
|
|
22
|
+
* the incident this prevents: a permanent 400 must never be retried.
|
|
23
|
+
* - `ClusterNodeUnreachable` is added via an ACTUAL RFC-6902 patch —
|
|
24
|
+
* `patches/nodes/task-polling.json` — to the four `/nodes/{node}/
|
|
25
|
+
* tasks/…` operations the vendor schema itself marks `proxyto: "node"`
|
|
26
|
+
* (this package's own `src/task.ts` polls one of them). It is NOT
|
|
27
|
+
* global: most PVE calls are answered by the node you connected to
|
|
28
|
+
* directly and never proxy at all, so declaring a 595 possible on
|
|
29
|
+
* every operation would be a claim the schema does not support for
|
|
30
|
+
* most of them. Matched purely by status (never a guessed message —
|
|
31
|
+
* see the patch file).
|
|
32
|
+
*/
|
|
33
|
+
export { BadGateway, BadRequest, Conflict, ConfigError, Forbidden, GatewayTimeout, InternalServerError, Locked, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity, HTTP_STATUS_MAP, DEFAULT_ERRORS, API_ERRORS, } from "@distilled.cloud/core/errors";
|
|
34
|
+
import type { BadRequest, DefaultErrors as CoreDefaultErrors } from "@distilled.cloud/core/errors";
|
|
35
|
+
import * as Schema from "effect/Schema";
|
|
36
|
+
import * as Category from "@distilled.cloud/core/category";
|
|
37
|
+
declare const ParameterVerificationFailed_base: Schema.Class<ParameterVerificationFailed, Schema.TaggedStruct<"ParameterVerificationFailed", {
|
|
38
|
+
readonly message: Schema.String;
|
|
39
|
+
readonly errors: Schema.$Record<Schema.String, Schema.String>;
|
|
40
|
+
}>, import("effect/Cause").YieldableError> & (new (...args: any[]) => {
|
|
41
|
+
"@distilled.cloud/error/categories": {
|
|
42
|
+
BadRequestError: true;
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* PVE's generic parameter-validation failure: `400` with `{"data":null,
|
|
47
|
+
* "errors":{"<param>":"<message>", …}, "message":"Parameter verification
|
|
48
|
+
* failed."}` — measured in `taslabs-net/homeflare-kit`'s
|
|
49
|
+
* `codegen/README.md` (the incident that package's whole vendor-schema
|
|
50
|
+
* pipeline exists to prevent): `PVE POST config/verify -> 400: parameter
|
|
51
|
+
* verification failed - comment: value may only be 128 characters long`.
|
|
52
|
+
* `errors` carries the per-field messages verbatim.
|
|
53
|
+
*/
|
|
54
|
+
export declare class ParameterVerificationFailed extends ParameterVerificationFailed_base {
|
|
55
|
+
}
|
|
56
|
+
declare const ClusterNodeUnreachable_base: Schema.Class<ClusterNodeUnreachable, Schema.TaggedStruct<"ClusterNodeUnreachable", {
|
|
57
|
+
readonly message: Schema.String;
|
|
58
|
+
}>, import("effect/Cause").YieldableError> & (new (...args: any[]) => {
|
|
59
|
+
"@distilled.cloud/error/categories": {
|
|
60
|
+
ServerError: true;
|
|
61
|
+
};
|
|
62
|
+
}) & (new (...args: any[]) => {
|
|
63
|
+
"@distilled.cloud/error/retryable": Category.RetryableInfo;
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* PVE's non-standard status for a cluster-forwarded request whose target
|
|
67
|
+
* node could not be reached (`pveproxy`/`pvedaemon` proxying — every
|
|
68
|
+
* endpoint the vendor schema marks `proxyto` can answer this). Standard
|
|
69
|
+
* HTTP has no 595; this is PVE's own convention, matched purely by status
|
|
70
|
+
* (never guessed message text — see `protocol.ts`). Treated as transient:
|
|
71
|
+
* the node the request was forwarded to may simply be mid-reboot or
|
|
72
|
+
* between cluster-membership changes.
|
|
73
|
+
*/
|
|
74
|
+
export declare class ClusterNodeUnreachable extends ClusterNodeUnreachable_base {
|
|
75
|
+
}
|
|
76
|
+
declare const UnknownProxmoxError_base: Schema.Class<UnknownProxmoxError, Schema.TaggedStruct<"UnknownProxmoxError", {
|
|
77
|
+
readonly status: Schema.optional<Schema.Number>;
|
|
78
|
+
readonly message: Schema.optional<Schema.String>;
|
|
79
|
+
readonly body: Schema.Unknown;
|
|
80
|
+
}>, import("effect/Cause").YieldableError> & (new (...args: any[]) => {
|
|
81
|
+
"@distilled.cloud/error/categories": {
|
|
82
|
+
ServerError: true;
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Unknown Proxmox error — returned when a failed response's HTTP status has
|
|
87
|
+
* no mapped error class. Carries the raw body for later cataloging.
|
|
88
|
+
*/
|
|
89
|
+
export declare class UnknownProxmoxError extends UnknownProxmoxError_base {
|
|
90
|
+
}
|
|
91
|
+
declare const ProxmoxParseError_base: Schema.Class<ProxmoxParseError, Schema.TaggedStruct<"ProxmoxParseError", {
|
|
92
|
+
readonly body: Schema.Unknown;
|
|
93
|
+
readonly cause: Schema.Unknown;
|
|
94
|
+
}>, import("effect/Cause").YieldableError> & (new (...args: any[]) => {
|
|
95
|
+
"@distilled.cloud/error/categories": {
|
|
96
|
+
ParseError: true;
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
/** Schema parse error wrapper. */
|
|
100
|
+
export declare class ProxmoxParseError extends ProxmoxParseError_base {
|
|
101
|
+
}
|
|
102
|
+
declare const ProxmoxTaskFailed_base: Schema.Class<ProxmoxTaskFailed, Schema.TaggedStruct<"ProxmoxTaskFailed", {
|
|
103
|
+
readonly node: Schema.String;
|
|
104
|
+
readonly upid: Schema.String;
|
|
105
|
+
readonly exitstatus: Schema.String;
|
|
106
|
+
}>, import("effect/Cause").YieldableError>;
|
|
107
|
+
/**
|
|
108
|
+
* A polled task ended with an `exitstatus` other than exactly `"OK"` — see
|
|
109
|
+
* `src/task.ts`. `exitstatus` carries PVE's own failure text verbatim
|
|
110
|
+
* (e.g. `"job errors"`, `"OK (warnings)"` — the latter is why the compare
|
|
111
|
+
* is exact-equality against `"OK"`, never a prefix/substring check).
|
|
112
|
+
*/
|
|
113
|
+
export declare class ProxmoxTaskFailed extends ProxmoxTaskFailed_base {
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Errors any Proxmox operation may surface in addition to the per-operation
|
|
117
|
+
* typed status errors.
|
|
118
|
+
*/
|
|
119
|
+
export type ClientErrors = UnknownProxmoxError | ProxmoxParseError;
|
|
120
|
+
/**
|
|
121
|
+
* Default Proxmox operation errors: the shared HTTP status errors from
|
|
122
|
+
* core, PVE's global parameter-verification failure, plus the client-level
|
|
123
|
+
* fallback/decode errors. `ClusterNodeUnreachable` is NOT here — see the
|
|
124
|
+
* header: it rides only the specific operations `patches/nodes/
|
|
125
|
+
* task-polling.json` adds it to.
|
|
126
|
+
*/
|
|
127
|
+
export type DefaultErrors = CoreDefaultErrors | BadRequest | ParameterVerificationFailed | ClientErrors;
|
|
128
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EACL,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,GACX,MAAM,8BAA8B,CAAC;AAOtC,OAAO,KAAK,EACV,UAAU,EACV,aAAa,IAAI,iBAAiB,EACnC,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,gCAAgC,CAAC;;;;;;;;;AAE3D;;;;;;;;GAQG;AACH,qBAAa,2BAA4B,SAAQ,gCAMb;CAAG;;;;;;;;;;AAEvC;;;;;;;;GAQG;AACH,qBAAa,sBAAuB,SAAQ,2BAKc;CAAG;;;;;;;;;;AAE7D;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,wBAOT;CAAG;;;;;;;;;AAEnC,kCAAkC;AAClC,qBAAa,iBAAkB,SAAQ,sBAMR;CAAG;;;;;;AAElC;;;;;GAKG;AACH,qBAAa,iBAAkB,SAAQ,sBAOtC;CAAG;AAEJ;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GACrB,iBAAiB,GACjB,UAAU,GACV,2BAA2B,GAC3B,YAAY,CAAC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxmox VE-specific error types.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the common HTTP errors from core and adds PVE's own failure
|
|
5
|
+
* shapes — see `src/protocol.ts` for how each is recognized on the wire.
|
|
6
|
+
*
|
|
7
|
+
* ★ TWO DIFFERENT WIRING STYLES, ON PURPOSE:
|
|
8
|
+
* - `ParameterVerificationFailed` (and the plain `BadRequest` fallback
|
|
9
|
+
* for a 400 PVE didn't attach an `errors` object to) is GLOBAL
|
|
10
|
+
* (`commonErrorClasses`) — recognized generically in `protocol.ts`'s
|
|
11
|
+
* `unknownError`, which core's `makeRestProtocol` reaches LAST, after
|
|
12
|
+
* per-op `matchTypedError` and the status map both miss (never
|
|
13
|
+
* "before per-op matching runs" — 400 is deliberately absent from
|
|
14
|
+
* `PROXMOX_STATUS_MAP` so it always lands there). ANY write can fail
|
|
15
|
+
* parameter verification, so patching all 680 generated operations
|
|
16
|
+
* with the same error shape would be the RFC-6902 equivalent of
|
|
17
|
+
* copy-pasting one line 680 times for no additional truth. `BadRequest`
|
|
18
|
+
* matters here specifically because it is NOT retryable
|
|
19
|
+
* (`Category.withBadRequestError`) where `UnknownProxmoxError`'s
|
|
20
|
+
* `Category.withServerError` IS (core's default retry policy treats
|
|
21
|
+
* `ServerError` as transient) — see `protocol.ts`'s `unknownError` for
|
|
22
|
+
* the incident this prevents: a permanent 400 must never be retried.
|
|
23
|
+
* - `ClusterNodeUnreachable` is added via an ACTUAL RFC-6902 patch —
|
|
24
|
+
* `patches/nodes/task-polling.json` — to the four `/nodes/{node}/
|
|
25
|
+
* tasks/…` operations the vendor schema itself marks `proxyto: "node"`
|
|
26
|
+
* (this package's own `src/task.ts` polls one of them). It is NOT
|
|
27
|
+
* global: most PVE calls are answered by the node you connected to
|
|
28
|
+
* directly and never proxy at all, so declaring a 595 possible on
|
|
29
|
+
* every operation would be a claim the schema does not support for
|
|
30
|
+
* most of them. Matched purely by status (never a guessed message —
|
|
31
|
+
* see the patch file).
|
|
32
|
+
*/
|
|
33
|
+
export { BadGateway, BadRequest, Conflict, ConfigError, Forbidden, GatewayTimeout, InternalServerError, Locked, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity, HTTP_STATUS_MAP, DEFAULT_ERRORS, API_ERRORS, } from "@distilled.cloud/core/errors";
|
|
34
|
+
import * as Schema from "effect/Schema";
|
|
35
|
+
import * as Category from "@distilled.cloud/core/category";
|
|
36
|
+
/**
|
|
37
|
+
* PVE's generic parameter-validation failure: `400` with `{"data":null,
|
|
38
|
+
* "errors":{"<param>":"<message>", …}, "message":"Parameter verification
|
|
39
|
+
* failed."}` — measured in `taslabs-net/homeflare-kit`'s
|
|
40
|
+
* `codegen/README.md` (the incident that package's whole vendor-schema
|
|
41
|
+
* pipeline exists to prevent): `PVE POST config/verify -> 400: parameter
|
|
42
|
+
* verification failed - comment: value may only be 128 characters long`.
|
|
43
|
+
* `errors` carries the per-field messages verbatim.
|
|
44
|
+
*/
|
|
45
|
+
export class ParameterVerificationFailed extends Schema.TaggedError()("ParameterVerificationFailed", {
|
|
46
|
+
message: Schema.String,
|
|
47
|
+
errors: Schema.Record(Schema.String, Schema.String),
|
|
48
|
+
}).pipe(Category.withBadRequestError) {
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* PVE's non-standard status for a cluster-forwarded request whose target
|
|
52
|
+
* node could not be reached (`pveproxy`/`pvedaemon` proxying — every
|
|
53
|
+
* endpoint the vendor schema marks `proxyto` can answer this). Standard
|
|
54
|
+
* HTTP has no 595; this is PVE's own convention, matched purely by status
|
|
55
|
+
* (never guessed message text — see `protocol.ts`). Treated as transient:
|
|
56
|
+
* the node the request was forwarded to may simply be mid-reboot or
|
|
57
|
+
* between cluster-membership changes.
|
|
58
|
+
*/
|
|
59
|
+
export class ClusterNodeUnreachable extends Schema.TaggedError()("ClusterNodeUnreachable", {
|
|
60
|
+
message: Schema.String,
|
|
61
|
+
}).pipe(Category.withServerError, Category.withRetryable()) {
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Unknown Proxmox error — returned when a failed response's HTTP status has
|
|
65
|
+
* no mapped error class. Carries the raw body for later cataloging.
|
|
66
|
+
*/
|
|
67
|
+
export class UnknownProxmoxError extends Schema.TaggedError()("UnknownProxmoxError", {
|
|
68
|
+
status: Schema.optional(Schema.Number),
|
|
69
|
+
message: Schema.optional(Schema.String),
|
|
70
|
+
body: Schema.Unknown,
|
|
71
|
+
}).pipe(Category.withServerError) {
|
|
72
|
+
}
|
|
73
|
+
/** Schema parse error wrapper. */
|
|
74
|
+
export class ProxmoxParseError extends Schema.TaggedError()("ProxmoxParseError", {
|
|
75
|
+
body: Schema.Unknown,
|
|
76
|
+
cause: Schema.Unknown,
|
|
77
|
+
}).pipe(Category.withParseError) {
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A polled task ended with an `exitstatus` other than exactly `"OK"` — see
|
|
81
|
+
* `src/task.ts`. `exitstatus` carries PVE's own failure text verbatim
|
|
82
|
+
* (e.g. `"job errors"`, `"OK (warnings)"` — the latter is why the compare
|
|
83
|
+
* is exact-equality against `"OK"`, never a prefix/substring check).
|
|
84
|
+
*/
|
|
85
|
+
export class ProxmoxTaskFailed extends Schema.TaggedError()("ProxmoxTaskFailed", {
|
|
86
|
+
node: Schema.String,
|
|
87
|
+
upid: Schema.String,
|
|
88
|
+
exitstatus: Schema.String,
|
|
89
|
+
}) {
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EACL,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,GACX,MAAM,8BAA8B,CAAC;AAYtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,gCAAgC,CAAC;AAE3D;;;;;;;;GAQG;AACH,MAAM,OAAO,2BAA4B,SAAQ,MAAM,CAAC,WAAW,EAA+B,CAChG,6BAA6B,EAC7B;IACE,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;CACpD,CACF,CAAC,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC;CAAG;AAEvC;;;;;;;;GAQG;AACH,MAAM,OAAO,sBAAuB,SAAQ,MAAM,CAAC,WAAW,EAA0B,CACtF,wBAAwB,EACxB;IACE,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CACF,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAC,aAAa,EAAE,CAAC;CAAG;AAE7D;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,MAAM,CAAC,WAAW,EAAuB,CAChF,qBAAqB,EACrB;IACE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACvC,IAAI,EAAE,MAAM,CAAC,OAAO;CACrB,CACF,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC;CAAG;AAEnC,kCAAkC;AAClC,MAAM,OAAO,iBAAkB,SAAQ,MAAM,CAAC,WAAW,EAAqB,CAC5E,mBAAmB,EACnB;IACE,IAAI,EAAE,MAAM,CAAC,OAAO;IACpB,KAAK,EAAE,MAAM,CAAC,OAAO;CACtB,CACF,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;CAAG;AAElC;;;;;GAKG;AACH,MAAM,OAAO,iBAAkB,SAAQ,MAAM,CAAC,WAAW,EAAqB,CAC5E,mBAAmB,EACnB;IACE,IAAI,EAAE,MAAM,CAAC,MAAM;IACnB,IAAI,EAAE,MAAM,CAAC,MAAM;IACnB,UAAU,EAAE,MAAM,CAAC,MAAM;CAC1B,CACF;CAAG"}
|