locum 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc68875fb645fd43a73b8f837756809570adaf49
4
- data.tar.gz: 193f8b1ad7b8bafe21090701fe334da06cfd0bfd
3
+ metadata.gz: f87d91e87fda786817550758ea0d4365cf58ef04
4
+ data.tar.gz: 9984285dd811c46e70108c990955156a3adf0a49
5
5
  SHA512:
6
- metadata.gz: 131f42630ef4346d45bfe8495992a26b1ab0d6778d9784421ef9328f1f63789bece3f63aa4f4166931177dc8f39891eeb62d30ae0ba2bedff900c44bfe12e0bd
7
- data.tar.gz: 104cedb4d2996d0d853b0a56b4ea976e1e066d18d242c94ac193be430a2377965fcaf2f0b61bef5c8b17c021846c82978cd69416e6426522049270bbb82726a0
6
+ metadata.gz: 4928f011a040e9121996a12e120c8c39e71beb8a5b7224dc55757f798ffa30e8b9145ea25f79534f5addeaab6e25bc8ba645fdff7e8fad562b94499ebc9ca962
7
+ data.tar.gz: b26529d4e406b214317910df40236904fc50cd9139c95aaf1677e60b130084d8433d76a7082be0a05c3a438882d339def90f6e4312da768aa10baba2b0f9d4e9
data/lib/locum/cli.rb CHANGED
@@ -3,27 +3,47 @@ require 'thor'
3
3
  require 'highline/import'
4
4
  require 'locum'
5
5
 
6
- class Locum::CLI < Thor
6
+ module Locum
7
+ class SshCLI < Thor
8
+ desc 'add', 'Настраивает беспарольную авторизацию по ключу'
9
+ option :key
10
+
11
+ def add
12
+ key_file = options[:key] || File.join(ENV['HOME'], '.ssh', 'id_rsa.pub')
13
+ until File.exist?(key_file) do
14
+ cn.say("Файл #{key_file} не найден.")
15
+ key_file = Locum.cn.ask('Имя файла с публичным ключом и путём: ')
16
+ end
17
+ cn.say "Используется ключ #{key_file}"
18
+
19
+ ssh_auth = Locum::Ssh.new(key_file)
20
+ ssh_auth.add_ssh_key
21
+
22
+ s_out "Теперь вы можете авторизоваться по SSH без пароля"
23
+ end
24
+ end
25
+
26
+ class CLI < Thor
7
27
 
8
- desc 'init', 'Получает token для работы с сервисом'
9
- option :login
10
- option :password
28
+ desc 'init', 'Получает token для работы с сервисом'
29
+ option :login
30
+ option :password
11
31
 
12
- def init
13
- cn.say("\nНастройка интерфейса командной строки locum.ru\n\n")
32
+ def init
33
+ cn.say("\nНастройка интерфейса командной строки locum.ru\n\n")
14
34
 
15
- login = options[:login] || cn.ask('login: ')
16
- password = options[:password] || cn.ask('пароль: ') { |q| q.echo = false }
35
+ login = options[:login] || cn.ask('login: ')
36
+ password = options[:password] || cn.ask('пароль: ') { |q| q.echo = false }
17
37
 
18
- s_out "Получаем токен https://locum.ru"
38
+ s_out "Получаем токен https://locum.ru"
19
39
 
20
- authenticator = Locum::Auth.new(login, password)
40
+ authenticator = Locum::Auth.new(login, password)
21
41
 
22
- authenticator.persist_token
42
+ authenticator.persist_token
23
43
 
24
- s_in "Токен получен\n\n"
44
+ s_in "Токен получен\n\n"
25
45
 
26
- cn.say <<EOFBLOCK
46
+ cn.say <<EOFBLOCK
27
47
  Авторизационный токен для доступа к вашим проектам сохранен в
28
48
  текущем каталоге в файле <%= color('.locum', BOLD) %>.
29
49
  Возможно, вы не хотите, чтобы этот токен попал в систему контроля
@@ -38,51 +58,54 @@ class Locum::CLI < Thor
38
58
 
39
59
  EOFBLOCK
40
60
 
41
- rescue ApiError => e
42
- display_error(e)
43
- end
61
+ rescue ApiError => e
62
+ display_error(e)
63
+ end
44
64
 
45
- desc 'ping', 'Проверка связи с API'
65
+ desc 'ping', 'Проверка связи с API'
46
66
 
47
- def ping
48
- s_out "PING"
67
+ def ping
68
+ s_out "PING"
49
69
 
50
- ping = Locum::Ping.new
51
- ping.call
70
+ ping = Locum::Ping.new
71
+ ping.call
52
72
 
53
- s_in "PONG login: #{ping.login} till #{ping.valid}\n\n"
73
+ s_in "PONG login: #{ping.login} till #{ping.valid}\n\n"
54
74
 
55
- rescue ApiError => e
56
- display_error(e)
57
- end
75
+ rescue ApiError => e
76
+ display_error(e)
77
+ end
58
78
 
59
- desc 'projects', 'Список проектов'
79
+ desc 'projects', 'Список проектов'
60
80
 
61
- def projects
62
- projects = Locum::Projects.new
63
- projects.call
81
+ def projects
82
+ projects = Locum::Projects.new
83
+ projects.call
64
84
 
65
- projects.projects.each {|p| say(" * #{p['name']} (##{p['id']} #{p['type']})") }
66
- end
85
+ projects.projects.each { |p| say(" * #{p['name']} (##{p['id']} #{p['type']})") }
86
+ end
67
87
 
88
+ desc 'ssh', 'Работа с ключами'
89
+ subcommand 'ssh', SshCLI
90
+ end
68
91
 
69
- private
92
+ end
70
93
 
71
- def display_error e
72
- cn = HighLine.new
73
- cn.say("\n<%= color('Произошла ошибка:', RED) %> #{e.message}")
74
- end
94
+ private
75
95
 
76
- def cn
77
- @cn ||= HighLine.new
78
- end
96
+ def display_error e
97
+ cn = HighLine.new
98
+ cn.say("\n<%= color('Произошла ошибка:', RED) %> #{e.message}")
99
+ end
79
100
 
80
- def s_out(s)
81
- cn.say("\n<%= color('->', GREEN) %> #{s}")
82
- end
101
+ def cn
102
+ @cn ||= HighLine.new
103
+ end
83
104
 
84
- def s_in(s)
85
- cn.say("<%= color('<-', CYAN) %> #{s}")
86
- end
105
+ def s_out(s)
106
+ cn.say("\n<%= color('->', GREEN) %> #{s}")
107
+ end
87
108
 
109
+ def s_in(s)
110
+ cn.say("<%= color('<-', CYAN) %> #{s}")
88
111
  end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ class Locum::HostingUnit
4
+ attr_accessor :login, :password, :server
5
+
6
+ def self.get
7
+ res = Locum::Api.call(:hosting_unit)
8
+ res = res['hosting_unit']
9
+ hu = self.new
10
+
11
+ hu.login = res['login']
12
+ hu.password = res['password']
13
+ hu.server = "#{res['server']}.locum.ru"
14
+
15
+ hu
16
+ end
17
+ end
data/lib/locum/ssh.rb ADDED
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require 'net/ssh'
3
+
4
+ class Locum::Ssh
5
+ def initialize(key_file)
6
+ @key = File.read(key_file).strip
7
+ end
8
+
9
+ def add_ssh_key
10
+ run_on_server("mkdir .ssh")
11
+ run_on_server("echo #{@key} >> .ssh/authorized_keys")
12
+ end
13
+
14
+ def hu
15
+ @hu ||= Locum::HostingUnit.get
16
+ end
17
+
18
+ private
19
+
20
+ def run_on_server(cmd)
21
+ begin
22
+ Net::SSH.start(hu.server, hu.login, :password => hu.password) do |ssh|
23
+ ssh.exec!(cmd)
24
+ end
25
+ rescue Net::SSH::HostKeyMismatch => e
26
+ e.remember_host!
27
+ retry
28
+ rescue StandardError => e
29
+ raise ApiError, e.to_s
30
+ end
31
+ end
32
+ end
data/lib/locum/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Locum
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/locum.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_runtime_dependency "highline", "~> 1.6"
26
26
  spec.add_runtime_dependency "thor", "~> 0.19"
27
27
  spec.add_runtime_dependency "json", "~> 1.8"
28
+ spec.add_runtime_dependency "net-ssh", "~> 2.9"
28
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasily Shmelev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-14 00:00:00.000000000 Z
11
+ date: 2014-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: net-ssh
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.9'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.9'
97
111
  description:
98
112
  email:
99
113
  - sleephunter@gmail.com
@@ -115,8 +129,10 @@ files:
115
129
  - lib/locum/cli.rb
116
130
  - lib/locum/config.rb
117
131
  - lib/locum/config_builder.rb
132
+ - lib/locum/hosting_unit.rb
118
133
  - lib/locum/ping.rb
119
134
  - lib/locum/projects.rb
135
+ - lib/locum/ssh.rb
120
136
  - lib/locum/version.rb
121
137
  - locum.gemspec
122
138
  homepage: https://github.com/locumru/locum