sambot 0.1.43 → 0.1.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sambot/cli.rb +8 -3
- data/lib/sambot/commands/secret.rb +5 -0
- data/lib/sambot/commands/session.rb +22 -0
- data/lib/sambot/commands/workstation.rb +23 -0
- data/lib/sambot/domain/secrets/vault.rb +1 -1
- data/lib/sambot/domain/workstations/env.rb +0 -0
- data/lib/sambot/domain/workstations/hosts.rb +0 -0
- data/lib/sambot/domain/workstations/install.sh +1 -0
- data/lib/sambot/domain/workstations/ssh_config_file.rb +81 -0
- data/lib/sambot/domain/workstations/ssh_config_section.rb +84 -0
- data/lib/sambot/domain/workstations/ssh_parser.rb +48 -0
- data/lib/sambot/version.rb +1 -1
- metadata +10 -3
- data/lib/sambot/commands/inventory.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ff206043b3d053e2f72817f49310550e883eb52
|
4
|
+
data.tar.gz: c0571205dfe9c6d50e0cf3ffdece5f0425b7f71d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc916312401b0e9ddc4ed9042c1980e5c75a6d87098d9018872fc1c299abbc18370ee3bac21e91600c1fc2fe993224f82d834d5f3d6ac9d13c2acab7c7d4e801
|
7
|
+
data.tar.gz: b1096e1a3eee52a6ba5d981e287dfbc5bce9d0ffda7caf92362d794ca2a880f4a0325a723c613452161a67ccacd2b564dba12c28debfe92316620c4bae06ca27
|
data/lib/sambot/cli.rb
CHANGED
@@ -2,6 +2,11 @@ require 'thor'
|
|
2
2
|
require_relative 'domain/common/application_exception'
|
3
3
|
require_relative 'domain/common/file_checker'
|
4
4
|
require_relative 'domain/secrets/vault'
|
5
|
+
require_relative 'domain/workstations/hosts'
|
6
|
+
require_relative 'domain/workstations/env'
|
7
|
+
require_relative 'domain/workstations/ssh_config_file'
|
8
|
+
require_relative 'domain/workstations/ssh_config_section'
|
9
|
+
require_relative 'domain/workstations/ssh_parser'
|
5
10
|
require_relative 'domain/common/ui'
|
6
11
|
require_relative 'domain/common/config'
|
7
12
|
require_relative 'domain/common/runtime'
|
@@ -12,7 +17,7 @@ require_relative 'domain/cookbooks/metadata'
|
|
12
17
|
require_relative 'commands/cookbook'
|
13
18
|
require_relative 'commands/secret'
|
14
19
|
require_relative 'commands/teamcity'
|
15
|
-
require_relative 'commands/
|
20
|
+
require_relative 'commands/workstation'
|
16
21
|
|
17
22
|
module Sambot
|
18
23
|
class CLI < Thor
|
@@ -26,8 +31,8 @@ module Sambot
|
|
26
31
|
desc 'secret', 'Manage secrets inside Chef cookbooks'
|
27
32
|
subcommand 'secret', Sambot::Commands::Secret
|
28
33
|
|
29
|
-
desc '
|
30
|
-
subcommand '
|
34
|
+
desc 'workstation', 'Manage engineer workstations'
|
35
|
+
subcommand 'workstation', Sambot::Commands::Workstation
|
31
36
|
|
32
37
|
end
|
33
38
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Sambot
|
2
|
+
module Commands
|
3
|
+
|
4
|
+
class Session < Thor
|
5
|
+
|
6
|
+
namespace 'session'
|
7
|
+
|
8
|
+
desc "start", "Start a new DEV/QE session"
|
9
|
+
def start
|
10
|
+
username = ask('What is your DEV/QE username?')
|
11
|
+
password = ask('What is your DEV/QE password?')
|
12
|
+
puts "not implemented"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "stop", "Stop the DEV/QE session"
|
16
|
+
def start
|
17
|
+
puts "not implemented"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Sambot
|
2
|
+
module Commands
|
3
|
+
|
4
|
+
class Workstation < Thor
|
5
|
+
|
6
|
+
namespace 'workstation'
|
7
|
+
|
8
|
+
desc "cnfigure", "Sets up an engineering workstation"
|
9
|
+
def configure
|
10
|
+
username = ask("What is your DEV/QE Active Directory username i.e. john.smith?")
|
11
|
+
debug("Updating your SSH configuration.")
|
12
|
+
config = Domain::Workstations::SshParser.new.update('DEV\\' + username)
|
13
|
+
config.save
|
14
|
+
debug("Updating your environment variables.")
|
15
|
+
Domain::Workstations::Env.new.update
|
16
|
+
debug("Generating the datasource for Free Remote Desktop Manager, your RDP client.")
|
17
|
+
filename = Domain::Workstations::Hosts.new.generate
|
18
|
+
info("Your workstation is now ready for use. The RDM datasource is available here: #{filename}")
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
brew install vault
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Sambot
|
2
|
+
module Domain
|
3
|
+
module Workstations
|
4
|
+
class SshConfigFile
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@make_backups = true
|
8
|
+
@header_lines = []
|
9
|
+
@sections = []
|
10
|
+
@sections_by_name = {}
|
11
|
+
read_config
|
12
|
+
end
|
13
|
+
|
14
|
+
def sections
|
15
|
+
@sections
|
16
|
+
end
|
17
|
+
|
18
|
+
def sections_by_name
|
19
|
+
@sections_by_name
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_section(name)
|
23
|
+
section = SshConfigSection.new(name)
|
24
|
+
@sections << section
|
25
|
+
@sections_by_name[section.name] = section
|
26
|
+
section
|
27
|
+
end
|
28
|
+
|
29
|
+
def read_config
|
30
|
+
current_section = nil
|
31
|
+
IO.readlines(File.expand_path("~/.ssh/config")).each_with_index do |line, i|
|
32
|
+
line.rstrip!
|
33
|
+
if line =~ /\bHost\s+(.+)/
|
34
|
+
current_section = add_section($1)
|
35
|
+
else
|
36
|
+
if current_section
|
37
|
+
current_section.lines << line
|
38
|
+
else
|
39
|
+
@header_lines << line
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def set(host_nick, key, value)
|
46
|
+
section = @sections_by_name[host_nick] || add_section(host_nick)
|
47
|
+
section[key] = value
|
48
|
+
end
|
49
|
+
|
50
|
+
def dump
|
51
|
+
to_text([@header_lines, @sections].flatten)
|
52
|
+
end
|
53
|
+
|
54
|
+
def rm(host_nick)
|
55
|
+
if @sections_by_name.key?(host_nick)
|
56
|
+
@sections_by_name.delete host_nick
|
57
|
+
@sections.delete_at(@sections.index{|s| s.name == host_nick})
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_alias(host_nick, new_alias)
|
62
|
+
section = @sections_by_name[host_nick] || add_section(host_nick)
|
63
|
+
section.aliases.push(new_alias) unless section.aliases.member?(new_alias)
|
64
|
+
end
|
65
|
+
|
66
|
+
def save
|
67
|
+
File.open(File.expand_path("~/.ssh/config"), "w") do |file|
|
68
|
+
file.puts dump
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def to_text(ray)
|
75
|
+
ray.map {|s| s.to_s } * "\n"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Sambot
|
2
|
+
module Domain
|
3
|
+
module Workstations
|
4
|
+
class SshConfigSection
|
5
|
+
|
6
|
+
attr_accessor :name, :aliases, :lines, :settings
|
7
|
+
|
8
|
+
def initialize(name)
|
9
|
+
all_names = name.split(/\s+/)
|
10
|
+
@name = all_names.shift
|
11
|
+
@aliases = all_names
|
12
|
+
@settings = {}
|
13
|
+
@lines = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def [](setting)
|
17
|
+
unless @settings.key? setting
|
18
|
+
if line = lines[setting_index(setting)]
|
19
|
+
key,val = line.split(nil, 2)
|
20
|
+
@settings[key] = val
|
21
|
+
end
|
22
|
+
end
|
23
|
+
@settings[setting]
|
24
|
+
end
|
25
|
+
|
26
|
+
def unset(setting)
|
27
|
+
if line_num = setting_index(setting)
|
28
|
+
@settings.delete setting
|
29
|
+
@lines.delete_at line_num
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def header
|
34
|
+
name_with_aliases = [@name, *aliases].join(" ")
|
35
|
+
"Host #{name_with_aliases}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
[header, *lines] * "\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
def []=(setting, value)
|
43
|
+
if value.is_a?(Array)
|
44
|
+
value.each do |val|
|
45
|
+
line_num = lines.length
|
46
|
+
lines[line_num] = format_line(setting, val)
|
47
|
+
end
|
48
|
+
elsif value != '-'
|
49
|
+
line_num = lines.length
|
50
|
+
lines[line_num] = format_line(setting, value)
|
51
|
+
else
|
52
|
+
@settings.delete(setting)
|
53
|
+
@lines.delete_at(setting_index(setting))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def matches?(text)
|
58
|
+
r = Regexp.new text
|
59
|
+
name =~ r || aliases.any? {|a| a =~ r} || lines.any? {|line| line =~ r}
|
60
|
+
end
|
61
|
+
|
62
|
+
def matches_exactly?(text)
|
63
|
+
name == text || has_alias?(text)
|
64
|
+
end
|
65
|
+
|
66
|
+
def has_alias?(text)
|
67
|
+
aliases.member?(text)
|
68
|
+
end
|
69
|
+
|
70
|
+
protected
|
71
|
+
|
72
|
+
def format_line(setting, value)
|
73
|
+
" #{setting} #{value}"
|
74
|
+
end
|
75
|
+
|
76
|
+
def setting_index(setting)
|
77
|
+
r = Regexp.new(setting)
|
78
|
+
lines.index {|line| line =~ r}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative 'ssh_config_file'
|
2
|
+
require_relative 'ssh_config_section'
|
3
|
+
|
4
|
+
module Sambot
|
5
|
+
module Domain
|
6
|
+
module Workstations
|
7
|
+
class SshParser
|
8
|
+
|
9
|
+
ENTRIES = {
|
10
|
+
'bastion': {
|
11
|
+
username: '',
|
12
|
+
'HostName': '146.177.10.174',
|
13
|
+
'LocalForward': [
|
14
|
+
'8200 vault.brighter.io:8200',
|
15
|
+
'9997 splunk.brighter.io:9997'
|
16
|
+
]
|
17
|
+
},
|
18
|
+
'AVG-*': {
|
19
|
+
aliases: ['avg-*', 'GD-*', 'gd-*', 'NW-*', 'nw-*','PHX-* phx-* RS-* rs-* THD-* thd-*'],
|
20
|
+
username: '',
|
21
|
+
'ProxyJump': 'bastion',
|
22
|
+
'StrictHostKeyChecking': 'no'
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
def update(username)
|
27
|
+
config = SshConfigFile.new
|
28
|
+
sections = config.sections_by_name
|
29
|
+
ENTRIES.each_pair do |key, val|
|
30
|
+
config.rm(key.to_s)
|
31
|
+
val.each_pair do |x, y|
|
32
|
+
if x == :aliases
|
33
|
+
val[x].each do |new_alias|
|
34
|
+
config.add_alias(key.to_s, new_alias.to_s)
|
35
|
+
end
|
36
|
+
elsif x == :username
|
37
|
+
config.set(key.to_s, 'Username', username)
|
38
|
+
else
|
39
|
+
config.set(key.to_s, x.to_s, y)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/sambot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sambot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.44
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olivier Kouame
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -190,9 +190,10 @@ files:
|
|
190
190
|
- lib/sambot.rb
|
191
191
|
- lib/sambot/cli.rb
|
192
192
|
- lib/sambot/commands/cookbook.rb
|
193
|
-
- lib/sambot/commands/inventory.rb
|
194
193
|
- lib/sambot/commands/secret.rb
|
194
|
+
- lib/sambot/commands/session.rb
|
195
195
|
- lib/sambot/commands/teamcity.rb
|
196
|
+
- lib/sambot/commands/workstation.rb
|
196
197
|
- lib/sambot/domain/common/application_exception.rb
|
197
198
|
- lib/sambot/domain/common/config.rb
|
198
199
|
- lib/sambot/domain/common/file_checker.rb
|
@@ -203,6 +204,12 @@ files:
|
|
203
204
|
- lib/sambot/domain/cookbooks/kitchen.rb
|
204
205
|
- lib/sambot/domain/cookbooks/metadata.rb
|
205
206
|
- lib/sambot/domain/secrets/vault.rb
|
207
|
+
- lib/sambot/domain/workstations/env.rb
|
208
|
+
- lib/sambot/domain/workstations/hosts.rb
|
209
|
+
- lib/sambot/domain/workstations/install.sh
|
210
|
+
- lib/sambot/domain/workstations/ssh_config_file.rb
|
211
|
+
- lib/sambot/domain/workstations/ssh_config_section.rb
|
212
|
+
- lib/sambot/domain/workstations/ssh_parser.rb
|
206
213
|
- lib/sambot/templates/.gitignore
|
207
214
|
- lib/sambot/templates/.kitchen.centos.yml
|
208
215
|
- lib/sambot/templates/.kitchen.gcp.centos.yml
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Sambot
|
2
|
-
module Commands
|
3
|
-
|
4
|
-
class Inventory < Thor
|
5
|
-
|
6
|
-
namespace 'inventory'
|
7
|
-
|
8
|
-
desc "generate", "Gets the Rackspace inventory list for use with Remote Desktop Manager"
|
9
|
-
def generate
|
10
|
-
say("Not implemented yet")
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|