factor 0.0.8 → 0.0.81

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,18 +9,24 @@ module Factor
9
9
  def start
10
10
  engine = Factor::Runtime::Engine.new(get_config[:email],get_config[:token])
11
11
 
12
- options.tags.each {|tag,value| engine.tag(tag,value)}
12
+ options.tags.each {|tag,value| engine.tag(tag,value)} if options.tags?
13
13
 
14
14
  puts "loading channels"
15
- engine = @client.load_channels(engine)
15
+ engine = @client.load_channels(engine) do |message|
16
+ puts " #{message}"
17
+ end
16
18
  puts "loading channels complete"
17
19
 
18
20
  puts "loading workflows"
19
- engine = @client.load_workflows(engine)
21
+ engine = @client.load_workflows(engine) do |message|
22
+ puts " #{message}"
23
+ end
20
24
  puts "loading workflows complete"
21
25
 
22
26
  puts "loading credentials"
23
- engine = @client.load_credentials(engine)
27
+ engine = @client.load_credentials(engine) do |message|
28
+ puts " #{message}"
29
+ end
24
30
  puts "loading credentials complete"
25
31
 
26
32
  puts "starting the server..."
@@ -21,7 +21,7 @@ module Factor
21
21
  desc "list", "list all the workflows"
22
22
  #method_option :key, :alias=>"-k", :type=>:string, :desc=>"key reference"
23
23
  def list
24
- puts @client.get_workflow
24
+ puts @client.get_workflows
25
25
  end
26
26
 
27
27
  desc "add NAME FILENAME", "add a key and value for the credential"
data/lib/client/client.rb CHANGED
@@ -8,8 +8,12 @@ require 'open-uri'
8
8
  module Factor
9
9
  module Client
10
10
  class Client
11
- #HOST = "http://factor.io"
12
- HOST = "http://localhost:3000"
11
+ attr_accessor :host
12
+
13
+ def initialize(host="http://localhost:3000")
14
+ #def initialize(host="http://factor.io")
15
+ @host=host
16
+ end
13
17
 
14
18
  def register(email,password)
15
19
  end
@@ -21,23 +25,69 @@ module Factor
21
25
  @token=token
22
26
  end
23
27
 
24
- def load_workflows(engine)
28
+ def load_workflows(engine,&code)
29
+ code.call("downloading workflow list")
25
30
  workflows = rest_get("workflows")
26
- workflows.each do |workflow|
27
- workflow_definition = JSON.parse(workflow['definition'])
31
+ code.call("downloaded #{workflows.size} workflows")
32
+ workflows.each do |workflow_info|
33
+ code.call("parsing '#{workflow_info['name']}'")
34
+ workflow_definition = JSON.parse(workflow_info['definition'])
35
+ code.call("loading '#{workflow_info['name']}' into runtime")
28
36
  workflow=Factor::Runtime::Workflow.new(workflow_definition)
29
37
  engine.load_workflow(workflow)
38
+ code.call("loading complete for '#{workflow_info['name']}'")
30
39
  end
31
40
  engine
32
41
  end
33
42
 
34
- def load_credentials(engine)
43
+ def load_credentials(engine,&code)
44
+ code.call("downloading credential list")
35
45
  credentials = rest_get("credentials")
46
+ code.call("loading credentials")
36
47
  engine.load_credentials(credentials)
37
48
 
38
49
  engine
39
50
  end
40
51
 
52
+ def load_channels(engine,&code)
53
+
54
+ # get list of channels
55
+ code.call("downloading channels list")
56
+ channels = rest_get("channels")
57
+
58
+ #load each channel
59
+ channels.each do |channel|
60
+ code.call("downloading '#{channel['zip_url']}'")
61
+ # URI of the zip file containing the module
62
+ uri = URI.parse(channel['zip_url'])
63
+
64
+ # temp file to store the zip for download
65
+ temp_file = Tempfile.new([uri.to_s.gsub(/\W+/,'-'), '.zip'], :encoding => 'ascii-8bit')
66
+
67
+ # temp directory where zip will be decompressed
68
+ unzip_dir=temp_file.path[0..-5]
69
+
70
+ # download
71
+ open(uri.to_s,"rb") do |bin|
72
+ temp_file.print bin.read
73
+ end
74
+ temp_file.close
75
+
76
+ code.call("unzipping '#{channel['name']}'")
77
+ # unzip download zip into unzipped directory
78
+ unzip(temp_file.path,unzip_dir)
79
+
80
+ code.call("loading '#{channel['zip_url']}' into engine")
81
+ Dir.glob("#{unzip_dir}/**/*.rb").each do |file|
82
+ engine.load_channel(file)
83
+ end
84
+
85
+ end
86
+
87
+
88
+ engine
89
+ end
90
+
41
91
 
42
92
  def set_credential(key,value)
43
93
  # this is a PUT not POST because it is technically editing, not creating a new one
@@ -60,9 +110,9 @@ module Factor
60
110
  rest_post("workflows",{:name=>key,:definition=>definition})
61
111
  end
62
112
 
63
- # def get_workflow()
64
- # rest_get("workflows")
65
- # end
113
+ def get_workflows()
114
+ rest_get("workflows")
115
+ end
66
116
 
67
117
  def remove_workflow(name="")
68
118
  rest_delete("workflows",{:name=>name})
@@ -75,9 +125,9 @@ module Factor
75
125
  rest_post("channels",{:name=>key,:zip=>file})
76
126
  end
77
127
 
78
- # def get_channel()
79
- # rest_get("channels")
80
- # end
128
+ def get_channels()
129
+ rest_get("channels")
130
+ end
81
131
 
82
132
  def remove_channel(name="")
83
133
  rest_delete("channels",{:name=>name})
@@ -85,41 +135,7 @@ module Factor
85
135
 
86
136
 
87
137
 
88
- def load_channels(engine)
89
-
90
- # get list of channels
91
- channels = rest_get("channels")
92
-
93
- #load each channel
94
- channels.each do |channel|
95
-
96
- # URI of the zip file containing the module
97
- uri = URI.parse(channel['zip_url'])
98
-
99
- # temp file to store the zip for download
100
- temp_file = Tempfile.new([uri.to_s.gsub(/\W+/,'-'), '.zip'], :encoding => 'ascii-8bit')
101
-
102
- # temp directory where zip will be decompressed
103
- unzip_dir=temp_file.path[0..-5]
104
-
105
- # download
106
- open(uri.to_s,"rb") do |bin|
107
- temp_file.print bin.read
108
- end
109
- temp_file.close
110
-
111
- # unzip download zip into unzipped directory
112
- unzip(temp_file.path,unzip_dir)
113
-
114
- Dir.glob("#{unzip_dir}/#{channel['name'].downcase}/*.rb").each do |file|
115
- engine.load_channel(file)
116
- end
117
-
118
- end
119
-
120
-
121
- engine
122
- end
138
+
123
139
 
124
140
 
125
141
  private
@@ -173,19 +189,19 @@ module Factor
173
189
 
174
190
  param_string=params.map{|key,value| "#{key}=#{value}"}.join("&")
175
191
 
176
- JSON.parse(RestClient.get("#{HOST}/#{path}.json?#{param_string}"))
192
+ JSON.parse(RestClient.get("#{@host}/#{path}.json?#{param_string}"))
177
193
  end
178
194
 
179
195
  def rest_put(path,params={})
180
196
  params["auth_token"]=@token
181
197
 
182
- JSON.parse(RestClient.put("#{HOST}/#{path}.json",params))
198
+ JSON.parse(RestClient.put("#{@host}/#{path}.json",params))
183
199
  end
184
200
 
185
201
  def rest_post(path,params={})
186
202
  #params["auth_token"]=@token
187
203
 
188
- JSON.parse(RestClient.post("#{HOST}/#{path}.json?auth_token=#{@token}",params))
204
+ JSON.parse(RestClient.post("#{@host}/#{path}.json?auth_token=#{@token}",params))
189
205
  end
190
206
 
191
207
  def rest_delete(path,params={})
@@ -193,7 +209,7 @@ module Factor
193
209
 
194
210
  param_string=params.map{|key,value| "#{key}=#{value}"}.join("&")
195
211
 
196
- JSON.parse(RestClient.delete("#{HOST}/#{path}.json?#{param_string}"))
212
+ JSON.parse(RestClient.delete("#{@host}/#{path}.json?#{param_string}"))
197
213
  end
198
214
 
199
215
  end
@@ -31,7 +31,8 @@ module Factor
31
31
  require file
32
32
  channel_module_name = File.basename(file).gsub('.rb','').split('_').map{|ea| ea.capitalize}.join('')
33
33
  channel_module= self.class.const_get(channel_module_name)
34
-
34
+ puts "[channel_module.definition['module']] #{channel_module.definition["module"]}"
35
+ puts "[channel_module] #{channel_module.inspect}"
35
36
  @channel_modules[channel_module.definition["module"]]=channel_module
36
37
  end
37
38
 
@@ -117,7 +118,9 @@ module Factor
117
118
 
118
119
  def match(target)
119
120
  return true if target==nil || target==""
120
- facts Facter.collection.merge(@tags)
121
+ facts={}
122
+ Facter.each {|k,v| facts[k]=v}
123
+ @tags.each {|k,v| facts[k]=v}
121
124
  key,value=target.split("=")
122
125
  facts[key]==value
123
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.81
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -123,38 +123,22 @@ dependencies:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: 0.9.8
126
- - !ruby/object:Gem::Dependency
127
- name: rubyzip
128
- requirement: !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ! '>='
132
- - !ruby/object:Gem::Version
133
- version: '0'
134
- type: :runtime
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: '0'
142
126
  - !ruby/object:Gem::Dependency
143
127
  name: facter
144
128
  requirement: !ruby/object:Gem::Requirement
145
129
  none: false
146
130
  requirements:
147
- - - ! '>='
131
+ - - '='
148
132
  - !ruby/object:Gem::Version
149
- version: '0'
133
+ version: 1.6.16
150
134
  type: :runtime
151
135
  prerelease: false
152
136
  version_requirements: !ruby/object:Gem::Requirement
153
137
  none: false
154
138
  requirements:
155
- - - ! '>='
139
+ - - '='
156
140
  - !ruby/object:Gem::Version
157
- version: '0'
141
+ version: 1.6.16
158
142
  description: Friendly command-line interface and library for Factor
159
143
  email: maciej@skierkowski.com
160
144
  executables: