heroku-api-postgres 0.1.0.alpha1 → 0.1.0.alpha5
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/Gemfile.lock +1 -1
- data/README.md +51 -3
- data/docs/models.md +1 -0
- data/docs/services.md +96 -0
- data/lib/heroku/api/postgres/backups.rb +11 -0
- data/lib/heroku/api/postgres/client.rb +38 -7
- data/lib/heroku/api/postgres/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35ae932c7a584955c98c5e5bd156f49fa6d99216700e6b8f7ea6c55d00977328
|
4
|
+
data.tar.gz: 061e27956266ba1cc8e6598ca5b9b38302fb793fe174e6128319ee797d91b295
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17edfb6515f870a5094783950afefeab465a12a64921115e484def72d896f7e523afe21bf09d6df531e9d3cde1dfe0604660e255a8a6399a90b9cd92004e5e59
|
7
|
+
data.tar.gz: 92370ca4f9d1d7d13f05f12c03d703fd9e41d21af543eb16cd025dc02ab3cc6c9f1738f4f924787fc859c78c3ab8dc0d5ea5709511a7ccbc0d8bf203789b338d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,9 @@ both this gem and the official Heroku CLI.
|
|
12
12
|
|
13
13
|
Not all APIs are implemented at the moment but we are working hard on implementing all of them.
|
14
14
|
|
15
|
-
|
15
|
+
Please check the [list of implemented and not implemented services](docs/services.md).
|
16
|
+
|
17
|
+
Contributes and Pull Requests are welcome!
|
16
18
|
|
17
19
|
## Installation
|
18
20
|
|
@@ -49,6 +51,29 @@ postgres_api_client = Heroku::Api::Postgres.connect_oauth(ENV['HEROKU_OAUTH_TOKE
|
|
49
51
|
Look into [Models](docs/models.rb) for a detailed description of the JSON objects returned by the APIs.
|
50
52
|
Those are the bare objects returned by the official Heroku API.
|
51
53
|
|
54
|
+
#### Wait
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
databases = postgres_api_client.wait(database_id, wait_interval: 5)
|
58
|
+
```
|
59
|
+
|
60
|
+
Waits for the given database to be ready. Polls every `wait_interval` seconds (default 3).
|
61
|
+
|
62
|
+
|
63
|
+
### Databases
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
databases_client = postgres_api_client.database
|
67
|
+
```
|
68
|
+
|
69
|
+
#### Info
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
database_info = databases_client.info(database_id)
|
73
|
+
```
|
74
|
+
|
75
|
+
returns a [Database](docs/models.md#database).
|
76
|
+
|
52
77
|
### Backups
|
53
78
|
|
54
79
|
```ruby
|
@@ -63,7 +88,9 @@ backups = backups_client.list(app_id)
|
|
63
88
|
|
64
89
|
returns an array of [Backup](docs/models.md#backup).
|
65
90
|
|
66
|
-
The app_id can be either the name of your heroku app or the id.
|
91
|
+
The app_id can be either the name of your heroku app or the id.
|
92
|
+
|
93
|
+
[Check official API](https://devcenter.heroku.com/articles/platform-api-reference#app)
|
67
94
|
|
68
95
|
#### Schedules
|
69
96
|
|
@@ -73,8 +100,29 @@ schedules = backups_client.schedules(database_id)
|
|
73
100
|
|
74
101
|
returns an array of [Schedule](docs/models.md#schedule)
|
75
102
|
|
103
|
+
### Schedule
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
schedule = backups_client.schedule(database_id)
|
107
|
+
```
|
108
|
+
|
109
|
+
Schedules the backups at 00:00 UTC.
|
110
|
+
|
111
|
+
Returns a [Schedule](docs/models.md#schedule)
|
112
|
+
|
113
|
+
|
114
|
+
#### Capture
|
115
|
+
Captures a new backup for the given database
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
backup = backups_client.capture(database_id)
|
119
|
+
```
|
120
|
+
|
121
|
+
returns a [Backup](docs/models.md#backup)
|
122
|
+
|
76
123
|
|
77
|
-
|
124
|
+
### How do I get the database_id ?
|
125
|
+
You can obtain a database id by calling the Heroku Platform API
|
78
126
|
|
79
127
|
```ruby
|
80
128
|
addons = heroku.addon.list
|
data/docs/models.md
CHANGED
data/docs/services.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# Heroku CLI Postgres commands
|
2
|
+
|
3
|
+
This list contains all postgres commands supported by the official CLI.
|
4
|
+
Source: https://devcenter.heroku.com/articles/heroku-cli-commands
|
5
|
+
|
6
|
+
- [x] pg --> `client.databases.info(database_id)`
|
7
|
+
|
8
|
+
- [x] pg:backups --> `client.backups.list(app_id)`
|
9
|
+
|
10
|
+
- [ ] pg:backups:cancel
|
11
|
+
|
12
|
+
- [x] pg:backups:capture ---> `client.backups.capture(database_id)`
|
13
|
+
The command returns immediately, without waiting for the capture to be completed.
|
14
|
+
`--wait-interval` not implemented. `--snapshot` not implemented.
|
15
|
+
|
16
|
+
- [ ] pg:backups:delete
|
17
|
+
|
18
|
+
- [ ] pg:backups:download
|
19
|
+
|
20
|
+
- [ ] pg:backups:info
|
21
|
+
|
22
|
+
- [ ] pg:backups:restore
|
23
|
+
|
24
|
+
- [x] pg:backups:schedule --> `client.backups.schedule(database_id)`
|
25
|
+
|
26
|
+
|
27
|
+
- [x] pg:backups:schedules --> `client.backups.schedules(database_id)`
|
28
|
+
|
29
|
+
- [ ] pg:backups:unschedule
|
30
|
+
|
31
|
+
- [ ] pg:backups:url
|
32
|
+
|
33
|
+
- [ ] pg:connection-pooling:attach
|
34
|
+
|
35
|
+
- [ ] pg:copy
|
36
|
+
|
37
|
+
- [ ] pg:credentials
|
38
|
+
|
39
|
+
- [ ] pg:credentials:create
|
40
|
+
|
41
|
+
- [ ] pg:credentials:destroy
|
42
|
+
|
43
|
+
- [ ] pg:credentials:repair-default
|
44
|
+
|
45
|
+
- [ ] pg:credentials:rotate
|
46
|
+
|
47
|
+
- [ ] pg:credentials:url
|
48
|
+
|
49
|
+
- [ ] pg:diagnose
|
50
|
+
|
51
|
+
- [x] pg:info --> `client.databases.info(database_id)`
|
52
|
+
|
53
|
+
- [ ] pg:kill
|
54
|
+
|
55
|
+
- [ ] pg:killall
|
56
|
+
|
57
|
+
- [ ] pg:links
|
58
|
+
|
59
|
+
- [ ] pg:links:create
|
60
|
+
|
61
|
+
- [ ] pg:links:destroy
|
62
|
+
|
63
|
+
- [ ] pg:maintenance
|
64
|
+
|
65
|
+
- [ ] pg:maintenance:run
|
66
|
+
|
67
|
+
- [ ] pg:maintenance:window
|
68
|
+
|
69
|
+
- [ ] pg:outliers
|
70
|
+
|
71
|
+
- [ ] pg:promote
|
72
|
+
|
73
|
+
- [ ] pg:ps
|
74
|
+
|
75
|
+
- [ ] pg:psql
|
76
|
+
|
77
|
+
- [ ] pg:pull
|
78
|
+
|
79
|
+
- [ ] pg:push
|
80
|
+
|
81
|
+
- [ ] pg:reset
|
82
|
+
|
83
|
+
- [ ] pg:settings
|
84
|
+
|
85
|
+
- [ ] pg:settings:log-lock-waits
|
86
|
+
|
87
|
+
- [ ] pg:settings:log-min-duration-statement
|
88
|
+
|
89
|
+
- [ ] pg:settings:log-statement
|
90
|
+
|
91
|
+
- [ ] pg:unfollow
|
92
|
+
|
93
|
+
- [ ] pg:upgrade
|
94
|
+
|
95
|
+
- [x] pg:wait --> `client.wait(database_id)`
|
96
|
+
Waits for a database to be ready.
|
@@ -19,6 +19,17 @@ module Heroku
|
|
19
19
|
def schedules(database_id)
|
20
20
|
@client.perform_get_request("/client/v11/databases/#{database_id}/transfer-schedules")
|
21
21
|
end
|
22
|
+
|
23
|
+
def schedule(database_id)
|
24
|
+
@client.perform_post_request("/client/v11/databases/#{database_id}/transfer-schedules",
|
25
|
+
hour: 00,
|
26
|
+
timezone: 'UTC',
|
27
|
+
schedule_name: 'DATABASE_URL')
|
28
|
+
end
|
29
|
+
|
30
|
+
def capture(database_id)
|
31
|
+
@client.perform_post_request("/client/v11/databases/#{database_id}/backups")
|
32
|
+
end
|
22
33
|
end
|
23
34
|
end
|
24
35
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Heroku
|
2
2
|
module Api
|
3
3
|
module Postgres
|
4
|
-
|
5
4
|
def self.connect_oauth(oauth_client_key = ENV['HEROKU_OAUTH_TOKEN'])
|
6
5
|
Client.new(oauth_client_key)
|
7
6
|
end
|
@@ -12,29 +11,61 @@ module Heroku
|
|
12
11
|
@basic_url = 'https://postgres-starter-api.heroku.com'
|
13
12
|
end
|
14
13
|
|
14
|
+
# original call returns simply a database object, therefore I call the info API.
|
15
|
+
# perform_get_request "/client/v11/databases/#{database_id}/wait_status"
|
16
|
+
def wait(database_id, options = { wait_interval: 3 })
|
17
|
+
waiting = true
|
18
|
+
while waiting do
|
19
|
+
database = databases.info(database_id)
|
20
|
+
break unless database[:waiting?]
|
21
|
+
sleep(options[:wait_interval])
|
22
|
+
end
|
23
|
+
database
|
24
|
+
end
|
25
|
+
|
15
26
|
def backups
|
16
27
|
@backups ||= Backups.new(self)
|
17
28
|
end
|
18
29
|
|
19
30
|
def databases
|
20
|
-
@
|
31
|
+
@databases ||= Databases.new(self)
|
21
32
|
end
|
22
33
|
|
23
34
|
def perform_get_request(path)
|
24
|
-
url =
|
35
|
+
url = build_uri(path)
|
25
36
|
req = Net::HTTP::Get.new(url)
|
37
|
+
set_headers(req)
|
38
|
+
response = start_request(req, url)
|
39
|
+
parse_response(response)
|
40
|
+
end
|
41
|
+
|
42
|
+
def perform_post_request(path, params = {})
|
43
|
+
url = build_uri(path)
|
44
|
+
req = Net::HTTP::Post.new(url)
|
45
|
+
set_headers(req)
|
46
|
+
req.body = params.to_json
|
47
|
+
response = start_request(req, url)
|
48
|
+
parse_response(response)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def build_uri(path)
|
53
|
+
URI.join(@basic_url, path)
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_headers(req)
|
26
57
|
req['Accept'] = 'application/vnd.heroku+json; version=3'
|
27
58
|
req.basic_auth '', @oauth_client_key
|
59
|
+
end
|
60
|
+
|
61
|
+
def start_request(req, url)
|
28
62
|
http_new = Net::HTTP.new(url.hostname, url.port)
|
29
63
|
http_new.use_ssl = true
|
30
64
|
response = http_new.start { |http| http.request(req) }
|
31
|
-
parse_response(response)
|
32
65
|
end
|
33
66
|
|
34
|
-
private
|
35
|
-
|
36
67
|
def parse_response(response)
|
37
|
-
if response.code
|
68
|
+
if %w[200 201].include? response.code
|
38
69
|
JSON.parse(response.body, symbolize_names: true)
|
39
70
|
else
|
40
71
|
{ error: { status: response.code.to_i } }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroku-api-postgres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.alpha5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Rodi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- bin/console
|
130
130
|
- bin/setup
|
131
131
|
- docs/models.md
|
132
|
+
- docs/services.md
|
132
133
|
- heroku-api-postgres.gemspec
|
133
134
|
- lib/heroku/api/postgres.rb
|
134
135
|
- lib/heroku/api/postgres/backups.rb
|