mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-01 02:12:50 +02:00
proxy: add route portal json (#5428)
* proxy: add route portal json * fix 405 issue * add link to issue * Update proxy/portal/filter_test.go Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com> --------- Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com>
This commit is contained in:
parent
6e1fabec0b
commit
e816cef2a1
10 changed files with 628 additions and 5 deletions
60
proxy/portal/portal.go
Normal file
60
proxy/portal/portal.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
// Package portal contains the code for the routes portal
|
||||
package portal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/pomerium/pomerium/config"
|
||||
"github.com/pomerium/pomerium/internal/urlutil"
|
||||
"github.com/pomerium/pomerium/pkg/zero/importutil"
|
||||
)
|
||||
|
||||
// A Route is a portal route.
|
||||
type Route struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
From string `json:"from"`
|
||||
Description string `json:"description"`
|
||||
ConnectCommand string `json:"connect_command,omitempty"`
|
||||
LogoURL string `json:"logo_url"`
|
||||
}
|
||||
|
||||
// RoutesFromConfigRoutes converts config routes into portal routes.
|
||||
func RoutesFromConfigRoutes(routes []*config.Policy) []Route {
|
||||
prs := make([]Route, len(routes))
|
||||
for i, route := range routes {
|
||||
pr := Route{}
|
||||
pr.ID = route.ID
|
||||
if pr.ID == "" {
|
||||
pr.ID = fmt.Sprintf("%x", route.MustRouteID())
|
||||
}
|
||||
pr.Name = route.Name
|
||||
pr.From = route.From
|
||||
fromURL, err := urlutil.ParseAndValidateURL(route.From)
|
||||
if err == nil {
|
||||
if strings.HasPrefix(fromURL.Scheme, "tcp+") {
|
||||
pr.Type = "tcp"
|
||||
pr.ConnectCommand = "pomerium-cli tcp " + fromURL.Host
|
||||
} else if strings.HasPrefix(fromURL.Scheme, "udp+") {
|
||||
pr.Type = "udp"
|
||||
pr.ConnectCommand = "pomerium-cli udp " + fromURL.Host
|
||||
} else {
|
||||
pr.Type = "http"
|
||||
}
|
||||
} else {
|
||||
pr.Type = "http"
|
||||
}
|
||||
pr.Description = route.Description
|
||||
pr.LogoURL = route.LogoURL
|
||||
prs[i] = pr
|
||||
}
|
||||
// generate names if they're empty
|
||||
for i, name := range importutil.GenerateRouteNames(routes) {
|
||||
if prs[i].Name == "" {
|
||||
prs[i].Name = name
|
||||
}
|
||||
}
|
||||
return prs
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue