The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as netapp from "@distilled.cloud/gcp/netapp_v1"; |
| 2 | import { Unowned } from "alchemy/AdoptPolicy"; |
| 3 | import { isResolved } from "alchemy/Diff"; |
| 4 | import * as Provider from "alchemy/Provider"; |
| 5 | import { Resource } from "alchemy/Resource"; |
| 6 | import { tagRecord } from "alchemy/Tags"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import { GcpEnvironment } from "../Environment.ts"; |
| 10 | import { createInternalLabels, diffLabels, hasAlchemyLabels, toLabels } from "../Labels.ts"; |
| 11 | import type { Providers } from "../Providers.ts"; |
| 12 | import { |
| 13 | expandParent, |
| 14 | fieldMask, |
| 15 | fingerprint, |
| 16 | gibOf, |
| 17 | lastSegment, |
| 18 | listAtLocation, |
| 19 | listLabeledPages, |
| 20 | normalizeLocation, |
| 21 | parentOf, |
| 22 | parseName, |
| 23 | replaceOnIdentity, |
| 24 | ResourceNotResolved, |
| 25 | sameStringList, |
| 26 | toPhysicalId, |
| 27 | userLabels, |
| 28 | waitForDeleteOperation, |
| 29 | waitForOperation, |
| 30 | waitUntilExists, |
| 31 | waitUntilGone, |
| 32 | waitUntilReady, |
| 33 | } from "./internal.ts"; |
| 34 | |
| 35 | const DEFAULT_PROTOCOL: netapp.VolumeProtocolsItemEnum = "NFSV3"; |
| 36 | const DEFAULT_CAPACITY_GIB = 100; |
| 37 | |
| 38 | export type ExportPolicyRule = { |
| 39 | /** Access type (`READ_ONLY`, `READ_WRITE`, `READ_NONE`). */ |
| 40 | accessType?: netapp.SimpleExportPolicyRuleAccessTypeEnum | (string & {}); |
| 41 | /** Squash mode. Takes precedence over `hasRootAccess`. */ |
| 42 | squashMode?: netapp.SimpleExportPolicyRuleSquashModeEnum | (string & {}); |
| 43 | /** Comma-separated allowed client IPs or CIDRs. */ |
| 44 | allowedClients?: string; |
| 45 | /** Enable NFSv3. */ |
| 46 | nfsv3?: boolean; |
| 47 | /** Enable NFSv4. */ |
| 48 | nfsv4?: boolean; |
| 49 | /** Unix root access (`true` / `false`). */ |
| 50 | hasRootAccess?: string; |
| 51 | /** Anonymous user id when squash is ROOT_SQUASH or ALL_SQUASH. */ |
| 52 | anonUid?: string; |
| 53 | kerberos5ReadOnly?: boolean; |
| 54 | kerberos5ReadWrite?: boolean; |
| 55 | kerberos5iReadOnly?: boolean; |
| 56 | kerberos5iReadWrite?: boolean; |
| 57 | kerberos5pReadOnly?: boolean; |
| 58 | kerberos5pReadWrite?: boolean; |
| 59 | }; |
| 60 | |
| 61 | export type ExportPolicy = { |
| 62 | /** Export policy rules. */ |
| 63 | rules?: ExportPolicyRule[]; |
| 64 | }; |
| 65 | |
| 66 | export type SnapshotSchedule = { |
| 67 | snapshotsToKeep?: number; |
| 68 | minute?: number; |
| 69 | hour?: number; |
| 70 | day?: string; |
| 71 | daysOfMonth?: string; |
| 72 | }; |
| 73 | |
| 74 | export type SnapshotPolicy = { |
| 75 | enabled?: boolean; |
| 76 | hourlySchedule?: SnapshotSchedule; |
| 77 | dailySchedule?: SnapshotSchedule; |
| 78 | weeklySchedule?: SnapshotSchedule; |
| 79 | monthlySchedule?: SnapshotSchedule; |
| 80 | }; |
| 81 | |
| 82 | export type BackupConfig = { |
| 83 | /** Backup vault name or id. */ |
| 84 | backupVault?: string; |
| 85 | /** Backup policy names. */ |
| 86 | backupPolicies?: string[]; |
| 87 | /** Enable scheduled backups. */ |
| 88 | scheduledBackupEnabled?: boolean; |
| 89 | }; |
| 90 | |
| 91 | export type TieringPolicy = { |
| 92 | tierAction?: netapp.TieringPolicyTierActionEnum | (string & {}); |
| 93 | coolingThresholdDays?: number; |
| 94 | hotTierBypassModeEnabled?: boolean; |
| 95 | }; |
| 96 | |
| 97 | export type RestoreParameters = { |
| 98 | sourceSnapshot?: string; |
| 99 | sourceBackup?: string; |
| 100 | }; |
| 101 | |
| 102 | export type BlockDevice = { |
| 103 | osType?: netapp.BlockDeviceOsTypeEnum | (string & {}); |
| 104 | name?: string; |
| 105 | sizeGib?: number | string; |
| 106 | hostGroups?: string[]; |
| 107 | }; |
| 108 | |
| 109 | export type VolumeProps = { |
| 110 | /** |
| 111 | * Volume id (the `{volume}` segment of |
| 112 | * `projects/{project}/locations/{location}/volumes/{volume}`). |
| 113 | * If omitted, a unique RFC1035 name is generated from the stack, stage, |
| 114 | * and logical id. Immutable — changing it replaces the volume. |
| 115 | */ |
| 116 | volumeId?: string; |
| 117 | /** |
| 118 | * Region (`us-central1`, `us-east1`, …). Immutable — changing it |
| 119 | * replaces the volume. `US-CENTRAL1` is accepted and normalized to |
| 120 | * `us-central1`. |
| 121 | * @default the stack's GCP region (`GCP.Region`, profile region, `us-central1`) |
| 122 | */ |
| 123 | location?: string; |
| 124 | /** |
| 125 | * Storage pool name or id. Immutable — changing it replaces the volume. |
| 126 | */ |
| 127 | storagePool: string; |
| 128 | /** |
| 129 | * NFS/SMB share name. Defaults to the volume id. Immutable — changing |
| 130 | * it replaces the volume. |
| 131 | */ |
| 132 | shareName?: string; |
| 133 | /** |
| 134 | * Protocols. Immutable — changing them replaces the volume. |
| 135 | * @default ["NFSV3"] |
| 136 | */ |
| 137 | protocols?: Array<netapp.VolumeProtocolsItemEnum | (string & {})>; |
| 138 | /** |
| 139 | * Capacity in GiB. |
| 140 | * @default 100 |
| 141 | */ |
| 142 | capacityGib?: number | string; |
| 143 | /** |
| 144 | * Unix permissions on the mount point (NFS). |
| 145 | */ |
| 146 | unixPermissions?: string; |
| 147 | /** |
| 148 | * Security style. Immutable — changing it replaces the volume. |
| 149 | */ |
| 150 | securityStyle?: netapp.VolumeSecurityStyleEnum | (string & {}); |
| 151 | /** |
| 152 | * Percentage of capacity reserved for snapshots. |
| 153 | */ |
| 154 | snapReserve?: number; |
| 155 | /** |
| 156 | * Expose a read-only `.snapshot` directory. |
| 157 | */ |
| 158 | snapshotDirectory?: boolean; |
| 159 | /** |
| 160 | * Throughput in MiB/s. |
| 161 | */ |
| 162 | throughputMibps?: number; |
| 163 | /** |
| 164 | * Enable Kerberos. Immutable — changing it replaces the volume. |
| 165 | */ |
| 166 | kerberosEnabled?: boolean; |
| 167 | /** |
| 168 | * SMB share settings. |
| 169 | */ |
| 170 | smbSettings?: Array<netapp.VolumeSmbSettingsItemEnum | (string & {})>; |
| 171 | /** |
| 172 | * Restricted actions (`DELETE`, …). |
| 173 | */ |
| 174 | restrictedActions?: Array<netapp.VolumeRestrictedActionsItemEnum | (string & {})>; |
| 175 | /** |
| 176 | * NFS export policy. |
| 177 | */ |
| 178 | exportPolicy?: ExportPolicy; |
| 179 | /** |
| 180 | * Snapshot schedule. |
| 181 | */ |
| 182 | snapshotPolicy?: SnapshotPolicy; |
| 183 | /** |
| 184 | * Backup configuration. |
| 185 | */ |
| 186 | backupConfig?: BackupConfig; |
| 187 | /** |
| 188 | * Auto-tiering policy. |
| 189 | */ |
| 190 | tieringPolicy?: TieringPolicy; |
| 191 | /** |
| 192 | * Restore from a snapshot or backup. Immutable. |
| 193 | */ |
| 194 | restoreParameters?: RestoreParameters; |
| 195 | /** |
| 196 | * Block devices (unified pools). Currently one device per volume. |
| 197 | */ |
| 198 | blockDevices?: BlockDevice[]; |
| 199 | /** |
| 200 | * Large-capacity volume (legacy FILE pools). Immutable. |
| 201 | */ |
| 202 | largeCapacity?: boolean; |
| 203 | /** |
| 204 | * Large-capacity constituent config (unified pools). Immutable. |
| 205 | */ |
| 206 | largeCapacityConfig?: { constituentCount?: number }; |
| 207 | /** |
| 208 | * One IP per node for large-capacity volumes. Immutable. |
| 209 | */ |
| 210 | multipleEndpoints?: boolean; |
| 211 | /** |
| 212 | * Human-readable description. |
| 213 | */ |
| 214 | description?: string; |
| 215 | /** |
| 216 | * User labels. Alchemy ownership labels are merged in automatically. |
| 217 | */ |
| 218 | labels?: Record<string, string>; |
| 219 | }; |
| 220 | |
| 221 | export type MountOption = { |
| 222 | export: string | undefined; |
| 223 | exportFull: string | undefined; |
| 224 | protocol: string | undefined; |
| 225 | instructions: string | undefined; |
| 226 | ipAddress: string | undefined; |
| 227 | }; |
| 228 | |
| 229 | export type Volume = Resource< |
| 230 | "GCP.NetApp.Volume", |
| 231 | VolumeProps, |
| 232 | { |
| 233 | /** Full resource name. */ |
| 234 | name: string; |
| 235 | /** Volume id (last path segment). */ |
| 236 | volumeId: string; |
| 237 | /** Project id. */ |
| 238 | project: string; |
| 239 | /** Location id. */ |
| 240 | location: string; |
| 241 | /** Storage pool name. */ |
| 242 | storagePool: string | undefined; |
| 243 | /** Share name. */ |
| 244 | shareName: string | undefined; |
| 245 | /** Protocols. */ |
| 246 | protocols: string[]; |
| 247 | /** Capacity in GiB. */ |
| 248 | capacityGib: string | undefined; |
| 249 | /** Used capacity in GiB. */ |
| 250 | usedGib: string | undefined; |
| 251 | /** VPC network path. */ |
| 252 | network: string | undefined; |
| 253 | /** Service level inherited from the pool. */ |
| 254 | serviceLevel: string | undefined; |
| 255 | /** Unix permissions. */ |
| 256 | unixPermissions: string | undefined; |
| 257 | /** Security style. */ |
| 258 | securityStyle: string | undefined; |
| 259 | /** Snapshot reserve percent. */ |
| 260 | snapReserve: number | undefined; |
| 261 | /** Whether `.snapshot` is exposed. */ |
| 262 | snapshotDirectory: boolean | undefined; |
| 263 | /** Throughput in MiB/s. */ |
| 264 | throughputMibps: number | undefined; |
| 265 | /** Whether Kerberos is enabled. */ |
| 266 | kerberosEnabled: boolean | undefined; |
| 267 | /** SMB settings. */ |
| 268 | smbSettings: string[]; |
| 269 | /** Restricted actions. */ |
| 270 | restrictedActions: string[]; |
| 271 | /** Export policy. */ |
| 272 | exportPolicy: ExportPolicy | undefined; |
| 273 | /** Snapshot policy. */ |
| 274 | snapshotPolicy: SnapshotPolicy | undefined; |
| 275 | /** Backup configuration. */ |
| 276 | backupConfig: BackupConfig | undefined; |
| 277 | /** Tiering policy. */ |
| 278 | tieringPolicy: TieringPolicy | undefined; |
| 279 | /** Mount options. */ |
| 280 | mountOptions: MountOption[]; |
| 281 | /** Active zone. */ |
| 282 | zone: string | undefined; |
| 283 | /** Replica zone. */ |
| 284 | replicaZone: string | undefined; |
| 285 | /** KMS config name. */ |
| 286 | kmsConfig: string | undefined; |
| 287 | /** Active Directory name. */ |
| 288 | activeDirectory: string | undefined; |
| 289 | /** Whether NFS LDAP is enabled. */ |
| 290 | ldapEnabled: boolean | undefined; |
| 291 | /** Whether the volume is in a replication. */ |
| 292 | hasReplication: boolean | undefined; |
| 293 | /** Encryption key source. */ |
| 294 | encryptionType: string | undefined; |
| 295 | /** Cold-tier usage in GiB. */ |
| 296 | coldTierSizeGib: string | undefined; |
| 297 | /** Hot-tier usage in GiB. */ |
| 298 | hotTierSizeUsedGib: string | undefined; |
| 299 | /** Human-readable description. */ |
| 300 | description: string | undefined; |
| 301 | /** User labels (Alchemy ownership labels stripped). */ |
| 302 | labels: Record<string, string>; |
| 303 | /** Server-reported state. */ |
| 304 | state: string | undefined; |
| 305 | /** State details. */ |
| 306 | stateDetails: string | undefined; |
| 307 | /** RFC3339 creation timestamp. */ |
| 308 | createTime: string | undefined; |
| 309 | }, |
| 310 | never, |
| 311 | Providers |
| 312 | >; |
| 313 | |
| 314 | /** |
| 315 | * A Cloud NetApp Volumes file or block volume hosted in a storage pool. |
| 316 | * |
| 317 | * Changing `volumeId`, `location`, `storagePool`, `shareName`, |
| 318 | * `protocols`, `securityStyle`, `kerberosEnabled`, `restoreParameters`, |
| 319 | * or large-capacity flags replaces the volume. Capacity, export policy, |
| 320 | * snapshots, backups, description, and labels update in place. |
| 321 | * |
| 322 | * ### Creating a Volume |
| 323 | * **Example:** NFS volume |
| 324 | * ```typescript |
| 325 | * const volume = yield* GCP.NetApp.Volume("Share", { |
| 326 | * storagePool: pool.name, |
| 327 | * protocols: ["NFSV3"], |
| 328 | * capacityGib: 100, |
| 329 | * }); |
| 330 | * ``` |
| 331 | * |
| 332 | * **Example:** Explicit share name and export policy |
| 333 | * ```typescript |
| 334 | * const volume = yield* GCP.NetApp.Volume("Share", { |
| 335 | * storagePool: pool.name, |
| 336 | * shareName: "app", |
| 337 | * protocols: ["NFSV3"], |
| 338 | * capacityGib: 200, |
| 339 | * unixPermissions: "0770", |
| 340 | * exportPolicy: { |
| 341 | * rules: [{ allowedClients: "10.0.0.0/24", accessType: "READ_WRITE" }], |
| 342 | * }, |
| 343 | * labels: { env: "prod" }, |
| 344 | * }); |
| 345 | * ``` |
| 346 | * |
| 347 | * ### Updating a Volume |
| 348 | * **Example:** Capacity and labels |
| 349 | * ```typescript |
| 350 | * const volume = yield* GCP.NetApp.Volume("Share", { |
| 351 | * storagePool: pool.name, |
| 352 | * capacityGib: 300, |
| 353 | * description: "app share v2", |
| 354 | * labels: { env: "prod", team: "storage" }, |
| 355 | * }); |
| 356 | * ``` |
| 357 | * |
| 358 | * @resource |
| 359 | * @category NetApp |
| 360 | */ |
| 361 | export const Volume = Resource<Volume>("GCP.NetApp.Volume"); |
| 362 | |
| 363 | const resourceName = (project: string, location: string, volumeId: string) => |
| 364 | `projects/${project}/locations/${location}/volumes/${volumeId}`; |
| 365 | |
| 366 | const toBackupConfig = (config: netapp.BackupConfig | undefined): BackupConfig | undefined => |
| 367 | config === undefined |
| 368 | ? undefined |
| 369 | : { |
| 370 | backupVault: config.backupVault, |
| 371 | backupPolicies: config.backupPolicies, |
| 372 | scheduledBackupEnabled: config.scheduledBackupEnabled, |
| 373 | }; |
| 374 | |
| 375 | const toExportPolicy = (policy: netapp.ExportPolicy | undefined): ExportPolicy | undefined => |
| 376 | policy === undefined |
| 377 | ? undefined |
| 378 | : { |
| 379 | rules: policy.rules?.map((rule) => ({ |
| 380 | accessType: rule.accessType, |
| 381 | squashMode: rule.squashMode, |
| 382 | allowedClients: rule.allowedClients, |
| 383 | nfsv3: rule.nfsv3, |
| 384 | nfsv4: rule.nfsv4, |
| 385 | hasRootAccess: rule.hasRootAccess, |
| 386 | anonUid: rule.anonUid, |
| 387 | kerberos5ReadOnly: rule.kerberos5ReadOnly, |
| 388 | kerberos5ReadWrite: rule.kerberos5ReadWrite, |
| 389 | kerberos5iReadOnly: rule.kerberos5iReadOnly, |
| 390 | kerberos5iReadWrite: rule.kerberos5iReadWrite, |
| 391 | kerberos5pReadOnly: rule.kerberos5pReadOnly, |
| 392 | kerberos5pReadWrite: rule.kerberos5pReadWrite, |
| 393 | })), |
| 394 | }; |
| 395 | |
| 396 | const toSnapshotPolicy = (policy: netapp.SnapshotPolicy | undefined): SnapshotPolicy | undefined => |
| 397 | policy === undefined |
| 398 | ? undefined |
| 399 | : { |
| 400 | enabled: policy.enabled, |
| 401 | hourlySchedule: policy.hourlySchedule, |
| 402 | dailySchedule: policy.dailySchedule, |
| 403 | weeklySchedule: policy.weeklySchedule, |
| 404 | monthlySchedule: policy.monthlySchedule, |
| 405 | }; |
| 406 | |
| 407 | const toTieringPolicy = (policy: netapp.TieringPolicy | undefined): TieringPolicy | undefined => |
| 408 | policy === undefined |
| 409 | ? undefined |
| 410 | : { |
| 411 | tierAction: policy.tierAction, |
| 412 | coolingThresholdDays: policy.coolingThresholdDays, |
| 413 | hotTierBypassModeEnabled: policy.hotTierBypassModeEnabled, |
| 414 | }; |
| 415 | |
| 416 | const toAttrs = (item: netapp.Volume, project: string, region: string) => { |
| 417 | const name = item.name ?? ""; |
| 418 | const parsed = parseName(name, "volumes", region); |
| 419 | return { |
| 420 | name, |
| 421 | volumeId: parsed.id, |
| 422 | project: parsed.project || project, |
| 423 | location: parsed.location, |
| 424 | storagePool: item.storagePool, |
| 425 | shareName: item.shareName, |
| 426 | protocols: item.protocols ?? [], |
| 427 | capacityGib: item.capacityGib, |
| 428 | usedGib: item.usedGib, |
| 429 | network: item.network, |
| 430 | serviceLevel: item.serviceLevel, |
| 431 | unixPermissions: item.unixPermissions, |
| 432 | securityStyle: item.securityStyle, |
| 433 | snapReserve: item.snapReserve, |
| 434 | snapshotDirectory: item.snapshotDirectory, |
| 435 | throughputMibps: item.throughputMibps, |
| 436 | kerberosEnabled: item.kerberosEnabled, |
| 437 | smbSettings: item.smbSettings ?? [], |
| 438 | restrictedActions: item.restrictedActions ?? [], |
| 439 | exportPolicy: toExportPolicy(item.exportPolicy), |
| 440 | snapshotPolicy: toSnapshotPolicy(item.snapshotPolicy), |
| 441 | backupConfig: toBackupConfig(item.backupConfig), |
| 442 | tieringPolicy: toTieringPolicy(item.tieringPolicy), |
| 443 | mountOptions: (item.mountOptions ?? []).map((option) => ({ |
| 444 | export: option.export, |
| 445 | exportFull: option.exportFull, |
| 446 | protocol: option.protocol, |
| 447 | instructions: option.instructions, |
| 448 | ipAddress: option.ipAddress, |
| 449 | })), |
| 450 | zone: item.zone, |
| 451 | replicaZone: item.replicaZone, |
| 452 | kmsConfig: item.kmsConfig, |
| 453 | activeDirectory: item.activeDirectory, |
| 454 | ldapEnabled: item.ldapEnabled, |
| 455 | hasReplication: item.hasReplication, |
| 456 | encryptionType: item.encryptionType, |
| 457 | coldTierSizeGib: item.coldTierSizeGib, |
| 458 | hotTierSizeUsedGib: item.hotTierSizeUsedGib, |
| 459 | description: item.description, |
| 460 | labels: userLabels(item.labels), |
| 461 | state: item.state, |
| 462 | stateDetails: item.stateDetails, |
| 463 | createTime: item.createTime, |
| 464 | }; |
| 465 | }; |
| 466 | |
| 467 | const getByName = (name: string) => |
| 468 | netapp |
| 469 | .getProjectsLocationsVolumes({ name }) |
| 470 | .pipe(Effect.catchTag("NotFound", () => Effect.undefined)); |
| 471 | |
| 472 | const listOwned = (project: string) => |
| 473 | listAtLocation(project, (parent) => |
| 474 | listLabeledPages( |
| 475 | netapp.listProjectsLocationsVolumes.pages({ |
| 476 | parent, |
| 477 | pageSize: 1000, |
| 478 | }), |
| 479 | (page) => page.volumes, |
| 480 | (item) => item.labels, |
| 481 | ), |
| 482 | ); |
| 483 | |
| 484 | const desiredBackupConfig = ( |
| 485 | project: string, |
| 486 | location: string, |
| 487 | config: BackupConfig | undefined, |
| 488 | ): netapp.BackupConfig | undefined => { |
| 489 | if (config === undefined) return undefined; |
| 490 | return { |
| 491 | backupVault: |
| 492 | config.backupVault === undefined |
| 493 | ? undefined |
| 494 | : expandParent(config.backupVault, project, location, "backupVaults"), |
| 495 | backupPolicies: config.backupPolicies?.map((policy) => |
| 496 | expandParent(policy, project, location, "backupPolicies"), |
| 497 | ), |
| 498 | scheduledBackupEnabled: config.scheduledBackupEnabled, |
| 499 | }; |
| 500 | }; |
| 501 | |
| 502 | export const VolumeProvider = () => |
| 503 | Provider.succeed(Volume, { |
| 504 | stables: ["name", "volumeId", "project", "location", "createTime"], |
| 505 | |
| 506 | diff: Effect.fn(function* ({ news, olds, output }) { |
| 507 | if (!isResolved(news)) return undefined; |
| 508 | const env = yield* GcpEnvironment.current; |
| 509 | const previousPool = olds?.storagePool ?? output?.storagePool; |
| 510 | const previousShare = olds?.shareName ?? output?.shareName; |
| 511 | const previousProtocols = olds?.protocols ?? output?.protocols; |
| 512 | const previousStyle = olds?.securityStyle ?? output?.securityStyle; |
| 513 | const previousKerberos = olds?.kerberosEnabled ?? output?.kerberosEnabled; |
| 514 | const nextProtocols = news.protocols ?? [DEFAULT_PROTOCOL]; |
| 515 | return replaceOnIdentity({ |
| 516 | previousId: olds?.volumeId ?? output?.volumeId, |
| 517 | nextId: news.volumeId ?? olds?.volumeId ?? output?.volumeId, |
| 518 | previousLocation: normalizeLocation(olds?.location ?? output?.location, env.region), |
| 519 | nextLocation: normalizeLocation( |
| 520 | news.location ?? olds?.location ?? output?.location, |
| 521 | env.region, |
| 522 | ), |
| 523 | extra: |
| 524 | (previousPool !== undefined && |
| 525 | news.storagePool !== previousPool && |
| 526 | !previousPool.endsWith(`/${news.storagePool}`)) || |
| 527 | (previousShare !== undefined && |
| 528 | news.shareName !== undefined && |
| 529 | news.shareName !== previousShare) || |
| 530 | (previousProtocols !== undefined && !sameStringList(previousProtocols, nextProtocols)) || |
| 531 | (previousStyle !== undefined && |
| 532 | news.securityStyle !== undefined && |
| 533 | news.securityStyle !== previousStyle) || |
| 534 | (previousKerberos !== undefined && |
| 535 | news.kerberosEnabled !== undefined && |
| 536 | news.kerberosEnabled !== previousKerberos) || |
| 537 | (olds?.restoreParameters !== undefined && |
| 538 | news.restoreParameters !== undefined && |
| 539 | fingerprint(olds.restoreParameters) !== fingerprint(news.restoreParameters)) || |
| 540 | (olds?.largeCapacity !== undefined && |
| 541 | news.largeCapacity !== undefined && |
| 542 | news.largeCapacity !== olds.largeCapacity) || |
| 543 | (olds?.multipleEndpoints !== undefined && |
| 544 | news.multipleEndpoints !== undefined && |
| 545 | news.multipleEndpoints !== olds.multipleEndpoints), |
| 546 | }); |
| 547 | }), |
| 548 | |
| 549 | read: Effect.fn(function* ({ id, olds, output }) { |
| 550 | const env = yield* GcpEnvironment.current; |
| 551 | const volumeId = yield* toPhysicalId(id, olds?.volumeId, output?.volumeId, "volume"); |
| 552 | const location = normalizeLocation(olds?.location ?? output?.location, env.region); |
| 553 | const name = output?.name ?? resourceName(env.project, location, volumeId); |
| 554 | const existing = yield* getByName(name); |
| 555 | if (existing === undefined) return undefined; |
| 556 | const attrs = toAttrs(existing, env.project, env.region); |
| 557 | return (yield* hasAlchemyLabels(id, tagRecord(existing.labels))) ? attrs : Unowned(attrs); |
| 558 | }), |
| 559 | |
| 560 | list: () => |
| 561 | Effect.gen(function* () { |
| 562 | const env = yield* GcpEnvironment.current; |
| 563 | const items = yield* listOwned(env.project); |
| 564 | return items.map((item) => toAttrs(item, env.project, env.region)); |
| 565 | }), |
| 566 | |
| 567 | reconcile: Effect.fn(function* ({ id, news, output }) { |
| 568 | const env = yield* GcpEnvironment.current; |
| 569 | const volumeId = yield* toPhysicalId(id, news.volumeId, output?.volumeId, "volume"); |
| 570 | const location = normalizeLocation(news.location ?? output?.location, env.region); |
| 571 | const name = resourceName(env.project, location, volumeId); |
| 572 | // Volumes reference their pool by id; a full resource name is rejected |
| 573 | // with `BadRequest: specified storage pool not found`. |
| 574 | const storagePool = lastSegment(news.storagePool); |
| 575 | const shareName = news.shareName ?? volumeId; |
| 576 | const protocols = news.protocols ?? [DEFAULT_PROTOCOL]; |
| 577 | const capacityGib = gibOf(news.capacityGib ?? DEFAULT_CAPACITY_GIB); |
| 578 | const desiredLabels = { |
| 579 | ...toLabels(news.labels), |
| 580 | ...(yield* createInternalLabels(id)), |
| 581 | }; |
| 582 | const backupConfig = desiredBackupConfig(env.project, location, news.backupConfig); |
| 583 | const blockDevices = news.blockDevices?.map((device) => ({ |
| 584 | osType: device.osType, |
| 585 | name: device.name, |
| 586 | sizeGib: gibOf(device.sizeGib), |
| 587 | hostGroups: device.hostGroups?.map((group) => |
| 588 | expandParent(group, env.project, location, "hostGroups"), |
| 589 | ), |
| 590 | })); |
| 591 | |
| 592 | let current = yield* getByName(output?.name ?? name); |
| 593 | |
| 594 | if (current === undefined) { |
| 595 | const created = yield* netapp |
| 596 | .createProjectsLocationsVolumes({ |
| 597 | parent: parentOf(env.project, location), |
| 598 | volumeId, |
| 599 | body: { |
| 600 | storagePool, |
| 601 | shareName, |
| 602 | protocols, |
| 603 | capacityGib, |
| 604 | unixPermissions: news.unixPermissions, |
| 605 | securityStyle: news.securityStyle, |
| 606 | snapReserve: news.snapReserve, |
| 607 | snapshotDirectory: news.snapshotDirectory, |
| 608 | throughputMibps: news.throughputMibps, |
| 609 | kerberosEnabled: news.kerberosEnabled, |
| 610 | smbSettings: news.smbSettings, |
| 611 | restrictedActions: news.restrictedActions, |
| 612 | exportPolicy: news.exportPolicy, |
| 613 | snapshotPolicy: news.snapshotPolicy, |
| 614 | backupConfig, |
| 615 | tieringPolicy: news.tieringPolicy, |
| 616 | restoreParameters: news.restoreParameters, |
| 617 | blockDevices, |
| 618 | largeCapacity: news.largeCapacity, |
| 619 | largeCapacityConfig: news.largeCapacityConfig, |
| 620 | multipleEndpoints: news.multipleEndpoints, |
| 621 | description: news.description, |
| 622 | labels: desiredLabels, |
| 623 | }, |
| 624 | }) |
| 625 | .pipe(Effect.catchTag("Conflict", () => Effect.undefined)); |
| 626 | if (created !== undefined) { |
| 627 | yield* waitForOperation(created); |
| 628 | } |
| 629 | current = yield* waitUntilExists(getByName(name), name); |
| 630 | } |
| 631 | |
| 632 | if (current === undefined) { |
| 633 | return yield* new ResourceNotResolved({ resourceName: name }); |
| 634 | } |
| 635 | |
| 636 | current = yield* waitUntilReady( |
| 637 | getByName(current.name ?? name), |
| 638 | current.name ?? name, |
| 639 | (item) => item.state, |
| 640 | (item) => item.stateDetails, |
| 641 | ); |
| 642 | |
| 643 | const observedLabels = tagRecord(current.labels); |
| 644 | const { upsert, removed } = diffLabels(observedLabels, desiredLabels); |
| 645 | const mask = fieldMask([ |
| 646 | (upsert.length > 0 || removed.length > 0) && "labels", |
| 647 | (current.description ?? "") !== (news.description ?? "") && "description", |
| 648 | (current.capacityGib ?? "") !== (capacityGib ?? "") && "capacityGib", |
| 649 | news.unixPermissions !== undefined && |
| 650 | (current.unixPermissions ?? "") !== news.unixPermissions && |
| 651 | "unixPermissions", |
| 652 | news.snapReserve !== undefined && |
| 653 | (current.snapReserve ?? 0) !== news.snapReserve && |
| 654 | "snapReserve", |
| 655 | news.snapshotDirectory !== undefined && |
| 656 | (current.snapshotDirectory ?? false) !== news.snapshotDirectory && |
| 657 | "snapshotDirectory", |
| 658 | news.throughputMibps !== undefined && |
| 659 | (current.throughputMibps ?? 0) !== news.throughputMibps && |
| 660 | "throughputMibps", |
| 661 | news.smbSettings !== undefined && |
| 662 | !sameStringList(current.smbSettings, news.smbSettings) && |
| 663 | "smbSettings", |
| 664 | news.restrictedActions !== undefined && |
| 665 | !sameStringList(current.restrictedActions, news.restrictedActions) && |
| 666 | "restrictedActions", |
| 667 | news.exportPolicy !== undefined && |
| 668 | fingerprint(toExportPolicy(current.exportPolicy)) !== fingerprint(news.exportPolicy) && |
| 669 | "exportPolicy", |
| 670 | news.snapshotPolicy !== undefined && |
| 671 | fingerprint(toSnapshotPolicy(current.snapshotPolicy)) !== |
| 672 | fingerprint(news.snapshotPolicy) && |
| 673 | "snapshotPolicy", |
| 674 | news.backupConfig !== undefined && |
| 675 | fingerprint(toBackupConfig(current.backupConfig)) !== fingerprint(backupConfig) && |
| 676 | "backupConfig", |
| 677 | news.tieringPolicy !== undefined && |
| 678 | fingerprint(toTieringPolicy(current.tieringPolicy)) !== fingerprint(news.tieringPolicy) && |
| 679 | "tieringPolicy", |
| 680 | news.blockDevices !== undefined && |
| 681 | fingerprint(current.blockDevices) !== fingerprint(blockDevices) && |
| 682 | "blockDevices", |
| 683 | ]); |
| 684 | |
| 685 | if (mask.length > 0) { |
| 686 | const operation = yield* netapp.patchProjectsLocationsVolumes({ |
| 687 | name: current.name ?? name, |
| 688 | updateMask: mask, |
| 689 | body: { |
| 690 | name: current.name ?? name, |
| 691 | labels: desiredLabels, |
| 692 | description: news.description, |
| 693 | capacityGib, |
| 694 | unixPermissions: news.unixPermissions, |
| 695 | snapReserve: news.snapReserve, |
| 696 | snapshotDirectory: news.snapshotDirectory, |
| 697 | throughputMibps: news.throughputMibps, |
| 698 | smbSettings: news.smbSettings, |
| 699 | restrictedActions: news.restrictedActions, |
| 700 | exportPolicy: news.exportPolicy, |
| 701 | snapshotPolicy: news.snapshotPolicy, |
| 702 | backupConfig, |
| 703 | tieringPolicy: news.tieringPolicy, |
| 704 | blockDevices, |
| 705 | }, |
| 706 | }); |
| 707 | yield* waitForOperation(operation); |
| 708 | current = yield* waitUntilReady( |
| 709 | getByName(current.name ?? name), |
| 710 | current.name ?? name, |
| 711 | (item) => item.state, |
| 712 | (item) => item.stateDetails, |
| 713 | ); |
| 714 | } |
| 715 | |
| 716 | return toAttrs(current, env.project, env.region); |
| 717 | }), |
| 718 | |
| 719 | delete: Effect.fn(function* ({ output }) { |
| 720 | const operation = yield* netapp.deleteProjectsLocationsVolumes({ name: output.name }).pipe( |
| 721 | Effect.retry({ |
| 722 | while: (error) => error._tag === "Conflict", |
| 723 | times: 8, |
| 724 | schedule: Schedule.spaced("2 seconds"), |
| 725 | }), |
| 726 | Effect.catchTag("NotFound", () => Effect.undefined), |
| 727 | ); |
| 728 | if (operation !== undefined) { |
| 729 | yield* waitForDeleteOperation(operation); |
| 730 | } |
| 731 | yield* waitUntilGone(getByName(output.name), output.name); |
| 732 | }), |
| 733 | }); |