sillydev 1.1.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 +325 -20
- 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)
|
|
@@ -247,6 +260,31 @@ module SillyDev
|
|
|
247
260
|
req("DELETE", "#{server_path(server)}/settings/badge")
|
|
248
261
|
end
|
|
249
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
|
+
|
|
250
288
|
# Where a paid server can move, whether a backup is made first, and any move waiting. operationId: getNodeMove
|
|
251
289
|
def node_move(server)
|
|
252
290
|
req("GET", "#{server_path(server)}/settings/node-move")
|
|
@@ -380,9 +418,10 @@ module SillyDev
|
|
|
380
418
|
req("DELETE", "#{server_path(server)}/backups/#{seg(backup)}")
|
|
381
419
|
end
|
|
382
420
|
|
|
383
|
-
# A single-use download link for a backup, valid for 15 minutes.
|
|
384
|
-
|
|
385
|
-
|
|
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
|
|
386
425
|
end
|
|
387
426
|
|
|
388
427
|
# Lock an unlocked backup or unlock a locked one. operationId: toggleBackupLock
|
|
@@ -390,9 +429,40 @@ module SillyDev
|
|
|
390
429
|
req("POST", "#{server_path(server)}/backups/#{seg(backup)}/lock")
|
|
391
430
|
end
|
|
392
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
|
+
|
|
393
437
|
# Restore a backup; truncate: true deletes every file first. operationId: restoreBackup
|
|
394
|
-
def restore(server, backup, truncate: false)
|
|
395
|
-
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")
|
|
396
466
|
end
|
|
397
467
|
end
|
|
398
468
|
|
|
@@ -534,12 +604,15 @@ module SillyDev
|
|
|
534
604
|
|
|
535
605
|
# Link a repository ("github", "gitlab" or "url" source), or change the link's settings. operationId: linkGitRepository
|
|
536
606
|
def link(server, source:, repository:, branch:, installation: nil, directory: nil, auto_deploy: nil,
|
|
537
|
-
|
|
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)
|
|
538
609
|
req("PUT", "#{server_path(server)}/git",
|
|
539
610
|
json: body(source: source, installation: installation, repository: repository, branch: branch,
|
|
540
|
-
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,
|
|
541
613
|
start_if_offline: start_if_offline, apply_config: apply_config, sync_startup: sync_startup,
|
|
542
|
-
write_config: write_config
|
|
614
|
+
write_config: write_config, release_command: release_command,
|
|
615
|
+
auto_rollback: auto_rollback))
|
|
543
616
|
end
|
|
544
617
|
|
|
545
618
|
# Unlink the repository; the files stay. operationId: unlinkGitRepository
|
|
@@ -562,6 +635,23 @@ module SillyDev
|
|
|
562
635
|
req("POST", "#{server_path(server)}/git/deployments/#{seg(deployment)}/cancel")
|
|
563
636
|
end
|
|
564
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
|
+
|
|
565
655
|
# A sillydev.conf written from the server's current settings. operationId: getGitConfigTemplate
|
|
566
656
|
def config_template(server)
|
|
567
657
|
req("GET", "#{server_path(server)}/git/config")
|
|
@@ -591,6 +681,12 @@ module SillyDev
|
|
|
591
681
|
req("GET", "/account")
|
|
592
682
|
end
|
|
593
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
|
+
|
|
594
690
|
# The account's activity log, fetching page after page. operationId: listAccountActivity
|
|
595
691
|
def activity(event: nil, sort: nil, include: nil, per_page: nil)
|
|
596
692
|
@client.paginate("/account/activity",
|
|
@@ -602,6 +698,46 @@ module SillyDev
|
|
|
602
698
|
@client.page("/account/activity",
|
|
603
699
|
{ page: page, per_page: per_page, "filter[event]" => event, sort: sort, include: include })
|
|
604
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
|
|
605
741
|
end
|
|
606
742
|
|
|
607
743
|
# Create free servers (tag Server creation).
|
|
@@ -617,16 +753,61 @@ module SillyDev
|
|
|
617
753
|
end
|
|
618
754
|
end
|
|
619
755
|
|
|
620
|
-
# 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.
|
|
621
760
|
class Databases < Base
|
|
622
761
|
# {"limit", "owned", "can_create", "quota_bytes", "versions", "databases"}. operationId: listDatabases
|
|
623
762
|
def list
|
|
624
763
|
req("GET", "/databases")
|
|
625
764
|
end
|
|
626
765
|
|
|
627
|
-
# Create a database; the result holds its password.
|
|
628
|
-
|
|
629
|
-
|
|
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))
|
|
630
811
|
end
|
|
631
812
|
|
|
632
813
|
# Give the database a new password. operationId: rotateDatabasePassword
|
|
@@ -653,6 +834,83 @@ module SillyDev
|
|
|
653
834
|
def delete(database)
|
|
654
835
|
req("DELETE", "/databases/#{seg(database)}")
|
|
655
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
|
|
656
914
|
end
|
|
657
915
|
|
|
658
916
|
# Paid servers and databases (tag Billing). Prices are in pence.
|
|
@@ -663,14 +921,17 @@ module SillyDev
|
|
|
663
921
|
end
|
|
664
922
|
|
|
665
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.
|
|
666
926
|
#
|
|
667
927
|
# An Idempotency-Key is always sent, so a retried request never buys twice: pass your own
|
|
668
928
|
# idempotency_key: to make retries across runs safe too. operationId: createCheckout
|
|
669
929
|
def checkout(name: nil, runtime: nil, description: nil, server_uuid: nil, use_saved_card: nil,
|
|
670
|
-
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)
|
|
671
931
|
req("POST", "/billing/checkout",
|
|
672
932
|
json: body(server_uuid: server_uuid, name: name, description: description, runtime: runtime,
|
|
673
|
-
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),
|
|
674
935
|
headers: { "Idempotency-Key" => idempotency_key || SecureRandom.uuid })
|
|
675
936
|
end
|
|
676
937
|
|
|
@@ -836,12 +1097,55 @@ module SillyDev
|
|
|
836
1097
|
req("GET", "#{project_path(project)}/usage")
|
|
837
1098
|
end
|
|
838
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
|
|
839
1143
|
end
|
|
840
1144
|
|
|
841
1145
|
# The panel API: client.panel.servers, client.panel.files and the rest.
|
|
842
1146
|
class Panel
|
|
843
1147
|
attr_reader :servers, :settings, :startup, :files, :backups, :schedules, :network, :subusers, :git,
|
|
844
|
-
:account, :server_creation, :databases, :billing, :monitoring
|
|
1148
|
+
:account, :server_creation, :databases, :billing, :monitoring, :folders
|
|
845
1149
|
|
|
846
1150
|
def initialize(client)
|
|
847
1151
|
@client = client
|
|
@@ -859,6 +1163,7 @@ module SillyDev
|
|
|
859
1163
|
@databases = Resources::Databases.new(client)
|
|
860
1164
|
@billing = Resources::Billing.new(client)
|
|
861
1165
|
@monitoring = Resources::Monitoring.new(client)
|
|
1166
|
+
@folders = Resources::Folders.new(client)
|
|
862
1167
|
end
|
|
863
1168
|
|
|
864
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: []
|