-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
routes: add routes list command (#487)
* routes: add routes list command * handle missing dir in jwt cache
- Loading branch information
1 parent
8723bbb
commit 3cd6e58
Showing
22 changed files
with
2,024 additions
and
650 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
"google.golang.org/protobuf/proto" | ||
|
||
"github.com/pomerium/cli/internal/portal" | ||
pb "github.com/pomerium/cli/proto" | ||
) | ||
|
||
func (srv *server) FetchRoutes( | ||
ctx context.Context, | ||
req *pb.FetchRoutesRequest, | ||
) (*pb.FetchRoutesResponse, error) { | ||
tlsConfig, err := getTLSConfig(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
p := portal.New( | ||
portal.WithBrowserCommand(srv.browserCmd), | ||
portal.WithServiceAccount(srv.serviceAccount), | ||
portal.WithServiceAccountFile(srv.serviceAccountFile), | ||
portal.WithTLSConfig(tlsConfig), | ||
) | ||
|
||
routes, err := p.ListRoutes(ctx, req.GetServerUrl()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := new(pb.FetchRoutesResponse) | ||
for _, route := range routes { | ||
r := &pb.PortalRoute{ | ||
Id: route.ID, | ||
Name: route.Name, | ||
Type: route.Type, | ||
From: route.From, | ||
Description: route.Description, | ||
LogoUrl: route.LogoURL, | ||
} | ||
if route.ConnectCommand != "" { | ||
r.ConnectCommand = proto.String(route.ConnectCommand) | ||
} | ||
res.Routes = append(res.Routes, r) | ||
} | ||
return res, nil | ||
} |
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,71 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/pomerium/cli/internal/portal" | ||
) | ||
|
||
func init() { | ||
addBrowserFlags(routesListCmd) | ||
addServiceAccountFlags(routesListCmd) | ||
addTLSFlags(routesListCmd) | ||
routesCmd.AddCommand(routesListCmd) | ||
rootCmd.AddCommand(routesCmd) | ||
} | ||
|
||
var routesCmd = &cobra.Command{ | ||
Use: "routes", | ||
Short: "commands for routes", | ||
} | ||
|
||
var routesListCmd = &cobra.Command{ | ||
Use: "list server-url", | ||
Short: "list routes", | ||
Args: cobra.MaximumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
rawServerURL := "" | ||
if len(args) > 0 { | ||
rawServerURL = args[0] | ||
} else { | ||
rawServerURL = loadLastURL() | ||
} | ||
if rawServerURL == "" { | ||
return fmt.Errorf("server-url is required") | ||
} | ||
|
||
cacheLastURL(rawServerURL) | ||
|
||
tlsConfig, err := getTLSConfig() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
p := portal.New( | ||
portal.WithBrowserCommand(browserOptions.command), | ||
portal.WithServiceAccount(serviceAccountOptions.serviceAccount), | ||
portal.WithServiceAccountFile(serviceAccountOptions.serviceAccountFile), | ||
portal.WithTLSConfig(tlsConfig), | ||
) | ||
routes, err := p.ListRoutes(cmd.Context(), rawServerURL) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, route := range routes { | ||
fmt.Println("Route", route.Name) | ||
fmt.Println("id:", route.ID) | ||
fmt.Println("type:", route.Type) | ||
fmt.Println("from:", route.From) | ||
fmt.Println("description:", route.Description) | ||
if route.ConnectCommand != "" { | ||
fmt.Println("connect_command:", route.ConnectCommand) | ||
} | ||
fmt.Println() | ||
} | ||
|
||
return nil | ||
}, | ||
} |
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
Oops, something went wrong.