appforce-spawn 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.appforce.example +4 -0
  3. data/.gitignore +8 -0
  4. data/Gemfile +17 -0
  5. data/History +85 -0
  6. data/README.md +144 -0
  7. data/ansible/README.md +31 -0
  8. data/ansible/common.yml +6 -0
  9. data/ansible/roles/common/tasks/.keep +0 -0
  10. data/ansible/roles/common/tasks/active_users.yml +23 -0
  11. data/ansible/roles/common/tasks/groups.yml +28 -0
  12. data/ansible/roles/common/tasks/inactive_users.yml +26 -0
  13. data/ansible/roles/common/tasks/main.yml +5 -0
  14. data/ansible/roles/common/tasks/setup.yml +6 -0
  15. data/ansible/roles/scout/tasks/.keep +0 -0
  16. data/ansible/roles/scout/tasks/install.yml +28 -0
  17. data/ansible/roles/scout/tasks/main.yml +2 -0
  18. data/ansible/roles/scout/vars/.keep +0 -0
  19. data/ansible/rvm.yml +13 -0
  20. data/ansible/scout.yml +6 -0
  21. data/ansible/site.yml +4 -0
  22. data/appforce-spawn.gemspec +24 -0
  23. data/bin/appforce-spawn +161 -0
  24. data/lib/appforce-spawn.rb +1 -0
  25. data/lib/appforce/config.rb +50 -0
  26. data/lib/appforce/logger.rb +25 -0
  27. data/lib/appforce/spawn.rb +312 -0
  28. data/lib/appforce/spawn/api.rb +4 -0
  29. data/lib/appforce/spawn/api/call.rb +217 -0
  30. data/lib/appforce/spawn/exceptions.rb +30 -0
  31. data/lib/appforce/spawn/runner.rb +143 -0
  32. data/lib/appforce/spawn/template.rb +102 -0
  33. data/lib/appforce/spawn/version.rb +10 -0
  34. data/spec/api_call_spec.rb +380 -0
  35. data/spec/config_spec.rb +51 -0
  36. data/spec/fixtures/all_host_data.json +12 -0
  37. data/spec/fixtures/appforce_config.yml +4 -0
  38. data/spec/fixtures/fake_private_key.yml +2 -0
  39. data/spec/fixtures/host_scout_vars.yml +10 -0
  40. data/spec/fixtures/hosts +8 -0
  41. data/spec/fixtures/inactive_users.yml +3 -0
  42. data/spec/fixtures/malformed_appforce_config.yml +4 -0
  43. data/spec/fixtures/private_key_vars.yml +4 -0
  44. data/spec/fixtures/scout_main.yml +2 -0
  45. data/spec/fixtures/users.yml +6 -0
  46. data/spec/fixtures/vars.yml +4 -0
  47. data/spec/logger_spec.rb +85 -0
  48. data/spec/runner_spec.rb +308 -0
  49. data/spec/spec_helper.rb +53 -0
  50. data/spec/template_spec.rb +160 -0
  51. data/spec/version_spec.rb +9 -0
  52. data/tmp/.keep +0 -0
  53. metadata +151 -0
@@ -0,0 +1,53 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'appforce/spawn'
5
+ require 'json'
6
+
7
+ def file_fixture(filename)
8
+ open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
9
+ end
10
+
11
+ def file_fixture_to_json(filename)
12
+ JSON::parse(open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read)
13
+ end
14
+
15
+ def file_fixture_path(filename)
16
+ File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")
17
+ end
18
+
19
+ def open_tmp_file(filename)
20
+ open(File.join(File.dirname(__FILE__), '..', 'tmp', "#{filename.to_s}")).read
21
+ end
22
+
23
+ RSpec.configure do |config|
24
+ config.expect_with :rspec do |expectations|
25
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
26
+ end
27
+
28
+ config.mock_with :rspec do |mocks|
29
+ mocks.verify_partial_doubles = false
30
+ end
31
+
32
+ # config.filter_run :focus
33
+ # config.run_all_when_everything_filtered = true
34
+ # config.profile_examples = 10
35
+
36
+ config.disable_monkey_patching!
37
+
38
+ config.warnings = false
39
+
40
+ if config.files_to_run.one?
41
+ config.default_formatter = 'doc'
42
+ end
43
+
44
+
45
+ config.order = :random
46
+ Kernel.srand config.seed
47
+
48
+ config.after(:suite) do
49
+ FileUtils.rm('tmp/fork') if File.exist? 'tmp/fork'
50
+ FileUtils.rm('tmp/.appforce.example') if File.exist? 'tmp/.appforce.example'
51
+ FileUtils.rm_rf('tmp/template_test') if File.exist? 'tmp/template_test'
52
+ end
53
+ end
@@ -0,0 +1,160 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ RSpec.describe Appforce::Spawn::Template do
4
+ before do
5
+ logger = Logger.new('/dev/null')
6
+ Appforce::Spawn.logger = logger
7
+ Appforce::Config.load_config(file_fixture_path('appforce_config.yml'))
8
+ end
9
+
10
+ describe '.run_path' do
11
+ it 'should return the current run path' do
12
+ expect(Appforce::Spawn::Template.run_path).to eq Dir.pwd
13
+ end
14
+ end
15
+
16
+ describe '.gem_path' do
17
+ it 'should return the path of the directory the gem is run from' do
18
+ path = Appforce::Spawn::Template.gem_path
19
+ expect(path).to end_with "lib/appforce/spawn"
20
+ expect(File.exist?("#{path}/version.rb")).to be_truthy
21
+ end
22
+ end
23
+
24
+ describe '.ansible_source_path' do
25
+ it 'should return the path of the directory for the Ansible source' do
26
+ path = Appforce::Spawn::Template.ansible_source_path
27
+ expect(File.exist?("#{path}/site.yml")).to be_truthy
28
+ end
29
+ end
30
+
31
+ describe '.ansible_dest_path' do
32
+ it 'should return a path to the client api name in the root directory' do
33
+ path = Appforce::Spawn::Template.ansible_dest_path('testclient')
34
+ expect(path).to end_with "testclient"
35
+ expect(path).to match Dir.pwd
36
+ end
37
+ end
38
+
39
+ describe '.create_dirs' do
40
+ context 'missing parameters (Client API Name)' do
41
+ it 'should raise an exception' do
42
+ expect { Appforce::Spawn::Template.create_dirs(*[nil, {}]) }.to raise_exception(Appforce::Spawn::MissingParameters)
43
+ end
44
+ end
45
+
46
+ context 'it has correct parameters' do
47
+ before do
48
+ allow(Appforce::Spawn::Template).to receive(:ansible_dest_path).and_return("tmp/template_test")
49
+ end
50
+
51
+ it 'should create directories for the template' do
52
+ Appforce::Spawn::Template.create_dirs(*[nil, {:client_api_name => 'template_test'}])
53
+ expect(Dir.exist?("tmp/template_test")).to be_truthy
54
+ end
55
+ end
56
+
57
+ context 'it has correct parameters & dir already exists' do
58
+ before do
59
+ allow(Appforce::Spawn::Template).to receive(:ansible_dest_path).and_return("tmp/template_test")
60
+ FileUtils.mkdir("tmp/template_test") rescue true
61
+ end
62
+
63
+ it 'should handle the Errno::EEXIST exception and move on' do
64
+ Appforce::Spawn::Template.create_dirs(*[nil, {:client_api_name => 'template_test'}])
65
+ expect(Dir.exist?("tmp/template_test")).to be_truthy
66
+ end
67
+
68
+ after do
69
+ `rm -rf tmp/template_test`
70
+ end
71
+ end
72
+ end
73
+
74
+ describe '.copy_template' do
75
+ context 'missing parameters (Client API Name)' do
76
+ it 'should raise an exception' do
77
+ expect { Appforce::Spawn::Template.copy_template(*[nil, {}]) }.to raise_exception(Appforce::Spawn::MissingParameters)
78
+ end
79
+ end
80
+
81
+ context 'it has correct parameters' do
82
+ before do
83
+ allow(Appforce::Spawn::Template).to receive(:ansible_dest_path).and_return("tmp/template_test")
84
+ end
85
+
86
+ it 'should copy files from the template' do
87
+ Appforce::Spawn::Template.copy_template(*[nil, {:client_api_name => 'template_test'}])
88
+ expect(File.exist?("tmp/template_test/site.yml")).to be_truthy
89
+ end
90
+
91
+ after do
92
+ `rm -rf tmp/template_test`
93
+ end
94
+ end
95
+ end
96
+
97
+ describe '.download_files' do
98
+ context 'missing parameters (Client API Name)' do
99
+ it 'should raise an exception' do
100
+ expect { Appforce::Spawn::Template.download_files(*[nil, {}]) }.to raise_exception(Appforce::Spawn::MissingParameters)
101
+ end
102
+ end
103
+
104
+ context 'it has correct parameters' do
105
+ before do
106
+ allow(Appforce::Spawn::Template).to receive(:ansible_dest_path).and_return("tmp/template_test")
107
+ Appforce::Spawn::Template.copy_template(*[nil, {:client_api_name => 'template_test'}])
108
+ allow(Appforce::Spawn::Api::Call).to receive(:get_hosts).and_return(file_fixture('hosts'))
109
+ allow(Appforce::Spawn::Api::Call).to receive(:get_active_users).and_return(file_fixture('users.yml'))
110
+ allow(Appforce::Spawn::Api::Call).to receive(:get_inactive_users).and_return(file_fixture('inactive_users.yml'))
111
+ allow(Appforce::Spawn::Api::Call).to receive(:get_vars).and_return(file_fixture('vars.yml'))
112
+ allow(Appforce::Spawn::Api::Call).to receive(:get_main_scout).and_return(file_fixture('scout_main.yml'))
113
+ allow(Appforce::Spawn::Api::Call).to receive(:get_all_host_data).and_return(file_fixture_to_json('all_host_data.json'))
114
+ allow(Appforce::Spawn::Api::Call).to receive(:get_host_scout_vars).and_return(file_fixture('host_scout_vars.yml'))
115
+ allow(Appforce::Spawn::Api::Call).to receive(:get_private_key).and_return(file_fixture('fake_private_key.yml'))
116
+ Appforce::Spawn::Template.create_dirs(*[nil, {:client_api_name => 'template_test'}])
117
+ end
118
+
119
+ it 'should copy files from the template' do
120
+ Appforce::Spawn::Template.download_files(*[nil, {:client_api_name => 'template_test'}])
121
+ expect(File.exist?("tmp/template_test/hosts")).to be_truthy
122
+ expect(File.exist?("tmp/template_test/active_users.yml")).to be_truthy
123
+ expect(File.exist?("tmp/template_test/inactive_users.yml")).to be_truthy
124
+ expect(File.exist?("tmp/template_test/vars.yml")).to be_truthy
125
+ expect(File.exist?("tmp/template_test/roles/scout/vars/ubuntu-test01.yml")).to be_truthy
126
+ expect(File.exist?("tmp/template_test/roles/scout/vars/main.yml")).to be_truthy
127
+ end
128
+
129
+ after do
130
+ `rm -rf tmp/template_test`
131
+ end
132
+ end
133
+
134
+ context 'it has correct parameters, but there is an error writing files' do
135
+ before do
136
+ allow(Appforce::Spawn::Template).to receive(:ansible_dest_path).and_return("tmp/template_test")
137
+ Appforce::Spawn::Template.copy_template(*[nil, {:client_api_name => 'template_test'}])
138
+ allow(Appforce::Spawn::Api::Call).to receive(:get_hosts).and_return(file_fixture('hosts'))
139
+ allow(Appforce::Spawn::Api::Call).to receive(:get_active_users).and_return(file_fixture('users.yml'))
140
+ allow(Appforce::Spawn::Api::Call).to receive(:get_inactive_users).and_return(file_fixture('inactive_users.yml'))
141
+ allow(Appforce::Spawn::Api::Call).to receive(:get_vars).and_return(file_fixture('vars.yml'))
142
+ allow(Appforce::Spawn::Api::Call).to receive(:get_main_scout).and_return(file_fixture('scout_main.yml'))
143
+ allow(Appforce::Spawn::Api::Call).to receive(:get_all_host_data).and_return(file_fixture_to_json('all_host_data.json'))
144
+ allow(Appforce::Spawn::Api::Call).to receive(:get_host_scout_vars).and_return(file_fixture('host_scout_vars.yml'))
145
+ allow(Appforce::Spawn::Api::Call).to receive(:get_private_key).and_return(file_fixture('fake_private_key.yml'))
146
+ allow(File).to receive(:open).and_raise(IOError)
147
+ Appforce::Spawn::Template.create_dirs(*[nil, {:client_api_name => 'template_test'}])
148
+ end
149
+
150
+ it 'should copy files from the template' do
151
+ expect { Appforce::Spawn::Template.download_files(*[nil, {:client_api_name => 'template_test'}]) }.to raise_exception
152
+ end
153
+
154
+ after do
155
+ `rm -rf tmp/template_test`
156
+ end
157
+ end
158
+ end
159
+
160
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ RSpec.describe Appforce::Spawn do
4
+ describe "version" do
5
+ it 'should be a string type' do
6
+ expect(Appforce::Spawn::VERSION).to be_a(String)
7
+ end
8
+ end
9
+ end
File without changes
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: appforce-spawn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
5
+ platform: ruby
6
+ authors:
7
+ - Derek Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.10.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.10'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.10.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: highline
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.7'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '1.7'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.7'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '1.7'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '3.0'
67
+ description: A gem that uses the Appforce SSH key manager API to install users on
68
+ client machines.
69
+ email: derek@synctree.com
70
+ executables:
71
+ - appforce-spawn
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".appforce.example"
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - History
79
+ - README.md
80
+ - ansible/README.md
81
+ - ansible/common.yml
82
+ - ansible/roles/common/tasks/.keep
83
+ - ansible/roles/common/tasks/active_users.yml
84
+ - ansible/roles/common/tasks/groups.yml
85
+ - ansible/roles/common/tasks/inactive_users.yml
86
+ - ansible/roles/common/tasks/main.yml
87
+ - ansible/roles/common/tasks/setup.yml
88
+ - ansible/roles/scout/tasks/.keep
89
+ - ansible/roles/scout/tasks/install.yml
90
+ - ansible/roles/scout/tasks/main.yml
91
+ - ansible/roles/scout/vars/.keep
92
+ - ansible/rvm.yml
93
+ - ansible/scout.yml
94
+ - ansible/site.yml
95
+ - appforce-spawn.gemspec
96
+ - bin/appforce-spawn
97
+ - lib/appforce-spawn.rb
98
+ - lib/appforce/config.rb
99
+ - lib/appforce/logger.rb
100
+ - lib/appforce/spawn.rb
101
+ - lib/appforce/spawn/api.rb
102
+ - lib/appforce/spawn/api/call.rb
103
+ - lib/appforce/spawn/exceptions.rb
104
+ - lib/appforce/spawn/runner.rb
105
+ - lib/appforce/spawn/template.rb
106
+ - lib/appforce/spawn/version.rb
107
+ - spec/api_call_spec.rb
108
+ - spec/config_spec.rb
109
+ - spec/fixtures/all_host_data.json
110
+ - spec/fixtures/appforce_config.yml
111
+ - spec/fixtures/fake_private_key.yml
112
+ - spec/fixtures/host_scout_vars.yml
113
+ - spec/fixtures/hosts
114
+ - spec/fixtures/inactive_users.yml
115
+ - spec/fixtures/malformed_appforce_config.yml
116
+ - spec/fixtures/private_key_vars.yml
117
+ - spec/fixtures/scout_main.yml
118
+ - spec/fixtures/users.yml
119
+ - spec/fixtures/vars.yml
120
+ - spec/logger_spec.rb
121
+ - spec/runner_spec.rb
122
+ - spec/spec_helper.rb
123
+ - spec/template_spec.rb
124
+ - spec/version_spec.rb
125
+ - tmp/.keep
126
+ homepage: http://synctree.com
127
+ licenses:
128
+ - Private
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ - ansible
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: 1.9.3
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.4.6
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Synctree user installation tool
151
+ test_files: []