peas-cli 0.4.0 → 0.6.0

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: faee8809a414a35708ca312da7d0058383c2f16f
4
- data.tar.gz: 96f7c1fcdbf0efcc9551c6404ec4031f9d4cba03
3
+ metadata.gz: ff6bd17390d126df42251a27d4b7cbf3ecee90e9
4
+ data.tar.gz: d57aad2e837e5aa3eeca287cd631d4cb23c0600c
5
5
  SHA512:
6
- metadata.gz: b8c95f478440542ac91133997d017a908b6b585a674981e5fe423ab839b506b087e583fbf51b710a2497e0af4c470da6e28e0e6042a87cc42fb0d2a10fffff14
7
- data.tar.gz: 7ec91fd22ad6b72f52baf27daeca94949f3996297aeb9c94c617b89e651439a6e681774ed1383f5d3170e0189b1af6a3e073dd140ddb37a99c8640a15dc63b52
6
+ metadata.gz: 2e13f14149f6ec04c6775781978b705b84b3492b5ba73551c8a2cba4e7a02652a98b012438a3f3bc39fd48682d2e0697d930ba5ea718266e2f719f46dcffdd05
7
+ data.tar.gz: b6b6557852a4cee0b445071fec9f79f220848123324bded6fe121c112bd2a25b47cfd7baa4c059ff5729b71757805046cb2c5eaa97fd76d6374d0f524a9fbd50
data/Gemfile CHANGED
@@ -11,5 +11,5 @@ group :test do
11
11
  end
12
12
 
13
13
  group :development do
14
- gem 'jeweler'
15
- end
14
+ gem 'jeweler'
15
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.6.0
data/lib/peas/api.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  require 'httparty'
2
2
  require 'socket'
3
+ require 'openssl'
3
4
 
4
5
  class API
5
6
  include HTTParty
7
+ # TODO: Don't want to genuine SSL cert errors, say if there's a CA root cert
8
+ default_options.update(verify: false) # Ignore self-signed SSL error
6
9
 
7
10
  LONG_POLL_TIMEOUT = 10 * 60
8
11
  LONG_POLL_INTERVAL = 0.5
@@ -51,7 +54,11 @@ class API
51
54
  end
52
55
 
53
56
  def self.switchboard_connection
54
- TCPSocket.new Peas.host, Peas::SWITCHBOARD_PORT
57
+ socket = TCPSocket.new Peas.host, Peas::SWITCHBOARD_PORT
58
+ ssl = OpenSSL::SSL::SSLSocket.new socket
59
+ ssl.sync_close = true
60
+ ssl.connect
61
+ ssl
55
62
  end
56
63
 
57
64
  # Stream the output of a Switchboard job
@@ -86,7 +93,7 @@ class API
86
93
 
87
94
  # Create 2 threads to allow raw TTY to be sent at the same time as outputting
88
95
  # data from the socket.
89
- def self.duplex_socket socket
96
+ def self.duplex_socket(socket)
90
97
  threads = []
91
98
 
92
99
  # Copy STDIN to socket
@@ -94,7 +101,7 @@ class API
94
101
  STDIN.raw do |stdin|
95
102
  IO.copy_stream stdin, socket
96
103
  end
97
- socket.close_write
104
+ socket.close
98
105
  end
99
106
 
100
107
  # Write response to STDOUT
@@ -19,7 +19,7 @@ command :admin do |admin|
19
19
  if args.count > 1
20
20
  if args.first == 'peas.domain'
21
21
  domain = args[1]
22
- domain = "http://#{domain}" unless domain.start_with? 'http://'
22
+ domain = "https://#{domain}" unless domain.start_with? 'https://'
23
23
  # Update Git config
24
24
  Git.sh "git config peas.domain #{domain}"
25
25
  # Update file
@@ -5,7 +5,7 @@ command :logs do |c|
5
5
  c.switch [:f, :follow]
6
6
 
7
7
  c.action do |_global_options, options, _args|
8
- follow = options[:follow] ? 'follow' : ''
9
- API.stream_output "stream_logs.#{Git.name_from_remote} #{follow}"
8
+ follow = options[:follow] ? ' follow' : ''
9
+ API.stream_output "stream_logs.#{Git.name_from_remote}#{follow}"
10
10
  end
11
11
  end
data/lib/peas/config.rb CHANGED
@@ -28,7 +28,7 @@ module Peas
28
28
  'vcap.me:4000'
29
29
  end
30
30
  unless domain[/\Ahttp:\/\//] || domain[/\Ahttps:\/\//]
31
- "http://#{domain}"
31
+ "https://#{domain}"
32
32
  else
33
33
  domain
34
34
  end
data/lib/peas/git.rb CHANGED
@@ -25,6 +25,6 @@ class Git
25
25
  remote_uri = remote unless remote_uri
26
26
  exit_now! "No Peas remote. I can't figure out what app this is.", 1 if remote_uri == ''
27
27
  parts = Addressable::URI.parse remote_uri
28
- parts.path.split('/').last.gsub('.git', '')
28
+ parts.path.split('/').last.gsub('.git', '').downcase
29
29
  end
30
30
  end
data/peas-cli.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: peas-cli 0.4.0 ruby lib
5
+ # stub: peas-cli 0.6.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "peas-cli"
9
- s.version = "0.4.0"
9
+ s.version = "0.6.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Tom Buckley-Houston"]
14
- s.date = "2014-11-19"
14
+ s.date = "2015-01-03"
15
15
  s.description = "Peas is an open source Heroku-style PaaS written in Ruby and using Docker"
16
16
  s.email = "tom@tombh.co.uk"
17
17
  s.executables = ["peas"]
data/spec/cli_spec.rb CHANGED
@@ -18,25 +18,25 @@ describe 'Peas CLI' do
18
18
 
19
19
  describe 'Settings' do
20
20
  it 'should set and use the domain setting' do
21
- stub_request(:put, 'http://new-domain.com:4000/admin/settings?peas.domain=new-domain.com:4000')
21
+ stub_request(:put, 'https://new-domain.com:4000/admin/settings?peas.domain=new-domain.com:4000')
22
22
  .to_return(body: response_mock({}))
23
- expect(Git).to receive(:sh).with("git config peas.domain http://new-domain.com:4000")
23
+ expect(Git).to receive(:sh).with("git config peas.domain https://new-domain.com:4000")
24
24
  cli %w(admin settings peas.domain new-domain.com:4000)
25
25
  config = JSON.parse File.open('/tmp/.peas').read
26
- expect(config).to eq("domain" => "http://new-domain.com:4000")
26
+ expect(config).to eq("domain" => "https://new-domain.com:4000")
27
27
  end
28
28
 
29
29
  it 'should set a normal setting' do
30
- stub_request(:put, 'http://vcap.me:4000/admin/settings?mongodb.uri=mongodb://uri')
30
+ stub_request(:put, 'https://vcap.me:4000/admin/settings?mongodb.uri=mongodb://uri')
31
31
  .to_return(body: response_mock(
32
- defaults: { 'peas.domain' => 'http://boss.com' },
32
+ defaults: { 'peas.domain' => 'https://boss.com' },
33
33
  services: {
34
34
  'mongodb.uri' => 'mongodb://uri',
35
35
  'postgres.uri' => 'xsgfd'
36
36
  }
37
37
  ))
38
38
  output = cli %w(admin settings mongodb.uri mongodb://uri)
39
- expect(output).to eq("Available settings\n\nDefaults:\n peas.domain http://boss.com\n\nServices:\n mongodb.uri mongodb://uri\n postgres.uri xsgfd\n\n")
39
+ expect(output).to eq("Available settings\n\nDefaults:\n peas.domain https://boss.com\n\nServices:\n mongodb.uri mongodb://uri\n postgres.uri xsgfd\n\n")
40
40
  end
41
41
 
42
42
  end
@@ -78,6 +78,7 @@ describe 'Peas CLI' do
78
78
  end
79
79
 
80
80
  it 'should scale an app', :with_socket do
81
+ expect(@socket).to receive(:puts).with('subscribe.job_progress.123')
81
82
  stub_request(
82
83
  :put,
83
84
  TEST_DOMAIN + '/app/test-test/scale?scaling_hash=%7B%22web%22:%223%22,%22worker%22:%222%22%7D'
@@ -95,10 +96,17 @@ describe 'Peas CLI' do
95
96
  output = cli %w(run FINAL COMMAND)
96
97
  expect(output).to eq "tty.test-test\nFINAL COMMAND\n"
97
98
  end
98
- it 'should run one-off with input from STDIN' do
99
- io = StringIO.new 'FINAL COMMAND'
99
+ # This one has taken me soooooo long to figure out. This is testing the ability to open up
100
+ # an SSH-like TTY, that among other things will let you interact with ncurses programs like
101
+ # VIM. So it's important that the duplex (simultaneous read/write) connections are tested.
102
+ it 'should run one-off commands with input from STDIN' do
103
+ # Using a pipe rather than a plain string means that no EOF is sent, which prematurely
104
+ # closes the connection.
105
+ read, write = IO.pipe
106
+ write.write "FINAL COMMAND\n"
107
+ # Stub the pipe into STDIN.raw to simulate typing
100
108
  allow(STDIN).to receive(:raw) do |&block|
101
- block.call io
109
+ block.call read
102
110
  end
103
111
  output = cli %w(run WITH STDIN)
104
112
  expect(output).to eq "tty.test-test\nWITH STDIN\nFINAL COMMAND\n"
@@ -130,21 +138,17 @@ describe 'Peas CLI' do
130
138
  end
131
139
 
132
140
  describe 'Logs' do
133
- it 'should stream logs' do
134
- socket = double 'TCPSocket'
135
- allow(socket).to receive(:puts)
136
- allow(socket).to receive(:gets).and_return("Here's ya logs", "MOAR", false)
137
- allow(TCPSocket).to receive(:new).and_return(socket)
141
+ it 'should stream logs', :with_socket do
142
+ expect(@socket).to receive(:puts).with('stream_logs.test-test')
143
+ allow(@socket).to receive(:gets).and_return("Here's ya logs", "MOAR", false)
138
144
  output = cli %w(logs)
139
145
  expect(output).to eq "Here's ya logs\nMOAR\n"
140
146
  end
141
147
  end
142
148
 
143
- it 'should retrieve and output a long-running command' do
144
- socket = double 'TCPSocket'
145
- expect(socket).to receive(:puts).with('subscribe.job_progress.123')
146
- allow(socket).to receive(:gets).and_return("doing", "something", "done", false)
147
- allow(TCPSocket).to receive(:new).and_return(socket)
149
+ it 'should retrieve and output a long-running command', :with_socket do
150
+ expect(@socket).to receive(:puts).with('subscribe.job_progress.123')
151
+ allow(@socket).to receive(:gets).and_return("doing", "something", "done", false)
148
152
  expect(API).to receive(:puts).with "doing"
149
153
  expect(API).to receive(:puts).with "something"
150
154
  expect(API).to receive(:puts).with "done"
@@ -153,7 +157,7 @@ describe 'Peas CLI' do
153
157
 
154
158
  it 'should show a warning when there is a version mismatch' do
155
159
  stub_request(:get, TEST_DOMAIN + '/app/test-test/config')
156
- .to_return(body: '{"version": "100000.1000000.100000"}')
160
+ .to_return(body: '{"version": "100000.1000000.100000"}')
157
161
  output = cli %w(config)
158
162
  expect(output).to include 'Your version of the CLI client is out of date'
159
163
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
- require 'rubygems'
2
1
  require 'stringio'
2
+ require 'rubygems'
3
3
  require 'webmock/rspec'
4
+ require 'openssl'
4
5
 
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "../"))
6
7
  require 'lib/peas'
@@ -8,8 +9,12 @@ require 'lib/peas'
8
9
  ENV['GLI_ENV'] = 'test'
9
10
  ROOT = File.join(File.expand_path(File.dirname(__FILE__)), '..')
10
11
  $LOAD_PATH.unshift(File.join(ROOT, 'lib'))
11
- TEST_DOMAIN = 'http://vcap.me:4000'
12
+ TEST_DOMAIN = 'https://vcap.me:4000'
12
13
  SWITCHBOARD_TEST_PORT = 79345
14
+ SSL_KEY_PATH = "#{ROOT}/../contrib/ssl-keys/server.key"
15
+ SSL_KEY = OpenSSL::PKey::RSA.new File.read(SSL_KEY_PATH)
16
+ SSL_CERT_PATH = "#{ROOT}/../contrib/ssl-keys/server.crt"
17
+ SSL_CERT = OpenSSL::X509::Certificate.new File.read(SSL_CERT_PATH)
13
18
 
14
19
  RSpec.configure do |config|
15
20
  config.mock_with :rspec
@@ -20,19 +25,26 @@ RSpec.configure do |config|
20
25
  end
21
26
 
22
27
  config.before(:each, :with_socket) do
23
- @socket = double 'TCPSocket'
24
- expect(@socket).to receive(:puts).with('subscribe.job_progress.123')
25
- allow(TCPSocket).to receive(:new).and_return(@socket)
28
+ tcp = instance_double TCPSocket
29
+ allow(TCPSocket).to receive(:new).and_return(tcp)
30
+ @socket = instance_double OpenSSL::SSL::SSLSocket
31
+ allow(OpenSSL::SSL::SSLSocket).to receive(:new).and_return(@socket)
32
+ allow(@socket).to receive(:sync_close=)
33
+ allow(@socket).to receive(:connect)
26
34
  end
27
35
 
28
36
  config.before(:each, :with_echo_server) do
29
- @server = TCPServer.new 'vcap.me', SWITCHBOARD_TEST_PORT
37
+ tcp_server = TCPServer.new 'vcap.me', SWITCHBOARD_TEST_PORT
38
+ context = OpenSSL::SSL::SSLContext.new
39
+ context.key = SSL_KEY
40
+ context.cert = SSL_CERT
30
41
  Thread.new do
42
+ @server = OpenSSL::SSL::SSLServer.new tcp_server, context
31
43
  @connection = @server.accept
32
44
  begin
33
45
  Timeout.timeout(2) do
34
46
  while (line = @connection.gets)
35
- @connection.puts line
47
+ @connection.write line
36
48
  @connection.close if line.strip == 'FINAL COMMAND'
37
49
  end
38
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peas-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Buckley-Houston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2015-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli