aboutsummaryrefslogtreecommitdiff
path: root/lib/leap_cli/config
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-03-27 00:40:59 -0700
committerelijah <elijah@riseup.net>2013-03-27 00:40:59 -0700
commitb0d061af5dc4b700ce6fcf56f49c900e9138119a (patch)
tree6cff1da447f8f554a1a96d28f8c88c978ee236e9 /lib/leap_cli/config
parent441d01ef891636c3f7a8084c309db273e8ee33e5 (diff)
downloadleap_cli-b0d061af5dc4b700ce6fcf56f49c900e9138119a.tar.gz
leap_cli-b0d061af5dc4b700ce6fcf56f49c900e9138119a.tar.bz2
added config macros for stunnel_client, stunnel_server, stunnel_port
Diffstat (limited to 'lib/leap_cli/config')
-rw-r--r--lib/leap_cli/config/object.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb
index 35637f1..c298882 100644
--- a/lib/leap_cli/config/object.rb
+++ b/lib/leap_cli/config/object.rb
@@ -334,6 +334,66 @@ module LeapCli
entries.join("\n")
end
+ #
+ # stunnel configuration for the client side.
+ #
+ # +node_list+ is a ObjectList of nodes running stunnel servers.
+ #
+ # +port+ is the real port of the ultimate service running on the servers
+ # that the client wants to connect to.
+ #
+ # About ths stunnel puppet names:
+ #
+ # * accept_port is the port on localhost to which local clients
+ # can connect. it is auto generated serially.
+ # * connect_port is the port on the stunnel server to connect to.
+ # it is auto generated from the +port+ argument.
+ #
+ # The network looks like this:
+ #
+ # |------ stunnel client ---------------| |--------- stunnel server -----------------------|
+ # consumer app -> localhost:accept_port -> server:connect_port -> server:port -> service app
+ #
+ # generates an entry appropriate to be passed directly to
+ # create_resources(stunnel::service, hiera('..'), defaults)
+ #
+ def stunnel_client(node_list, port, options={})
+ @next_stunnel_port ||= 4000
+ node_list.values.inject(Config::ObjectList.new) do |hsh, node|
+ if node.name != self.name || options[:include_self]
+ hsh["#{node.name}#{port}"] = Config::Object[
+ 'accept_port', @next_stunnel_port,
+ 'connect', node.domain.internal,
+ 'connect_port', stunnel_port(port)
+ ]
+ @next_stunnel_port += 1
+ end
+ hsh
+ end
+ end
+
+ #
+ # generates a stunnel server entry.
+ #
+ # +port+ is the real port targeted service.
+ #
+ def stunnel_server(port)
+ {"accept" => stunnel_port(port), "connect" => "127.0.0.1:#{port}"}
+ end
+
+ #
+ # maps a real port to a stunnel port (used as the connect_port in the client config
+ # and the accept_port in the server config)
+ #
+ def stunnel_port(port)
+ port = port.to_i
+ if port < 50000
+ return port + 10000
+ else
+ return port - 10000
+ end
+ end
+
protected
#