-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(agent,api,pkg): add VPN capability
It adds to the ShellHub's Agent the capability to connect to a ShellHub's Enterprise service, which provides a virtual private network between devices registered into the same namespace. To enable it, the ShellHub's instance must support it, and the `SHELLHUB_VPN` environmental variable must be set to `TRUE` on the ShellHub Agent startup.
- Loading branch information
1 parent
89ad8e9
commit f05d169
Showing
20 changed files
with
870 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package vpn | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/labstack/echo/v4" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func handler(handler func(net.Conn, *Settings) error) func(c echo.Context) error { | ||
return func(c echo.Context) error { | ||
log.Debug("handler started") | ||
defer log.Debug("handler done") | ||
|
||
conn, _, err := c.Response().Hijack() | ||
if err != nil { | ||
log.Error(err) | ||
|
||
return err | ||
} | ||
|
||
defer conn.Close() | ||
|
||
settings, err := ParseSettings(c.Request().Body) | ||
if err != nil { | ||
log.WithError(err).Error("faild to parse the settings") | ||
|
||
return err | ||
} | ||
|
||
// NOTE: the [handler] is called to handler the core logic of the VPN client, while this handler is used to extract | ||
// the connection and the settings data. | ||
if err := handler(conn, settings); err != nil { | ||
log.WithError(err).Error("failed to handler the vpn connection between server and agent") | ||
|
||
return err | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func closeHandler(callback func() error) func(c echo.Context) error { | ||
return func(c echo.Context) error { | ||
log.Trace("close handler called") | ||
|
||
return callback() | ||
} | ||
} |
Oops, something went wrong.