locum 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/locum/cli.rb +68 -45
- data/lib/locum/hosting_unit.rb +17 -0
- data/lib/locum/ssh.rb +32 -0
- data/lib/locum/version.rb +1 -1
- data/locum.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f87d91e87fda786817550758ea0d4365cf58ef04
|
4
|
+
data.tar.gz: 9984285dd811c46e70108c990955156a3adf0a49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
28
|
+
desc 'init', 'Получает token для работы с сервисом'
|
29
|
+
option :login
|
30
|
+
option :password
|
11
31
|
|
12
|
-
|
13
|
-
|
32
|
+
def init
|
33
|
+
cn.say("\nНастройка интерфейса командной строки locum.ru\n\n")
|
14
34
|
|
15
|
-
|
16
|
-
|
35
|
+
login = options[:login] || cn.ask('login: ')
|
36
|
+
password = options[:password] || cn.ask('пароль: ') { |q| q.echo = false }
|
17
37
|
|
18
|
-
|
38
|
+
s_out "Получаем токен https://locum.ru"
|
19
39
|
|
20
|
-
|
40
|
+
authenticator = Locum::Auth.new(login, password)
|
21
41
|
|
22
|
-
|
42
|
+
authenticator.persist_token
|
23
43
|
|
24
|
-
|
44
|
+
s_in "Токен получен\n\n"
|
25
45
|
|
26
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
61
|
+
rescue ApiError => e
|
62
|
+
display_error(e)
|
63
|
+
end
|
44
64
|
|
45
|
-
|
65
|
+
desc 'ping', 'Проверка связи с API'
|
46
66
|
|
47
|
-
|
48
|
-
|
67
|
+
def ping
|
68
|
+
s_out "PING"
|
49
69
|
|
50
|
-
|
51
|
-
|
70
|
+
ping = Locum::Ping.new
|
71
|
+
ping.call
|
52
72
|
|
53
|
-
|
73
|
+
s_in "PONG login: #{ping.login} till #{ping.valid}\n\n"
|
54
74
|
|
55
|
-
|
56
|
-
|
57
|
-
|
75
|
+
rescue ApiError => e
|
76
|
+
display_error(e)
|
77
|
+
end
|
58
78
|
|
59
|
-
|
79
|
+
desc 'projects', 'Список проектов'
|
60
80
|
|
61
|
-
|
62
|
-
|
63
|
-
|
81
|
+
def projects
|
82
|
+
projects = Locum::Projects.new
|
83
|
+
projects.call
|
64
84
|
|
65
|
-
|
66
|
-
|
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
|
-
|
92
|
+
end
|
70
93
|
|
71
|
-
|
72
|
-
cn = HighLine.new
|
73
|
-
cn.say("\n<%= color('Произошла ошибка:', RED) %> #{e.message}")
|
74
|
-
end
|
94
|
+
private
|
75
95
|
|
76
|
-
|
77
|
-
|
78
|
-
|
96
|
+
def display_error e
|
97
|
+
cn = HighLine.new
|
98
|
+
cn.say("\n<%= color('Произошла ошибка:', RED) %> #{e.message}")
|
99
|
+
end
|
79
100
|
|
80
|
-
|
81
|
-
|
82
|
-
|
101
|
+
def cn
|
102
|
+
@cn ||= HighLine.new
|
103
|
+
end
|
83
104
|
|
84
|
-
|
85
|
-
|
86
|
-
|
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
data/locum.gemspec
CHANGED
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.
|
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
|
+
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
|