sillydev 1.0.0 → 1.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.
- checksums.yaml +4 -4
- data/README.md +56 -6
- data/lib/sillydev/cli.rb +510 -3
- data/lib/sillydev/client.rb +35 -8
- data/lib/sillydev/console.rb +17 -0
- data/lib/sillydev/errors.rb +24 -4
- data/lib/sillydev/mcp_server.rb +255 -10
- data/lib/sillydev/monitoring/client.rb +23 -3
- data/lib/sillydev/monitoring/runtime.rb +5 -5
- data/lib/sillydev/monitoring.rb +11 -1
- data/lib/sillydev/resources.rb +365 -27
- data/lib/sillydev/version.rb +1 -1
- metadata +2 -2
data/lib/sillydev/resources.rb
CHANGED
|
@@ -101,16 +101,29 @@ module SillyDev
|
|
|
101
101
|
# SillyDev::WaitTimeoutError if it isn't after timeout seconds. For example
|
|
102
102
|
# servers.start(id) then servers.wait_for_state(id). operationId: getServerResources
|
|
103
103
|
def wait_for_state(server, state = "running", timeout: 120.0, interval: 2.0)
|
|
104
|
+
raise ArgumentError, "timeout and interval must not be negative" if timeout.negative? || interval.negative?
|
|
105
|
+
|
|
106
|
+
interval = [interval, 0.5].max # never poll the panel in a tight loop
|
|
104
107
|
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout
|
|
108
|
+
now_state = nil
|
|
105
109
|
loop do
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
# A check that fails (a timeout, a 5xx) doesn't end the wait; one that can't succeed (the
|
|
111
|
+
# server is gone, the key may not see it) does.
|
|
112
|
+
last_error = nil
|
|
113
|
+
begin
|
|
114
|
+
current = resources(server)
|
|
115
|
+
now_state = current["current_state"] if current.is_a?(Hash)
|
|
116
|
+
return current if current.is_a?(Hash) && current["current_state"] == state
|
|
117
|
+
rescue AuthenticationError, PermissionDeniedError, NotFoundError
|
|
118
|
+
raise
|
|
119
|
+
rescue Error => e
|
|
120
|
+
last_error = e
|
|
121
|
+
end
|
|
108
122
|
|
|
109
|
-
now_state = current.is_a?(Hash) ? current["current_state"] : nil
|
|
110
123
|
remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
111
124
|
if remaining <= 0
|
|
112
125
|
raise WaitTimeoutError.new("server #{server} is #{now_state}, not #{state}, after #{timeout} seconds",
|
|
113
|
-
state: now_state)
|
|
126
|
+
state: now_state, last_error: last_error)
|
|
114
127
|
end
|
|
115
128
|
|
|
116
129
|
@client.sleeper.call([interval, remaining].min)
|
|
@@ -210,7 +223,7 @@ module SillyDev
|
|
|
210
223
|
end
|
|
211
224
|
end
|
|
212
225
|
|
|
213
|
-
# Rename, reinstall, change the Docker image
|
|
226
|
+
# Rename, reinstall, change the Docker image, the status badge and alerts (tag Settings).
|
|
214
227
|
class Settings < Base
|
|
215
228
|
# Rename a server and optionally change its description. operationId: renameServer
|
|
216
229
|
def rename(server, name, description: nil)
|
|
@@ -246,6 +259,46 @@ module SillyDev
|
|
|
246
259
|
def disable_badge(server)
|
|
247
260
|
req("DELETE", "#{server_path(server)}/settings/badge")
|
|
248
261
|
end
|
|
262
|
+
|
|
263
|
+
# Crash, memory and disk alerts: {"email", "events", "disk_percent", "webhook", ...}. operationId: getServerAlerts
|
|
264
|
+
def alerts(server)
|
|
265
|
+
req("GET", "#{server_path(server)}/alerts")
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
# Change which alerts are sent and where. events maps "crash", "crash_loop", "oom" and "disk" to
|
|
269
|
+
# true or false; remove_webhook: true removes the webhook. operationId: updateServerAlerts
|
|
270
|
+
def update_alerts(server, email: nil, events: nil, disk_percent: nil, webhook_url: nil, remove_webhook: false,
|
|
271
|
+
rotate_secret: nil)
|
|
272
|
+
payload = body(email: email, events: events, disk_percent: disk_percent, webhook_url: webhook_url,
|
|
273
|
+
rotate_secret: rotate_secret)
|
|
274
|
+
payload["webhook_url"] = nil if remove_webhook
|
|
275
|
+
req("PUT", "#{server_path(server)}/alerts", json: payload)
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
# Send a test alert to the server's email and webhook (a few an hour). operationId: sendTestServerAlert
|
|
279
|
+
def send_test_alert(server)
|
|
280
|
+
req("POST", "#{server_path(server)}/alerts/test")
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# The webhook's last 15 deliveries, newest first. operationId: listWebhookDeliveries
|
|
284
|
+
def alert_deliveries(server)
|
|
285
|
+
req("GET", "#{server_path(server)}/alerts/deliveries")
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
# Where a paid server can move, whether a backup is made first, and any move waiting. operationId: getNodeMove
|
|
289
|
+
def node_move(server)
|
|
290
|
+
req("GET", "#{server_path(server)}/settings/node-move")
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
# Move a paid server to another node kept for paid servers, after a backup if it has a slot spare. operationId: moveServerToNode
|
|
294
|
+
def move_to_node(server, node)
|
|
295
|
+
req("POST", "#{server_path(server)}/settings/node-move", json: { node: node })
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
# Clear a move that did not go ahead. operationId: dismissNodeMove
|
|
299
|
+
def dismiss_node_move(server)
|
|
300
|
+
req("DELETE", "#{server_path(server)}/settings/node-move")
|
|
301
|
+
end
|
|
249
302
|
end
|
|
250
303
|
|
|
251
304
|
# The startup command and variables (tag Startup).
|
|
@@ -365,9 +418,10 @@ module SillyDev
|
|
|
365
418
|
req("DELETE", "#{server_path(server)}/backups/#{seg(backup)}")
|
|
366
419
|
end
|
|
367
420
|
|
|
368
|
-
# A single-use download link for a backup, valid for 15 minutes.
|
|
369
|
-
|
|
370
|
-
|
|
421
|
+
# A single-use download link for a backup, valid for 15 minutes. source: "remote" is the copy
|
|
422
|
+
# in the server's own bucket. operationId: getBackupDownloadUrl
|
|
423
|
+
def download_url(server, backup, source: nil)
|
|
424
|
+
req("GET", "#{server_path(server)}/backups/#{seg(backup)}/download", params: body(source: source))["url"].to_s
|
|
371
425
|
end
|
|
372
426
|
|
|
373
427
|
# Lock an unlocked backup or unlock a locked one. operationId: toggleBackupLock
|
|
@@ -375,17 +429,53 @@ module SillyDev
|
|
|
375
429
|
req("POST", "#{server_path(server)}/backups/#{seg(backup)}/lock")
|
|
376
430
|
end
|
|
377
431
|
|
|
432
|
+
# Try the copy to the server's own bucket again after it failed; the copy is queued. operationId: retryBackupCopy
|
|
433
|
+
def retry_copy(server, backup)
|
|
434
|
+
req("POST", "#{server_path(server)}/backups/#{seg(backup)}/copy")
|
|
435
|
+
end
|
|
436
|
+
|
|
378
437
|
# Restore a backup; truncate: true deletes every file first. operationId: restoreBackup
|
|
379
|
-
def restore(server, backup, truncate: false)
|
|
380
|
-
req("POST", "#{server_path(server)}/backups/#{seg(backup)}/restore", json:
|
|
438
|
+
def restore(server, backup, truncate: false, source: nil)
|
|
439
|
+
req("POST", "#{server_path(server)}/backups/#{seg(backup)}/restore", json: body(truncate: truncate, source: source))
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
# Whether copying backups to your own bucket is available, and the bucket set up (never its keys). operationId: getBackupDestination
|
|
443
|
+
def destination(server)
|
|
444
|
+
req("GET", "#{server_path(server)}/backups/destination")
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
# Set up or change the S3-compatible bucket backups are copied to, or pause it with
|
|
448
|
+
# enabled: false. clear_endpoint: true sends a null endpoint, which moves the bucket back to
|
|
449
|
+
# Amazon S3. Owner only; the bucket is tested first. operationId: updateBackupDestination
|
|
450
|
+
def set_destination(server, bucket: nil, access_key: nil, secret_key: nil, endpoint: nil, region: nil,
|
|
451
|
+
prefix: nil, path_style: nil, enabled: nil, clear_endpoint: false)
|
|
452
|
+
payload = body(bucket: bucket, access_key: access_key, secret_key: secret_key, endpoint: endpoint,
|
|
453
|
+
region: region, prefix: prefix, path_style: path_style, enabled: enabled)
|
|
454
|
+
payload["endpoint"] = nil if clear_endpoint
|
|
455
|
+
req("PUT", "#{server_path(server)}/backups/destination", json: payload)
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
# Write, read and delete a small test file in the saved bucket. operationId: testBackupDestination
|
|
459
|
+
def test_destination(server)
|
|
460
|
+
req("POST", "#{server_path(server)}/backups/destination/test")
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
# Forget the bucket and its keys; copies already in it are kept. operationId: deleteBackupDestination
|
|
464
|
+
def delete_destination(server)
|
|
465
|
+
req("DELETE", "#{server_path(server)}/backups/destination")
|
|
381
466
|
end
|
|
382
467
|
end
|
|
383
468
|
|
|
384
469
|
# Schedules and their tasks (tag Schedules).
|
|
385
470
|
class Schedules < Base
|
|
386
|
-
# Every schedule on the server, with its tasks. operationId: listSchedules
|
|
471
|
+
# Every schedule on the server, with its tasks, fetching every page. operationId: listSchedules
|
|
387
472
|
def list(server)
|
|
388
|
-
|
|
473
|
+
@client.paginate("#{server_path(server)}/schedules", { per_page: 100 }).to_a
|
|
474
|
+
end
|
|
475
|
+
|
|
476
|
+
# One page of schedules (50 a page unless per_page says otherwise, at most 100). operationId: listSchedules
|
|
477
|
+
def list_page(server, page: 1, per_page: nil)
|
|
478
|
+
@client.page("#{server_path(server)}/schedules", { page: page, per_page: per_page })
|
|
389
479
|
end
|
|
390
480
|
|
|
391
481
|
# Create a schedule from a cron timetable. operationId: createSchedule
|
|
@@ -441,9 +531,14 @@ module SillyDev
|
|
|
441
531
|
|
|
442
532
|
# The server's allocations, its IP and port pairs (tag Network).
|
|
443
533
|
class Network < Base
|
|
444
|
-
# Every allocation on the server. operationId: listAllocations
|
|
534
|
+
# Every allocation on the server, fetching every page. operationId: listAllocations
|
|
445
535
|
def list(server)
|
|
446
|
-
|
|
536
|
+
@client.paginate("#{server_path(server)}/network/allocations", { per_page: 100 }).to_a
|
|
537
|
+
end
|
|
538
|
+
|
|
539
|
+
# One page of allocations (50 a page unless per_page says otherwise, at most 100). operationId: listAllocations
|
|
540
|
+
def list_page(server, page: 1, per_page: nil)
|
|
541
|
+
@client.page("#{server_path(server)}/network/allocations", { page: page, per_page: per_page })
|
|
447
542
|
end
|
|
448
543
|
|
|
449
544
|
# Add a port, where an administrator has allowed it. operationId: createAllocation
|
|
@@ -469,9 +564,14 @@ module SillyDev
|
|
|
469
564
|
|
|
470
565
|
# Other accounts with access to the server (tag Subusers).
|
|
471
566
|
class Subusers < Base
|
|
472
|
-
# Every subuser of the server. operationId: listSubusers
|
|
567
|
+
# Every subuser of the server, fetching every page. operationId: listSubusers
|
|
473
568
|
def list(server)
|
|
474
|
-
|
|
569
|
+
@client.paginate("#{server_path(server)}/users", { per_page: 100 }).to_a
|
|
570
|
+
end
|
|
571
|
+
|
|
572
|
+
# One page of subusers (50 a page unless per_page says otherwise, at most 100). operationId: listSubusers
|
|
573
|
+
def list_page(server, page: 1, per_page: nil)
|
|
574
|
+
@client.page("#{server_path(server)}/users", { page: page, per_page: per_page })
|
|
475
575
|
end
|
|
476
576
|
|
|
477
577
|
# Invite an account by email with a list of permissions. operationId: createSubuser
|
|
@@ -504,12 +604,15 @@ module SillyDev
|
|
|
504
604
|
|
|
505
605
|
# Link a repository ("github", "gitlab" or "url" source), or change the link's settings. operationId: linkGitRepository
|
|
506
606
|
def link(server, source:, repository:, branch:, installation: nil, directory: nil, auto_deploy: nil,
|
|
507
|
-
|
|
607
|
+
skip_marked_commits: nil, report_deployments: nil, restart_on_deploy: nil, start_if_offline: nil,
|
|
608
|
+
apply_config: nil, sync_startup: nil, write_config: nil, release_command: nil, auto_rollback: nil)
|
|
508
609
|
req("PUT", "#{server_path(server)}/git",
|
|
509
610
|
json: body(source: source, installation: installation, repository: repository, branch: branch,
|
|
510
|
-
directory: directory, auto_deploy: auto_deploy,
|
|
611
|
+
directory: directory, auto_deploy: auto_deploy, skip_marked_commits: skip_marked_commits,
|
|
612
|
+
report_deployments: report_deployments, restart_on_deploy: restart_on_deploy,
|
|
511
613
|
start_if_offline: start_if_offline, apply_config: apply_config, sync_startup: sync_startup,
|
|
512
|
-
write_config: write_config
|
|
614
|
+
write_config: write_config, release_command: release_command,
|
|
615
|
+
auto_rollback: auto_rollback))
|
|
513
616
|
end
|
|
514
617
|
|
|
515
618
|
# Unlink the repository; the files stay. operationId: unlinkGitRepository
|
|
@@ -532,6 +635,23 @@ module SillyDev
|
|
|
532
635
|
req("POST", "#{server_path(server)}/git/deployments/#{seg(deployment)}/cancel")
|
|
533
636
|
end
|
|
534
637
|
|
|
638
|
+
# One deployment, with "output": what its build step and release command printed. operationId: getGitDeployment
|
|
639
|
+
def deployment(server, deployment)
|
|
640
|
+
req("GET", "#{server_path(server)}/git/deployments/#{seg(deployment)}")
|
|
641
|
+
end
|
|
642
|
+
|
|
643
|
+
# Deploy an earlier deployment's commit again (a rollback); auto deploy pauses until #resume.
|
|
644
|
+
# Pass previous["uuid"] from #get to roll back to the previous deployment. operationId: redeployGitDeployment
|
|
645
|
+
def redeploy(server, deployment)
|
|
646
|
+
req("POST", "#{server_path(server)}/git/deployments/#{seg(deployment)}/redeploy")
|
|
647
|
+
end
|
|
648
|
+
|
|
649
|
+
# Resume auto deploy after a rollback; deploy: true also deploys the newest commit.
|
|
650
|
+
# Returns {"repository", "deployment"}. operationId: resumeGitDeploys
|
|
651
|
+
def resume(server, deploy: nil)
|
|
652
|
+
req("POST", "#{server_path(server)}/git/resume", json: body(deploy: deploy))
|
|
653
|
+
end
|
|
654
|
+
|
|
535
655
|
# A sillydev.conf written from the server's current settings. operationId: getGitConfigTemplate
|
|
536
656
|
def config_template(server)
|
|
537
657
|
req("GET", "#{server_path(server)}/git/config")
|
|
@@ -561,6 +681,12 @@ module SillyDev
|
|
|
561
681
|
req("GET", "/account")
|
|
562
682
|
end
|
|
563
683
|
|
|
684
|
+
# The Discord, Google and GitHub accounts it signs in with, and whether it has a password
|
|
685
|
+
# (has_password). operationId: listSignInMethods
|
|
686
|
+
def sign_in_methods
|
|
687
|
+
req("GET", "/account/sign-in-methods")
|
|
688
|
+
end
|
|
689
|
+
|
|
564
690
|
# The account's activity log, fetching page after page. operationId: listAccountActivity
|
|
565
691
|
def activity(event: nil, sort: nil, include: nil, per_page: nil)
|
|
566
692
|
@client.paginate("/account/activity",
|
|
@@ -572,6 +698,46 @@ module SillyDev
|
|
|
572
698
|
@client.page("/account/activity",
|
|
573
699
|
{ page: page, per_page: per_page, "filter[event]" => event, sort: sort, include: include })
|
|
574
700
|
end
|
|
701
|
+
|
|
702
|
+
# Whether the account is emailed about status page incidents, and its Discord webhooks:
|
|
703
|
+
# {"available", "presets", "email" => {"subscribed", "preset"}, "discord" => [...]}. A webhook's URL is
|
|
704
|
+
# never returned. operationId: getStatusSubscription
|
|
705
|
+
def get_status_subscription
|
|
706
|
+
req("GET", "/account/status-subscription")["data"]
|
|
707
|
+
end
|
|
708
|
+
|
|
709
|
+
# Turn status page incident emails to the account's own address on or off. preset is "everything",
|
|
710
|
+
# "new_resolved" or "major"; left out, it keeps the current choice. Needs the status.write scope.
|
|
711
|
+
# operationId: updateStatusSubscription
|
|
712
|
+
def update_status_subscription(subscribed:, preset: nil)
|
|
713
|
+
req("PUT", "/account/status-subscription", json: body(subscribed: subscribed, preset: preset))["data"]
|
|
714
|
+
end
|
|
715
|
+
|
|
716
|
+
# Send status page incidents to a Discord webhook (https://discord.com/api/webhooks/<id>/<token>); a test
|
|
717
|
+
# message is sent first and the webhook is only kept if it arrives. Returns the subscriptions. Needs the
|
|
718
|
+
# status.write scope. operationId: addStatusDiscordWebhook
|
|
719
|
+
def add_status_discord_webhook(url:, label: nil, preset: nil)
|
|
720
|
+
req("POST", "/account/status-subscription/discord", json: body(url: url, label: label, preset: preset))["data"]
|
|
721
|
+
end
|
|
722
|
+
|
|
723
|
+
# Stop sending status page incidents to a Discord webhook, by its ID from the subscriptions. Needs the
|
|
724
|
+
# status.write scope. operationId: removeStatusDiscordWebhook
|
|
725
|
+
def remove_status_discord_webhook(webhook_id)
|
|
726
|
+
req("DELETE", "/account/status-subscription/discord/#{seg(webhook_id)}")
|
|
727
|
+
end
|
|
728
|
+
|
|
729
|
+
# The account's passkeys (name, device, synced, created_at, last_used_at), without key
|
|
730
|
+
# material. Adding and removing them is only possible in the panel. operationId: listAccountPasskeys
|
|
731
|
+
def passkeys
|
|
732
|
+
req("GET", "/account/passkeys")
|
|
733
|
+
end
|
|
734
|
+
|
|
735
|
+
# The browsers the account is signed in on, most recently active first (browser, platform, ip_address,
|
|
736
|
+
# current, created_at, last_active_at). With an API key none is marked current. Signing them out is only
|
|
737
|
+
# possible in the panel. operationId: listAccountSessions
|
|
738
|
+
def sessions
|
|
739
|
+
req("GET", "/account/sessions")
|
|
740
|
+
end
|
|
575
741
|
end
|
|
576
742
|
|
|
577
743
|
# Create free servers (tag Server creation).
|
|
@@ -587,16 +753,61 @@ module SillyDev
|
|
|
587
753
|
end
|
|
588
754
|
end
|
|
589
755
|
|
|
590
|
-
# The account's free MariaDB and Postgres databases (tag Databases).
|
|
756
|
+
# The account's free MariaDB and Postgres databases and Redis (Valkey) stores (tag Databases).
|
|
757
|
+
#
|
|
758
|
+
# Keys of a Redis store are given as strings (any bytes); they travel as hex, so keys that are
|
|
759
|
+
# not text work too. Listed keys carry "key_hex": pass [hex].pack("H*") back.
|
|
591
760
|
class Databases < Base
|
|
592
761
|
# {"limit", "owned", "can_create", "quota_bytes", "versions", "databases"}. operationId: listDatabases
|
|
593
762
|
def list
|
|
594
763
|
req("GET", "/databases")
|
|
595
764
|
end
|
|
596
765
|
|
|
597
|
-
# Create a database; the result holds its password.
|
|
598
|
-
|
|
599
|
-
|
|
766
|
+
# Create a database or, on a valkey version, a Redis store; the result holds its password.
|
|
767
|
+
# eviction_policy: (Redis stores only) is what happens when the store is full, such as
|
|
768
|
+
# "allkeys-lru" (the default) or "noeviction". operationId: createDatabase
|
|
769
|
+
def create(label:, version_id:, eviction_policy: nil)
|
|
770
|
+
req("POST", "/databases", json: body(label: label, version_id: version_id, eviction_policy: eviction_policy))
|
|
771
|
+
end
|
|
772
|
+
|
|
773
|
+
# Change what a Redis store does when full. operationId: setDatabaseEvictionPolicy
|
|
774
|
+
def set_eviction_policy(database, eviction_policy)
|
|
775
|
+
req("POST", "/databases/#{seg(database)}/eviction-policy", json: { "eviction_policy" => eviction_policy })
|
|
776
|
+
end
|
|
777
|
+
|
|
778
|
+
# One SCAN page of a Redis store's keys: {"cursor", "keys"}. Send cursor back until it is "0".
|
|
779
|
+
# operationId: listStoreKeys
|
|
780
|
+
def list_keys(database, pattern: nil, cursor: nil, count: nil, db: nil)
|
|
781
|
+
check_count(count)
|
|
782
|
+
req("POST", "/databases/#{seg(database)}/explorer/keys",
|
|
783
|
+
json: body(pattern: pattern, cursor: cursor, count: count, db: db))
|
|
784
|
+
end
|
|
785
|
+
|
|
786
|
+
# A key's type, expiry and value (a string's "value", or a page of "items"). operationId: getStoreKey
|
|
787
|
+
def get_key(database, key, cursor: nil, count: nil, db: nil)
|
|
788
|
+
check_count(count)
|
|
789
|
+
req("POST", "/databases/#{seg(database)}/explorer/keys/value",
|
|
790
|
+
json: body(key_hex: key_hex(key), cursor: cursor, count: count, db: db))
|
|
791
|
+
end
|
|
792
|
+
|
|
793
|
+
# Set a string, or with field: one field of a hash. operationId: setStoreKey
|
|
794
|
+
def set_key(database, key, value, field: nil, ttl_seconds: nil, db: nil)
|
|
795
|
+
req("POST", "/databases/#{seg(database)}/explorer/keys/set",
|
|
796
|
+
json: body(key_hex: key_hex(key), value: value, field: field, ttl_seconds: ttl_seconds, db: db))
|
|
797
|
+
end
|
|
798
|
+
|
|
799
|
+
# Set how many seconds a key lives; 0 removes its expiry. operationId: expireStoreKey
|
|
800
|
+
def expire_key(database, key, ttl_seconds, db: nil)
|
|
801
|
+
req("POST", "/databases/#{seg(database)}/explorer/keys/expire",
|
|
802
|
+
json: body(key_hex: key_hex(key), ttl_seconds: ttl_seconds, db: db))
|
|
803
|
+
end
|
|
804
|
+
|
|
805
|
+
# Delete 1 to 100 keys: {"deleted" => n}. operationId: deleteStoreKeys
|
|
806
|
+
def delete_keys(database, keys, db: nil)
|
|
807
|
+
raise ArgumentError, "delete_keys takes 1 to 100 keys" unless (1..100).cover?(Array(keys).size)
|
|
808
|
+
|
|
809
|
+
req("POST", "/databases/#{seg(database)}/explorer/keys/delete",
|
|
810
|
+
json: body(keys_hex: Array(keys).map { |k| key_hex(k) }, db: db))
|
|
600
811
|
end
|
|
601
812
|
|
|
602
813
|
# Give the database a new password. operationId: rotateDatabasePassword
|
|
@@ -623,6 +834,83 @@ module SillyDev
|
|
|
623
834
|
def delete(database)
|
|
624
835
|
req("DELETE", "/databases/#{seg(database)}")
|
|
625
836
|
end
|
|
837
|
+
|
|
838
|
+
# The database's backups (newest first), schedule state and how many manual backups are left
|
|
839
|
+
# today. operationId: listDatabaseBackups
|
|
840
|
+
def backups(database)
|
|
841
|
+
req("GET", "/databases/#{seg(database)}/backups")
|
|
842
|
+
end
|
|
843
|
+
|
|
844
|
+
# Back the database up now (a few a day). operationId: createDatabaseBackup
|
|
845
|
+
def back_up(database)
|
|
846
|
+
req("POST", "/databases/#{seg(database)}/backups")
|
|
847
|
+
end
|
|
848
|
+
|
|
849
|
+
# Keep a backup past retention (paid plans). operationId: pinDatabaseBackup
|
|
850
|
+
def pin_backup(database, backup)
|
|
851
|
+
req("POST", "/databases/#{seg(database)}/backups/#{seg(backup)}/pin")
|
|
852
|
+
end
|
|
853
|
+
|
|
854
|
+
# Let retention have a pinned backup again. operationId: unpinDatabaseBackup
|
|
855
|
+
def unpin_backup(database, backup)
|
|
856
|
+
req("DELETE", "/databases/#{seg(database)}/backups/#{seg(backup)}/pin")
|
|
857
|
+
end
|
|
858
|
+
|
|
859
|
+
# A backup as a gzipped SQL dump (.sql.gz), as a binary String. operationId: downloadDatabaseBackup
|
|
860
|
+
def download_backup(database, backup)
|
|
861
|
+
req("GET", "/databases/#{seg(database)}/backups/#{seg(backup)}/download", text: true).b
|
|
862
|
+
end
|
|
863
|
+
|
|
864
|
+
# Restore a backup into the database itself (undoable), or with new_label: and version_id:
|
|
865
|
+
# into a new database. Returns the database being restored; poll #list until its status is
|
|
866
|
+
# "ready". operationId: restoreDatabaseBackup
|
|
867
|
+
def restore_backup(database, backup, new_label: nil, version_id: nil)
|
|
868
|
+
raise ArgumentError, "restore_backup needs new_label and version_id together, or neither" if new_label.nil? != version_id.nil?
|
|
869
|
+
|
|
870
|
+
body = if new_label.nil?
|
|
871
|
+
{ "target" => "same" }
|
|
872
|
+
else
|
|
873
|
+
{ "target" => "new", "label" => new_label, "version_id" => version_id }
|
|
874
|
+
end
|
|
875
|
+
req("POST", "/databases/#{seg(database)}/backups/#{seg(backup)}/restore", json: body)
|
|
876
|
+
end
|
|
877
|
+
|
|
878
|
+
# Put back what the database held before its last restore. operationId: undoDatabaseRestore
|
|
879
|
+
def undo_restore(database)
|
|
880
|
+
req("POST", "/databases/#{seg(database)}/undo-restore")
|
|
881
|
+
end
|
|
882
|
+
|
|
883
|
+
# Keep the last restore, deleting the backup that could undo it. operationId: keepDatabaseRestore
|
|
884
|
+
def keep_restore(database)
|
|
885
|
+
req("POST", "/databases/#{seg(database)}/keep-restore")
|
|
886
|
+
end
|
|
887
|
+
|
|
888
|
+
# Deleted databases whose backups are still kept. operationId: listDeletedDatabases
|
|
889
|
+
def deleted
|
|
890
|
+
req("GET", "/databases/deleted-backups")
|
|
891
|
+
end
|
|
892
|
+
|
|
893
|
+
# A deleted database's backup as a gzipped SQL dump. operationId: downloadDeletedDatabaseBackup
|
|
894
|
+
def download_deleted_backup(archive, backup)
|
|
895
|
+
req("GET", "/databases/deleted-backups/#{seg(archive)}/backups/#{seg(backup)}/download", text: true).b
|
|
896
|
+
end
|
|
897
|
+
|
|
898
|
+
# Restore a deleted database's backup into a new database. operationId: restoreDeletedDatabaseBackup
|
|
899
|
+
def restore_deleted_backup(archive, backup, label:, version_id:)
|
|
900
|
+
req("POST", "/databases/deleted-backups/#{seg(archive)}/backups/#{seg(backup)}/restore",
|
|
901
|
+
json: { "label" => label, "version_id" => version_id })
|
|
902
|
+
end
|
|
903
|
+
|
|
904
|
+
private
|
|
905
|
+
|
|
906
|
+
def check_count(count)
|
|
907
|
+
raise ArgumentError, "count is 1 to 500" unless count.nil? || (1..500).cover?(count)
|
|
908
|
+
end
|
|
909
|
+
|
|
910
|
+
# A Redis store key as the API takes it: its bytes as hex.
|
|
911
|
+
def key_hex(key)
|
|
912
|
+
key.to_s.b.unpack1("H*")
|
|
913
|
+
end
|
|
626
914
|
end
|
|
627
915
|
|
|
628
916
|
# Paid servers and databases (tag Billing). Prices are in pence.
|
|
@@ -633,14 +921,17 @@ module SillyDev
|
|
|
633
921
|
end
|
|
634
922
|
|
|
635
923
|
# Order a new paid server (name: and runtime:) or upgrade a free one (server_uuid:).
|
|
924
|
+
# free_month_offer: true uses the account's one-time free month offer; pay_with_credit: true
|
|
925
|
+
# pays the first month from account credit alone, with no card.
|
|
636
926
|
#
|
|
637
927
|
# An Idempotency-Key is always sent, so a retried request never buys twice: pass your own
|
|
638
928
|
# idempotency_key: to make retries across runs safe too. operationId: createCheckout
|
|
639
929
|
def checkout(name: nil, runtime: nil, description: nil, server_uuid: nil, use_saved_card: nil,
|
|
640
|
-
promotion_code: nil, plan: nil, idempotency_key: nil)
|
|
930
|
+
promotion_code: nil, plan: nil, free_month_offer: nil, pay_with_credit: nil, idempotency_key: nil)
|
|
641
931
|
req("POST", "/billing/checkout",
|
|
642
932
|
json: body(server_uuid: server_uuid, name: name, description: description, runtime: runtime,
|
|
643
|
-
use_saved_card: use_saved_card, promotion_code: promotion_code, plan: plan
|
|
933
|
+
use_saved_card: use_saved_card, promotion_code: promotion_code, plan: plan,
|
|
934
|
+
free_month_offer: free_month_offer, pay_with_credit: pay_with_credit),
|
|
644
935
|
headers: { "Idempotency-Key" => idempotency_key || SecureRandom.uuid })
|
|
645
936
|
end
|
|
646
937
|
|
|
@@ -678,7 +969,10 @@ module SillyDev
|
|
|
678
969
|
result = credit(view: view, page: number)
|
|
679
970
|
entries = result["data"] || []
|
|
680
971
|
entries.each { |entry| yielder << entry }
|
|
681
|
-
|
|
972
|
+
# Under meta.pagination, like every other list; panels from before that change put it
|
|
973
|
+
# at the top level.
|
|
974
|
+
pagination = (result["meta"] || {})["pagination"] || result["pagination"] || {}
|
|
975
|
+
pages = (pagination["total_pages"] || 1).to_i
|
|
682
976
|
break if entries.empty? || number >= pages
|
|
683
977
|
|
|
684
978
|
number += 1
|
|
@@ -803,12 +1097,55 @@ module SillyDev
|
|
|
803
1097
|
req("GET", "#{project_path(project)}/usage")
|
|
804
1098
|
end
|
|
805
1099
|
end
|
|
1100
|
+
|
|
1101
|
+
# Dashboard folders and bulk server actions (tag Folders). Only available while an administrator
|
|
1102
|
+
# has switched server folders on; otherwise every method raises NotFoundError. Reading needs the
|
|
1103
|
+
# account.read scope, changing folders needs folders.write. Folders belong to the account alone.
|
|
1104
|
+
#
|
|
1105
|
+
# The folder methods return { "data" => [{ "id", "name", "colour", "position" }],
|
|
1106
|
+
# "meta" => { "assignments" => { server_uuid => folder_id }, "max" => 20 } }.
|
|
1107
|
+
class Folders < Base
|
|
1108
|
+
# The account's folders and which server is in which. operationId: listDashboardFolders
|
|
1109
|
+
def list
|
|
1110
|
+
req("GET", "/account/folders")
|
|
1111
|
+
end
|
|
1112
|
+
|
|
1113
|
+
# Make a folder (up to 20). colour is slate, red, orange, amber, green, teal, blue, violet or pink.
|
|
1114
|
+
# operationId: createDashboardFolder
|
|
1115
|
+
def create(name:, colour:)
|
|
1116
|
+
req("POST", "/account/folders", json: { "name" => name, "colour" => colour })
|
|
1117
|
+
end
|
|
1118
|
+
|
|
1119
|
+
# Rename or recolour a folder. operationId: updateDashboardFolder
|
|
1120
|
+
def update(folder, name: nil, colour: nil)
|
|
1121
|
+
req("PATCH", "/account/folders/#{seg(folder)}", json: body(name: name, colour: colour))
|
|
1122
|
+
end
|
|
1123
|
+
|
|
1124
|
+
# Delete a folder; its servers go back to no folder. operationId: deleteDashboardFolder
|
|
1125
|
+
def delete(folder)
|
|
1126
|
+
req("DELETE", "/account/folders/#{seg(folder)}")
|
|
1127
|
+
end
|
|
1128
|
+
|
|
1129
|
+
# Put servers (by UUID) in a folder, or in none with nil. operationId: assignServersToDashboardFolder
|
|
1130
|
+
def assign(folder, servers)
|
|
1131
|
+
req("PUT", "/account/folders/assign", json: { "folder" => folder, "servers" => servers.to_a })
|
|
1132
|
+
end
|
|
1133
|
+
|
|
1134
|
+
# Start, stop, restart, kill or back up up to 25 servers (by UUID) and report each one:
|
|
1135
|
+
# { "data" => [{ "uuid", "name", "status" => "done" | "skipped" | "failed", "reason" }] }.
|
|
1136
|
+
# operationId: bulkServerAction
|
|
1137
|
+
def bulk(action, servers)
|
|
1138
|
+
raise ArgumentError, "bulk takes at most 25 servers" if servers.to_a.size > 25
|
|
1139
|
+
|
|
1140
|
+
req("POST", "/account/servers/bulk", json: { "action" => action, "servers" => servers.to_a })
|
|
1141
|
+
end
|
|
1142
|
+
end
|
|
806
1143
|
end
|
|
807
1144
|
|
|
808
1145
|
# The panel API: client.panel.servers, client.panel.files and the rest.
|
|
809
1146
|
class Panel
|
|
810
1147
|
attr_reader :servers, :settings, :startup, :files, :backups, :schedules, :network, :subusers, :git,
|
|
811
|
-
:account, :server_creation, :databases, :billing, :monitoring
|
|
1148
|
+
:account, :server_creation, :databases, :billing, :monitoring, :folders
|
|
812
1149
|
|
|
813
1150
|
def initialize(client)
|
|
814
1151
|
@client = client
|
|
@@ -826,6 +1163,7 @@ module SillyDev
|
|
|
826
1163
|
@databases = Resources::Databases.new(client)
|
|
827
1164
|
@billing = Resources::Billing.new(client)
|
|
828
1165
|
@monitoring = Resources::Monitoring.new(client)
|
|
1166
|
+
@folders = Resources::Folders.new(client)
|
|
829
1167
|
end
|
|
830
1168
|
|
|
831
1169
|
# The live console: websocket, streamed, polled or relayed through the panel. Loaded on first
|
data/lib/sillydev/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sillydev
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Silly Development
|
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
61
61
|
- !ruby/object:Gem::Version
|
|
62
62
|
version: '0'
|
|
63
63
|
requirements: []
|
|
64
|
-
rubygems_version: 3.6.
|
|
64
|
+
rubygems_version: 3.6.7
|
|
65
65
|
specification_version: 4
|
|
66
66
|
summary: Ruby client for the Silly Development panel API
|
|
67
67
|
test_files: []
|