databasus_ruby 0.1.0 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +58 -0
- data/lib/databasus_ruby/client.rb +75 -20
- data/lib/databasus_ruby/collection.rb +27 -36
- data/lib/databasus_ruby/endpoint.rb +3 -10
- data/lib/databasus_ruby/error.rb +39 -9
- data/lib/databasus_ruby/objects/auth.rb +31 -26
- data/lib/databasus_ruby/objects/backups.rb +54 -29
- data/lib/databasus_ruby/objects/databases.rb +39 -56
- data/lib/databasus_ruby/objects/notifiers.rb +14 -22
- data/lib/databasus_ruby/objects/restores.rb +72 -0
- data/lib/databasus_ruby/objects/storages.rb +19 -18
- data/lib/databasus_ruby/objects/users.rb +24 -41
- data/lib/databasus_ruby/objects/workspaces.rb +26 -33
- data/lib/databasus_ruby/records/database.rb +1 -0
- data/lib/databasus_ruby/version.rb +1 -1
- data/lib/databasus_ruby.rb +6 -2
- data/sig/databasus_ruby.rbs +159 -101
- metadata +3 -2
|
@@ -3,40 +3,59 @@
|
|
|
3
3
|
module DatabasusRuby
|
|
4
4
|
# Databases under backup.
|
|
5
5
|
#
|
|
6
|
-
# client.databases.list(workspace_id: id)
|
|
7
|
-
# client.databases.create(name: "primary",
|
|
8
|
-
#
|
|
6
|
+
# client.databases.list(workspace_id: id).each { |database| database.name }
|
|
7
|
+
# client.databases.create(name: "primary", workspaceId: id, notifierIds: [],
|
|
8
|
+
# settings: { type: "POSTGRES_LOGICAL", ... })
|
|
9
9
|
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
# `postgresqlPhysical`, `mysql`, `mariadb` or `mongodb`.
|
|
10
|
+
# `settings` is the engine-specific half, discriminated by its `type`
|
|
11
|
+
# (POSTGRES_LOGICAL, POSTGRES_PHYSICAL, MYSQL, MARIADB, MONGODB).
|
|
13
12
|
class Databases < Object
|
|
14
13
|
include Endpoint
|
|
15
14
|
|
|
16
15
|
TYPES = %w[POSTGRES_LOGICAL POSTGRES_PHYSICAL MYSQL MARIADB MONGODB].freeze
|
|
17
|
-
HEALTH_STATUSES = %w[AVAILABLE UNAVAILABLE].freeze
|
|
18
16
|
|
|
19
17
|
# GET /databases
|
|
20
|
-
def list(workspace_id: nil)
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
def list(workspace_id: nil, notifier_id: nil, limit: nil, after: nil)
|
|
19
|
+
response = http_get("databases", {
|
|
20
|
+
workspaceId: workspace_id || client.workspace_id!,
|
|
21
|
+
notifierId: notifier_id,
|
|
22
|
+
limit: limit,
|
|
23
|
+
after: after
|
|
24
|
+
})
|
|
25
|
+
collection(response, as: Database)
|
|
23
26
|
end
|
|
24
27
|
alias all list
|
|
25
28
|
|
|
29
|
+
# Every database of the workspace, following the cursor across pages.
|
|
30
|
+
#
|
|
31
|
+
# @return [Array<DatabasusRuby::Database>]
|
|
32
|
+
def list_all(workspace_id: nil, limit: 100)
|
|
33
|
+
databases = []
|
|
34
|
+
after = nil
|
|
35
|
+
loop do
|
|
36
|
+
page = list(workspace_id: workspace_id, limit: limit, after: after)
|
|
37
|
+
databases.concat(page.data)
|
|
38
|
+
break if page.last_page?
|
|
39
|
+
|
|
40
|
+
after = page.next_cursor
|
|
41
|
+
end
|
|
42
|
+
databases
|
|
43
|
+
end
|
|
44
|
+
|
|
26
45
|
# GET /databases/{id}
|
|
27
46
|
def get(id)
|
|
28
47
|
object(http_get("databases/#{escape(id)}"), as: Database)
|
|
29
48
|
end
|
|
30
49
|
alias find get
|
|
31
50
|
|
|
32
|
-
# POST /databases
|
|
51
|
+
# POST /databases
|
|
33
52
|
def create(**attributes)
|
|
34
|
-
object(http_post("databases
|
|
53
|
+
object(http_post("databases", with_default_workspace(attributes)), as: Database)
|
|
35
54
|
end
|
|
36
55
|
|
|
37
|
-
#
|
|
38
|
-
def update(**attributes)
|
|
39
|
-
object(
|
|
56
|
+
# PUT /databases/{id} — the body is the full DatabaseUpdate payload.
|
|
57
|
+
def update(id, **attributes)
|
|
58
|
+
object(http_put("databases/#{escape(id)}", attributes), as: Database)
|
|
40
59
|
end
|
|
41
60
|
|
|
42
61
|
# DELETE /databases/{id}
|
|
@@ -49,43 +68,17 @@ module DatabasusRuby
|
|
|
49
68
|
object(http_post("databases/#{escape(id)}/copy"), as: Database)
|
|
50
69
|
end
|
|
51
70
|
|
|
52
|
-
# POST /databases/{id}/test
|
|
53
|
-
def
|
|
54
|
-
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# POST /databases/test-connection-direct — tests a payload that has not
|
|
58
|
-
# been saved yet.
|
|
59
|
-
def test_connection_direct(**attributes)
|
|
60
|
-
acknowledged(http_post("databases/test-connection-direct", attributes))
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# POST /databases/create-readonly-user -> { username, password }
|
|
64
|
-
def create_readonly_user(**attributes)
|
|
65
|
-
object(http_post("databases/create-readonly-user", attributes))
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# POST /databases/create-replication-only-user (PostgreSQL physical only)
|
|
69
|
-
def create_replication_only_user(**attributes)
|
|
70
|
-
object(http_post("databases/create-replication-only-user", attributes))
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# POST /databases/is-readonly -> { isReadOnly, privileges }
|
|
74
|
-
def readonly(**attributes)
|
|
75
|
-
object(http_post("databases/is-readonly", attributes))
|
|
71
|
+
# POST /databases/{id}/test -> { isConnected, reason, error }
|
|
72
|
+
def test(id)
|
|
73
|
+
object(http_post("databases/#{escape(id)}/test"))
|
|
76
74
|
end
|
|
77
75
|
|
|
78
|
-
def
|
|
79
|
-
|
|
76
|
+
def connected?(id)
|
|
77
|
+
test(id).is_connected == true
|
|
80
78
|
end
|
|
81
79
|
|
|
82
80
|
# The backups of one database by id. A database returned by this endpoint
|
|
83
81
|
# answers the same two methods without the id — see Database.
|
|
84
|
-
#
|
|
85
|
-
# client.databases.backups(database.id, status: "COMPLETED")
|
|
86
|
-
# client.databases.backup(database.id) # queue a run
|
|
87
|
-
#
|
|
88
|
-
# #backups takes the same filters as Backups#list.
|
|
89
82
|
def backups(id, **filters)
|
|
90
83
|
client.backups.list(database_id: require_id(id), **filters)
|
|
91
84
|
end
|
|
@@ -93,15 +86,5 @@ module DatabasusRuby
|
|
|
93
86
|
def backup(id)
|
|
94
87
|
client.backups.create(database_id: require_id(id))
|
|
95
88
|
end
|
|
96
|
-
|
|
97
|
-
# GET /databases/notifier/{id}/databases-count
|
|
98
|
-
def notifier_databases_count(notifier_id)
|
|
99
|
-
single_value(http_get("databases/notifier/#{escape(notifier_id)}/databases-count"))
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# GET /databases/notifier/{id}/is-using
|
|
103
|
-
def notifier_using?(notifier_id)
|
|
104
|
-
single_value(http_get("databases/notifier/#{escape(notifier_id)}/is-using")) == true
|
|
105
|
-
end
|
|
106
89
|
end
|
|
107
90
|
end
|
|
@@ -3,23 +3,17 @@
|
|
|
3
3
|
module DatabasusRuby
|
|
4
4
|
# Notification channels.
|
|
5
5
|
#
|
|
6
|
-
# client.notifiers.
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
# POST /notifiers both creates and updates: include `id` in the payload to
|
|
10
|
-
# update an existing notifier.
|
|
6
|
+
# client.notifiers.create(workspaceId: id, name: "ops", settings: { type: "SLACK", ... })
|
|
7
|
+
# client.notifiers.update(notifier.id, name: "ops", settings: { type: "SLACK", ... })
|
|
11
8
|
class Notifiers < Object
|
|
12
9
|
include Endpoint
|
|
13
10
|
|
|
14
11
|
TYPES = %w[EMAIL TELEGRAM WEBHOOK SLACK DISCORD TEAMS].freeze
|
|
15
|
-
NOTIFICATION_TYPES = %w[
|
|
16
|
-
ALL BACKUP_SUCCESS BACKUP_FAILED HEALTHCHECK_SUCCESS HEALTHCHECK_FAILED
|
|
17
|
-
VERIFICATION_SUCCESS VERIFICATION_FAILED
|
|
18
|
-
].freeze
|
|
19
12
|
|
|
20
13
|
# GET /notifiers
|
|
21
|
-
def list(workspace_id: nil)
|
|
22
|
-
collection(http_get("notifiers",
|
|
14
|
+
def list(workspace_id: nil, limit: nil, after: nil)
|
|
15
|
+
collection(http_get("notifiers",
|
|
16
|
+
{ workspaceId: workspace_id || client.workspace_id!, limit: limit, after: after }))
|
|
23
17
|
end
|
|
24
18
|
alias all list
|
|
25
19
|
|
|
@@ -29,12 +23,15 @@ module DatabasusRuby
|
|
|
29
23
|
end
|
|
30
24
|
alias find get
|
|
31
25
|
|
|
32
|
-
# POST /notifiers
|
|
33
|
-
def
|
|
26
|
+
# POST /notifiers — `workspaceId`, `name` and the type-specific `settings`.
|
|
27
|
+
def create(**attributes)
|
|
34
28
|
object(http_post("notifiers", with_default_workspace(attributes)))
|
|
35
29
|
end
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
|
|
31
|
+
# PUT /notifiers/{id} — `name` and `settings`.
|
|
32
|
+
def update(id, **attributes)
|
|
33
|
+
object(http_put("notifiers/#{escape(id)}", attributes))
|
|
34
|
+
end
|
|
38
35
|
|
|
39
36
|
# DELETE /notifiers/{id}
|
|
40
37
|
def delete(id)
|
|
@@ -43,17 +40,12 @@ module DatabasusRuby
|
|
|
43
40
|
|
|
44
41
|
# POST /notifiers/{id}/test — sends a test notification.
|
|
45
42
|
def test(id)
|
|
46
|
-
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# POST /notifiers/direct-test — tests a payload that has not been saved yet.
|
|
50
|
-
def direct_test(**attributes)
|
|
51
|
-
acknowledged(http_post("notifiers/direct-test", attributes))
|
|
43
|
+
object(http_post("notifiers/#{escape(id)}/test"))
|
|
52
44
|
end
|
|
53
45
|
|
|
54
46
|
# POST /notifiers/{id}/transfer
|
|
55
47
|
def transfer(id, target_workspace_id:)
|
|
56
|
-
|
|
48
|
+
object(http_post("notifiers/#{escape(id)}/transfer", { targetWorkspaceId: target_workspace_id }))
|
|
57
49
|
end
|
|
58
50
|
end
|
|
59
51
|
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DatabasusRuby
|
|
4
|
+
# Restores of a logical backup into a target database.
|
|
5
|
+
#
|
|
6
|
+
# target = DatabasusRuby::Restores.postgresql_target(
|
|
7
|
+
# host: "db.internal", port: 5432, username: "app", password: "secret",
|
|
8
|
+
# database: "copy_of_prod"
|
|
9
|
+
# )
|
|
10
|
+
# restore = client.restores.start(backup_id: backup.id, target: target)
|
|
11
|
+
# client.restores.get(restore.id).status # IN_PROGRESS -> COMPLETED | FAILED | CANCELED
|
|
12
|
+
#
|
|
13
|
+
# The target's secrets are used only by the running restore; Databasus does
|
|
14
|
+
# not store them.
|
|
15
|
+
class Restores < Object
|
|
16
|
+
include Endpoint
|
|
17
|
+
|
|
18
|
+
STATUSES = %w[IN_PROGRESS COMPLETED FAILED CANCELED].freeze
|
|
19
|
+
SSL_MODES = %w[disable require verify-ca verify-full].freeze
|
|
20
|
+
|
|
21
|
+
# Builds a PostgreSQL logical restore target.
|
|
22
|
+
#
|
|
23
|
+
# Ownership and privileges are off by default: restoring them needs the
|
|
24
|
+
# source cluster's roles on the target, and their absence is the usual
|
|
25
|
+
# cause of a restore that loads every row and still fails.
|
|
26
|
+
#
|
|
27
|
+
# @param cpu_count [Integer] parallel pg_restore jobs (Databasus caps it at 8)
|
|
28
|
+
# @param exclude_extensions [Boolean] skip CREATE EXTENSION entries
|
|
29
|
+
# @return [Hash] the `target` body of #start
|
|
30
|
+
def self.postgresql_target(host:, port:, username:, password:, database:, ssl_mode: "disable", cpu_count: 1,
|
|
31
|
+
exclude_extensions: false, restore_ownership: false, restore_privileges: false,
|
|
32
|
+
ssh_tunnel: nil)
|
|
33
|
+
{
|
|
34
|
+
type: "POSTGRES_LOGICAL",
|
|
35
|
+
host: host,
|
|
36
|
+
port: port,
|
|
37
|
+
username: username,
|
|
38
|
+
password: password,
|
|
39
|
+
database: database,
|
|
40
|
+
sslMode: ssl_mode,
|
|
41
|
+
sshTunnel: ssh_tunnel || { isEnabled: false },
|
|
42
|
+
cpuCount: cpu_count,
|
|
43
|
+
isExcludeExtensions: exclude_extensions,
|
|
44
|
+
isRestoreOwnership: restore_ownership,
|
|
45
|
+
isRestorePrivileges: restore_privileges
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# GET /restores — the restores of one backup, newest first.
|
|
50
|
+
def list(backup_id:, limit: nil, after: nil)
|
|
51
|
+
collection(http_get("restores", { backupId: require_id(backup_id), limit: limit, after: after }))
|
|
52
|
+
end
|
|
53
|
+
alias all list
|
|
54
|
+
|
|
55
|
+
# POST /restores — answers at once with the restore IN_PROGRESS.
|
|
56
|
+
def start(backup_id:, target:)
|
|
57
|
+
object(http_post("restores", { backupId: require_id(backup_id), target: target }))
|
|
58
|
+
end
|
|
59
|
+
alias create start
|
|
60
|
+
|
|
61
|
+
# GET /restores/{id}
|
|
62
|
+
def get(id)
|
|
63
|
+
object(http_get("restores/#{escape(id)}"))
|
|
64
|
+
end
|
|
65
|
+
alias find get
|
|
66
|
+
|
|
67
|
+
# POST /restores/{id}/cancel
|
|
68
|
+
def cancel(id)
|
|
69
|
+
object(http_post("restores/#{escape(id)}/cancel"))
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -3,19 +3,17 @@
|
|
|
3
3
|
module DatabasusRuby
|
|
4
4
|
# Backup destinations.
|
|
5
5
|
#
|
|
6
|
-
# client.storages.
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
# POST /storages both creates and updates: include `id` in the payload to
|
|
10
|
-
# update an existing storage.
|
|
6
|
+
# client.storages.create(workspaceId: id, name: "offsite", settings: { type: "S3", ... })
|
|
7
|
+
# client.storages.backup_usage(storage.id)
|
|
11
8
|
class Storages < Object
|
|
12
9
|
include Endpoint
|
|
13
10
|
|
|
14
11
|
TYPES = %w[LOCAL S3 GOOGLE_DRIVE NAS AZURE_BLOB FTP SFTP RCLONE].freeze
|
|
15
12
|
|
|
16
13
|
# GET /storages
|
|
17
|
-
def list(workspace_id: nil)
|
|
18
|
-
collection(http_get("storages",
|
|
14
|
+
def list(workspace_id: nil, limit: nil, after: nil)
|
|
15
|
+
collection(http_get("storages",
|
|
16
|
+
{ workspaceId: workspace_id || client.workspace_id!, limit: limit, after: after }))
|
|
19
17
|
end
|
|
20
18
|
alias all list
|
|
21
19
|
|
|
@@ -25,31 +23,34 @@ module DatabasusRuby
|
|
|
25
23
|
end
|
|
26
24
|
alias find get
|
|
27
25
|
|
|
28
|
-
# POST /storages
|
|
29
|
-
def
|
|
26
|
+
# POST /storages — `workspaceId`, `name` and the type-specific `settings`.
|
|
27
|
+
def create(**attributes)
|
|
30
28
|
object(http_post("storages", with_default_workspace(attributes)))
|
|
31
29
|
end
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
|
|
31
|
+
# PUT /storages/{id} — `name` and `settings`.
|
|
32
|
+
def update(id, **attributes)
|
|
33
|
+
object(http_put("storages/#{escape(id)}", attributes))
|
|
34
|
+
end
|
|
34
35
|
|
|
35
36
|
# DELETE /storages/{id}
|
|
36
37
|
def delete(id)
|
|
37
38
|
acknowledged(http_delete("storages/#{escape(id)}"))
|
|
38
39
|
end
|
|
39
40
|
|
|
40
|
-
#
|
|
41
|
-
def
|
|
42
|
-
|
|
41
|
+
# GET /storages/{id}/backup-usage — the catalog-recorded usage of the storage.
|
|
42
|
+
def backup_usage(id)
|
|
43
|
+
object(http_get("storages/#{escape(id)}/backup-usage"))
|
|
43
44
|
end
|
|
44
45
|
|
|
45
|
-
# POST /storages/
|
|
46
|
-
def
|
|
47
|
-
|
|
46
|
+
# POST /storages/{id}/test
|
|
47
|
+
def test(id)
|
|
48
|
+
object(http_post("storages/#{escape(id)}/test"))
|
|
48
49
|
end
|
|
49
50
|
|
|
50
51
|
# POST /storages/{id}/transfer
|
|
51
52
|
def transfer(id, target_workspace_id:)
|
|
52
|
-
|
|
53
|
+
object(http_post("storages/#{escape(id)}/transfer", { targetWorkspaceId: target_workspace_id }))
|
|
53
54
|
end
|
|
54
55
|
end
|
|
55
56
|
end
|
|
@@ -1,79 +1,62 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module DatabasusRuby
|
|
4
|
-
#
|
|
5
|
-
# settings.
|
|
4
|
+
# Instance-wide user administration and instance settings.
|
|
6
5
|
#
|
|
7
|
-
# client.users.me.email
|
|
8
6
|
# client.users.list(query: "ops", limit: 25).each { |user| ... }
|
|
9
7
|
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
8
|
+
# Everything here except #update and #change_password on your own user is
|
|
9
|
+
# ADMIN-only and answers 403 for a MEMBER token.
|
|
12
10
|
class Users < Object
|
|
13
11
|
include Endpoint
|
|
14
12
|
|
|
15
13
|
ROLES = %w[ADMIN MEMBER].freeze
|
|
16
14
|
|
|
17
|
-
# GET /users
|
|
18
|
-
def
|
|
19
|
-
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# PUT /users/me
|
|
23
|
-
def update_me(name: nil, email: nil)
|
|
24
|
-
object(http_put("users/me", { name: name, email: email }))
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# PUT /users/change-password
|
|
28
|
-
def change_password(new_password:)
|
|
29
|
-
object(http_put("users/change-password", { newPassword: new_password }))
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# POST /users/invite
|
|
33
|
-
def invite(email:, intended_workspace_id: nil, intended_workspace_role: nil)
|
|
34
|
-
object(http_post("users/invite", {
|
|
35
|
-
email: email,
|
|
36
|
-
intendedWorkspaceId: intended_workspace_id,
|
|
37
|
-
intendedWorkspaceRole: intended_workspace_role
|
|
38
|
-
}))
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# GET /users (ADMIN)
|
|
42
|
-
def list(limit: nil, offset: nil, before_date: nil, query: nil)
|
|
43
|
-
response = http_get("users", { limit: limit, offset: offset, beforeDate: before_date, query: query })
|
|
44
|
-
collection(response, key: "users")
|
|
15
|
+
# GET /users
|
|
16
|
+
def list(query: nil, limit: nil, after: nil)
|
|
17
|
+
collection(http_get("users", { query: query, limit: limit, after: after }))
|
|
45
18
|
end
|
|
46
19
|
alias all list
|
|
47
20
|
|
|
48
|
-
# GET /users/{id}
|
|
21
|
+
# GET /users/{id}
|
|
49
22
|
def get(id)
|
|
50
23
|
object(http_get("users/#{escape(id)}"))
|
|
51
24
|
end
|
|
52
25
|
alias find get
|
|
53
26
|
|
|
54
|
-
#
|
|
27
|
+
# PUT /users/{id}
|
|
28
|
+
def update(id, name:, email:)
|
|
29
|
+
object(http_put("users/#{escape(id)}", { name: name, email: email }))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# PUT /users/{id}/password
|
|
33
|
+
def change_password(id, new_password:)
|
|
34
|
+
acknowledged(http_put("users/#{escape(id)}/password", { newPassword: new_password }))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# POST /users/{id}/activate
|
|
55
38
|
def activate(id)
|
|
56
39
|
acknowledged(http_post("users/#{escape(id)}/activate"))
|
|
57
40
|
end
|
|
58
41
|
|
|
59
|
-
# POST /users/{id}/deactivate
|
|
42
|
+
# POST /users/{id}/deactivate
|
|
60
43
|
def deactivate(id)
|
|
61
44
|
acknowledged(http_post("users/#{escape(id)}/deactivate"))
|
|
62
45
|
end
|
|
63
46
|
|
|
64
|
-
# PUT /users/{id}/role
|
|
47
|
+
# PUT /users/{id}/role — role is one of ROLES.
|
|
65
48
|
def change_role(id, role:)
|
|
66
49
|
acknowledged(http_put("users/#{escape(id)}/role", { role: role }))
|
|
67
50
|
end
|
|
68
51
|
|
|
69
|
-
# GET /
|
|
52
|
+
# GET /instance-settings
|
|
70
53
|
def settings
|
|
71
|
-
object(http_get("
|
|
54
|
+
object(http_get("instance-settings"))
|
|
72
55
|
end
|
|
73
56
|
|
|
74
|
-
# PUT /
|
|
57
|
+
# PUT /instance-settings
|
|
75
58
|
def update_settings(**attributes)
|
|
76
|
-
object(http_put("
|
|
59
|
+
object(http_put("instance-settings", attributes))
|
|
77
60
|
end
|
|
78
61
|
end
|
|
79
62
|
end
|
|
@@ -4,21 +4,18 @@ module DatabasusRuby
|
|
|
4
4
|
# Workspaces, their members and their audit trail.
|
|
5
5
|
#
|
|
6
6
|
# workspace = client.workspaces.create(name: "production")
|
|
7
|
-
# client.workspaces.add_member(workspace.id, email: "ops@example.com",
|
|
8
|
-
# role: "WORKSPACE_ADMIN")
|
|
7
|
+
# client.workspaces.add_member(workspace.id, email: "ops@example.com", role: "WORKSPACE_ADMIN")
|
|
9
8
|
#
|
|
10
|
-
#
|
|
11
|
-
# where {id} is still the workspace id.
|
|
9
|
+
# Members are addressed by their member id (from #members), not their user id.
|
|
12
10
|
class Workspaces < Object
|
|
13
11
|
include Endpoint
|
|
14
12
|
|
|
15
13
|
MEMBER_ROLES = %w[WORKSPACE_OWNER WORKSPACE_ADMIN WORKSPACE_MEMBER WORKSPACE_VIEWER].freeze
|
|
16
14
|
|
|
17
15
|
# GET /workspaces — the workspaces the current user belongs to.
|
|
18
|
-
def list
|
|
19
|
-
collection(http_get("workspaces"
|
|
16
|
+
def list(limit: nil, after: nil)
|
|
17
|
+
collection(http_get("workspaces", { limit: limit, after: after }))
|
|
20
18
|
end
|
|
21
|
-
|
|
22
19
|
alias all list
|
|
23
20
|
|
|
24
21
|
# POST /workspaces
|
|
@@ -33,8 +30,8 @@ module DatabasusRuby
|
|
|
33
30
|
alias find get
|
|
34
31
|
|
|
35
32
|
# PUT /workspaces/{id}
|
|
36
|
-
def update(id,
|
|
37
|
-
object(http_put("workspaces/#{escape(id)}",
|
|
33
|
+
def update(id, name:)
|
|
34
|
+
object(http_put("workspaces/#{escape(id)}", { name: name }))
|
|
38
35
|
end
|
|
39
36
|
|
|
40
37
|
# DELETE /workspaces/{id}
|
|
@@ -42,40 +39,36 @@ module DatabasusRuby
|
|
|
42
39
|
acknowledged(http_delete("workspaces/#{escape(id)}"))
|
|
43
40
|
end
|
|
44
41
|
|
|
45
|
-
#
|
|
46
|
-
def
|
|
47
|
-
|
|
48
|
-
{ limit: limit, offset: offset, beforeDate: before_date })
|
|
49
|
-
collection(response, key: "auditLogs")
|
|
42
|
+
# POST /workspaces/{id}/transfer-ownership
|
|
43
|
+
def transfer_ownership(id, new_owner_member_id:)
|
|
44
|
+
acknowledged(http_post("workspaces/#{escape(id)}/transfer-ownership", { newOwnerMemberId: new_owner_member_id }))
|
|
50
45
|
end
|
|
51
46
|
|
|
52
|
-
# GET /
|
|
53
|
-
def
|
|
54
|
-
collection(http_get("
|
|
47
|
+
# GET /audit-events
|
|
48
|
+
def audit_events(id, author_user_id: nil, limit: nil, after: nil)
|
|
49
|
+
collection(http_get("audit-events", {
|
|
50
|
+
workspaceId: require_id(id), authorUserId: author_user_id, limit: limit, after: after
|
|
51
|
+
}))
|
|
55
52
|
end
|
|
56
53
|
|
|
57
|
-
#
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
def add_member(id, email:, role:)
|
|
61
|
-
object(http_post("workspaces/memberships/#{escape(id)}/members", { email: email, role: role }))
|
|
54
|
+
# GET /workspace-members
|
|
55
|
+
def members(id, limit: nil, after: nil)
|
|
56
|
+
collection(http_get("workspace-members", { workspaceId: require_id(id), limit: limit, after: after }))
|
|
62
57
|
end
|
|
63
58
|
|
|
64
|
-
#
|
|
65
|
-
def
|
|
66
|
-
|
|
59
|
+
# POST /workspace-members — `role` is one of MEMBER_ROLES except the owner.
|
|
60
|
+
def add_member(id, email:, role:)
|
|
61
|
+
object(http_post("workspace-members", { workspaceId: require_id(id), email: email, role: role }))
|
|
67
62
|
end
|
|
68
63
|
|
|
69
|
-
#
|
|
70
|
-
def
|
|
71
|
-
acknowledged(
|
|
72
|
-
{ role: role }))
|
|
64
|
+
# DELETE /workspace-members/{memberId}
|
|
65
|
+
def remove_member(member_id)
|
|
66
|
+
acknowledged(http_delete("workspace-members/#{escape(member_id)}"))
|
|
73
67
|
end
|
|
74
68
|
|
|
75
|
-
#
|
|
76
|
-
def
|
|
77
|
-
|
|
78
|
-
{ newOwnerEmail: new_owner_email }))
|
|
69
|
+
# PUT /workspace-members/{memberId}
|
|
70
|
+
def change_member_role(member_id, role:)
|
|
71
|
+
object(http_put("workspace-members/#{escape(member_id)}", { role: role }))
|
|
79
72
|
end
|
|
80
73
|
end
|
|
81
74
|
end
|
|
@@ -6,6 +6,7 @@ module DatabasusRuby
|
|
|
6
6
|
# database = client.databases.get(id)
|
|
7
7
|
# database.backups(status: "COMPLETED")
|
|
8
8
|
# database.backup # queue a run
|
|
9
|
+
# database.settings.database # name of the database on its server (PostgreSQL)
|
|
9
10
|
#
|
|
10
11
|
# Both delegate to the Backups endpoint, which owns the requests.
|
|
11
12
|
class Database < Record
|
data/lib/databasus_ruby.rb
CHANGED
|
@@ -6,10 +6,12 @@ require_relative "databasus_ruby/version"
|
|
|
6
6
|
|
|
7
7
|
# Ruby client for the Databasus backup-management API.
|
|
8
8
|
#
|
|
9
|
-
# client = DatabasusRuby::Client.new(
|
|
10
|
-
#
|
|
9
|
+
# client = DatabasusRuby::Client.new(url: "https://databasus.example.com/api/v1/")
|
|
10
|
+
# client.auth.signin(email: ENV["DATABASUS_EMAIL"], password: ENV["DATABASUS_PASSWORD"])
|
|
11
11
|
# client.databases.list(workspace_id: workspace_id)
|
|
12
12
|
#
|
|
13
|
+
# Targets the Databasus API of 3.65 and later.
|
|
14
|
+
#
|
|
13
15
|
# See DatabasusRuby::Client for how the endpoint domains hang off the client.
|
|
14
16
|
module DatabasusRuby
|
|
15
17
|
autoload :Client, "databasus_ruby/client"
|
|
@@ -20,6 +22,7 @@ module DatabasusRuby
|
|
|
20
22
|
|
|
21
23
|
autoload :Error, "databasus_ruby/error"
|
|
22
24
|
autoload :ConfigurationError, "databasus_ruby/error"
|
|
25
|
+
autoload :SignInCodeRequiredError, "databasus_ruby/error"
|
|
23
26
|
autoload :APIError, "databasus_ruby/error"
|
|
24
27
|
autoload :BadRequestError, "databasus_ruby/error"
|
|
25
28
|
autoload :AuthenticationError, "databasus_ruby/error"
|
|
@@ -33,6 +36,7 @@ module DatabasusRuby
|
|
|
33
36
|
autoload :Backups, "databasus_ruby/objects/backups"
|
|
34
37
|
autoload :Databases, "databasus_ruby/objects/databases"
|
|
35
38
|
autoload :Notifiers, "databasus_ruby/objects/notifiers"
|
|
39
|
+
autoload :Restores, "databasus_ruby/objects/restores"
|
|
36
40
|
autoload :Storages, "databasus_ruby/objects/storages"
|
|
37
41
|
autoload :Users, "databasus_ruby/objects/users"
|
|
38
42
|
autoload :Workspaces, "databasus_ruby/objects/workspaces"
|