syncthing-helper 0.1.1
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 +7 -0
- data/.gitignore +50 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +6 -0
- data/bin/setup +8 -0
- data/bin/syncthing-helper +4 -0
- data/lib/syncthing/helper/api/config.rb +35 -0
- data/lib/syncthing/helper/api/updater.rb +75 -0
- data/lib/syncthing/helper/api.rb +36 -0
- data/lib/syncthing/helper/cli/abstract_command.rb +58 -0
- data/lib/syncthing/helper/cli/demo_command.rb +13 -0
- data/lib/syncthing/helper/cli/device_command.rb +52 -0
- data/lib/syncthing/helper/cli/folder_command.rb +55 -0
- data/lib/syncthing/helper/cli/main_command.rb +11 -0
- data/lib/syncthing/helper/cli/updater_command.rb +41 -0
- data/lib/syncthing/helper/cli.rb +9 -0
- data/lib/syncthing/helper/version.rb +5 -0
- data/lib/syncthing/helper.rb +38 -0
- data/syncthing-helper.gemspec +64 -0
- metadata +293 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5716dadce00cc9ed1f69ae22e03d32585351027b3d87307043e38abb5d1d347d
|
4
|
+
data.tar.gz: beca3376350dcf0f5a24df9d268046cb3e32d101791cd3eba57f0b2a9455e496
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9c839fa5b527219ab6b0eb557ff7ccb6dea3b697db529bab7ef1596f2a8e9389306cfec0a9adca932d4308a79bd483d679ee47113ad27528c4d2be89b0961e6
|
7
|
+
data.tar.gz: 132f7c20e11675039442a8a3cb8529ff22507bc1ddd452fddd4387bf79095087e7edf77ca85161816213308ac47e5b7d69da79cfe0a8dc6a5f37a9dcc6b5939c
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 njkli
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Adminius
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Syncthing::Helper
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/syncthing/helper`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'syncthing-helper'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install syncthing-helper
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/syncthing-helper.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Syncthing
|
2
|
+
module Helper
|
3
|
+
module API
|
4
|
+
class Config < OpenStruct
|
5
|
+
include Roar::Client
|
6
|
+
include Roar::JSON
|
7
|
+
|
8
|
+
property :version
|
9
|
+
property :gui
|
10
|
+
property :options
|
11
|
+
collection :folders
|
12
|
+
collection :devices
|
13
|
+
|
14
|
+
def connect syncthing_uri: nil, syncthing_api_key: nil
|
15
|
+
@opts = {uri: URI(syncthing_uri) + 'rest/system/config', as: 'application/json'}
|
16
|
+
@syncthing_api_key = syncthing_api_key
|
17
|
+
end
|
18
|
+
|
19
|
+
def retrieve
|
20
|
+
get(@opts) { |r| auth(r) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def update
|
24
|
+
post(@opts) { |r| auth(r) }
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def auth r
|
29
|
+
r.add_field('X-API-Key', @syncthing_api_key)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Syncthing
|
2
|
+
module Helper
|
3
|
+
module API
|
4
|
+
class UpdaterBase
|
5
|
+
include Concurrent::Async
|
6
|
+
attr_accessor :current_snapshot, :listener, :config_obj
|
7
|
+
|
8
|
+
def initialize config_obj: nil, col: nil
|
9
|
+
super()
|
10
|
+
@config_obj = config_obj
|
11
|
+
@col = col
|
12
|
+
listen
|
13
|
+
end
|
14
|
+
|
15
|
+
def listen
|
16
|
+
Logger.tagged('firestore/' + @col) {Logger.info 'Starting query listener'}
|
17
|
+
@listener = (Firestore.col @col).listen do |snapshot|
|
18
|
+
if snapshot.changes.count > 0
|
19
|
+
@config_obj.retrieve
|
20
|
+
@current_snapshot = snapshot
|
21
|
+
snapshot.changes.each do |chng|
|
22
|
+
@chng_obj = chng
|
23
|
+
send "#{@col}_#{chng.type.to_s}".to_sym
|
24
|
+
end
|
25
|
+
@config_obj.update
|
26
|
+
Logger.tagged('config_api: ' + @col.singularize + '/update') { Logger.debug 'Written' }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def removed
|
32
|
+
id_field = API::DB_FIELDS_CONFIG_OBJ[@col]
|
33
|
+
@config_obj[@col].delete_if { |f| f[id_field] == @chng_obj.doc.document_id }
|
34
|
+
Logger.tagged('config_api: ' + @col.singularize + '/rm') { Logger.debug @chng_obj.doc.document_id }
|
35
|
+
end
|
36
|
+
alias_method :folders_removed, :removed
|
37
|
+
alias_method :devices_removed, :removed
|
38
|
+
end
|
39
|
+
|
40
|
+
class DevicesUpdater < UpdaterBase
|
41
|
+
# TODO: validate input!
|
42
|
+
def devices_added
|
43
|
+
device_exists = @config_obj.devices.find{ |d| d['deviceID'] == @chng_obj.doc.document_id }
|
44
|
+
unless device_exists
|
45
|
+
new_device = @config_obj.devices.first.dup
|
46
|
+
new_device['deviceID'] = @chng_obj.doc.document_id
|
47
|
+
new_device['name'] = @chng_obj.doc.data[:label]
|
48
|
+
new_device['compression'] = 'always'
|
49
|
+
@config_obj.devices << new_device
|
50
|
+
Logger.tagged('config_api: ' + @col.singularize + '/add') { Logger.debug @chng_obj.doc.document_id }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
alias_method :devices_modified, :devices_added
|
54
|
+
end
|
55
|
+
|
56
|
+
class FoldersUpdater < UpdaterBase
|
57
|
+
# TODO: validate input!
|
58
|
+
def folders_added
|
59
|
+
folders_removed
|
60
|
+
new_folder = @config_obj.folders.first.dup
|
61
|
+
new_folder['id'] = @chng_obj.doc.document_id
|
62
|
+
new_folder['path'] = @chng_obj.doc.data[:path]
|
63
|
+
new_folder['label'] = @chng_obj.doc.data[:label]
|
64
|
+
new_folder['type'] = @chng_obj.doc.data[:type]
|
65
|
+
new_folder['maxConflicts'] = -1
|
66
|
+
new_folder['devices'] = API::Firestore.col('devices').get.map { |d| {'deviceID' => d.document_id, 'introducedBy' => '' }}
|
67
|
+
@config_obj.folders << new_folder
|
68
|
+
Logger.tagged('config_api: ' + @col.singularize + '/add') { Logger.debug @chng_obj.doc.document_id }
|
69
|
+
end
|
70
|
+
alias_method :folders_modified, :folders_added
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'syncthing/helper/api/config'
|
2
|
+
require 'syncthing/helper/api/updater'
|
3
|
+
|
4
|
+
module Syncthing
|
5
|
+
module Helper
|
6
|
+
module API
|
7
|
+
module Xml
|
8
|
+
class Gui
|
9
|
+
include ROXML
|
10
|
+
xml_accessor :apikey
|
11
|
+
end
|
12
|
+
class Config
|
13
|
+
include ROXML
|
14
|
+
xml_name :configuration
|
15
|
+
xml_accessor :gui, as: Gui
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
attr_accessor :firestore
|
21
|
+
def init_firestore project_id: nil, credentials: nil
|
22
|
+
@firestore ||= Google::Cloud::Firestore.new project_id: project_id, credentials: credentials
|
23
|
+
const_set :Firestore, @firestore
|
24
|
+
const_set :DB_FIELDS, {'devices' => [:device_id, :label],
|
25
|
+
'folders' => [:id, :path, :label]}
|
26
|
+
const_set :DB_FIELDS_CONFIG_OBJ, {'devices' => 'deviceID',
|
27
|
+
'folders' => 'id'}
|
28
|
+
end
|
29
|
+
|
30
|
+
def api_key_from_xml xml_file
|
31
|
+
Xml::Config.from_xml(rio(xml_file).expand_path.read).gui.apikey
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Syncthing
|
2
|
+
module Helper
|
3
|
+
module CLI
|
4
|
+
module InstanceMethods
|
5
|
+
# DB_FIELDS = {'devices' => [:device_id, :label],
|
6
|
+
# 'folders' => [:id, :path, :label]}
|
7
|
+
|
8
|
+
def tabled_stdout header: nil, rows: nil
|
9
|
+
puts (TTY::Table.new header: header, rows: rows).
|
10
|
+
render(:unicode, alignment: [:center], multiline: true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def query
|
14
|
+
API::DB_FIELDS[col].map do |f|
|
15
|
+
API::Firestore.col(col).where(f, :eq, @ident)
|
16
|
+
end.map(&:get).find(&:first)
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete_record
|
20
|
+
idents.each do |ident|
|
21
|
+
@ident = ident
|
22
|
+
query ? API::Firestore.doc(col + '/' + query.first.document_id).delete : puts('record not found')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def col
|
27
|
+
self.class.name.split('::').last.underscore.split('_').first.pluralize
|
28
|
+
end
|
29
|
+
|
30
|
+
def trigger_updates
|
31
|
+
API::Firestore.col('folders').get.map(&:document_id).each do |d|
|
32
|
+
API::Firestore.col('folders').doc(d).update(devices: [])
|
33
|
+
end
|
34
|
+
Logger.tagged('trigger') {Logger.debug 'Update firestore folders'}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class AbstractCommand < Clamp::Command
|
39
|
+
include InstanceMethods
|
40
|
+
|
41
|
+
option "--version", :flag, "show version" do
|
42
|
+
puts Syncthing::Helper::VERSION
|
43
|
+
exit(0)
|
44
|
+
end
|
45
|
+
|
46
|
+
option ['-u', '--uri'], 'URI', 'Syncthing URI', environment_variable: 'SYNCTHING_URI', attribute_name: :syncthing_uri, default: 'http://127.0.0.1:8384'
|
47
|
+
option ['-p', '--project'], 'GCP_PROJECT_ID', 'GCP project_id', environment_variable: 'GOOGLE_APPLICATION_PROJECT_ID', attribute_name: :gcp_project_id
|
48
|
+
option ['-a', '--auth'], 'GCP_CREDS_JSON', 'Path to json keyfile', environment_variable: 'GOOGLE_APPLICATION_CREDENTIALS', attribute_name: :credentials
|
49
|
+
option ['-l', '--log'], 'LOG_LEVEL', 'trace, debug, info, warn, error, fatal', environment_variable: 'SYNCTHING_LOG_LEVEL', attribute_name: :log_level, default: :info
|
50
|
+
|
51
|
+
def execute
|
52
|
+
SemanticLogger.default_level = log_level.downcase.to_sym
|
53
|
+
API.init_firestore project_id: gcp_project_id, credentials: credentials
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Syncthing
|
2
|
+
module Helper
|
3
|
+
module CLI
|
4
|
+
class DemoCommand < AbstractCommand
|
5
|
+
parameter 'INPUT', 'xml config to read', attribute_name: :src, required: true
|
6
|
+
|
7
|
+
def execute
|
8
|
+
puts Syncthing::Helper::API.api_key_from_xml src
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Syncthing
|
2
|
+
module Helper
|
3
|
+
module CLI
|
4
|
+
class DeviceCreateCommand < AbstractCommand
|
5
|
+
parameter 'DEVICE_ID:DEVICE_NAME ...', 'Syncthing device UUID:NAME', attribute_name: :device_ids, required: true
|
6
|
+
# parameter 'DEVICE_LABEL', 'Syncthing human readable device label', attribute_name: :device_label, required: true
|
7
|
+
|
8
|
+
def execute
|
9
|
+
super
|
10
|
+
device_ids.each do |d|
|
11
|
+
device_id, device_label = d.split ':'
|
12
|
+
API::Firestore.doc('devices/' + device_id).set(device_id: device_id, label: device_label)
|
13
|
+
end
|
14
|
+
trigger_updates
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class DeviceReadCommand < AbstractCommand
|
19
|
+
def execute
|
20
|
+
super
|
21
|
+
col = 'devices'
|
22
|
+
docs = API::Firestore.col(col).get.map(&:document_id)
|
23
|
+
res = docs.map{|d| dr = API::Firestore.doc(col + '/' + d).get.data; [dr[:device_id], dr[:label]]}
|
24
|
+
tabled_stdout header: ['Device Id', 'Label'], rows: res
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class DeviceUpdateCommand < AbstractCommand
|
29
|
+
def execute
|
30
|
+
raise NotImplementedError, 'Not required currently'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class DeviceDeleteCommand < AbstractCommand
|
35
|
+
parameter 'DEVICE_IDS ...', 'Syncthing device ids or names', attribute_name: :idents, required: true
|
36
|
+
|
37
|
+
def execute
|
38
|
+
super
|
39
|
+
delete_record
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class DeviceCommand < AbstractCommand
|
44
|
+
self.default_subcommand = 'ls'
|
45
|
+
subcommand ['add', 'create'], 'Create device', DeviceCreateCommand
|
46
|
+
subcommand ['ls', 'read'], 'Read device tables', DeviceReadCommand
|
47
|
+
subcommand ['set', 'update'], 'Update devices', DeviceUpdateCommand
|
48
|
+
subcommand ['rm', 'delete'], 'Delete devices', DeviceDeleteCommand
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Syncthing
|
2
|
+
module Helper
|
3
|
+
module CLI
|
4
|
+
class FolderCreateCommand < AbstractCommand
|
5
|
+
parameter 'ID:PATH:LABEL ...', 'Folder ID:PATH:LABEL', attribute_name: :folders, required: true
|
6
|
+
|
7
|
+
def execute
|
8
|
+
super
|
9
|
+
folders.each do |f|
|
10
|
+
folder_id, folder_path, folder_label = f.split ':'
|
11
|
+
|
12
|
+
folder = {"id" => folder_id,
|
13
|
+
"path" => folder_path,
|
14
|
+
"label" => folder_label,
|
15
|
+
"type" =>"readwrite",
|
16
|
+
"devices" => [],
|
17
|
+
"maxConflicts" => -1}
|
18
|
+
API::Firestore.doc('folders/' + folder_id).set(folder)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class FolderReadCommand < AbstractCommand
|
24
|
+
def execute
|
25
|
+
super
|
26
|
+
col = 'folders'
|
27
|
+
docs = API::Firestore.col(col).get.map(&:document_id)
|
28
|
+
res = docs.map do |d|
|
29
|
+
dr = API::Firestore.doc(col + '/' + d).get.data
|
30
|
+
[dr[:id], dr[:path], dr[:label]]
|
31
|
+
end
|
32
|
+
tabled_stdout header: ['Folder Id', 'Path', 'Label'], rows: res
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class FolderDeleteCommand < AbstractCommand
|
37
|
+
parameter 'FOLDER_IDS ...', 'Syncthing device ids or names', attribute_name: :idents, required: true
|
38
|
+
|
39
|
+
def execute
|
40
|
+
super
|
41
|
+
delete_record
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class FolderCommand < AbstractCommand
|
46
|
+
self.default_subcommand = 'ls'
|
47
|
+
subcommand ['add', 'create'], 'Create device', FolderCreateCommand
|
48
|
+
subcommand ['ls', 'read'], 'Read device tables', FolderReadCommand
|
49
|
+
# subcommand ['set', 'update'], 'Update devices', FolderUpdateCommand
|
50
|
+
subcommand ['rm', 'delete'], 'Delete devices', FolderDeleteCommand
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Syncthing
|
2
|
+
module Helper
|
3
|
+
module CLI
|
4
|
+
class MainCommand < AbstractCommand
|
5
|
+
subcommand ['dev', 'devices'], 'Participating devices', DeviceCommand
|
6
|
+
subcommand ['fol', 'folders'], 'Synchronized folders operations', FolderCommand
|
7
|
+
subcommand ['updater'], 'Config sync daemon', UpdaterCommand
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Syncthing
|
2
|
+
module Helper
|
3
|
+
module CLI
|
4
|
+
class UpdaterCommand < AbstractCommand
|
5
|
+
option ['-k', '--key'], 'API_KEY', 'Syncthing Api key', environment_variable: 'SYNCTHING_API_KEY', attribute_name: :syncthing_api_key
|
6
|
+
option ['-c', '--config'], 'PATH', 'config.xml path', environment_variable: 'SYNCTHING_CONFIG_PATH', attribute_name: :xml_config
|
7
|
+
|
8
|
+
def execute
|
9
|
+
super
|
10
|
+
config_obj = API::Config.new
|
11
|
+
config_obj.connect(syncthing_uri: syncthing_uri,
|
12
|
+
syncthing_api_key: api_key)
|
13
|
+
|
14
|
+
%w(devices folders).each do |col_name|
|
15
|
+
klass = ('Syncthing::Helper::API::' + col_name.capitalize + 'Updater').constantize
|
16
|
+
instance_variable_set ('@' + col_name).to_sym, klass.new(config_obj: config_obj, col: col_name)
|
17
|
+
end
|
18
|
+
|
19
|
+
%w(term int quit).map(&:upcase).each do |sig|
|
20
|
+
Signal.trap(sig) do
|
21
|
+
Thread.new {shutdown}
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
loop { sleep 60 }
|
27
|
+
end
|
28
|
+
|
29
|
+
def shutdown
|
30
|
+
@devices.listener.stop
|
31
|
+
@folders.listener.stop
|
32
|
+
sleep 5
|
33
|
+
end
|
34
|
+
|
35
|
+
def api_key
|
36
|
+
syncthing_api_key || Syncthing::Helper::API.api_key_from_xml(xml_config)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Clamp.allow_options_after_parameters = true
|
2
|
+
%w(syncthing/helper/cli/abstract_command
|
3
|
+
syncthing/helper/cli/demo_command
|
4
|
+
syncthing/helper/cli/device_command
|
5
|
+
syncthing/helper/cli/folder_command
|
6
|
+
|
7
|
+
syncthing/helper/cli/updater_command
|
8
|
+
|
9
|
+
syncthing/helper/cli/main_command).each(&method(:require))
|
@@ -0,0 +1,38 @@
|
|
1
|
+
gem_reqs = %w(multi_json
|
2
|
+
active_support/core_ext/hash
|
3
|
+
roar/client
|
4
|
+
roar/json
|
5
|
+
roxml
|
6
|
+
concurrent
|
7
|
+
rio
|
8
|
+
tty-table
|
9
|
+
clamp
|
10
|
+
semantic_logger
|
11
|
+
google/cloud/firestore
|
12
|
+
google/cloud/pubsub)
|
13
|
+
|
14
|
+
app_reqs = %w(syncthing/helper/version
|
15
|
+
syncthing/helper/api
|
16
|
+
syncthing/helper/cli
|
17
|
+
syncthing/helper/xml/config)
|
18
|
+
|
19
|
+
(gem_reqs + app_reqs).each(&method(:require))
|
20
|
+
# require 'syncthing/helper/api/model'
|
21
|
+
|
22
|
+
module Syncthing
|
23
|
+
module Helper
|
24
|
+
class LogFormatter < SemanticLogger::Formatters::Color
|
25
|
+
|
26
|
+
def call(log, logger)
|
27
|
+
self.log = log
|
28
|
+
self.logger = logger
|
29
|
+
self.color = color_map[log.level]
|
30
|
+
|
31
|
+
# [time, level, process_info, tags, named_tags, duration, name, message, payload, exception].compact.join(' ')
|
32
|
+
[level, tags, named_tags, duration, message, payload, exception].compact.join(' ')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
Logger = SemanticLogger['Syncthing::Helper']
|
36
|
+
SemanticLogger.add_appender(io: STDOUT, formatter: LogFormatter.new)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "syncthing/helper/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "syncthing-helper"
|
8
|
+
spec.version = Syncthing::Helper::VERSION
|
9
|
+
spec.authors = ["voobscout"]
|
10
|
+
spec.email = ["voobscout+syncthing.helper@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{syncthing-helper semi-automates management of multiple installs on NixOS}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/njkli/syncthing-helper"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "bin"
|
30
|
+
spec.executables = ['syncthing-helper']
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "pry"
|
37
|
+
|
38
|
+
# spec.add_dependency 'rom'
|
39
|
+
# spec.add_dependency 'rom-sql'
|
40
|
+
# spec.add_dependency 'rom-repository'
|
41
|
+
# spec.add_dependency 'sqlite3'
|
42
|
+
|
43
|
+
# spec.add_dependency 'rom-yaml'
|
44
|
+
# spec.add_dependency 'rom-json'
|
45
|
+
# spec.add_dependency 'rom-relation'
|
46
|
+
# spec.add_dependency 'rom-mapper'
|
47
|
+
# spec.add_dependency 'rom-repository'
|
48
|
+
# spec.add_dependency 'rom-changeset'
|
49
|
+
|
50
|
+
# spec.add_dependency 'rom-model'
|
51
|
+
|
52
|
+
spec.add_dependency 'semantic_logger'
|
53
|
+
spec.add_dependency 'activesupport'
|
54
|
+
spec.add_dependency "tty-table"
|
55
|
+
spec.add_dependency 'nokogiri'
|
56
|
+
spec.add_dependency 'roxml'
|
57
|
+
spec.add_dependency 'multi_json'
|
58
|
+
spec.add_dependency 'roar'
|
59
|
+
spec.add_dependency 'concurrent-ruby'
|
60
|
+
spec.add_dependency 'rio'
|
61
|
+
spec.add_dependency 'clamp'
|
62
|
+
spec.add_dependency 'google-cloud-firestore'
|
63
|
+
spec.add_dependency 'google-cloud-pubsub'
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,293 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: syncthing-helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- voobscout
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: semantic_logger
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activesupport
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: tty-table
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: nokogiri
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: roxml
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: multi_json
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: roar
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: concurrent-ruby
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rio
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: clamp
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: google-cloud-firestore
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :runtime
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: google-cloud-pubsub
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
type: :runtime
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
237
|
+
description: syncthing-helper semi-automates management of multiple installs on NixOS
|
238
|
+
email:
|
239
|
+
- voobscout+syncthing.helper@gmail.com
|
240
|
+
executables:
|
241
|
+
- syncthing-helper
|
242
|
+
extensions: []
|
243
|
+
extra_rdoc_files: []
|
244
|
+
files:
|
245
|
+
- ".gitignore"
|
246
|
+
- ".rspec"
|
247
|
+
- ".travis.yml"
|
248
|
+
- Gemfile
|
249
|
+
- LICENSE
|
250
|
+
- LICENSE.txt
|
251
|
+
- README.md
|
252
|
+
- Rakefile
|
253
|
+
- bin/console
|
254
|
+
- bin/setup
|
255
|
+
- bin/syncthing-helper
|
256
|
+
- lib/syncthing/helper.rb
|
257
|
+
- lib/syncthing/helper/api.rb
|
258
|
+
- lib/syncthing/helper/api/config.rb
|
259
|
+
- lib/syncthing/helper/api/updater.rb
|
260
|
+
- lib/syncthing/helper/cli.rb
|
261
|
+
- lib/syncthing/helper/cli/abstract_command.rb
|
262
|
+
- lib/syncthing/helper/cli/demo_command.rb
|
263
|
+
- lib/syncthing/helper/cli/device_command.rb
|
264
|
+
- lib/syncthing/helper/cli/folder_command.rb
|
265
|
+
- lib/syncthing/helper/cli/main_command.rb
|
266
|
+
- lib/syncthing/helper/cli/updater_command.rb
|
267
|
+
- lib/syncthing/helper/version.rb
|
268
|
+
- syncthing-helper.gemspec
|
269
|
+
homepage: https://github.com/njkli/syncthing-helper
|
270
|
+
licenses:
|
271
|
+
- MIT
|
272
|
+
metadata: {}
|
273
|
+
post_install_message:
|
274
|
+
rdoc_options: []
|
275
|
+
require_paths:
|
276
|
+
- lib
|
277
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
278
|
+
requirements:
|
279
|
+
- - ">="
|
280
|
+
- !ruby/object:Gem::Version
|
281
|
+
version: '0'
|
282
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
283
|
+
requirements:
|
284
|
+
- - ">="
|
285
|
+
- !ruby/object:Gem::Version
|
286
|
+
version: '0'
|
287
|
+
requirements: []
|
288
|
+
rubyforge_project:
|
289
|
+
rubygems_version: 2.7.6
|
290
|
+
signing_key:
|
291
|
+
specification_version: 4
|
292
|
+
summary: syncthing-helper semi-automates management of multiple installs on NixOS
|
293
|
+
test_files: []
|