sambot 0.1.115 → 0.1.117

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sambot/chef/cookbook.rb +39 -74
  3. data/lib/sambot/chef/generator.rb +53 -0
  4. data/lib/sambot/chef/hooks.rb +17 -0
  5. data/lib/sambot/chef/kitchen.rb +49 -36
  6. data/lib/sambot/chef/metadata.rb +27 -25
  7. data/lib/sambot/cli.rb +7 -3
  8. data/lib/sambot/commands/base_command.rb +13 -3
  9. data/lib/sambot/commands/cookbook_cmd.rb +45 -0
  10. data/lib/sambot/commands/session_cmd.rb +26 -0
  11. data/lib/sambot/commands/{workstation.rb → workstation_cmd.rb} +5 -2
  12. data/lib/sambot/dns/records.rb +1 -1
  13. data/lib/sambot/template.rb +27 -0
  14. data/lib/sambot/templates/.config.yml.erb +16 -0
  15. data/lib/sambot/templates/{.gitignore → .gitignore.sample} +0 -0
  16. data/lib/sambot/templates/.kitchen.yml.erb +10 -1
  17. data/lib/sambot/templates/Vagrantfile.erb +143 -0
  18. data/lib/sambot/templates/bootstrap.ps1 +33 -0
  19. data/lib/sambot/templates/bootstrap.sh +24 -0
  20. data/lib/sambot/templates/metadata.rb.erb +1 -0
  21. data/lib/sambot/ui.rb +8 -0
  22. data/lib/sambot/version.rb +1 -1
  23. data/lib/sambot/{developer_workflow → workflow}/brew.rb +1 -1
  24. data/lib/sambot/{developer_workflow → workflow}/dns.rb +1 -1
  25. data/lib/sambot/{developer_workflow → workflow}/networking.rb +1 -1
  26. data/lib/sambot/{developer_workflow → workflow}/proxy.rb +1 -1
  27. data/lib/sambot/{developer_workflow → workflow}/session.rb +1 -1
  28. data/lib/sambot/{developer_workflow → workflow}/tunnel.rb +1 -1
  29. data/lib/sambot/{developer_workflow → workflow}/tunnels.rb +1 -1
  30. data/lib/sambot/{developer_workflow → workflow}/vault.rb +1 -1
  31. data/lib/sambot/{developer_workflow → workflow}/workstation.rb +1 -1
  32. data/lib/sambot.rb +12 -21
  33. metadata +22 -28
  34. data/lib/sambot/commands/cookbook.rb +0 -47
  35. data/lib/sambot/commands/session.rb +0 -28
  36. data/lib/sambot/docs/dns/add.txt +0 -0
  37. data/lib/sambot/docs/dns/list.txt +0 -0
  38. data/lib/sambot/docs/dns/remove.txt +0 -0
  39. data/lib/sambot/docs/dns/show.txt +0 -0
  40. data/lib/sambot/docs/instance/generate.txt +0 -0
  41. data/lib/sambot/docs/report/consistency.txt +0 -18
  42. data/lib/sambot/docs/team/list.txt +0 -0
  43. data/lib/sambot/file_management/file_checker.rb +0 -43
  44. data/lib/sambot/file_management/template_provider.rb +0 -13
  45. data/lib/sambot/reports/consistency_report.rb +0 -0
  46. data/lib/sambot/ssh/config_file.rb +0 -75
  47. data/lib/sambot/ssh/config_section.rb +0 -84
  48. data/lib/sambot/ssh/parser.rb +0 -48
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5742c77c94b4e5245f39774393981f03f2aad332
4
- data.tar.gz: 11a5ecc8000f096f24c2068c3d3f872c85de457a
3
+ metadata.gz: 5410b3c608857a6491424bf29399106cf7023930
4
+ data.tar.gz: 529645ac3268d9f87102f4e0311f1368d368d4c0
5
5
  SHA512:
6
- metadata.gz: 3ee54c2067a11ba0ef302fc21f599b7ce8d5630789ac437a854956a710670b344a0906b11cd95b74625f4cd721e5f2ec3f37a667fdb209f042ebb34617108935
7
- data.tar.gz: 8e766dbb6b0f1ea7988c273ff7d9ec7f2468aa0e46dbec6ad46ed07d893eba45c4e0423eae5299750ade13dcbeefca56c872581bb295b3cfd730449cb4039952
6
+ metadata.gz: 1903dee501f46a5658f80a318e957ef75919d1799e65874b1fa99037c106825a4def5f509c38afcefaca9e03669dddb9b088ba29bb78747a2531c4d13f17a7b2
7
+ data.tar.gz: f1960f6ebcb4b8b699f344da6314cb6ba10446d3357f80f1bb2b2e41f224124a440d82461996b0cba451934b7f744715f81a7836057b508f28840ddbfc65277d
@@ -7,100 +7,65 @@ module Sambot
7
7
  module Chef
8
8
  class Cookbook
9
9
 
10
- def self.register(config)
11
- name = config['name']
12
- identifier = config['identifier']
13
-
14
- end
10
+ ESSENTIAL_FILES = [
11
+ '.config.yml',
12
+ 'recipes',
13
+ 'README.md'
14
+ ].freeze
15
+
16
+ GENERATED_FILES = {
17
+ 'teamcity.sh.erb': {eruby: true, dest: 'teamcity.sh', platform: [:windows, :centos]},
18
+ 'chefignore': {eruby: false, dest: 'chefignore', platform: [:windows, :centos]},
19
+ 'Berksfile': {eruby: false, dest: 'Berksfile', platform: [:windows, :centos]},
20
+ '.rubocop.yml': {eruby: false, dest: '.rubocop.yml', platform: [:windows, :centos]},
21
+ '.gitignore.sample': {eruby: false, dest: '.gitignore', platform: [:windows, :centos]},
22
+ 'bootstrap.sh': {eruby: false, dest: 'bootstrap.sh', platform: [:centos]},
23
+ 'bootstrap.ps1': {eruby: false, dest: 'bootstrap.ps1', platform: [:windows]},
24
+ 'Vagrantfile.erb': {eruby: false, dest: 'Vagrantfile.erb', platform: [:windows, :centos]},
25
+ 'winrm_config': {eruby: false, dest: 'winrm_config', platform: [:windows]}
26
+ }
27
+
28
+ CHEF_ARTEFACTS = ['Berksfile.lock']
29
+
30
+ KITCHEN_FILES_PATTERN = '\.kitchen*\.yml'
31
+
32
+ class << self
15
33
 
16
- def self.build(config, essential_files, generated_files)
17
- validate_cookbook_structure(config['platforms'], essential_files, generated_files)
18
- setup_test_kitchen(config)
19
- build_metadata(config)
20
- copy_git_hooks()
34
+ def build(config)
35
+ Generator.from_templates(config['platforms'], ESSENTIAL_FILES, GENERATED_FILES)
36
+ Kitchen.setup(config)
37
+ Metadata.generate(config)
38
+ Hooks.copy()
21
39
  UI.info('The cookbook has been successfully built.')
22
40
  end
23
41
 
24
- def self.clean(generated_files)
42
+ def clean()
25
43
  UI.info('Removing all generated files from this cookbook.')
26
- targets = ['metadata.rb', 'winrm_config', 'Berksfile.lock'] + generated_files + Dir.glob('\.kitchen*\.yml')
27
- targets.each do |file|
28
- delete_file(file)
29
- end
44
+ targets = ['metadata.rb', 'Berksfile.lock'] + GENERATED_FILES.map{ |key, val| val[:dest]} + Dir.glob(KITCHEN_FILES_PATTERN) - ['.gitignore']
45
+ targets.each { |file| delete(file) }
30
46
  UI.info('The cookbook has been successfully cleaned.')
31
47
  end
32
48
 
33
- def self.generate(config, name, platforms, type, description, essential_files, generated_files)
34
- Git.init(name)
35
- Dir.chdir(name) do
36
- ['test', 'spec', 'recipes'].each {|target| FileUtils.mkdir(target) }
49
+ def generate(config)
50
+ Git.init(config[:name])
51
+ Dir.chdir(config[:name]) do
52
+ ['test', 'spec', 'recipes'].each {|target| FileUtils.mkdir(target) }
37
53
  FileUtils.touch('README.md')
38
- write_config(name, description, platforms, type)
39
- build(config, essential_files, generated_files)
54
+ Template.new('.config.yml.erb').write(config, '.config.yml')
55
+ UI.debug("./.config.yml has been added to the cookbook.")
40
56
  end
41
57
  UI.info('The cookbook has been successfully generated.')
42
58
  end
43
59
 
44
60
  private
45
61
 
46
- def self.write_config(name, description, platforms, type)
47
- contents = {
48
- 'name' => name,
49
- 'version' => '0.0.1',
50
- 'platforms' => platforms,
51
- 'identifier' => '',
52
- 'suites' => [{
53
- 'name' => 'default',
54
- 'run_list' => [
55
- "recipe[#{name}]"
56
- ],
57
- 'verifier' => {
58
- 'inspec_tests' => ['./test']
59
- }
60
- }],
61
- 'description' => description,
62
- }.to_yaml
63
- File.write('.config.yml', contents)
64
- UI.debug("./.config.yml has been added to the cookbook.")
65
- end
66
-
67
- def self.copy_git_hooks
68
- working_path = '.git/hooks/pre-push'
69
- template_path = FileManagement::TemplateProvider.get_path('pre-push')
70
- File.delete(working_path) if File.exist?(working_path)
71
- FileUtils.cp(template_path, working_path)
72
- UI.debug("The pre-push Git hook has been added to the cookbook.")
73
- end
74
-
75
- def self.delete_file(filename)
76
- filename = filename.gsub(/\.erb/, '') if filename.end_with?(".erb")
62
+ def delete(filename)
77
63
  return unless File.exist?(filename)
78
64
  File.delete(filename)
79
65
  UI.debug("./#{filename} has been removed.")
80
66
  end
81
67
 
82
- def self.validate_cookbook_structure(platform, essential_files, generated_files)
83
- essential_files.each { |path| FileManagement::FileChecker.new.verify(path) }
84
- if platform.include?('windows')
85
- FileManagement::FileChecker.new.update(['winrm_config'])
86
- end
87
- FileManagement::FileChecker.new.update(generated_files)
88
- end
89
-
90
- def self.setup_test_kitchen(config)
91
- files = Chef::Kitchen.generate_yml(config['name'], config['platforms'], config['suites'])
92
- files.each do |filename, contents|
93
- File.write(filename.to_s, contents)
94
- UI.debug("#{filename.to_s} has been added to the cookbook.")
95
- end
96
- end
97
-
98
- def self.build_metadata(config)
99
- result = Chef::Metadata.generate(config['name'], config['platforms'], config['version'], config['description'], config['dependencies'], config['gems'])
100
- File.write('metadata.rb', result)
101
- UI.debug("A new metadata.rb file has been generated.")
102
- end
103
-
104
68
  end
69
+ end
105
70
  end
106
71
  end
@@ -0,0 +1,53 @@
1
+ #frozen_string_literal: true
2
+
3
+ module Sambot
4
+ module Chef
5
+ class Generator
6
+
7
+ def self.from_templates(platforms, cookbook_essentials, cookbook_generated_files)
8
+ cookbook_essentials.each { |path| exists!(path) } if cookbook_essentials
9
+ cookbook_generated_files.each do |template_name, opts|
10
+ generate_from_template(template_name.to_s, opts, platforms)
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def self.exists!(path)
17
+ return if File.exist?(path) || Dir.exist?(path)
18
+ raise ApplicationError, "The file or directory #{path} was not found in the current directory."
19
+ end
20
+
21
+ def self.generate_from_template(template_file, opts, platforms)
22
+ UI.debug("Processing #{template_file} with opts #{opts.inspect} on platform #{platforms}")
23
+ template = Template.new(template_file)
24
+ if valid_platform?(opts, platforms)
25
+ File.delete(opts[:dest]) if File.exist?(opts[:dest])
26
+ if opts[:eruby]
27
+ UI.debug("Parsing #{template.path} using Erubis")
28
+ template.write({}, opts[:dest])
29
+ else
30
+ FileUtils.cp(template.path, opts[:dest].to_s)
31
+ end
32
+ if File.executable?(template.path)
33
+ UI.debug("Making #{opts[:dest]} executable")
34
+ make_executable(template.path, opts[:dest])
35
+ end
36
+ UI.debug("#{opts[:dest]} has been added to the cookbook.")
37
+ end
38
+ end
39
+
40
+ def self.valid_platform?(opts, platforms)
41
+ targets = opts[:platform].map { |x| x.to_s}
42
+ result = targets & platforms
43
+ result.size > 0
44
+ end
45
+
46
+ def self.make_executable(file, working_path)
47
+ current_mask = File.stat(file).mode
48
+ new_mask = current_mask | '0000000000000001'.to_i(2)
49
+ File.chmod(new_mask, working_path)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,17 @@
1
+ #frozen_string_literal: true
2
+
3
+ module Sambot
4
+ module Chef
5
+ class Hooks
6
+
7
+ def self.copy
8
+ working_path = '.git/hooks/pre-push'
9
+ template_path = Template.new('pre-push').path
10
+ File.delete(working_path) if File.exist?(working_path)
11
+ FileUtils.cp(template_path, working_path)
12
+ UI.debug("The pre-push Git hook has been added to the cookbook.")
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -4,49 +4,62 @@ module Sambot
4
4
  module Chef
5
5
  class Kitchen
6
6
 
7
- KITCHEN_LOCAL_YML = '.kitchen.yml'
8
- KITCHEN_GCP_YML = '.kitchen.gcp.yml'
9
- KITCHEN_RACKSPACE_YML = '.kitchen.rackspace.yml'
10
-
11
- def self.generate_yml(cookbook_name, platforms, suites = nil)
12
- raise ApplicationError, 'Missing platforms when trying to generate Test-Kitchen YAML.' unless platforms
13
- raise ApplicationError, 'Missing cookbook name when trying to generate Test-Kitchen YAML.' unless cookbook_name
14
- test_kitchen_configs = {
15
- "#{KITCHEN_LOCAL_YML}": read_template(KITCHEN_LOCAL_YML, cookbook_name, platforms),
16
- "#{KITCHEN_GCP_YML}": read_template(KITCHEN_GCP_YML, cookbook_name, platforms),
17
- "#{KITCHEN_RACKSPACE_YML}": read_template(KITCHEN_RACKSPACE_YML, cookbook_name, platforms)
18
- }
19
- test_kitchen_configs.each do |key, value|
20
- if suites
21
- value['suites'] = Marshal.load(Marshal.dump(suites))
22
- case key.to_s
23
- when KITCHEN_GCP_YML
24
- value['suites'].each do |config|
25
- config['attributes'] = config['attributes'] || {}
26
- config['attributes']['cloud_platform'] = 'GCP'
27
- end
28
- when KITCHEN_RACKSPACE_YML
29
- value['suites'].each do |config|
30
- config['attributes'] = config['attributes'] || {}
31
- config['attributes']['cloud_platform'] = 'RACKSPACE'
7
+ LOCAL = '.kitchen.yml'
8
+ GCP = '.kitchen.gcp.yml'
9
+ RACKSPACE = '.kitchen.rackspace.yml'
10
+
11
+ class << self
12
+
13
+ def setup(config)
14
+ files = generate_yml(config['name'], config['platforms'], config['suites'])
15
+ files.each do |filename, contents|
16
+ File.write(filename.to_s, contents)
17
+ UI.debug("#{filename.to_s} has been added to the cookbook.")
18
+ end
19
+ end
20
+
21
+ def generate_yml(cookbook_name, platforms, suites = nil)
22
+ raise ApplicationError, 'Missing platforms when trying to generate Test-Kitchen YAML.' unless platforms
23
+ raise ApplicationError, 'Missing cookbook name when trying to generate Test-Kitchen YAML.' unless cookbook_name
24
+ test_kitchen_configs = {
25
+ "#{LOCAL}": read_template(LOCAL, cookbook_name, platforms),
26
+ "#{GCP}": read_template(GCP, cookbook_name, platforms),
27
+ "#{RACKSPACE}": read_template(RACKSPACE, cookbook_name, platforms)
28
+ }
29
+ test_kitchen_configs.each do |key, value|
30
+ if suites
31
+ value['suites'] = Marshal.load(Marshal.dump(suites))
32
+ case key.to_s
33
+ when LOCAL
34
+ add_platform_identifier(value, 'LOCAL')
35
+ when GCP
36
+ add_platform_identifier(value, 'GCP')
37
+ when RACKSPACE
38
+ add_platform_identifier(value, 'RACKSPACE')
32
39
  end
33
40
  end
41
+ test_kitchen_configs[key] = value.to_yaml
34
42
  end
35
- test_kitchen_configs[key] = value.to_yaml
43
+ test_kitchen_configs
36
44
  end
37
- test_kitchen_configs
38
- end
39
45
 
40
- private
46
+ private
41
47
 
42
- def self.read_template(template, cookbook_name, platforms)
43
- filename = File.join(FileManagement::TemplateProvider.get_path("#{template}.erb"))
44
- contents = File.read(filename).gsub(/@@cookbook_name@@/, cookbook_name)
45
- eruby = Erubis::Eruby.new(contents)
46
- yaml = eruby.evaluate({platforms: platforms}).gsub(/\_@/, '<%=').gsub(/@\_/, '%>')
47
- YAML.load(yaml)
48
- end
48
+ def add_platform_identifier(value, platform)
49
+ value['suites'].each do |config|
50
+ config['attributes'] = config['attributes'] || {}
51
+ config['attributes']['cloud_platform'] = platform
52
+ end
53
+ end
54
+
55
+ def read_template(template, cookbook_name, platforms)
56
+ result = Template.new("#{template}.erb").evaluate({platforms: platforms}) do |contents|
57
+ contents.gsub(/@@cookbook_name@@/, cookbook_name)
58
+ end
59
+ YAML.load(result.gsub(/\_@/, '<%=').gsub(/@\_/, '%>'))
60
+ end
49
61
 
50
62
  end
63
+ end
51
64
  end
52
65
  end
@@ -3,37 +3,39 @@
3
3
  require 'erubis'
4
4
 
5
5
  module Sambot
6
- module Chef
7
- class Metadata
8
-
9
- TemplateProvider = FileManagement::TemplateProvider
10
-
11
- def self.generate(name, platforms, version, description, dependencies = nil, gems = nil)
12
-
13
- if dependencies
14
- dependencies = dependencies.map { |x| x.is_a?(Hash) ? "#{x.keys.first}', '#{x.values.first}" : x }
15
- end
16
-
17
- context = {
18
- 'cookbook_name' => name,
19
- 'cookbook_platforms' => platforms,
20
- 'cookbook_version' => version,
21
- 'cookbook_description' => description,
22
- 'cookbook_dependencies' => dependencies,
23
- 'cookbook_gems' => gems,
24
- }
25
- generate_metadata(context)
6
+ module Chef
7
+ class Metadata
8
+
9
+ class << self
10
+
11
+ def generate(config, dest = 'metadata.rb')
12
+ write({
13
+ 'cookbook_name' => config['name'],
14
+ 'cookbook_platforms' => config['platforms'],
15
+ 'cookbook_version' => config['version'],
16
+ 'cookbook_description' => config['description'],
17
+ 'cookbook_dependencies' => map_dependencies(config),
18
+ 'cookbook_gems' => config['gems'] || [],
19
+ }, dest)
26
20
  end
27
21
 
28
22
  private
29
23
 
30
- def self.generate_metadata(context)
31
- filename = TemplateProvider.get_path('metadata.rb.erb')
32
- input = File.read(filename)
33
- eruby = Erubis::Eruby.new(input)
34
- eruby.evaluate(context)
24
+ def map_dependencies(config)
25
+ config['dependencies'] ? config['dependencies'].map { |x| transform_hashes(x) } : []
26
+ end
27
+
28
+ def transform_hashes(obj)
29
+ obj.is_a?(Hash) ? "#{obj.keys.first}', '#{obj.values.first}" : obj
30
+ end
31
+
32
+ def write(ctx, dest)
33
+ template = Sambot::Template.new('metadata.rb.erb').write(ctx, dest)
34
+ UI.debug("A new metadata.rb file has been generated.")
35
35
  end
36
36
 
37
37
  end
38
+
39
+ end
38
40
  end
39
41
  end
data/lib/sambot/cli.rb CHANGED
@@ -1,16 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'commands/cookbook_cmd'
4
+ require_relative 'commands/session_cmd'
5
+ require_relative 'commands/workstation_cmd'
6
+
3
7
  module Sambot
4
8
  class CLI < Thor
5
9
 
6
10
  desc 'cookbook', 'Manage Chef cookbooks'
7
- subcommand 'cookbook', Sambot::Commands::Cookbook
11
+ subcommand 'cookbook', Sambot::Commands::CookbookCmd
8
12
 
9
13
  desc 'session', 'Manage sessions'
10
- subcommand 'session', Sambot::Commands::Session
14
+ subcommand 'session', Sambot::Commands::SessionCmd
11
15
 
12
16
  desc 'workstation', 'Manage engineer workstations'
13
- subcommand 'workstation', Sambot::Commands::Workstation
17
+ subcommand 'workstation', Sambot::Commands::WorkstationCmd
14
18
 
15
19
  end
16
20
  end
@@ -60,15 +60,25 @@ module Sambot
60
60
 
61
61
  no_commands do
62
62
 
63
+ def missing_credentials(need_dev_credentials, need_sudo_password)
64
+ return true if need_dev_credentials && (!ENV['SAMBOT_DEV_USERNAME'] && !ENV['SAMBOT_DEV_PASSWORD'])
65
+ return need_sudo_password && !ENV['SAMBOT_SUDO_PASSWORD']
66
+ end
67
+
63
68
  def execute(need_dev_credentials: false, need_sudo_password: false)
69
+ if missing_credentials(need_dev_credentials, need_sudo_password)
70
+ UI.info("Sambot will need to make some secure operations on your behalf. You can provide your credentials below or set them as environment variables:")
71
+ end
64
72
  if need_dev_credentials && !ENV['SAMBOT_DEV_USERNAME']
65
- raise ApplicationError, 'Your DEV/QE username needs to be set in the environment variable SAMBOT_DEV_USERNAME before this command can be run.'
73
+ ENV['SAMBOT_DEV_USERNAME'] = UI.ask("Please provide your DEV/QE AD username: ")
66
74
  end
67
75
  if need_dev_credentials && !ENV['SAMBOT_DEV_PASSWORD']
68
- raise ApplicationError, 'Your DEV/QE password needs to be set in the environment variable SAMBOT_DEV_PASSWORD before this command can be run.'
76
+ ENV['SAMBOT_DEV_USERNAME'] = UI.ask_password("Please provide your DEV/QE AD password: ")
77
+ puts "\n"
69
78
  end
70
79
  if need_sudo_password && !ENV['SAMBOT_SUDO_PASSWORD']
71
- raise ApplicationError, 'Your local password needs to be set in the environment variable SAMBOT_SUDO_PASSWORD before this command can be run.'
80
+ ENV['SAMBOT_DEV_USERNAME'] = UI.ask_password("Please provide your sudo password - this is required for operations such as setting up your local SSH tunnels: ")
81
+ puts "\n"
72
82
  end
73
83
  Runtime.ensure_latest
74
84
  yield
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_command'
4
+ require_relative '../chef/cookbook'
5
+
6
+ module Sambot
7
+ module Commands
8
+
9
+ class CookbookCmd < BaseCommand
10
+
11
+ namespace 'cookbook'
12
+
13
+ desc 'clean', 'Remove all generated build files from a cookbook'
14
+ def clean
15
+ execute { Chef::Cookbook.clean() }
16
+ end
17
+
18
+ desc 'build', 'Builds a cookbook from its configuration file'
19
+ def build
20
+ execute { Chef::Cookbook.build(config) }
21
+ end
22
+
23
+ desc 'generate', 'Creates a new cookbook'
24
+ def generate
25
+ execute do
26
+ config = {
27
+ name: ask(' What is the name of this cookbook?'),
28
+ type: ask(' What type of cookbook will this be?', :limited_to => ['wrapper', 'role']),
29
+ platforms: ask(' What operating system will this cookbook run on?', :limited_to => ['windows', 'centos', 'both']),
30
+ description: ask(' What does this cookbook do?')
31
+ }
32
+ config[:identifier] = ask(' What will be the unique machiner identifier for this role cookbook?') if config[:type] == 'role'
33
+ config[:platforms] = config[:platforms] == 'both' ? ['centos', 'windows'] : [config[:platforms]]
34
+ Chef::Cookbook.generate(config)
35
+ end
36
+ end
37
+
38
+ desc 'version', 'Gives the cookbook version as a TeamCity service message'
39
+ def version
40
+ execute { puts "##teamcity[buildNumber '#{config['version'].to_s}']" }
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_command'
4
+ require_relative '../workflow/session'
5
+
6
+ module Sambot
7
+ module Commands
8
+ class SessionCmd < BaseCommand
9
+
10
+ namespace 'session'
11
+
12
+ desc 'start', 'Start a new Sambot session'
13
+ def start
14
+ execute(need_dev_credentials: true, need_sudo_password: true) do
15
+ Workflow::Session.new.start(ENV['SAMBOT_DEV_USERNAME'], ENV['SAMBOT_DEV_PASSWORD'], ENV['SAMBOT_SUDO_PASSWORD'])
16
+ end
17
+ end
18
+
19
+ desc 'stop', 'Stop any active Sambot session'
20
+ def stop
21
+ execute(need_sudo_password: true) { Workflow::Session.new.stop }
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -1,15 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'base_command'
4
+ require_relative '../workflow/workstation'
5
+
3
6
  module Sambot
4
7
  module Commands
5
- class Workstation < BaseCommand
8
+ class WorkstationCmd < BaseCommand
6
9
 
7
10
  namespace 'workstation'
8
11
 
9
12
  desc 'configure', 'Sets up an engineering workstation'
10
13
  def configure
11
14
  execute(need_dev_credentials: true, need_sudo_password: true) do
12
- DeveloperWorkflow::Workstation.configure(ENV['SAMBOT_DEV_PASSWORD'])
15
+ Workflow::Workstation.configure(ENV['SAMBOT_DEV_PASSWORD'])
13
16
  end
14
17
  end
15
18
 
@@ -59,9 +59,9 @@ module Sambot
59
59
  if commit_changes
60
60
  commit_msg = "DNS update for hostname #{hostname}"
61
61
  `commit -am #{commit_msg}`
62
+ `git push`
62
63
  end
63
64
  end
64
- `git push`
65
65
  end
66
66
  end
67
67
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sambot
4
+ class Template
5
+
6
+ def initialize(filename)
7
+ @filename = filename
8
+ end
9
+
10
+ def path
11
+ File.expand_path(File.join(File.dirname(__FILE__), 'templates', @filename))
12
+ end
13
+
14
+ def evaluate(context = {})
15
+ input = File.read(path)
16
+ input = yield(input) if block_given?
17
+ eruby = Erubis::Eruby.new(input)
18
+ eruby.evaluate(context)
19
+ end
20
+
21
+ def write(ctx, dest)
22
+ contents = evaluate(ctx)
23
+ File.write(dest, contents)
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ name: <%= @name %>
2
+ version: 0.0.1
3
+ platforms:
4
+ <% @platforms.each do |platform| %>
5
+ - <%= platform %>
6
+ <% end %>
7
+ identifier: <%= @identifier %>
8
+ description: <%= @description %>
9
+ suites:
10
+ - name: default
11
+ run_list:
12
+ - recipe[<%= @name %>::default]
13
+ verifier:
14
+ inspec_tests:
15
+ - name: <%= @name %>-profile
16
+ git: git@github.exacttarget.com:ads-chef-profiles/<%= @name %>-profile.git
@@ -1,6 +1,10 @@
1
1
  ---
2
2
  driver:
3
3
  name: "vagrant"
4
+ synced_folders:
5
+ - [".", "/vagrant"]
6
+ provision: true
7
+ vagrantfile_erb: Vagrantfile.erb
4
8
 
5
9
  provisioner:
6
10
  name: chef_zero
@@ -12,11 +16,16 @@ provisioner:
12
16
  platforms:
13
17
  <% if @platforms.include?('centos') %>
14
18
  - name: "centos-7.2"
19
+ driver:
20
+ network:
21
+ - ["private_network", {ip: "192.168.255.10"}]
15
22
  <% end %>
16
23
  <% if @platforms.include?('windows') %>
17
24
  - name: windows-2012R2
18
- driver_config:
25
+ driver:
19
26
  box: salesforce/Server2012R2
27
+ network:
28
+ - ["private_network", {ip: "192.168.255.11"}]
20
29
  transport:
21
30
  name: winrm
22
31
  elevated: true