bastion-cli 0.7.8 → 0.8.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: 11f26c87173fd2fc37d108a782861a34df39ea08
4
- data.tar.gz: 3e9985e5301214e164072f0ae969fd9763452bd3
3
+ metadata.gz: 30e468497b9e751497941893f0078bf70d8a7088
4
+ data.tar.gz: 78cbf4d372567df0e755ddb0b817c524b1068a27
5
5
  SHA512:
6
- metadata.gz: 79cd0237e542b8d07b0293f72e874ccce896f931ca421b88bef8e8a4137502340f61601c7d62fafce53103510782de0c3970cfa235a652cf1d21e481395f7d71
7
- data.tar.gz: c49ceabc5bb587f82c197a28e8ef5981787fea5e6e6650b9f8eda80d5fae7de7392077f762ee45f65757f0f9be2f33123b76ad8723a1d07516837727be80e36b
6
+ metadata.gz: 317f92619bf0623345d0bf153a6edda2a21ce3ace5e26dd165d18c2499eb2a9beb98ee57370fd17d80c67a860abd879b6a9fc23792ca32eed26c79da04194e30
7
+ data.tar.gz: 013eae5e5fdbe28d5fa10c69002e27e4faefac0072c5b574258382f6cffef0882ff9baefdfb0ee72d2e14a852454fd1e747833d2a63b13442a548d913734f570
@@ -1,4 +1,4 @@
1
- # bastion-cli
1
+ # bastion
2
2
 
3
3
  Log into things through bastions.
4
4
 
@@ -54,6 +54,9 @@ bastion host:
54
54
 
55
55
  The pecking order is:
56
56
 
57
- - `BASTION_HOST` environment variable
58
- - The default value that lives in `${HOME}/.bastion`
57
+ - The `--host` option
58
+ - The `BASTION_HOST` environment variable
59
+ - The user default value that lives in `/etc/bastion/bastion`
60
+ - The system default value that lives in `${HOME}/.bastion`
59
61
 
62
+ In doubt, just run `bastion host --all` to see what are your options.
@@ -1,16 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)) + "/../lib")
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + "/../lib"
4
3
 
5
4
  require "rubygems"
6
5
  require "thor"
7
6
  require "bastion"
8
7
 
9
8
  module Bastion
10
- ### Main cli class
11
- ###
9
+ # Main cli class
10
+ #
11
+ #
12
12
  class Cli < Thor
13
- Config.load
13
+ class_option :host, type: :string
14
+ class_option :save, type: :boolean
15
+ class_option :v, type: :boolean
14
16
 
15
17
  desc "version", "Shows current version"
16
18
  def version
@@ -18,38 +20,33 @@ module Bastion
18
20
  end
19
21
 
20
22
  desc "host [HOST]", "Show or set the default bastion host"
23
+ option :all, type: :boolean
21
24
  def host(address = nil)
22
- return Config.save(address) if address
23
- puts Config.host
25
+ config = Config.new(options)
26
+ return config.save(address) if address
27
+ return config.info if options[:all]
28
+ puts config.host
24
29
  end
25
30
 
26
31
  desc "ssh [INSTANCE]", "Logs into an instance"
27
- option :host
28
- option :save, type: :boolean
29
- option :v, type: :boolean
30
32
  def ssh(instance = nil)
31
- host = options[:host] || Config.host
33
+ config = Config.new(options)
32
34
  verb = options[:v] ? " -vvv" : ""
33
- Config.save host if options[:save]
34
35
  if instance
35
- puts "==> Using #{host}"
36
+ puts "==> Using #{config.host}"
36
37
  puts "==> Logging into #{instance}"
37
- exec "ssh -A -t #{host} ssh #{instance}#{verb}"
38
+ exec "ssh -A -t #{config.host} ssh #{instance}#{verb}"
38
39
  else
39
- puts "==> Logging into #{host}"
40
- exec "ssh -A #{host}#{verb}"
40
+ puts "==> Logging into #{config.host}"
41
+ exec "ssh -A #{config.host}#{verb}"
41
42
  end
42
43
  end
43
44
 
44
45
  desc "tunnel [PORT]", "Starts a new tunnel"
45
- option :host
46
- option :save, type: :boolean
47
- option :v, type: :boolean
48
46
  def tunnel(port = 1200)
49
- host = options[:host] || Config.host
50
- Config.save host if options[:save]
51
- puts "==> Starting tunnel to host #{host} on port #{port}"
52
- exec "ssh -D#{port} #{host}"
47
+ config = Config.new(options)
48
+ puts "==> Starting tunnel to host #{config.host} on port #{port}"
49
+ exec "ssh -D#{port} #{config.host}"
53
50
  end
54
51
 
55
52
  def method_missing(name)
@@ -3,28 +3,41 @@ module Bastion
3
3
  #
4
4
  #
5
5
  class Config
6
- FILE = "#{ENV['HOME']}/.bastion"
7
- NAME = "BASTION_HOST"
8
- DEFAULT = "bastion.example.com"
6
+ USER = "#{ENV['HOME']}/.bastion"
7
+ SYSTEM = "/etc/bastion/bastion"
8
+ ENVVAR = "BASTION_HOST"
9
9
 
10
- def self.load
11
- @@default = DEFAULT
12
- @@env = ENV[NAME]
13
- begin
14
- @@file = File.open(FILE, "r").read
15
- rescue
16
- @@file = nil
17
- end
10
+ def initialize(options)
11
+ @system = read(SYSTEM)
12
+ @user = read(USER)
13
+ @env = ENV[ENVVAR]
14
+ @option = options[:host]
15
+ @host = @option || @env || @user || @system
16
+ save @host if options[:save]
17
+ end
18
+
19
+ def info
20
+ puts "System : #{@system}"
21
+ puts "User : #{@user}"
22
+ puts "Env : #{@env}"
23
+ puts "Option : #{@option}"
24
+ puts "Used : #{@host}"
25
+ end
18
26
 
19
- @@host = @@env || @@file || @@default
27
+ def read(file, default = nil)
28
+ return default unless File.exist?(file)
29
+ value = File.read(file)
30
+ value.empty? ? nil : value
20
31
  end
21
32
 
22
- def self.save(value)
23
- File.write(FILE, value)
33
+ def save(value)
34
+ puts "Saved with value #{value}"
35
+ File.write USER, value
24
36
  end
25
37
 
26
- def self.method_missing(name)
27
- class_variable_get(:"@@#{name}")
38
+ def method_missing(name)
39
+ instance_variable_get :"@#{name}"
40
+ # class_variable_get(:"@@#{name}")
28
41
  end
29
42
  end
30
43
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Bastion
3
- VERSION = "0.7.8"
3
+ VERSION = "0.8.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bastion-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.8
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ptdorf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-09 00:00:00.000000000 Z
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -65,13 +65,12 @@ files:
65
65
  - .travis.yml
66
66
  - Gemfile
67
67
  - Rakefile
68
+ - Readme.md
68
69
  - bastion-cli.gemspec
69
70
  - bin/bastion
70
71
  - lib/bastion.rb
71
72
  - lib/bastion/config.rb
72
73
  - lib/bastion/version.rb
73
- - license.txt
74
- - readme.md
75
74
  homepage: https://github.com/ptdorf/bastion-cli
76
75
  licenses:
77
76
  - MIT
@@ -1,22 +0,0 @@
1
- Copyright (c) 2016 ptdorf
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.