rails-baklite 0.1.0 → 1.0.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 +17 -4
- data/Rakefile +2 -2
- data/lib/generators/baklite_generator.rb +11 -0
- data/lib/rails/baklite/version.rb +1 -1
- data/lib/rails/baklite.rb +34 -0
- data/lib/tasks/rails/baklite_tasks.rake +5 -0
- 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: 32eca5dafdf9862d334828ede3e7ef0db0333e414b7a856da28b8462dbbac1b4
|
4
|
+
data.tar.gz: c93a9788b0be2d41344d1e501e426b3bd73d5cfe6988a4de83ff5441bca34c00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9376a92718e7aa73aef6cca467242221686126bdfa1a8c9b3a854e393537d97f4c3f19e2fa612063658b386cc0fd4fafe81f89bbd1e1b4adc9f460a355ac7e3
|
7
|
+
data.tar.gz: 3a6068cfca46237f33db1ccea09bfe2d04cb375569b7ebc4cf7bf0013cbb415b871f286312512778b5fcb2b0642397a8bbd514131ca3b4b1bafcfb0121c3646f
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Rails::Baklite
|
2
|
-
|
2
|
+
Baklite adapter for Rails.
|
3
3
|
|
4
4
|
## Usage
|
5
|
-
|
5
|
+
Head to the documentation on [baklite.tortitas.eu/docs/rails](https://baklite.tortitas.eu/docs/rails) for a complete guide on how to use this gem.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
Add this line to your application's Gemfile:
|
@@ -21,8 +21,21 @@ Or install it yourself as:
|
|
21
21
|
$ gem install rails-baklite
|
22
22
|
```
|
23
23
|
|
24
|
-
##
|
25
|
-
|
24
|
+
## Tests
|
25
|
+
For the tests to work you need an instance of Baklite running locally on port
|
26
|
+
3000. Then create a new user and head to http://localhost:3000/docs/rails, copy the code for credentials file.
|
27
|
+
|
28
|
+
Now execute the following commands:
|
29
|
+
```bash
|
30
|
+
cd test/dummy
|
31
|
+
bin/rails generate baklite
|
32
|
+
bin/rails credentials:edit -e test
|
33
|
+
```
|
34
|
+
|
35
|
+
Now run the tests from the root with:
|
36
|
+
```bash
|
37
|
+
bin/test
|
38
|
+
```
|
26
39
|
|
27
40
|
## License
|
28
41
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/setup'
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class BakliteGenerator < Rails::Generators::Base
|
2
|
+
desc 'This generator creates an initializer file at config/initializers/baklite.rb'
|
3
|
+
def create_initializer_file
|
4
|
+
create_file 'config/initializers/baklite.rb', <<~RUBY
|
5
|
+
Rails::Baklite.configure do |config|
|
6
|
+
config.token = Rails.application.credentials.baklite[:token]
|
7
|
+
config.name = Rails.application.class.module_parent_name
|
8
|
+
end
|
9
|
+
RUBY
|
10
|
+
end
|
11
|
+
end
|
data/lib/rails/baklite.rb
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
require 'rails/baklite/version'
|
2
2
|
require 'rails/baklite/railtie'
|
3
3
|
require 'sqlite3'
|
4
|
+
require 'net/http'
|
5
|
+
require 'active_support/configurable'
|
4
6
|
|
5
7
|
module Rails
|
6
8
|
module Baklite
|
9
|
+
include ActiveSupport::Configurable
|
10
|
+
|
11
|
+
class Error < StandardError; end
|
12
|
+
|
13
|
+
config_accessor(:token) do
|
14
|
+
''
|
15
|
+
end
|
16
|
+
|
7
17
|
def self.backup
|
8
18
|
db_config = ActiveRecord::Base.connection_db_config
|
9
19
|
database = db_config.configuration_hash
|
@@ -13,6 +23,8 @@ module Rails
|
|
13
23
|
|
14
24
|
_backup(ActiveRecord::Base.connection.raw_connection, backupfile)
|
15
25
|
|
26
|
+
upload(backupfile)
|
27
|
+
|
16
28
|
backupfile
|
17
29
|
end
|
18
30
|
|
@@ -42,5 +54,27 @@ module Rails
|
|
42
54
|
end while b.remaining > 0
|
43
55
|
b.finish
|
44
56
|
end
|
57
|
+
|
58
|
+
def self.upload(backupfile)
|
59
|
+
raise Error, 'No token provided' if Rails::Baklite.token.empty?
|
60
|
+
|
61
|
+
name = Rails::Baklite.config.name || Rails.application.class.module_parent_name
|
62
|
+
addr = Rails.env.test? ? 'http://localhost:3000' : 'https://baklite.tortitas.eu'
|
63
|
+
|
64
|
+
uri = URI.parse("#{addr}/databases/snapshots")
|
65
|
+
|
66
|
+
File.open(backupfile) do |file|
|
67
|
+
req = Net::HTTP::Post.new(uri.path)
|
68
|
+
req['Authorization'] =
|
69
|
+
"Bearer #{Rails::Baklite.token}"
|
70
|
+
req.set_form [['file', file], ['name', name]], 'multipart/form-data'
|
71
|
+
|
72
|
+
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
73
|
+
http.request(req)
|
74
|
+
end
|
75
|
+
|
76
|
+
raise Error, "Failed to upload the backup: #{res.code} #{res.body}" if res.code != '201'
|
77
|
+
end
|
78
|
+
end
|
45
79
|
end
|
46
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-baklite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor García Fernández
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- MIT-LICENSE
|
35
35
|
- README.md
|
36
36
|
- Rakefile
|
37
|
+
- lib/generators/baklite_generator.rb
|
37
38
|
- lib/rails/baklite.rb
|
38
39
|
- lib/rails/baklite/railtie.rb
|
39
40
|
- lib/rails/baklite/version.rb
|