haveapi-fs 0.1.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a14a50210ec4ce355b9ecc5dae75ea593a86036
4
- data.tar.gz: dac3cc874105f07b4ebae90e9b9642f4c1640979
3
+ metadata.gz: 9b569d2b03ccdaa731537062da0b22f2553e29bc
4
+ data.tar.gz: eb16c244b57f799a25d9dbf5a6c0cb1b6a6df6a0
5
5
  SHA512:
6
- metadata.gz: 7c671e57fc944d0b69bb3e965302250931bfb5fd3c2e79a131bd4e3fba0bf0ed96b87966f40bf7606af6ff050a050fc55b980db26c6d3dd42c888034c6515188
7
- data.tar.gz: 19e2183b8864263c8efe4499d64854e739aca10169ad8f952b5ac1a6c02dd0ef637a4bc24d3aa8d3dcd2b0a7c377f9b20d30ba783de2f10cf34945ef3f7b6148
6
+ metadata.gz: 2baa77348da4c6a2c41633d9dc5fff47528258f0312a6d85cf5b71b2b5d15f82dbed4811b4cd4b75cf46c2082cc5449fa726b335926ddde9a9b2a59195954020
7
+ data.tar.gz: 3be72625e389a3a40fca3d1bbe10d877d360c21de3b68607682fb1ed0c8451eca533e90222ba648cc36edeba89ba274879df8dd57b91d2ee9a072e4db2ea2b10
data/CHANGELOG CHANGED
@@ -1,2 +1,9 @@
1
+ * Thu Nov 24 2016 - version 0.7.0
2
+ - Option `block` enables action blocking mode
3
+ - Rename MetaDir and MetaFile to ProxyDir and ProxyFile
4
+ - Add metadata input/output parameters
5
+ - Fix typo in handling of boolean input parameters
6
+ - Show and parse custom parameters as JSON
7
+
1
8
  * Mon Apr 18 2016 - version 0.1.0
2
9
  - Initial release
data/README.md CHANGED
@@ -33,6 +33,7 @@ Debian:
33
33
  password Password
34
34
  token Authentication token
35
35
  nodaemonize Stay in the foreground
36
+ block Wait until blocking actions are finished
36
37
  log Enable logging while daemonized
37
38
  index_limit=LIMIT Limit number of objects in resource directory
38
39
 
data/haveapi-fs.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'haveapi/fs/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'haveapi-fs'
8
8
  spec.version = HaveAPI::Fs::VERSION
9
- spec.date = '2016-04-18'
9
+ spec.date = '2016-11-24'
10
10
  spec.authors = ['Jakub Skokan']
11
11
  spec.email = ['jakub.skokan@vpsfree.cz']
12
12
  spec.summary =
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'pry', '~> 0.10.3'
25
25
 
26
26
  spec.add_runtime_dependency 'rfusefs', '~> 1.0.3'
27
- spec.add_runtime_dependency 'haveapi-client', '~> 0.5.4'
27
+ spec.add_runtime_dependency 'haveapi-client', '~> 0.7.0'
28
28
  spec.add_runtime_dependency 'md2man', '~> 5.1.1'
29
29
  spec.add_runtime_dependency 'highline', '~> 1.7.8'
30
30
  end
@@ -19,23 +19,27 @@ module HaveAPI::Fs::Components
19
19
  children[:errors] = [ActionErrors, self, bound: true]
20
20
  children[:input] = [ActionInput, self, bound: true]
21
21
  children[:output] = [ActionOutput, self, bound: true]
22
+ children[:meta] = [ActionMeta, self, bound: true]
22
23
  children[:exec] = [ActionExec, self, bound: true]
23
24
  children[:reset] = [DirectoryReset, bound: true]
24
25
  end
25
26
 
26
27
  def contents
27
- ret = super + %w(input output status message errors exec reset)
28
+ ret = super + %w(input output status message meta errors exec reset)
28
29
  ret << 'exec.yml' if @action.input_params.any?
29
30
  ret
30
31
  end
31
32
 
32
33
  def exec(meta: {})
33
34
  @action.provide_args(*@resource.prepared_args)
35
+
36
+ params = children[:input].values
37
+ params[:meta] = meta
38
+ params[:meta].update(children[:meta].values)
39
+
34
40
  ret = HaveAPI::Client::Response.new(
35
41
  @action,
36
- @action.execute(
37
- children[:input].values.update({meta: meta})
38
- )
42
+ @action.execute(params)
39
43
  )
40
44
 
41
45
  children[:status].set(ret.ok?)
@@ -65,6 +69,9 @@ module HaveAPI::Fs::Components
65
69
  end
66
70
 
67
71
  children[:output].data = res
72
+ children[:meta].output = ret.meta
73
+
74
+ ret.wait_for_completion if @context.opts[:block] && @action.blocking?
68
75
 
69
76
  else
70
77
  children[:message].set(ret.message)
@@ -0,0 +1,33 @@
1
+ module HaveAPI::Fs::Components
2
+ class ActionMeta < Directory
3
+ component :action_meta
4
+
5
+ def initialize(action_dir, *args)
6
+ super(*args)
7
+ @action_dir = action_dir
8
+ end
9
+
10
+ def setup
11
+ super
12
+
13
+ children[:input] = [MetaInput, @action_dir, bound: true]
14
+ children[:output] = [MetaOutput, @action_dir, :global, bound: true]
15
+ end
16
+
17
+ def contents
18
+ super + %w(output)
19
+ end
20
+
21
+ def output=(data)
22
+ children[:output].data = data
23
+ end
24
+
25
+ def values
26
+ children[:input].values
27
+ end
28
+
29
+ def title
30
+ 'Input/output global metadata parameters'
31
+ end
32
+ end
33
+ end
@@ -62,7 +62,7 @@ module HaveAPI::Fs::Components
62
62
  [ListItem, @action_dir.action, :output, param]
63
63
  end
64
64
 
65
- elsif @action_dir.action.params.has_key?(name)
65
+ elsif parameters.has_key?(name)
66
66
  [
67
67
  Parameter,
68
68
  @action_dir.action,
@@ -0,0 +1,48 @@
1
+ module HaveAPI::Fs::Components
2
+ class MetaInput < Directory
3
+ component :meta_input
4
+ help_file :action_input
5
+
6
+ def initialize(action_dir, *args)
7
+ super(*args)
8
+
9
+ @action_dir = action_dir
10
+ end
11
+
12
+ def contents
13
+ super + parameters.keys.map(&:to_s)
14
+ end
15
+
16
+ def parameters
17
+ @action_dir.action.instance_variable_get('@spec')[:meta][:global][:input][:parameters]
18
+ end
19
+
20
+ def values
21
+ Hash[children.select { |n, c| c.is_a?(Parameter) && c.set? }.map { |n, c| [n, c.value] }]
22
+ end
23
+
24
+ def title
25
+ 'Input metadata parameters'
26
+ end
27
+
28
+ protected
29
+ def new_child(name)
30
+ if child = super
31
+ child
32
+
33
+ elsif parameters.has_key?(name)
34
+ [
35
+ Parameter,
36
+ @action_dir.action,
37
+ name,
38
+ :input,
39
+ nil,
40
+ meta: :global,
41
+ ]
42
+
43
+ else
44
+ nil
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,55 @@
1
+ module HaveAPI::Fs::Components
2
+ class MetaOutput < Directory
3
+ component :meta_output
4
+ help_file :action_output
5
+ attr_accessor :data
6
+ attr_reader :scope
7
+
8
+ def initialize(action_dir, scope, data = nil, *args)
9
+ super(*args)
10
+
11
+ @action_dir = action_dir
12
+ @scope = scope
13
+ @data = data
14
+ end
15
+
16
+ def contents
17
+ ret = super
18
+ return ret unless @data
19
+
20
+ ret.concat(parameters.keys.map(&:to_s))
21
+ ret
22
+ end
23
+
24
+ def parameters
25
+ @action_dir.action.instance_variable_get('@spec')[:meta][@scope][:output][:parameters]
26
+ end
27
+
28
+ def title
29
+ 'Output metadata parameters'
30
+ end
31
+
32
+ protected
33
+ def new_child(name)
34
+ if child = super
35
+ child
36
+
37
+ elsif !@data
38
+ nil
39
+
40
+ elsif parameters.has_key?(name)
41
+ [
42
+ Parameter,
43
+ @action_dir.action,
44
+ name,
45
+ :output,
46
+ @data,
47
+ meta: @scope,
48
+ ]
49
+
50
+ else
51
+ nil
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,4 +1,5 @@
1
1
  require 'time'
2
+ require 'json'
2
3
 
3
4
  module HaveAPI::Fs::Components
4
5
  class Parameter < File
@@ -13,12 +14,22 @@ module HaveAPI::Fs::Components
13
14
  @value = value
14
15
  @set = false
15
16
  @mirror = opts[:mirror]
16
-
17
- if dir == :input
18
- @params = @action.input_params
17
+
18
+ if opts[:meta]
19
+ if dir == :input
20
+ @params = @action.instance_variable_get('@spec')[:meta][opts[:meta]][:input][:parameters]
21
+
22
+ else
23
+ @params = @action.instance_variable_get('@spec')[:meta][opts[:meta]][:output][:parameters]
24
+ end
19
25
 
20
26
  else
21
- @params = @action.params
27
+ if dir == :input
28
+ @params = @action.input_params
29
+
30
+ else
31
+ @params = @action.params
32
+ end
22
33
  end
23
34
 
24
35
  @desc = @params[@name]
@@ -55,7 +66,7 @@ module HaveAPI::Fs::Components
55
66
  str.to_i
56
67
 
57
68
  when 'Boolean'
58
- HaveAPI::Client::Parameters::Typed.Boolean.to_b(str)
69
+ HaveAPI::Client::Parameters::Typed::Boolean.to_b(str)
59
70
 
60
71
  when 'Integer'
61
72
  str.to_i
@@ -66,6 +77,9 @@ module HaveAPI::Fs::Components
66
77
  when 'Datetime'
67
78
  Time.iso8601(str)
68
79
 
80
+ when 'Custom'
81
+ JSON.parse(str)
82
+
69
83
  else
70
84
  str.strip
71
85
  end
@@ -114,6 +128,9 @@ module HaveAPI::Fs::Components
114
128
  when 'Datetime'
115
129
  v.is_a?(::Time) ? v.iso8601 : v
116
130
 
131
+ when 'Custom'
132
+ JSON.generate(v)
133
+
117
134
  else
118
135
  v
119
136
  end
@@ -1,5 +1,5 @@
1
1
  module HaveAPI::Fs::Components
2
- class MetaDir < Directory
2
+ class ProxyDir < Directory
3
3
  def initialize(path)
4
4
  super()
5
5
  @path = path
@@ -32,10 +32,10 @@ module HaveAPI::Fs::Components
32
32
  path = ::File.join(@dir.path, real_name)
33
33
 
34
34
  if ::File.directory?(path)
35
- [MetaDir, path]
35
+ [ProxyDir, path]
36
36
 
37
37
  else
38
- [MetaFile, path]
38
+ [ProxyFile, path]
39
39
  end
40
40
  end
41
41
  end
@@ -1,5 +1,5 @@
1
1
  module HaveAPI::Fs::Components
2
- class MetaFile < File
2
+ class ProxyFile < File
3
3
  def initialize(path)
4
4
  super()
5
5
  @path = path
@@ -17,6 +17,7 @@ module HaveAPI::Fs::Components
17
17
  ret = super - %w(create.yml)
18
18
  ret.concat(attributes)
19
19
  ret.concat(%w(save edit.yml)) if @update
20
+ ret << 'meta'
20
21
  ret
21
22
  end
22
23
 
@@ -138,6 +139,9 @@ module HaveAPI::Fs::Components
138
139
  elsif name == :'edit.yml' && @update
139
140
  [InstanceEdit, @update]
140
141
 
142
+ elsif name == :meta
143
+ [MetaOutput, @show, :object, @resource.instance_variable_get('@meta')]
144
+
141
145
  else
142
146
  nil
143
147
  end
@@ -46,7 +46,7 @@ module HaveAPI::Fs::Components
46
46
 
47
47
  when :'.assets'
48
48
  [
49
- MetaDir,
49
+ ProxyDir,
50
50
  ::File.join(
51
51
  ::File.realpath(::File.dirname(__FILE__)),
52
52
  '..', '..', '..', '..',
@@ -3,8 +3,8 @@ require 'yaml'
3
3
 
4
4
  module HaveAPI::Fs
5
5
  # A list of accepted mount options
6
- OPTIONS = %i(api version auth_method user password token nodaemonize log
7
- index_limit)
6
+ OPTIONS = %i(api version auth_method user password token nodaemonize block
7
+ log index_limit)
8
8
  USAGE = <<END
9
9
  version=VERSION API version to use
10
10
  auth_method=METHOD Authentication method (basic, token, noauth)
@@ -12,6 +12,7 @@ module HaveAPI::Fs
12
12
  password Password
13
13
  token Authentication token
14
14
  nodaemonize Stay in the foreground
15
+ block Wait until blocking actions are finished
15
16
  log Enable logging while daemonized
16
17
  index_limit=LIMIT Limit number of objects in resource directory
17
18
  END
@@ -100,8 +101,9 @@ END
100
101
  cfg = server_config(opts[:device])
101
102
  client = HaveAPI::Client::Client.new(
102
103
  opts[:device],
103
- opts[:version],
104
+ version: opts[:version],
104
105
  identity: 'haveapi-fs',
106
+ block: opts[:block] || false,
105
107
  )
106
108
 
107
109
  auth_klass = auth_method(opts, cfg && cfg[:last_auth])
@@ -1,5 +1,5 @@
1
1
  module HaveAPI
2
2
  module Fs
3
- VERSION = '0.1.0'
3
+ VERSION = '0.7.0'
4
4
  end
5
5
  end
data/lib/haveapi/fs.rb CHANGED
@@ -47,6 +47,9 @@ require_relative 'fs/components/action_message'
47
47
  require_relative 'fs/components/action_errors'
48
48
  require_relative 'fs/components/action_exec'
49
49
  require_relative 'fs/components/action_exec_edit'
50
+ require_relative 'fs/components/action_meta'
51
+ require_relative 'fs/components/meta_input'
52
+ require_relative 'fs/components/meta_output'
50
53
  require_relative 'fs/components/parameter'
51
54
  require_relative 'fs/components/resource_id'
52
55
  require_relative 'fs/components/help_file'
@@ -57,8 +60,8 @@ require_relative 'fs/components/instance_create'
57
60
  require_relative 'fs/components/instance_edit'
58
61
  require_relative 'fs/components/unsaved_list'
59
62
  require_relative 'fs/components/component_list'
60
- require_relative 'fs/components/meta_dir'
61
- require_relative 'fs/components/meta_file'
63
+ require_relative 'fs/components/proxy_dir'
64
+ require_relative 'fs/components/proxy_file'
62
65
  require_relative 'fs/components/info_files'
63
66
  require_relative 'fs/components/cache_stats'
64
67
  require_relative 'fs/components/pry'
@@ -11,6 +11,9 @@ output parameters.
11
11
  <dt><a href="output/help.html">output/</a></dt>
12
12
  <dd>Contains output parameters after the action was executed.</dd>
13
13
 
14
+ <dt><a href="meta/help.html">meta/</a></dt>
15
+ <dd>Contains input and output global metadata parameters.</dd>
16
+
14
17
  <dt>exec</dt>
15
18
  <dd>Write <code>1</code> to this file to execute the action.</dd>
16
19
 
@@ -14,7 +14,7 @@ possible to send only a subset of input parameters.
14
14
  <th>Default value</th>
15
15
  <th>Description</th>
16
16
  </tr>
17
- <% @c.action_dir.action.input_params.each do |name, desc| %>
17
+ <% @c.parameters.each do |name, desc| %>
18
18
  <tr>
19
19
  <td><%= name %></td>
20
20
  <td><%= desc[:label] %></td>
@@ -0,0 +1,10 @@
1
+ <h2>Contents</h2>
2
+ <p>
3
+ This directory contains input and output global metadata parameters.
4
+ </p>
5
+ <dl>
6
+ <dt><a href="input/help.html">input/</a></dt>
7
+ <dd>Input parameters.</dd>
8
+ <dt><a href="output/help.html">output/</a></dt>
9
+ <dd>Output parameters.</dd>
10
+ </dl>
@@ -10,7 +10,7 @@ until the action has been executed.
10
10
  <th>Data type</th>
11
11
  <th>Description</th>
12
12
  </tr>
13
- <% @c.action_dir.action.params.each do |name, desc| %>
13
+ <% @c.parameters.each do |name, desc| %>
14
14
  <tr>
15
15
  <td><%= name %></td>
16
16
  <td><%= desc[:label] %></td>
@@ -18,6 +18,9 @@ and subresources. Associated resources are represented by a directory.
18
18
  <dt><code>&lt;association_id&gt;</code></dt>
19
19
  <dd>To change the associated resource, write its id to this file.</dd>
20
20
 
21
+ <dt><a href="meta/help.html">meta/</a></dt>
22
+ <dd>Output metadata parameters.</dd>
23
+
21
24
  <dt>save</dt>
22
25
  <dd>Trigger the update action. The same as using <code>actions/update/exec</code>.</dd>
23
26
 
@@ -9,6 +9,9 @@ output parameters.
9
9
  `output/`
10
10
  Contains output parameters after the action was executed.
11
11
 
12
+ `meta/`
13
+ Contains input and output global metadata parameters.
14
+
12
15
  `exec`
13
16
  Write `1` to this file to execute the action.
14
17
 
@@ -4,7 +4,7 @@ Every input parameter is represented by a file that can be written to. If a file
4
4
  is not changed, the parameter it represents will not be sent to the API -- it is
5
5
  possible to send only a subset of input parameters.
6
6
 
7
- <% @c.action_dir.action.input_params.each do |name, desc| %>
7
+ <% @c.parameters.each do |name, desc| %>
8
8
  *<%= safe_print(name) %>*
9
9
  Label: <%= desc[:label] %>
10
10
  Required: <%= desc[:required] ? 'yes' : 'no' %>
@@ -0,0 +1,3 @@
1
+ CONTENTS
2
+ --------
3
+ This directory contains input and output global metadata parameters.
@@ -3,7 +3,7 @@ CONTENTS
3
3
  Every output parameter is represented by a read-only file. The directory is empty
4
4
  until the action has been executed.
5
5
 
6
- <% @c.action_dir.action.params.each do |name, desc| %>
6
+ <% @c.parameters.each do |name, desc| %>
7
7
  *<%= safe_print(name) %>*
8
8
  Label: <%= desc[:label] %>
9
9
  Data type: <%= desc[:type] %>
@@ -13,6 +13,9 @@ actions and subresources. Associated resources are represented by a directory.
13
13
  `<association_id>`
14
14
  To change the associated resource, write its id to this file.
15
15
 
16
+ `meta/`
17
+ Output metadata parameters.
18
+
16
19
  `save`
17
20
  Trigger the update action. The same as using `actions/update/exec`.
18
21
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haveapi-fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Skokan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2016-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: 0.5.4
75
+ version: 0.7.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: 0.5.4
82
+ version: 0.7.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: md2man
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -141,6 +141,7 @@ files:
141
141
  - lib/haveapi/fs/components/action_exec_edit.rb
142
142
  - lib/haveapi/fs/components/action_input.rb
143
143
  - lib/haveapi/fs/components/action_message.rb
144
+ - lib/haveapi/fs/components/action_meta.rb
144
145
  - lib/haveapi/fs/components/action_output.rb
145
146
  - lib/haveapi/fs/components/action_status.rb
146
147
  - lib/haveapi/fs/components/cache_stats.rb
@@ -160,9 +161,11 @@ files:
160
161
  - lib/haveapi/fs/components/instance_edit.rb
161
162
  - lib/haveapi/fs/components/list_item.rb
162
163
  - lib/haveapi/fs/components/md_help_file.rb
163
- - lib/haveapi/fs/components/meta_dir.rb
164
- - lib/haveapi/fs/components/meta_file.rb
164
+ - lib/haveapi/fs/components/meta_input.rb
165
+ - lib/haveapi/fs/components/meta_output.rb
165
166
  - lib/haveapi/fs/components/parameter.rb
167
+ - lib/haveapi/fs/components/proxy_dir.rb
168
+ - lib/haveapi/fs/components/proxy_file.rb
166
169
  - lib/haveapi/fs/components/pry.rb
167
170
  - lib/haveapi/fs/components/remote_control_file.rb
168
171
  - lib/haveapi/fs/components/resource_action_dir.rb
@@ -186,6 +189,7 @@ files:
186
189
  - templates/help/html/action_dir.erb
187
190
  - templates/help/html/action_errors.erb
188
191
  - templates/help/html/action_input.erb
192
+ - templates/help/html/action_meta.erb
189
193
  - templates/help/html/action_output.erb
190
194
  - templates/help/html/index_filter.erb
191
195
  - templates/help/html/layout.erb
@@ -196,6 +200,7 @@ files:
196
200
  - templates/help/md/action_dir.erb
197
201
  - templates/help/md/action_errors.erb
198
202
  - templates/help/md/action_input.erb
203
+ - templates/help/md/action_meta.erb
199
204
  - templates/help/md/action_output.erb
200
205
  - templates/help/md/index_filter.erb
201
206
  - templates/help/md/layout.erb
@@ -223,9 +228,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
228
  version: '0'
224
229
  requirements: []
225
230
  rubyforge_project:
226
- rubygems_version: 2.2.5
231
+ rubygems_version: 2.5.2
227
232
  signing_key:
228
233
  specification_version: 4
229
234
  summary: Mount any HaveAPI based API as a filesystem based on FUSE
230
235
  test_files: []
231
- has_rdoc: