From 363a1f30c194505038be8e22df8659f54af1d080 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Fri, 13 Aug 2021 13:38:41 -0700 Subject: [PATCH] Add module for connection helper --- plugins/commands/serve/util.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugins/commands/serve/util.rb b/plugins/commands/serve/util.rb index 6c7ad55d1..1a6faedbb 100644 --- a/plugins/commands/serve/util.rb +++ b/plugins/commands/serve/util.rb @@ -1,6 +1,21 @@ module VagrantPlugins module CommandServe module Util + # Extracts connection information from a proto + # and establishes a new connection + module Connector + def connect(proto:, broker:) + if(proto.target.to_s.empty?) + conn = broker.dial(proto.stream_id) + else + conn = proto.target.to_s.start_with?('/') ? + "unix:#{proto.target}" : + proto.target.to_s + end + conn.to_s + end + end + # Requires a broker to be set when initializing an # instance and adds an accessor to the broker module HasBroker