Merge branch 'master' into website_agent_can_parse_payload

Andrew Cantino vor 9 Jahren
Ursprung
Commit
054f7f1cc6

+ 1 - 1
.travis.yml

@@ -5,7 +5,7 @@ env:
5 5
     - APP_SECRET_TOKEN=b2724973fd81c2f4ac0f92ac48eb3f0152c4a11824c122bcf783419a4c51d8b9bba81c8ba6a66c7de599677c7f486242cf819775c433908e77c739c5c8ae118d
6 6
   matrix:
7 7
     - DATABASE_ADAPTER=mysql2
8
-    - DATABASE_ADAPTER=postgresql DATABASE_USERNAME=postgres ON_HEROKU=true
8
+    - DATABASE_ADAPTER=postgresql DATABASE_USERNAME=postgres
9 9
 rvm:
10 10
 - 2.0.0
11 11
 - 2.1.5

+ 33 - 15
Gemfile

@@ -3,6 +3,15 @@ source 'https://rubygems.org'
3 3
 # Ruby 2.0 is the minimum requirement
4 4
 ruby ['2.0.0', RUBY_VERSION].max
5 5
 
6
+# Load vendored dotenv gem and .env file
7
+require File.join(File.dirname(__FILE__), 'lib/gemfile_helper.rb')
8
+GemfileHelper.load_dotenv do |dotenv_dir|
9
+  path dotenv_dir do
10
+    gem 'dotenv'
11
+    gem 'dotenv-rails'
12
+  end
13
+end
14
+
6 15
 # Optional libraries.  To conserve RAM, comment out any that you don't need,
7 16
 # then run `bundle` and commit the updated Gemfile and Gemfile.lock.
8 17
 gem 'twilio-ruby', '~> 3.11.5'    # TwilioAgent
@@ -64,7 +73,6 @@ gem 'daemons', '~> 1.1.9'
64 73
 gem 'delayed_job', '~> 4.0.0'
65 74
 gem 'delayed_job_active_record', :git => 'https://github.com/cantino/delayed_job_active_record', :branch => 'configurable-reserve-sql-strategy'
66 75
 gem 'devise', '~> 3.4.0'
67
-gem 'dotenv-rails', '~> 2.0.1'
68 76
 gem 'em-http-request', '~> 1.1.2'
69 77
 gem 'faraday', '~> 0.9.0'
70 78
 gem 'faraday_middleware', github: 'lostisland/faraday_middleware', branch: 'master'  # '>= 0.10.1'
@@ -83,9 +91,8 @@ gem 'kaminari', '~> 0.16.1'
83 91
 gem 'kramdown', '~> 1.3.3'
84 92
 gem 'liquid', '~> 3.0.3'
85 93
 gem 'mini_magick'
86
-gem 'mysql2', '~> 0.3.16'
87 94
 gem 'multi_xml'
88
-gem 'nokogiri', '~> 1.6.4'
95
+gem 'nokogiri', '1.6.7.1'
89 96
 gem 'omniauth'
90 97
 gem 'rails', '4.2.4'
91 98
 gem 'rufus-scheduler', '~> 3.0.8', require: false
@@ -95,7 +102,7 @@ gem 'spectrum-rails'
95 102
 gem 'string-scrub'	# for ruby <2.1
96 103
 gem 'therubyracer', '~> 0.12.2'
97 104
 gem 'typhoeus', '~> 0.6.3'
98
-gem 'uglifier', '>= 1.3.0'
105
+gem 'uglifier', '~> 2.7.2'
99 106
 
100 107
 group :development do
101 108
   gem 'better_errors', '~> 1.1'
@@ -136,22 +143,33 @@ gem 'tzinfo', '>= 1.2.0'	# required by rails; 1.2.0 has support for *BSD and Sol
136 143
 # Windows does not have zoneinfo files, so bundle the tzinfo-data gem.
137 144
 gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
138 145
 
139
-# Introduces a scope for Heroku specific gems.
140
-def on_heroku
141
-  if ENV['ON_HEROKU'] ||
142
-     ENV['HEROKU_POSTGRESQL_ROSE_URL'] ||
143
-     ENV['HEROKU_POSTGRESQL_GOLD_URL'] ||
144
-     File.read(File.join(File.dirname(__FILE__), 'Procfile')) =~ /intended for Heroku/
146
+
147
+# Introduces a scope for gem loading based on a condition
148
+def if_true(condition)
149
+  if condition
145 150
     yield
146 151
   else
147
-    # When not on Heroku, we still want our Gemfile.lock to include
148
-    # Heroku specific gems, so we scope them to an unsupported
149
-    # platform.
152
+    # When not including the gems, we still want our Gemfile.lock
153
+    # to include them, so we scope them to an unsupported platform.
150 154
     platform :ruby_18, &proc
151 155
   end
152 156
 end
153 157
 
154
-on_heroku do
155
-  gem 'pg'
158
+on_heroku = ENV['ON_HEROKU'] ||
159
+            ENV['HEROKU_POSTGRESQL_ROSE_URL'] ||
160
+            ENV['HEROKU_POSTGRESQL_GOLD_URL'] ||
161
+            File.read(File.join(File.dirname(__FILE__), 'Procfile')) =~ /intended for Heroku/
162
+
163
+ENV['DATABASE_ADAPTER'] ||= 'postgresql' if on_heroku
164
+
165
+if_true(on_heroku) do
156 166
   gem 'rails_12factor', group: :production
157 167
 end
168
+
169
+if_true(ENV['DATABASE_ADAPTER'].strip == 'postgresql') do
170
+  gem 'pg', '~> 0.18.3'
171
+end
172
+
173
+if_true(ENV['DATABASE_ADAPTER'].strip == 'mysql2') do
174
+  gem 'mysql2', '~> 0.3.16'
175
+end

+ 18 - 13
Gemfile.lock

@@ -58,6 +58,13 @@ GIT
58 58
       activerecord (>= 3.0, < 5.0)
59 59
       delayed_job (>= 3.0, < 4.1)
60 60
 
61
+PATH
62
+  remote: vendor/gems/dotenv-2.0.1
63
+  specs:
64
+    dotenv (2.0.1)
65
+    dotenv-rails (2.0.1)
66
+      dotenv (= 2.0.1)
67
+
61 68
 GEM
62 69
   remote: https://rubygems.org/
63 70
   specs:
@@ -162,9 +169,6 @@ GEM
162 169
     docile (1.1.5)
163 170
     domain_name (0.5.24)
164 171
       unf (>= 0.0.5, < 1.0.0)
165
-    dotenv (2.0.1)
166
-    dotenv-rails (2.0.1)
167
-      dotenv (= 2.0.1)
168 172
     dropbox-api (0.4.2)
169 173
       hashie
170 174
       multi_json
@@ -191,7 +195,7 @@ GEM
191 195
     evernote_oauth (0.2.3)
192 196
       evernote-thrift
193 197
       oauth (>= 0.4.1)
194
-    execjs (2.3.0)
198
+    execjs (2.6.0)
195 199
     extlib (0.9.16)
196 200
     faraday (0.9.1)
197 201
       multipart-post (>= 1.2, < 3)
@@ -298,7 +302,7 @@ GEM
298 302
     method_source (0.8.2)
299 303
     mime-types (2.6.1)
300 304
     mini_magick (4.2.3)
301
-    mini_portile (0.6.2)
305
+    mini_portile2 (2.0.0)
302 306
     minitest (5.8.1)
303 307
     mqtt (0.3.1)
304 308
     multi_json (1.11.2)
@@ -311,8 +315,8 @@ GEM
311 315
       net-ssh (>= 2.6.5)
312 316
     net-ssh (2.9.2)
313 317
     netrc (0.10.3)
314
-    nokogiri (1.6.6.2)
315
-      mini_portile (~> 0.6.0)
318
+    nokogiri (1.6.7.1)
319
+      mini_portile2 (~> 2.0.0.rc2)
316 320
     oauth (0.4.7)
317 321
     oauth2 (0.9.4)
318 322
       faraday (>= 0.8, < 0.10)
@@ -346,7 +350,7 @@ GEM
346 350
       multi_json (~> 1.3)
347 351
       omniauth-oauth (~> 1.0)
348 352
     orm_adapter (0.5.0)
349
-    pg (0.17.1)
353
+    pg (0.18.3)
350 354
     polyglot (0.3.5)
351 355
     protected_attributes (1.0.8)
352 356
       activemodel (>= 4.0.1, < 5.0)
@@ -510,7 +514,7 @@ GEM
510 514
       ethon (>= 0.7.1)
511 515
     tzinfo (1.2.2)
512 516
       thread_safe (~> 0.1)
513
-    uglifier (2.7.0)
517
+    uglifier (2.7.2)
514 518
       execjs (>= 0.3.0)
515 519
       json (>= 1.8.0)
516 520
     unf (0.1.4)
@@ -554,7 +558,8 @@ DEPENDENCIES
554 558
   delayed_job_active_record!
555 559
   delorean
556 560
   devise (~> 3.4.0)
557
-  dotenv-rails (~> 2.0.1)
561
+  dotenv!
562
+  dotenv-rails!
558 563
   dropbox-api
559 564
   em-http-request (~> 1.1.2)
560 565
   evernote_oauth
@@ -587,7 +592,7 @@ DEPENDENCIES
587 592
   multi_xml
588 593
   mysql2 (~> 0.3.16)
589 594
   net-ftp-list (~> 3.2.8)
590
-  nokogiri (~> 1.6.4)
595
+  nokogiri (= 1.6.7.1)
591 596
   omniauth
592 597
   omniauth-37signals
593 598
   omniauth-dropbox
@@ -595,7 +600,7 @@ DEPENDENCIES
595 600
   omniauth-tumblr
596 601
   omniauth-twitter
597 602
   omniauth-wunderlist!
598
-  pg
603
+  pg (~> 0.18.3)
599 604
   protected_attributes (~> 1.0.8)
600 605
   pry-rails
601 606
   quiet_assets
@@ -624,7 +629,7 @@ DEPENDENCIES
624 629
   typhoeus (~> 0.6.3)
625 630
   tzinfo (>= 1.2.0)
626 631
   tzinfo-data
627
-  uglifier (>= 1.3.0)
632
+  uglifier (~> 2.7.2)
628 633
   unicorn (~> 4.9.0)
629 634
   vcr
630 635
   webmock (~> 1.17.4)

+ 2 - 2
Procfile

@@ -3,7 +3,7 @@
3 3
 ###############################
4 4
 
5 5
 # Procfile for development using the new threaded worker (scheduler, twitter stream and delayed job)
6
-web: bundle exec rails server -b0.0.0.0
6
+web: bundle exec rails server -p ${PORT-3000} -b ${IP-0.0.0.0}
7 7
 jobs: bundle exec rails runner bin/threaded.rb
8 8
 
9 9
 # Old version with separate processes (use this if you have issues with the threaded version)
@@ -47,4 +47,4 @@ jobs: bundle exec rails runner bin/threaded.rb
47 47
 #dj7: bundle exec script/delayed_job -i 7 run
48 48
 #dj8: bundle exec script/delayed_job -i 8 run
49 49
 #dj9: bundle exec script/delayed_job -i 9 run
50
-#dj10: bundle exec script/delayed_job -i 10 run
50
+#dj10: bundle exec script/delayed_job -i 10 run

+ 1 - 0
app/views/devise/registrations/new.html.erb

@@ -22,6 +22,7 @@
22 22
 heroku git:clone --app <%= content_tag :var, app_name %>
23 23
 cd <%= content_tag :var, app_name %>
24 24
 bundle
25
+cp .env.example .env
25 26
 bin/setup_heroku
26 27
 <%- end %>
27 28
 

+ 5 - 7
doc/manual/installation.md

@@ -165,13 +165,6 @@ You are done installing the database and can go back to the rest of the installa
165 165
     # Copy the example Unicorn config
166 166
     sudo -u huginn -H cp config/unicorn.rb.example config/unicorn.rb
167 167
 
168
-### Install Gems
169
-
170
-**Note:** As of bundler 1.5.2, you can invoke `bundle install -jN` (where `N` the number of your processor cores) and enjoy parallel gem installation with measurable difference in completion time (~60% faster). Check the number of your cores with `nproc`. For more information check this [post](http://robots.thoughtbot.com/parallel-gem-installing-using-bundler). First make sure you have bundler >= 1.5.2 (run `bundle -v`) as it addresses some [issues](https://devcenter.heroku.com/changelog-items/411) that were [fixed](https://github.com/bundler/bundler/pull/2817) in 1.5.2.
171
-
172
-    sudo -u huginn -H bundle install --deployment --without development test
173
-
174
-
175 168
 ### Configure it
176 169
 
177 170
     # Update Huginn config file and follow the instructions
@@ -211,6 +204,11 @@ Change the Unicorn config if needed, the [requirements.md](./requirements.md#uni
211 204
 
212 205
 **Note:** If you want to use HTTPS, which is what we recommend, see [Using HTTPS](#using-https) for the additional steps.
213 206
 
207
+### Install Gems
208
+
209
+**Note:** As of bundler 1.5.2, you can invoke `bundle install -jN` (where `N` the number of your processor cores) and enjoy parallel gem installation with measurable difference in completion time (~60% faster). Check the number of your cores with `nproc`. For more information check this [post](http://robots.thoughtbot.com/parallel-gem-installing-using-bundler). First make sure you have bundler >= 1.5.2 (run `bundle -v`) as it addresses some [issues](https://devcenter.heroku.com/changelog-items/411) that were [fixed](https://github.com/bundler/bundler/pull/2817) in 1.5.2.
210
+
211
+    sudo -u huginn -H bundle install --deployment --without development test
214 212
 
215 213
 ### Initialize Database
216 214
 

+ 8 - 2
docker/README.md

@@ -67,11 +67,17 @@ To link to another mysql container, for example:
67 67
 
68 68
 To link to another container named 'postgres':
69 69
 
70
+    docker run --name huginn_postgres \
71
+        -e POSTGRES_PASSWORD=mysecretpassword \
72
+        -e POSTGRES_USER=huginn -d postgres
73
+    docker run -it --link huginn_postgres:postgres --rm postgres \
74
+        sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U huginn -c "create database huginn_development;"'
70 75
     docker run --rm --name huginn \
71 76
         --link huginn_postgres:postgres \
72 77
         -p 3000:3000 \
73
-        -e "HUGINN_DATABASE_USERNAME=huginn" \
74
-        -e "HUGINN_DATABASE_PASSWORD=pass@word" \
78
+        -e HUGINN_DATABASE_USERNAME=huginn \
79
+        -e HUGINN_DATABASE_PASSWORD=mysecretpassword \
80
+        -e HUGINN_DATABASE_ADAPTER=postgresql \
75 81
         cantino/huginn
76 82
 
77 83
 The `docker/` folder also has a `docker-compose.yml` that allows for a sample database formation with a data volume container:

+ 9 - 8
docker/scripts/init

@@ -18,10 +18,10 @@ if [ -n "${MYSQL_PORT_3306_TCP_ADDR}" ]; then
18 18
   HUGINN_DATABASE_ADAPTER=${HUGINN_DATABASE_ADAPTER:-mysql2}
19 19
   HUGINN_DATABASE_HOST=${HUGINN_DATABASE_HOST:-${MYSQL_PORT_3306_TCP_ADDR}}
20 20
   HUGINN_DATABASE_PORT=${HUGINN_DATABASE_PORT:-${MYSQL_PORT_3306_TCP_PORT}}
21
-elif [ -n "${POSTGRESQL_PORT_5432_TCP_ADDR}" ]; then
22
-  HUGINN_DATABASE_ADAPTER=${HUGINN_DATABASE_ADAPTER:-postgres}
23
-  HUGINN_DATABASE_HOST=${HUGINN_DATABASE_HOST:-${POSTGRESQL_PORT_5432_TCP_ADDR}}
24
-  HUGINN_DATABASE_PORT=${HUGINN_DATABASE_PORT:-${POSTGRESQL_PORT_5432_TCP_PORT}}
21
+elif [ -n "${POSTGRES_PORT_5432_TCP_ADDR}" ]; then
22
+  HUGINN_DATABASE_ADAPTER=${HUGINN_DATABASE_ADAPTER:-postgresql}
23
+  HUGINN_DATABASE_HOST=${HUGINN_DATABASE_HOST:-${POSTGRES_PORT_5432_TCP_ADDR}}
24
+  HUGINN_DATABASE_PORT=${HUGINN_DATABASE_PORT:-${POSTGRES_PORT_5432_TCP_PORT}}
25 25
 fi
26 26
 
27 27
 grep = /app/.env.example | sed -e 's/^#\([^ ]\)/\1/' | grep -v -e '^#' | cut -d= -f1 | \
@@ -31,6 +31,7 @@ grep = /app/.env.example | sed -e 's/^#\([^ ]\)/\1/' | grep -v -e '^#' | cut -d=
31 31
 
32 32
 chmod ugo+r /app/.env
33 33
 source /app/.env
34
+sudo -u huginn -H bundle install --deployment --without test
34 35
 
35 36
 DATABASE_HOST=${HUGINN_DATABASE_HOST:-${DATABASE_HOST:-localhost}}
36 37
 DATABASE_ENCODING=${HUGINN_DATABASE_ENCODING:-${DATABASE_ENCODING}}
@@ -39,8 +40,8 @@ USE_GRAPHVIZ_DOT=${HUGINN_USE_GRAPHVIZ_DOT:-${USE_GRAPHVIZ_DOT}}
39 40
 # use default port number if it is still not set
40 41
 case "${DATABASE_ADAPTER}" in
41 42
   mysql2) DATABASE_PORT=${DATABASE_PORT:-3306} ;;
42
-  postgres) DATABASE_PORT=${DATABASE_PORT:-5432} ;;
43
-  *) echo "Unsupported database adapter. Available adapters are mysql2, and postgres." && exit 1 ;;
43
+  postgresql) DATABASE_PORT=${DATABASE_PORT:-5432} ;;
44
+  *) echo "Unsupported database adapter. Available adapters are mysql2, and postgresql." && exit 1 ;;
44 45
 esac
45 46
 
46 47
 # initialize supervisord config
@@ -71,8 +72,8 @@ echo DATABASE_HOST=\${DATABASE_HOST}
71 72
 
72 73
 # start mysql server if \${DATABASE_HOST} is the .env.example default
73 74
 if [ "\${DATABASE_HOST}" = "your-domain-here.com" -o "\${DATABASE_HOST}" = "" ]; then
74
-  if [ "\${DATABASE_ADAPTER}" = "postgres" ]; then
75
-    echo "DATABASE_ADAPTER 'postgres' is not supported internally. Please provide DATABASE_HOST."
75
+  if [ "\${DATABASE_ADAPTER}" = "postgresql" ]; then
76
+    echo "DATABASE_ADAPTER 'postgresql' is not supported internally. Please provide DATABASE_HOST."
76 77
     exit 1
77 78
   fi
78 79
 

+ 3 - 6
docker/scripts/setup

@@ -1,11 +1,6 @@
1 1
 #!/bin/bash
2 2
 set -e
3 3
 
4
-# Initialize variables used by Huginn at installation time
5
-
6
-# Huginn is 12factor aware, embrace that fact for use inside of docker
7
-ON_HEROKU=${ON_HEROKU:-true}
8
-
9 4
 # Shallow clone the huginn project repo
10 5
 git clone --depth 1 https://github.com/cantino/huginn /app
11 6
 
@@ -29,7 +24,9 @@ if [ -d "/scripts/cache" ]; then
29 24
   mv /scripts/cache vendor/
30 25
   chown -R huginn:huginn vendor/cache
31 26
 fi
32
-sudo -u huginn -H bundle install --deployment --without test
27
+sudo -u huginn -H cp .env.example .env
28
+sudo -u huginn -H ON_HEROKU=true bundle install --deployment --without test
29
+sudo -u huginn -H rm .env
33 30
 
34 31
 # silence setlocale message (THANKS DEBIAN!)
35 32
 cat > /etc/default/locale <<EOF

+ 1 - 1
lib/agents_exporter.rb

@@ -27,7 +27,7 @@ class AgentsExporter
27 27
   end
28 28
 
29 29
   def agents
30
-    options[:agents].to_a
30
+    options[:agents].sort_by{|agent| agent.guid}.to_a
31 31
   end
32 32
 
33 33
   def links

+ 40 - 0
lib/gemfile_helper.rb

@@ -0,0 +1,40 @@
1
+class GemfileHelper
2
+  class << self
3
+    def load_dotenv
4
+      dotenv_dir = Dir[File.join(File.dirname(__FILE__), '../vendor/gems/dotenv-[0-9]*')].sort.last
5
+
6
+      yield dotenv_dir
7
+
8
+      return if ENV['ON_HEROKU'] == 'true'
9
+
10
+      $:.unshift File.join(dotenv_dir, 'lib')
11
+      require "dotenv"
12
+      $:.shift
13
+
14
+      root = Pathname.new(File.join(File.dirname(__FILE__), '..'))
15
+      sanity_check Dotenv.load(
16
+                                root.join(".env.local"),
17
+                                root.join(".env.#{ENV['RAILS_ENV']}"),
18
+                                root.join(".env")
19
+                              )
20
+    end
21
+
22
+    private
23
+
24
+    def sanity_check(env)
25
+      return if ENV['CI'] == 'true' || !env.empty?
26
+      puts warning
27
+      raise "Could not load huginn settings from .env file."
28
+    end
29
+
30
+    def warning
31
+      <<-EOF
32
+Could not load huginn settings from .env file.
33
+
34
+Make sure to copy the .env.example to .env and change it to match your configuration.
35
+
36
+Capistrano 2 users: Make sure shared files are symlinked before bundle runs: before 'bundle:install', 'deploy:symlink_configs'
37
+EOF
38
+    end
39
+  end
40
+end

+ 10 - 6
spec/lib/agents_exporter_spec.rb

@@ -23,27 +23,27 @@ describe AgentsExporter do
23 23
       expect(data[:tag_fg_color]).to eq(tag_fg_color)
24 24
       expect(data[:tag_bg_color]).to eq(tag_bg_color)
25 25
       expect(Time.parse(data[:exported_at])).to be_within(2).of(Time.now.utc)
26
-      expect(data[:links]).to eq([{ :source => 0, :receiver => 1 }])
26
+      expect(data[:links]).to eq([{ :source => guid_order(agent_list, :jane_weather_agent), :receiver => guid_order(agent_list, :jane_rain_notifier_agent)}])
27 27
       expect(data[:control_links]).to eq([])
28
-      expect(data[:agents]).to eq(agent_list.map { |agent| exporter.agent_as_json(agent) })
28
+      expect(data[:agents]).to eq(agent_list.sort_by{|a| a.guid}.map { |agent| exporter.agent_as_json(agent) })
29 29
       expect(data[:agents].all? { |agent_json| agent_json[:guid].present? && agent_json[:type].present? && agent_json[:name].present? }).to be_truthy
30 30
 
31
-      expect(data[:agents][0]).not_to have_key(:propagate_immediately) # can't receive events
32
-      expect(data[:agents][1]).not_to have_key(:schedule) # can't be scheduled
31
+      expect(data[:agents][guid_order(agent_list, :jane_weather_agent)]).not_to have_key(:propagate_immediately) # can't receive events
32
+      expect(data[:agents][guid_order(agent_list, :jane_rain_notifier_agent)]).not_to have_key(:schedule) # can't be scheduled
33 33
     end
34 34
 
35 35
     it "does not output links to other agents outside of the incoming set" do
36 36
       Link.create!(:source_id => agents(:jane_weather_agent).id, :receiver_id => agents(:jane_website_agent).id)
37 37
       Link.create!(:source_id => agents(:jane_website_agent).id, :receiver_id => agents(:jane_rain_notifier_agent).id)
38 38
 
39
-      expect(exporter.as_json[:links]).to eq([{ :source => 0, :receiver => 1 }])
39
+      expect(exporter.as_json[:links]).to eq([{ :source => guid_order(agent_list, :jane_weather_agent), :receiver => guid_order(agent_list, :jane_rain_notifier_agent) }])
40 40
     end
41 41
 
42 42
     it "outputs control links to agents within the incoming set, but not outside it" do
43 43
       agents(:jane_rain_notifier_agent).control_targets = [agents(:jane_weather_agent), agents(:jane_basecamp_agent)]
44 44
       agents(:jane_rain_notifier_agent).save!
45 45
 
46
-      expect(exporter.as_json[:control_links]).to eq([{ :controller => 1, :control_target => 0 }])
46
+      expect(exporter.as_json[:control_links]).to eq([{ :controller => guid_order(agent_list, :jane_rain_notifier_agent), :control_target => guid_order(agent_list, :jane_weather_agent) }])
47 47
     end
48 48
   end
49 49
 
@@ -71,4 +71,8 @@ describe AgentsExporter do
71 71
       expect(AgentsExporter.new(:name => ",,").filename).to eq("exported-agents.json")
72 72
     end
73 73
   end
74
+
75
+  def guid_order(agent_list, agent_name)
76
+    agent_list.map{|a|a.guid}.sort.find_index(agents(agent_name).guid)
77
+  end
74 78
 end

+ 22 - 0
vendor/gems/dotenv-2.0.1/LICENSE

@@ -0,0 +1,22 @@
1
+Copyright (c) 2012 Brandon Keepers
2
+
3
+MIT License
4
+
5
+Permission is hereby granted, free of charge, to any person obtaining
6
+a copy of this software and associated documentation files (the
7
+"Software"), to deal in the Software without restriction, including
8
+without limitation the rights to use, copy, modify, merge, publish,
9
+distribute, sublicense, and/or sell copies of the Software, and to
10
+permit persons to whom the Software is furnished to do so, subject to
11
+the following conditions:
12
+
13
+The above copyright notice and this permission notice shall be
14
+included in all copies or substantial portions of the Software.
15
+
16
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 136 - 0
vendor/gems/dotenv-2.0.1/README.md

@@ -0,0 +1,136 @@
1
+# dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.png?branch=master)](https://travis-ci.org/bkeepers/dotenv)
2
+
3
+Shim to load environment variables from `.env` into `ENV` in *development*.
4
+
5
+Storing [configuration in the environment](http://www.12factor.net/config) is one of the tenets of a [twelve-factor app](http://www.12factor.net/). Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables.
6
+
7
+But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. dotenv loads variables from a `.env` file into `ENV` when the environment is bootstrapped.
8
+
9
+## Installation
10
+
11
+### Rails
12
+
13
+Add this line to the top of your application's Gemfile:
14
+
15
+```ruby
16
+gem 'dotenv-rails', :groups => [:development, :test]
17
+```
18
+
19
+And then execute:
20
+
21
+```shell
22
+$ bundle
23
+```
24
+
25
+#### Note on load order
26
+
27
+dotenv is initialized in your Rails app during the `before_configuration` callback, which is fired when the `Application` constant is defined in `config/application.rb` with `class Application < Rails::Application`. If you need it to be initialized sooner, you can manually call `Dotenv::Railtie.load`.
28
+
29
+```ruby
30
+# config/application.rb
31
+Bundler.require(*Rails.groups)
32
+
33
+Dotenv::Railtie.load
34
+
35
+HOSTNAME = ENV['HOSTNAME']
36
+```
37
+
38
+If you use gems that require environment variables to be set before they are loaded, then list `dotenv-rails` in the `Gemfile` before those other gems and require `dotenv/rails-now`.
39
+
40
+```ruby
41
+gem 'dotenv-rails', :require => 'dotenv/rails-now'
42
+gem 'gem-that-requires-env-variables'
43
+```
44
+
45
+### Sinatra or Plain ol' Ruby
46
+
47
+Install the gem:
48
+
49
+```shell
50
+$ gem install dotenv
51
+```
52
+
53
+As early as possible in your application bootstrap process, load `.env`:
54
+
55
+```ruby
56
+require 'dotenv'
57
+Dotenv.load
58
+```
59
+
60
+Alternatively, you can use the `dotenv` executable to launch your application:
61
+
62
+```shell
63
+$ dotenv ./script.py
64
+```
65
+
66
+To ensure `.env` is loaded in rake, load the tasks:
67
+
68
+```ruby
69
+require 'dotenv/tasks'
70
+
71
+task :mytask => :dotenv do
72
+    # things that require .env
73
+end
74
+```
75
+
76
+## Usage
77
+
78
+Add your application configuration to your `.env` file in the root of your project:
79
+
80
+```shell
81
+S3_BUCKET=YOURS3BUCKET
82
+SECRET_KEY=YOURSECRETKEYGOESHERE
83
+```
84
+
85
+If you need multiline variables, for example private keys, you can double quote strings and use the `\n` character for newlines:
86
+
87
+```shell
88
+PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nHkVN9…\n-----END DSA PRIVATE KEY-----\n"
89
+```
90
+
91
+You may also add `export` in front of each line so you can `source` the file in bash:
92
+
93
+```shell
94
+export S3_BUCKET=YOURS3BUCKET
95
+export SECRET_KEY=YOURSECRETKEYGOESHERE
96
+```
97
+
98
+Whenever your application loads, these variables will be available in `ENV`:
99
+
100
+```ruby
101
+config.fog_directory  = ENV['S3_BUCKET']
102
+```
103
+
104
+Comments may be added to your file as such:
105
+
106
+```shell
107
+# This is a comment
108
+SECRET_KEY=YOURSECRETKEYGOESHERE # comment
109
+SECRET_HASH="something-with-a-#-hash"
110
+```
111
+
112
+Variable names may not contain the `#` symbol. Values can use the `#` if they are enclosed in quotes.
113
+
114
+## Multiple Rails Environments
115
+
116
+dotenv was originally created to load configuration variables into `ENV` in *development*. There are typically better ways to manage configuration in production environments - such as `/etc/environment` managed by [Puppet](https://github.com/puppetlabs/puppet) or [Chef](https://github.com/opscode/chef), `heroku config`, etc.
117
+
118
+However, some find dotenv to be a convenient way to configure Rails applications in staging and production environments, and you can do that by defining environment-specific files like `.env.production` or `.env.test`.
119
+
120
+You can also `.env.local` for local overrides.
121
+
122
+## Should I commit my .env file?
123
+
124
+Credentials should only be accessible on the machines that need access to them. Never commit sensitive information to a repository that is not needed by every development machine and server.
125
+
126
+Personally, I prefer to commit the `.env` file with development-only settings. This makes it easy for other developers to get started on the project without compromising credentials for other environments. If you follow this advice, make sure that all the credentials for your development environment are different from your other deployments and that the development credentials do not have access to any confidential data.
127
+
128
+## Contributing
129
+
130
+If you want a better idea of how dotenv works, check out the [Ruby Rogues Code Reading of dotenv](https://www.youtube.com/watch?v=lKmY_0uY86s).
131
+
132
+1. Fork it
133
+2. Create your feature branch (`git checkout -b my-new-feature`)
134
+3. Commit your changes (`git commit -am 'Added some feature'`)
135
+4. Push to the branch (`git push origin my-new-feature`)
136
+5. Create new Pull Request

+ 4 - 0
vendor/gems/dotenv-2.0.1/bin/dotenv

@@ -0,0 +1,4 @@
1
+#!/usr/bin/env ruby
2
+
3
+require "dotenv/cli"
4
+Dotenv::CLI.new(ARGV).run

+ 17 - 0
vendor/gems/dotenv-2.0.1/dotenv-rails.gemspec

@@ -0,0 +1,17 @@
1
+require File.expand_path("../lib/dotenv/version", __FILE__)
2
+require "English"
3
+
4
+Gem::Specification.new "dotenv-rails", Dotenv::VERSION do |gem|
5
+  gem.authors       = ["Brandon Keepers"]
6
+  gem.email         = ["brandon@opensoul.org"]
7
+  gem.description   = gem.summary = "Autoload dotenv in Rails."
8
+  gem.homepage      = "https://github.com/bkeepers/dotenv"
9
+  gem.license       = "MIT"
10
+  gem.files         = `git ls-files lib | grep rails`
11
+    .split($OUTPUT_RECORD_SEPARATOR) + ["README.md", "LICENSE"]
12
+
13
+  gem.add_dependency "dotenv", Dotenv::VERSION
14
+
15
+  gem.add_development_dependency "spring"
16
+  gem.add_development_dependency "railties", "~>4.0"
17
+end

+ 18 - 0
vendor/gems/dotenv-2.0.1/dotenv.gemspec

@@ -0,0 +1,18 @@
1
+require File.expand_path("../lib/dotenv/version", __FILE__)
2
+require "English"
3
+
4
+Gem::Specification.new "dotenv", Dotenv::VERSION do |gem|
5
+  gem.authors       = ["Brandon Keepers"]
6
+  gem.email         = ["brandon@opensoul.org"]
7
+  gem.description   = gem.summary = "Loads environment variables from `.env`."
8
+  gem.homepage      = "https://github.com/bkeepers/dotenv"
9
+  gem.license       = "MIT"
10
+
11
+  gem.files         = `git ls-files README.md LICENSE lib bin | grep -v rails`
12
+    .split($OUTPUT_RECORD_SEPARATOR)
13
+  gem.executables   = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
14
+
15
+  gem.add_development_dependency "rake"
16
+  gem.add_development_dependency "rspec"
17
+  gem.add_development_dependency "rubocop"
18
+end

+ 1 - 0
vendor/gems/dotenv-2.0.1/lib/dotenv-rails.rb

@@ -0,0 +1 @@
1
+require "dotenv/rails"

+ 62 - 0
vendor/gems/dotenv-2.0.1/lib/dotenv.rb

@@ -0,0 +1,62 @@
1
+require "dotenv/parser"
2
+require "dotenv/environment"
3
+
4
+# The top level Dotenv module. The entrypoint for the application logic.
5
+module Dotenv
6
+  class << self
7
+    attr_accessor :instrumenter
8
+  end
9
+
10
+  module_function
11
+
12
+  def load(*filenames)
13
+    with(*filenames) do |f|
14
+      ignoring_nonexistent_files do
15
+        env = Environment.new(f)
16
+        instrument("dotenv.load", :env => env) { env.apply }
17
+      end
18
+    end
19
+  end
20
+
21
+  # same as `load`, but raises Errno::ENOENT if any files don't exist
22
+  def load!(*filenames)
23
+    with(*filenames) do |f|
24
+      env = Environment.new(f)
25
+      instrument("dotenv.load", :env => env) { env.apply }
26
+    end
27
+  end
28
+
29
+  # same as `load`, but will override existing values in `ENV`
30
+  def overload(*filenames)
31
+    with(*filenames) do |f|
32
+      ignoring_nonexistent_files do
33
+        env = Environment.new(f)
34
+        instrument("dotenv.overload", :env => env) { env.apply! }
35
+      end
36
+    end
37
+  end
38
+
39
+  # Internal: Helper to expand list of filenames.
40
+  #
41
+  # Returns a hash of all the loaded environment variables.
42
+  def with(*filenames, &block)
43
+    filenames << ".env" if filenames.empty?
44
+
45
+    filenames.reduce({}) do |hash, filename|
46
+      hash.merge! block.call(File.expand_path(filename)) || {}
47
+    end
48
+  end
49
+
50
+  def instrument(name, payload = {}, &block)
51
+    if instrumenter
52
+      instrumenter.instrument(name, payload, &block)
53
+    else
54
+      block.call
55
+    end
56
+  end
57
+
58
+  def ignoring_nonexistent_files
59
+    yield
60
+  rescue Errno::ENOENT
61
+  end
62
+end

+ 36 - 0
vendor/gems/dotenv-2.0.1/lib/dotenv/cli.rb

@@ -0,0 +1,36 @@
1
+require "dotenv"
2
+
3
+module Dotenv
4
+  # The CLI is a class responsible of handling all the command line interface
5
+  # logic.
6
+  class CLI
7
+    attr_reader :argv
8
+
9
+    def initialize(argv = [])
10
+      @argv = argv.dup
11
+    end
12
+
13
+    def run
14
+      filenames = parse_filenames || []
15
+      begin
16
+        Dotenv.load!(*filenames)
17
+      rescue Errno::ENOENT => e
18
+        abort e.message
19
+      else
20
+        exec(*argv) unless argv.empty?
21
+      end
22
+    end
23
+
24
+    private
25
+
26
+    def parse_filenames
27
+      pos = argv.index("-f")
28
+      return nil unless pos
29
+      # drop the -f
30
+      argv.delete_at pos
31
+      # parse one or more comma-separated .env files
32
+      require "csv"
33
+      CSV.parse_line argv.delete_at(pos)
34
+    end
35
+  end
36
+end

+ 28 - 0
vendor/gems/dotenv-2.0.1/lib/dotenv/environment.rb

@@ -0,0 +1,28 @@
1
+module Dotenv
2
+  # This class inherits from Hash and represents the environemnt into which
3
+  # Dotenv will load key value pairs from a file.
4
+  class Environment < Hash
5
+    attr_reader :filename
6
+
7
+    def initialize(filename)
8
+      @filename = filename
9
+      load
10
+    end
11
+
12
+    def load
13
+      update Parser.call(read)
14
+    end
15
+
16
+    def read
17
+      File.read(@filename)
18
+    end
19
+
20
+    def apply
21
+      each { |k, v| ENV[k] ||= v }
22
+    end
23
+
24
+    def apply!
25
+      each { |k, v| ENV[k] = v }
26
+    end
27
+  end
28
+end

+ 93 - 0
vendor/gems/dotenv-2.0.1/lib/dotenv/parser.rb

@@ -0,0 +1,93 @@
1
+require "dotenv/substitutions/variable"
2
+require "dotenv/substitutions/command" if RUBY_VERSION > "1.8.7"
3
+
4
+module Dotenv
5
+  class FormatError < SyntaxError; end
6
+
7
+  # This class enables parsing of a string for key value pairs to be returned
8
+  # and stored in the Environment. It allows for variable substitutions and
9
+  # exporting of variables.
10
+  class Parser
11
+    @substitutions =
12
+      Substitutions.constants.map { |const| Substitutions.const_get(const) }
13
+
14
+    LINE = /
15
+      \A
16
+      (?:export\s+)?    # optional export
17
+      ([\w\.]+)         # key
18
+      (?:\s*=\s*|:\s+?) # separator
19
+      (                 # optional value begin
20
+        '(?:\'|[^'])*'  #   single quoted value
21
+        |               #   or
22
+        "(?:\"|[^"])*"  #   double quoted value
23
+        |               #   or
24
+        [^#\n]+         #   unquoted value
25
+      )?                # value end
26
+      (?:\s*\#.*)?      # optional comment
27
+      \z
28
+    /x
29
+
30
+    class << self
31
+      attr_reader :substitutions
32
+
33
+      def call(string)
34
+        new(string).call
35
+      end
36
+    end
37
+
38
+    def initialize(string)
39
+      @string = string
40
+      @hash = {}
41
+    end
42
+
43
+    def call
44
+      @string.split("\n").each do |line|
45
+        parse_line(line)
46
+      end
47
+      @hash
48
+    end
49
+
50
+    private
51
+
52
+    def parse_line(line)
53
+      if (match = line.match(LINE))
54
+        key, value = match.captures
55
+        @hash[key] = parse_value(value || "")
56
+      elsif line.split.first == "export"
57
+        if variable_not_set?(line)
58
+          fail FormatError, "Line #{line.inspect} has an unset variable"
59
+        end
60
+      elsif line !~ /\A\s*(?:#.*)?\z/ # not comment or blank line
61
+        fail FormatError, "Line #{line.inspect} doesn't match format"
62
+      end
63
+    end
64
+
65
+    def parse_value(value)
66
+      # Remove surrounding quotes
67
+      value = value.strip.sub(/\A(['"])(.*)\1\z/, '\2')
68
+
69
+      if Regexp.last_match(1) == '"'
70
+        value = unescape_characters(expand_newlines(value))
71
+      end
72
+
73
+      if Regexp.last_match(1) != "'"
74
+        self.class.substitutions.each do |proc|
75
+          value = proc.call(value, @hash)
76
+        end
77
+      end
78
+      value
79
+    end
80
+
81
+    def unescape_characters(value)
82
+      value.gsub(/\\([^$])/, '\1')
83
+    end
84
+
85
+    def expand_newlines(value)
86
+      value.gsub('\n', "\n")
87
+    end
88
+
89
+    def variable_not_set?(line)
90
+      !line.split[1..-1].all? { |var| @hash.member?(var) }
91
+    end
92
+  end
93
+end

+ 10 - 0
vendor/gems/dotenv-2.0.1/lib/dotenv/rails-now.rb

@@ -0,0 +1,10 @@
1
+# If you use gems that require environment variables to be set before they are
2
+# loaded, then list `dotenv-rails` in the `Gemfile` before those other gems and
3
+# require `dotenv/rails-now`.
4
+#
5
+#     gem "dotenv-rails", :require => "dotenv/rails-now"
6
+#     gem "gem-that-requires-env-variables"
7
+#
8
+
9
+require "dotenv/rails"
10
+Dotenv::Railtie.load

+ 47 - 0
vendor/gems/dotenv-2.0.1/lib/dotenv/rails.rb

@@ -0,0 +1,47 @@
1
+require "dotenv"
2
+
3
+Dotenv.instrumenter = ActiveSupport::Notifications
4
+
5
+# Watch all loaded env files with Spring
6
+begin
7
+  require "spring/watcher"
8
+  ActiveSupport::Notifications.subscribe(/^dotenv/) do |*args|
9
+    event = ActiveSupport::Notifications::Event.new(*args)
10
+    Spring.watch event.payload[:env].filename if Rails.application
11
+  end
12
+rescue LoadError
13
+  # Spring is not available
14
+end
15
+
16
+module Dotenv
17
+  # Dotenv Railtie for using Dotenv to load environment from a file into
18
+  # Rails applications
19
+  class Railtie < Rails::Railtie
20
+    config.before_configuration { load }
21
+
22
+    # Public: Load dotenv
23
+    #
24
+    # This will get called during the `before_configuration` callback, but you
25
+    # can manually call `Dotenv::Railtie.load` if you needed it sooner.
26
+    def load
27
+      Dotenv.load(
28
+        root.join(".env.local"),
29
+        root.join(".env.#{Rails.env}"),
30
+        root.join(".env")
31
+      )
32
+    end
33
+
34
+    # Internal: `Rails.root` is nil in Rails 4.1 before the application is
35
+    # initialized, so this falls back to the `RAILS_ROOT` environment variable,
36
+    # or the current working directory.
37
+    def root
38
+      Rails.root || Pathname.new(ENV["RAILS_ROOT"] || Dir.pwd)
39
+    end
40
+
41
+    # Rails uses `#method_missing` to delegate all class methods to the
42
+    # instance, which means `Kernel#load` gets called here. We don't want that.
43
+    def self.load
44
+      instance.load
45
+    end
46
+  end
47
+end

+ 41 - 0
vendor/gems/dotenv-2.0.1/lib/dotenv/substitutions/command.rb

@@ -0,0 +1,41 @@
1
+require "English"
2
+
3
+module Dotenv
4
+  module Substitutions
5
+    # Substitute shell commands in a value.
6
+    #
7
+    #   SHA=$(git rev-parse HEAD)
8
+    #
9
+    module Command
10
+      class << self
11
+        INTERPOLATED_SHELL_COMMAND = /
12
+          (?<backslash>\\)?   # is it escaped with a backslash?
13
+          \$                  # literal $
14
+          (?<cmd>             # collect command content for eval
15
+            \(                # require opening paren
16
+            ([^()]|\g<cmd>)+  # allow any number of non-parens, or balanced
17
+                              # parens (by nesting the <cmd> expression
18
+                              # recursively)
19
+            \)                # require closing paren
20
+          )
21
+        /x
22
+
23
+        def call(value, _env)
24
+          # Process interpolated shell commands
25
+          value.gsub(INTERPOLATED_SHELL_COMMAND) do |*|
26
+            # Eliminate opening and closing parentheses
27
+            command = $LAST_MATCH_INFO[:cmd][1..-2]
28
+
29
+            if $LAST_MATCH_INFO[:backslash]
30
+              # Command is escaped, don't replace it.
31
+              $LAST_MATCH_INFO[0][1..-1]
32
+            else
33
+              # Execute the command and return the value
34
+              `#{command}`.chomp
35
+            end
36
+          end
37
+        end
38
+      end
39
+    end
40
+  end
41
+end

+ 34 - 0
vendor/gems/dotenv-2.0.1/lib/dotenv/substitutions/variable.rb

@@ -0,0 +1,34 @@
1
+require "English"
2
+
3
+module Dotenv
4
+  module Substitutions
5
+    # Substitute variables in a value.
6
+    #
7
+    #   HOST=example.com
8
+    #   URL="https://$HOST"
9
+    #
10
+    module Variable
11
+      class << self
12
+        VARIABLE = /
13
+          (\\)?        # is it escaped with a backslash?
14
+          (\$)         # literal $
15
+          \{?          # allow brace wrapping
16
+          ([A-Z0-9_]+) # match the variable
17
+          \}?          # closing brace
18
+        /xi
19
+
20
+        def call(value, env)
21
+          value.gsub(VARIABLE) do |variable|
22
+            match = $LAST_MATCH_INFO
23
+
24
+            if match[1] == '\\'
25
+              variable[1..-1]
26
+            else
27
+              env.fetch(match[3]) { ENV[match[3]] }
28
+            end
29
+          end
30
+        end
31
+      end
32
+    end
33
+  end
34
+end

+ 7 - 0
vendor/gems/dotenv-2.0.1/lib/dotenv/tasks.rb

@@ -0,0 +1,7 @@
1
+desc "Load environment settings from .env"
2
+task :dotenv do
3
+  require "dotenv"
4
+  Dotenv.load
5
+end
6
+
7
+task :environment => :dotenv

+ 3 - 0
vendor/gems/dotenv-2.0.1/lib/dotenv/version.rb

@@ -0,0 +1,3 @@
1
+module Dotenv
2
+  VERSION = "2.0.1"
3
+end