learn-open 1.2.21 → 1.2.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/learn-open.gemspec +1 -1
- data/lib/learn_open.rb +6 -0
- data/lib/learn_open/adapters/ssh_adapter.rb +44 -0
- data/lib/learn_open/adapters/system_adapter.rb +6 -0
- data/lib/learn_open/environments.rb +3 -0
- data/lib/learn_open/environments/base_environment.rb +17 -7
- data/lib/learn_open/environments/ide_environment.rb +4 -0
- data/lib/learn_open/environments/jupyter_container_environment.rb +4 -0
- data/lib/learn_open/services/git_ssh_connector.rb +40 -0
- data/lib/learn_open/services/lesson_downloader.rb +16 -6
- data/lib/learn_open/version.rb +1 -1
- data/spec/learn_open/adapters/ssh_adapter_spec.rb +32 -0
- data/spec/learn_open/environments/ide_environment_spec.rb +57 -5
- data/spec/learn_open/opener_spec.rb +40 -1
- data/spec/learn_open/services/git_ssh_connector_spec.rb +55 -0
- data/spec/learn_open/services/lesson_downloader_spec.rb +60 -0
- metadata +12 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c7fb687795b2162c7744bff6b33218bd285534731d1b5f17fc5554b04c9c267
|
4
|
+
data.tar.gz: 0dfd4d3ab154f9866815b51dc774cb910680b152339c936f3f107b54b9cfa471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e16ad1551f023494bf8df4a4f683e7d8e39657f71426661d2182ee9436bed67ac598925daeb4d3c58302badc2178fadab7c78fd996fd5c80a6b8e0b9e842244c
|
7
|
+
data.tar.gz: 952bf6c0e7b04d4633f3bffcfda04b42e9a0ab5b17430189bd51e49cb47a3999d2e984d051f5e58fea61f751d96faf39b0af154c94be73ae6d8980e05b8c3dcc
|
data/learn-open.gemspec
CHANGED
data/lib/learn_open.rb
CHANGED
@@ -11,6 +11,7 @@ require 'learn_open/argument_parser'
|
|
11
11
|
require 'learn_open/adapters/system_adapter'
|
12
12
|
require 'learn_open/adapters/learn_web_adapter'
|
13
13
|
require 'learn_open/adapters/io_adapter'
|
14
|
+
require 'learn_open/adapters/ssh_adapter'
|
14
15
|
require 'learn_open/environments'
|
15
16
|
require 'learn_open/environments/base_environment'
|
16
17
|
require 'learn_open/environments/mac_environment'
|
@@ -27,6 +28,7 @@ require 'learn_open/services/dependency_installers/pip_installer'
|
|
27
28
|
require 'learn_open/services/lesson_downloader'
|
28
29
|
require 'learn_open/services/file_backup_starter'
|
29
30
|
require 'learn_open/services/logger'
|
31
|
+
require 'learn_open/services/git_ssh_connector'
|
30
32
|
require 'learn_open/lessons'
|
31
33
|
require 'learn_open/lessons/base_lesson'
|
32
34
|
require 'learn_open/lessons/jupyter_lesson'
|
@@ -61,6 +63,10 @@ module LearnOpen
|
|
61
63
|
ENV
|
62
64
|
end
|
63
65
|
|
66
|
+
def self.ssh_adapter
|
67
|
+
LearnOpen::Adapters::SshAdapter
|
68
|
+
end
|
69
|
+
|
64
70
|
def self.system_adapter
|
65
71
|
LearnOpen::Adapters::SystemAdapter
|
66
72
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module LearnOpen
|
2
|
+
module Adapters
|
3
|
+
class SshAdapter
|
4
|
+
attr_reader :user, :hostname
|
5
|
+
|
6
|
+
SSH_AUTH_SUCCESS_EXIT_STATUS = 1
|
7
|
+
SSH_AUTH_FAILURE_EXIT_STATUS = 255
|
8
|
+
|
9
|
+
def initialize(user:, hostname:)
|
10
|
+
@user = user
|
11
|
+
@hostname = hostname
|
12
|
+
end
|
13
|
+
|
14
|
+
def public_key
|
15
|
+
File.read("#{ENV['HOME']}/.ssh/id_rsa.pub").chomp
|
16
|
+
end
|
17
|
+
|
18
|
+
def unauthenticated?
|
19
|
+
!authenticated?
|
20
|
+
end
|
21
|
+
|
22
|
+
def authenticated?
|
23
|
+
_stdout, stderr, status = LearnOpen.system_adapter.run_command_with_capture("ssh -T #{user}@#{hostname}")
|
24
|
+
|
25
|
+
case status.exitstatus
|
26
|
+
when SSH_AUTH_SUCCESS_EXIT_STATUS
|
27
|
+
true
|
28
|
+
when SSH_AUTH_FAILURE_EXIT_STATUS
|
29
|
+
case stderr
|
30
|
+
when /permission denied/i
|
31
|
+
false
|
32
|
+
else
|
33
|
+
raise LearnOpen::Adapters::SshAdapter::UnknownError
|
34
|
+
end
|
35
|
+
else
|
36
|
+
raise LearnOpen::Adapters::SshAdapter::UnknownError
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class UnknownError < StandardError
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
1
3
|
module LearnOpen
|
2
4
|
module Adapters
|
3
5
|
class SystemAdapter
|
@@ -22,6 +24,10 @@ module LearnOpen
|
|
22
24
|
system(command)
|
23
25
|
end
|
24
26
|
|
27
|
+
def self.run_command_with_capture(command)
|
28
|
+
Open3.capture3(command)
|
29
|
+
end
|
30
|
+
|
25
31
|
def self.change_context_directory(dir)
|
26
32
|
Dir.chdir(dir)
|
27
33
|
end
|
@@ -12,6 +12,10 @@ module LearnOpen
|
|
12
12
|
@options = options
|
13
13
|
end
|
14
14
|
|
15
|
+
def managed?
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
15
19
|
def open_jupyter_lab(lesson, location, editor)
|
16
20
|
:noop
|
17
21
|
end
|
@@ -21,11 +25,17 @@ module LearnOpen
|
|
21
25
|
when LearnOpen::Lessons::IosLesson
|
22
26
|
io.puts "You need to be on a Mac to work on iOS lessons."
|
23
27
|
else
|
24
|
-
download_lesson(lesson, location)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
case download_lesson(lesson, location)
|
29
|
+
when :ok, :noop
|
30
|
+
open_editor(lesson, location, editor)
|
31
|
+
install_dependencies(lesson, location)
|
32
|
+
notify_of_completion
|
33
|
+
open_shell
|
34
|
+
when :ssh_unauthenticated
|
35
|
+
io.puts 'Failed to obtain an SSH connection!'
|
36
|
+
else
|
37
|
+
raise LearnOpen::Environments::UnknownLessonDownloadError
|
38
|
+
end
|
29
39
|
end
|
30
40
|
end
|
31
41
|
|
@@ -34,7 +44,7 @@ module LearnOpen
|
|
34
44
|
end
|
35
45
|
|
36
46
|
def download_lesson(lesson, location)
|
37
|
-
LessonDownloader.call(lesson, location, options)
|
47
|
+
LessonDownloader.call(lesson, location, self, options)
|
38
48
|
end
|
39
49
|
|
40
50
|
def open_editor(lesson, location, editor)
|
@@ -60,7 +70,7 @@ module LearnOpen
|
|
60
70
|
return unless lesson.later_lesson
|
61
71
|
|
62
72
|
io.puts 'WARNING: You are attempting to open a lesson that is beyond your current lesson.'
|
63
|
-
io.print 'Are you sure you want to continue? [
|
73
|
+
io.print 'Are you sure you want to continue? [Y/n]: '
|
64
74
|
|
65
75
|
warn_response = io.gets.chomp.downcase
|
66
76
|
exit if !['yes', 'y'].include?(warn_response)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module LearnOpen
|
2
|
+
class GitSSHConnector
|
3
|
+
attr_reader :ssh_connection, :environment
|
4
|
+
|
5
|
+
GIT_SSH_USER = 'git'
|
6
|
+
|
7
|
+
def self.call(git_server:, environment:)
|
8
|
+
self.new(git_server: git_server, environment: environment).call
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(git_server:, environment:)
|
12
|
+
@ssh_connection = LearnOpen.ssh_adapter.new(user: GIT_SSH_USER, hostname: git_server)
|
13
|
+
@environment = environment
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
if managed_environment? && ssh_unauthenticated?
|
18
|
+
upload_ssh_keys!
|
19
|
+
end
|
20
|
+
|
21
|
+
ssh_authenticated?
|
22
|
+
end
|
23
|
+
|
24
|
+
def upload_ssh_keys!
|
25
|
+
LearnOpen.learn_web_client.add_ssh_key(key: ssh_connection.public_key)
|
26
|
+
end
|
27
|
+
|
28
|
+
def managed_environment?
|
29
|
+
environment.managed?
|
30
|
+
end
|
31
|
+
|
32
|
+
def ssh_unauthenticated?
|
33
|
+
!ssh_authenticated?
|
34
|
+
end
|
35
|
+
|
36
|
+
def ssh_authenticated?
|
37
|
+
ssh_connection.authenticated?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
module LearnOpen
|
2
2
|
class LessonDownloader
|
3
|
-
attr_reader :lesson, :location, :io, :logger, :client, :git_adapter
|
3
|
+
attr_reader :lesson, :location, :environment, :io, :logger, :client, :git_adapter
|
4
4
|
|
5
|
-
def self.call(lesson, location, options = {})
|
6
|
-
self.new(lesson, location, options).call
|
5
|
+
def self.call(lesson, location, environment, options = {})
|
6
|
+
self.new(lesson, location, environment, options).call
|
7
7
|
end
|
8
8
|
|
9
|
-
def initialize(lesson, location, options = {})
|
9
|
+
def initialize(lesson, location, environment, options = {})
|
10
10
|
@lesson = lesson
|
11
11
|
@location = location
|
12
|
+
@environment = environment
|
12
13
|
@client = options.fetch(:learn_web_client) { LearnOpen.learn_web_client }
|
13
14
|
@logger = options.fetch(:logger) { LearnOpen.logger }
|
14
15
|
@io = options.fetch(:io) { LearnOpen.default_io }
|
@@ -17,13 +18,22 @@ module LearnOpen
|
|
17
18
|
|
18
19
|
def call
|
19
20
|
if !repo_exists?
|
20
|
-
|
21
|
-
|
21
|
+
if ensure_git_ssh!
|
22
|
+
fork_repo
|
23
|
+
clone_repo
|
24
|
+
:ok
|
25
|
+
else
|
26
|
+
:ssh_unauthenticated
|
27
|
+
end
|
22
28
|
else
|
23
29
|
:noop
|
24
30
|
end
|
25
31
|
end
|
26
32
|
|
33
|
+
def ensure_git_ssh!
|
34
|
+
LearnOpen::GitSSHConnector.call(git_server: lesson.git_server, environment: environment)
|
35
|
+
end
|
36
|
+
|
27
37
|
def fork_repo(retries = 3)
|
28
38
|
logger.log('Forking repository...')
|
29
39
|
io.puts "Forking lesson..."
|
data/lib/learn_open/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LearnOpen::Adapters::SshAdapter do
|
4
|
+
describe '#authenticated?' do
|
5
|
+
let(:status) { double() }
|
6
|
+
let(:ssh_adapter) { LearnOpen::Adapters::SshAdapter.new(user: 'foo', hostname: 'bar') }
|
7
|
+
|
8
|
+
it 'returns true on success' do
|
9
|
+
allow(status).to receive(:exitstatus).and_return(LearnOpen::Adapters::SshAdapter::SSH_AUTH_SUCCESS_EXIT_STATUS)
|
10
|
+
allow(LearnOpen.system_adapter).to receive(:run_command_with_capture).and_return(['', '', status])
|
11
|
+
expect(ssh_adapter.authenticated?).to be true
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'return false when permission denied' do
|
15
|
+
allow(status).to receive(:exitstatus).and_return(LearnOpen::Adapters::SshAdapter::SSH_AUTH_FAILURE_EXIT_STATUS)
|
16
|
+
allow(LearnOpen.system_adapter).to receive(:run_command_with_capture).and_return(['', 'permission denied', status])
|
17
|
+
expect(ssh_adapter.authenticated?).to be false
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'raises an unknown error for failures that arent permission denied' do
|
21
|
+
allow(status).to receive(:exitstatus).and_return(LearnOpen::Adapters::SshAdapter::SSH_AUTH_FAILURE_EXIT_STATUS)
|
22
|
+
allow(LearnOpen.system_adapter).to receive(:run_command_with_capture).and_return(['', 'core meltdown', status])
|
23
|
+
expect{ssh_adapter.authenticated?}.to raise_error LearnOpen::Adapters::SshAdapter::UnknownError
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'raises an unknown error for other exit statuses' do
|
27
|
+
allow(status).to receive(:exitstatus).and_return(1337)
|
28
|
+
allow(LearnOpen.system_adapter).to receive(:run_command_with_capture).and_return(['', 'alien abduction', status])
|
29
|
+
expect{ssh_adapter.authenticated?}.to raise_error LearnOpen::Adapters::SshAdapter::UnknownError
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -7,6 +7,13 @@ describe LearnOpen::Environments::IDEEnvironment do
|
|
7
7
|
|
8
8
|
let(:io) { instance_double(LearnOpen::Adapters::IOAdapter) }
|
9
9
|
|
10
|
+
before do
|
11
|
+
allow(LearnOpen::GitSSHConnector)
|
12
|
+
.to receive(:call)
|
13
|
+
.with(git_server: instance_of(String), environment: instance_of(LearnOpen::Environments::IDEEnvironment))
|
14
|
+
.and_return(true)
|
15
|
+
end
|
16
|
+
|
10
17
|
context "Invalid environment" do
|
11
18
|
before do
|
12
19
|
@home_dir = create_linux_home_dir("bobby")
|
@@ -44,9 +51,29 @@ describe LearnOpen::Environments::IDEEnvironment do
|
|
44
51
|
@home_dir = create_linux_home_dir("bobby")
|
45
52
|
end
|
46
53
|
|
47
|
-
let(:lesson)
|
48
|
-
|
49
|
-
|
54
|
+
let(:lesson) do
|
55
|
+
double(
|
56
|
+
name: "valid_lab",
|
57
|
+
later_lesson: false,
|
58
|
+
to_url: "valid-lesson-url",
|
59
|
+
to_path: @home_dir,
|
60
|
+
git_server: "github.com",
|
61
|
+
repo_path: "/org/lesson"
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
let(:env_vars) {{ "LAB_NAME" => "valid_lab", "CREATED_USER" => "bobby", "SHELL" => "/usr/local/fish"}}
|
66
|
+
let(:git_adapter) { double }
|
67
|
+
let(:system_adapter) { double }
|
68
|
+
let(:environment) do
|
69
|
+
subject.new({
|
70
|
+
io: io,
|
71
|
+
environment_vars: env_vars,
|
72
|
+
logger: spy,
|
73
|
+
git_adapter: git_adapter,
|
74
|
+
system_adapter: system_adapter
|
75
|
+
})
|
76
|
+
end
|
50
77
|
|
51
78
|
it "opens the readme in the browser" do
|
52
79
|
expect(io).to receive(:puts).with("Opening readme...")
|
@@ -55,8 +82,33 @@ describe LearnOpen::Environments::IDEEnvironment do
|
|
55
82
|
expect(custom_commands_log).to eq(%Q{{"command":"browser_open","url":"valid-lesson-url"}\n})
|
56
83
|
end
|
57
84
|
it "opens the lab" do
|
58
|
-
|
59
|
-
|
85
|
+
location = double
|
86
|
+
editor = "vim"
|
87
|
+
|
88
|
+
expect(io).to receive(:puts).with("Forking lesson...")
|
89
|
+
expect(io).to receive(:puts).with("Cloning lesson...")
|
90
|
+
expect(io).to receive(:puts).with("Opening lesson...")
|
91
|
+
expect(io).to receive(:puts).with("Done.")
|
92
|
+
expect(git_adapter)
|
93
|
+
.to receive(:clone)
|
94
|
+
.with("git@github.com:/org/lesson.git", "valid_lab", {:path=> location})
|
95
|
+
expect(system_adapter)
|
96
|
+
.to receive(:change_context_directory)
|
97
|
+
.with("/home/bobby")
|
98
|
+
expect(system_adapter)
|
99
|
+
.to receive(:open_editor)
|
100
|
+
.with("vim", {:path=>"."})
|
101
|
+
expect(system_adapter)
|
102
|
+
.to receive(:spawn)
|
103
|
+
.with("restore-lab", {:block=>true})
|
104
|
+
expect(system_adapter)
|
105
|
+
.to receive(:watch_dir)
|
106
|
+
.with("/home/bobby", "backup-lab")
|
107
|
+
expect(system_adapter)
|
108
|
+
.to receive(:open_login_shell)
|
109
|
+
.with("/usr/local/fish")
|
110
|
+
|
111
|
+
environment.open_lab(lesson, location, editor)
|
60
112
|
end
|
61
113
|
end
|
62
114
|
end
|
@@ -12,6 +12,11 @@ describe LearnOpen::Opener do
|
|
12
12
|
create_home_dir
|
13
13
|
create_netrc_file
|
14
14
|
create_learn_config_file
|
15
|
+
|
16
|
+
allow(LearnOpen::GitSSHConnector)
|
17
|
+
.to receive(:call)
|
18
|
+
.with(git_server: instance_of(String), environment: anything)
|
19
|
+
.and_return(true)
|
15
20
|
end
|
16
21
|
|
17
22
|
context "Initializer" do
|
@@ -47,6 +52,10 @@ describe LearnOpen::Opener do
|
|
47
52
|
.to receive(:fork_repo)
|
48
53
|
.with(repo_name: "rails-dynamic-request-lab-cb-000")
|
49
54
|
|
55
|
+
expect(LearnOpen::GitSSHConnector)
|
56
|
+
.to receive(:call)
|
57
|
+
.with(git_server: instance_of(String), environment: instance_of(LearnOpen::Environments::MacEnvironment))
|
58
|
+
|
50
59
|
opener = LearnOpen::Opener.new(nil, "atom", true,
|
51
60
|
learn_web_client: learn_web_client,
|
52
61
|
git_adapter: git_adapter,
|
@@ -160,7 +169,7 @@ describe LearnOpen::Opener do
|
|
160
169
|
|
161
170
|
expect(io)
|
162
171
|
.to receive(:print)
|
163
|
-
.with("Are you sure you want to continue? [
|
172
|
+
.with("Are you sure you want to continue? [Y/n]: ")
|
164
173
|
|
165
174
|
expect(io)
|
166
175
|
.to receive(:gets)
|
@@ -256,6 +265,35 @@ describe LearnOpen::Opener do
|
|
256
265
|
end
|
257
266
|
context "Logging" do
|
258
267
|
let(:environment) {{ "SHELL" => "/usr/local/bin/fish", "JUPYTER_CONTAINER" => "true" }}
|
268
|
+
|
269
|
+
it "logs if an SSH connection cannot be made" do
|
270
|
+
allow(LearnOpen::LessonDownloader).to receive(:call).and_return(:ssh_unauthenticated)
|
271
|
+
|
272
|
+
allow(system_adapter).to receive_messages(
|
273
|
+
open_editor: :noop,
|
274
|
+
spawn: :noop,
|
275
|
+
watch_dir: :noop,
|
276
|
+
open_login_shell: :noop,
|
277
|
+
change_context_directory: :noop,
|
278
|
+
run_command: :noop,
|
279
|
+
)
|
280
|
+
|
281
|
+
io = StringIO.new
|
282
|
+
|
283
|
+
opener = LearnOpen::Opener.new("ruby_lab", "atom", false,
|
284
|
+
learn_web_client: learn_web_client,
|
285
|
+
git_adapter: git_adapter,
|
286
|
+
environment_vars: environment,
|
287
|
+
system_adapter: system_adapter,
|
288
|
+
io: io)
|
289
|
+
opener.run
|
290
|
+
io.rewind
|
291
|
+
expect(io.read).to eq(<<-EOF)
|
292
|
+
Looking for lesson...
|
293
|
+
Failed to obtain an SSH connection!
|
294
|
+
EOF
|
295
|
+
end
|
296
|
+
|
259
297
|
it "prints the right things" do
|
260
298
|
allow(learn_web_client).to receive(:fork_repo)
|
261
299
|
|
@@ -743,6 +781,7 @@ Installing pip dependencies...
|
|
743
781
|
Done.
|
744
782
|
EOF
|
745
783
|
end
|
784
|
+
|
746
785
|
it "runs npm install if lab is a node lab" do
|
747
786
|
expect(system_adapter)
|
748
787
|
.to receive(:open_editor)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pry'
|
3
|
+
|
4
|
+
describe LearnOpen::GitSSHConnector do
|
5
|
+
let(:git_server) { 'github.example.com' }
|
6
|
+
let(:ssh_adapter_instance) { instance_double(LearnOpen::Adapters::SshAdapter) }
|
7
|
+
let(:ssh_adapter) { class_double(LearnOpen::Adapters::SshAdapter) }
|
8
|
+
let(:ssh_connector) { LearnOpen::GitSSHConnector.new(git_server: git_server, environment: environment) }
|
9
|
+
let(:environment) { instance_double(LearnOpen::Environments::IDEEnvironment) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(LearnOpen).to receive(:ssh_adapter).and_return(ssh_adapter)
|
13
|
+
allow(ssh_adapter).to receive(:new).with(user: 'git', hostname: git_server).and_return(ssh_adapter_instance)
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'for an authenticated SSH connection' do
|
17
|
+
before do
|
18
|
+
allow(ssh_adapter_instance).to receive(:authenticated?).and_return(true)
|
19
|
+
allow(environment).to receive(:managed?).and_return(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'does not attempt to upload keys' do
|
23
|
+
expect(ssh_connector).to_not receive(:upload_ssh_keys!)
|
24
|
+
ssh_connector.call
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'for an unauthenticated SSH connection' do
|
29
|
+
before do
|
30
|
+
allow(ssh_adapter_instance).to receive(:authenticated?).and_return(false)
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'on a managed server' do
|
34
|
+
before do
|
35
|
+
allow(environment).to receive(:managed?).and_return(true)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'attempts to upload a key' do
|
39
|
+
expect(ssh_connector).to receive(:upload_ssh_keys!).exactly(:once)
|
40
|
+
ssh_connector.call
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'on an unmanaged server' do
|
45
|
+
before do
|
46
|
+
allow(environment).to receive(:managed?).and_return(false)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'does not attempt to upload a key' do
|
50
|
+
expect(ssh_connector).to_not receive(:upload_ssh_keys!)
|
51
|
+
ssh_connector.call
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LearnOpen::LessonDownloader do
|
4
|
+
let(:lesson) { double }
|
5
|
+
let(:location) { double }
|
6
|
+
let(:environment) { double }
|
7
|
+
let(:downloader) { LearnOpen::LessonDownloader.new(lesson, location, environment) }
|
8
|
+
|
9
|
+
context 'downloaded lesson' do
|
10
|
+
before do
|
11
|
+
allow(downloader).to receive(:repo_exists?).and_return(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'able to make an SSH connection' do
|
15
|
+
before do
|
16
|
+
allow(downloader).to receive(:ensure_git_ssh!).and_return(true)
|
17
|
+
allow(downloader).to receive(:fork_repo)
|
18
|
+
allow(downloader).to receive(:clone_repo)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns status :noop' do
|
22
|
+
expect(downloader.call).to eq :noop
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'undownloaded lesson' do
|
28
|
+
before do
|
29
|
+
allow(downloader).to receive(:repo_exists?).and_return(false)
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'able to make an SSH connection' do
|
33
|
+
before do
|
34
|
+
allow(downloader).to receive(:ensure_git_ssh!).and_return(true)
|
35
|
+
allow(downloader).to receive(:fork_repo)
|
36
|
+
allow(downloader).to receive(:clone_repo)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'forks the repo' do
|
40
|
+
expect(downloader).to receive(:fork_repo)
|
41
|
+
downloader.call
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'clones the repo' do
|
45
|
+
expect(downloader).to receive(:clone_repo)
|
46
|
+
downloader.call
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'unable to make an SSH connection' do
|
51
|
+
before do
|
52
|
+
allow(downloader).to receive(:ensure_git_ssh!).and_return(false)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns status :ssh_unauthenticated' do
|
56
|
+
expect(downloader.call).to eq :ssh_unauthenticated
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: learn-open
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flatiron School
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.5.
|
159
|
+
version: 1.5.2
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.5.
|
166
|
+
version: 1.5.2
|
167
167
|
description:
|
168
168
|
email:
|
169
169
|
- learn@flatironschool.com
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- lib/learn_open.rb
|
184
184
|
- lib/learn_open/adapters/io_adapter.rb
|
185
185
|
- lib/learn_open/adapters/learn_web_adapter.rb
|
186
|
+
- lib/learn_open/adapters/ssh_adapter.rb
|
186
187
|
- lib/learn_open/adapters/system_adapter.rb
|
187
188
|
- lib/learn_open/argument_parser.rb
|
188
189
|
- lib/learn_open/environments.rb
|
@@ -206,14 +207,18 @@ files:
|
|
206
207
|
- lib/learn_open/services/dependency_installers/node_package_installer.rb
|
207
208
|
- lib/learn_open/services/dependency_installers/pip_installer.rb
|
208
209
|
- lib/learn_open/services/file_backup_starter.rb
|
210
|
+
- lib/learn_open/services/git_ssh_connector.rb
|
209
211
|
- lib/learn_open/services/lesson_downloader.rb
|
210
212
|
- lib/learn_open/services/logger.rb
|
211
213
|
- lib/learn_open/version.rb
|
212
214
|
- spec/fakes/fake_git.rb
|
213
215
|
- spec/fakes/fake_learn_client.rb
|
214
216
|
- spec/fixtures/learn-config
|
217
|
+
- spec/learn_open/adapters/ssh_adapter_spec.rb
|
215
218
|
- spec/learn_open/environments/ide_environment_spec.rb
|
216
219
|
- spec/learn_open/opener_spec.rb
|
220
|
+
- spec/learn_open/services/git_ssh_connector_spec.rb
|
221
|
+
- spec/learn_open/services/lesson_downloader_spec.rb
|
217
222
|
- spec/spec_helper.rb
|
218
223
|
homepage: https://github.com/learn-co/learn-open
|
219
224
|
licenses:
|
@@ -244,6 +249,9 @@ test_files:
|
|
244
249
|
- spec/fakes/fake_git.rb
|
245
250
|
- spec/fakes/fake_learn_client.rb
|
246
251
|
- spec/fixtures/learn-config
|
252
|
+
- spec/learn_open/adapters/ssh_adapter_spec.rb
|
247
253
|
- spec/learn_open/environments/ide_environment_spec.rb
|
248
254
|
- spec/learn_open/opener_spec.rb
|
255
|
+
- spec/learn_open/services/git_ssh_connector_spec.rb
|
256
|
+
- spec/learn_open/services/lesson_downloader_spec.rb
|
249
257
|
- spec/spec_helper.rb
|