factor 0.5.16 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3df70093d41d893436a8b43a6d08f4ffe87249fb
4
- data.tar.gz: 8b163aa8f9b1ebe4c9ddaf8c24f67d28917c2e10
3
+ metadata.gz: 5b3d20f8470d86ea79e6ad2646d2b7dac6695a9b
4
+ data.tar.gz: d8ef8ec97799a1f481581706c78e1631a0a4600c
5
5
  SHA512:
6
- metadata.gz: 0e1d4fa2b2775bc2d34bc43acc8bed86f518d0b1865a56647679536454e1e0c52f0ee20db18d5cae137b256e4fafd8cf8f85b8c4c282eef88117482638c519cb
7
- data.tar.gz: 29e9b70bf5ccf70e7cf1292c7ec4e8f11377c4a6efb1a96dc84c8b4939372a53151d486d73f9ee5464ee60b9a503f290b54ea56500101a240143f036d7ee6f87
6
+ metadata.gz: e540f40fd32b06cee12fcee1ae7e2a9a80d01cf878837b052eddb10e3af906b24460b697fb842a95e8244287ebe2a8bc6684ad0a0accbe992bbc504540de6956
7
+ data.tar.gz: 8234653325650c2a16ad5a2f92c7d99f8cc6230eb8e12efe2496e070bbbbb0af7246670805751ffd75d9597d1b04b4b7af7d236c4c94ee9a56e908c9641d2420
@@ -23,7 +23,72 @@ module Factor
23
23
  load_config(config_settings)
24
24
  load_all_workflows(workflow_filename)
25
25
  block_until_interupt
26
- log_message 'status' => 'info', 'message' => 'Good bye!'
26
+ info 'Good bye!'
27
+ end
28
+
29
+ def cloud(args, options)
30
+ account_id = args[0]
31
+ workflow_id = args[1]
32
+ api_key = args[2]
33
+
34
+ if !api_key || !workflow_id || !account_id
35
+ error "API Key, Worklfow ID and Acount ID are all required"
36
+ exit
37
+ end
38
+
39
+ info "Getting workflow (#{workflow_id}) from Factor.io Cloud"
40
+ begin
41
+ workflow_url = "https://factor.io/#{account_id}/workflows/#{workflow_id}.json?auth_token=#{api_key}"
42
+ raw_content = RestClient.get(workflow_url)
43
+ workflow_info = JSON.parse(raw_content)
44
+ rescue => ex
45
+ error "Couldn't retreive workflow: #{ex.message}"
46
+ exit
47
+ end
48
+
49
+ workflow_definition = workflow_info["workflow_definition"]
50
+
51
+ info "Getting credentials from Factor.io Cloud"
52
+ begin
53
+ credential_url = "https://factor.io/#{account_id}/credentials.json?auth_token=#{api_key}"
54
+ raw_content = RestClient.get(credential_url)
55
+ credential_info = JSON.parse(raw_content)
56
+ rescue => ex
57
+ error "Couldn't retreive workflow: #{ex.message}"
58
+ exit
59
+ end
60
+
61
+ credentials = {}
62
+ credential_info.each do |credential|
63
+ credentials[credential['service']] ||= {}
64
+ credentials[credential['service']][credential['name']] = credential['value']
65
+ end
66
+
67
+ configatron[:credentials].configure_from_hash(credentials)
68
+
69
+ info "Getting connector settings from Factor.io Index Server"
70
+ begin
71
+ connectors_url = options.index
72
+ connectors_url ||= 'https://raw.githubusercontent.com/factor-io/index/master/connectors.yml'
73
+ raw_content = RestClient.get(connectors_url)
74
+ connectors_info = YAML.parse(raw_content).to_ruby
75
+ rescue
76
+ error "Couldn't retreive connectors info"
77
+ exit
78
+ end
79
+
80
+ connectors = {}
81
+ connectors_info.each do |connector_id, connector_info|
82
+ connectors[connector_id] = connector_info['connectors']
83
+ end
84
+
85
+ configatron[:connectors].configure_from_hash(connectors)
86
+
87
+ @workflows[workflow_id] = load_workflow_from_definition(workflow_definition)
88
+
89
+ block_until_interupt
90
+
91
+ info 'Good bye!'
27
92
  end
28
93
 
29
94
  private
@@ -37,28 +102,26 @@ module Factor
37
102
  elsif file_list.count == 0
38
103
  error 'No workflows in this directory to run'
39
104
  else
40
- file_list.each { |filename| load_workflow(filename) }
105
+ file_list.each { |filename| load_workflow(File.expand_path(filename)) }
41
106
  end
42
107
  end
43
108
 
44
109
  def block_until_interupt
45
- log_message 'status' => 'info', 'message' => 'Ctrl-c to exit'
110
+ info 'Ctrl-c to exit'
46
111
  begin
47
112
  loop do
48
113
  sleep 1
49
114
  end
50
115
  rescue Interrupt
51
- log_message 'status' => 'info', 'message' => 'Exiting app...'
116
+ info 'Exiting app...'
52
117
  ensure
53
- @workflows.keys.each { |filename| unload_workflow(filename) }
118
+ @workflows.keys.each { |workflow_id| unload_workflow(workflow_id) }
54
119
  end
55
120
  end
56
121
 
57
122
  def load_workflow(filename)
58
- workflow_filename = File.expand_path(filename)
59
- log_message(
60
- 'status' => 'info',
61
- 'message' => "Loading workflow from #{workflow_filename}")
123
+ # workflow_filename = File.expand_path(filename)
124
+ info "Loading workflow from #{workflow_filename}"
62
125
  begin
63
126
  workflow_definition = File.read(workflow_filename)
64
127
  rescue => ex
@@ -66,9 +129,11 @@ module Factor
66
129
  return
67
130
  end
68
131
 
69
- log_message(
70
- 'status' => 'info',
71
- 'message' => 'Setting up workflow processor')
132
+ @workflows[workflow_filename] = load_workflow_from_definition(workflow_definition)
133
+ end
134
+
135
+ def load_workflow_from_definition(workflow_definition)
136
+ info "Setting up workflow processor"
72
137
  begin
73
138
  connector_settings = configatron.connectors.to_hash
74
139
  credential_settings = configatron.credentials.to_hash
@@ -79,24 +144,21 @@ module Factor
79
144
  exception message, ex
80
145
  end
81
146
 
82
- @workflows[workflow_filename] = fork do
147
+ workflow_thread = fork do
83
148
  begin
84
- log_message(
85
- 'status' => 'info',
86
- 'message' => "Starting #{workflow_filename}")
149
+ info "Starting workflow"
87
150
  runtime.load(workflow_definition)
88
151
  rescue => ex
89
- exception "Couldn't load #{workflow_filename}", ex
152
+ exception "Couldn't workflow", ex
90
153
  end
91
154
  end
155
+
156
+ workflow_thread
92
157
  end
93
158
 
94
- def unload_workflow(filename)
95
- workflow_filename = File.expand_path(filename)
96
- log_message(
97
- 'status' => 'info',
98
- 'message' => "Stopping #{workflow_filename}")
99
- Process.kill('SIGINT', @workflows[workflow_filename])
159
+ def unload_workflow(workflow_id)
160
+ info "Stopping #{workflow_id}"
161
+ Process.kill('SIGINT', @workflows[workflow_id])
100
162
  end
101
163
 
102
164
  def log_message(message_info)
data/lib/factor.rb CHANGED
@@ -20,6 +20,13 @@ command 'server' do |c|
20
20
  c.when_called Factor::Commands::Workflow, :server
21
21
  end
22
22
 
23
+ command 'cloud' do |c|
24
+ c.syntax = 'factor host <account id> <workflow id> <api key>'
25
+ c.description = 'Start the Factor.io Server using your workflows and credentials from Factor.io Cloud'
26
+ c.option '--index URL', String, 'Use non-default Index server to get list of available credentials'
27
+ c.when_called Factor::Commands::Workflow, :cloud
28
+ end
29
+
23
30
  command 'registry workflows' do |c|
24
31
  c.syntax = 'factor registry workflows'
25
32
  c.description = 'Get list of available workflow jumpstarts'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Primary Factor.io module
4
4
  module Factor
5
- VERSION = '0.5.16'
5
+ VERSION = '0.6.0'
6
6
  end
data/spec/base_spec.rb CHANGED
@@ -87,9 +87,6 @@ describe Factor::Commands::Command do
87
87
  @command.load_config config_settings
88
88
  end
89
89
 
90
- expect(output).to include('Loading credentials')
91
- expect(output).to include('Loading connectors')
92
-
93
90
  expect(configatron.credentials.github.api_key).to eq('fake_github_key')
94
91
  expect(configatron.credentials.heroku.api_key).to eq('fake_heroku_key')
95
92
  connectors_content.keys.each do |expected_connector_key|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.16
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Skierkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-22 00:00:00.000000000 Z
11
+ date: 2014-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander