console-websocket-cf-plugin 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -0
- data/lib/console-websocket-cf-plugin.rb +1 -0
- data/lib/console-websocket-cf-plugin/plugin.rb +95 -0
- metadata +97 -0
data/README.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
### console-websocket-cf-plugin
|
2
|
+
|
3
|
+
This is a [CF](https://github.com/cloudfoundry/cf) plugin for connecting to the STDIN / STDOUT of a remote process (rails console for example) on Cloud Foundry whilst simultaneously running the intended application in the same container.
|
4
|
+
It uses a binary written in Go on the server side to provide the websocket connection and also serve the application itself, if you wish to serve that up too.
|
5
|
+
|
6
|
+
## TL;DR Rails example
|
7
|
+
|
8
|
+
1. Install the Gem
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'console-websocket-cf-plugin/plugin'
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'console-websocket-cf-plugin'
|
2
|
+
require 'eventmachine'
|
3
|
+
require 'termios'
|
4
|
+
require 'stringio'
|
5
|
+
require 'base64'
|
6
|
+
require 'json'
|
7
|
+
require 'zlib'
|
8
|
+
require 'faye/websocket'
|
9
|
+
|
10
|
+
module ConsoleWebsocketCfPlugin
|
11
|
+
|
12
|
+
include EM::Protocols::LineText2
|
13
|
+
|
14
|
+
class KeyboardHandler < EM::Connection
|
15
|
+
|
16
|
+
include EM::Protocols::LineText2
|
17
|
+
|
18
|
+
def initialize(ws, guid)
|
19
|
+
@ws = ws
|
20
|
+
@guid = guid
|
21
|
+
@buffer = ''
|
22
|
+
end
|
23
|
+
|
24
|
+
def receive_line(data)
|
25
|
+
EM.stop if data == "exit"
|
26
|
+
@ws.lines_in << data
|
27
|
+
@ws.send data.gsub("\n", "")
|
28
|
+
end
|
29
|
+
|
30
|
+
def move_history(direction)
|
31
|
+
puts direction
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
class Plugin < CF::CLI
|
37
|
+
|
38
|
+
def precondition
|
39
|
+
# skip all default preconditions
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "Open a console to an application container"
|
43
|
+
group :admin
|
44
|
+
input :app, :desc => "Application to connect to", :argument => true,
|
45
|
+
:from_given => by_name(:app)
|
46
|
+
input :instance, :desc => "Instance (index) to connect", :default => 0
|
47
|
+
|
48
|
+
def console
|
49
|
+
|
50
|
+
app = input[:app]
|
51
|
+
|
52
|
+
app_version = app.manifest[:entity][:version]
|
53
|
+
guid = "#{app_version}/#{input[:instance]}"
|
54
|
+
ws_url = "wss://#{app.url}:4443/#{guid}"
|
55
|
+
|
56
|
+
puts "Starting connection to #{ws_url}"
|
57
|
+
|
58
|
+
start_connection(app, guid, ws_url)
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def start_connection(app, guid, ws_url)
|
65
|
+
|
66
|
+
EM.run {
|
67
|
+
|
68
|
+
Faye::WebSocket::Client.class_eval <<-BYTES_IN
|
69
|
+
attr_accessor :lines_in
|
70
|
+
BYTES_IN
|
71
|
+
|
72
|
+
ws = Faye::WebSocket::Client.new(ws_url, nil, { :headers => { 'Origin' => "http://#{app.url}:4443" }})
|
73
|
+
ws.lines_in = []
|
74
|
+
|
75
|
+
ws.on :error do |event|
|
76
|
+
p [:error]
|
77
|
+
p ws.status
|
78
|
+
end
|
79
|
+
|
80
|
+
ws.on :message do |event|
|
81
|
+
print event.data unless event.data.strip == ws.lines_in.last
|
82
|
+
end
|
83
|
+
|
84
|
+
ws.on :close do |event|
|
85
|
+
ws = nil
|
86
|
+
EM.stop
|
87
|
+
end
|
88
|
+
|
89
|
+
EM.open_keyboard(KeyboardHandler, ws, guid)
|
90
|
+
}
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: console-websocket-cf-plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- GoPivotal
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: cf
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faye-websocket
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: ruby-termios
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: CF command line extension to allow console access to an app container
|
63
|
+
via a secure WebSocket
|
64
|
+
email: support@cloudfoundry.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- lib/console-websocket-cf-plugin.rb
|
70
|
+
- lib/console-websocket-cf-plugin/plugin.rb
|
71
|
+
- README.md
|
72
|
+
homepage: https://github.com/danhigham/console-websocket-cf-plugin
|
73
|
+
licenses:
|
74
|
+
- Apache 2.0
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.9.3
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.25
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: CF WebSocket Console
|
97
|
+
test_files: []
|