mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-21 04:57:18 +02:00
Core-Zero Import (#5288)
* initial core-zero import implementation * Update /config/import openapi description and use PUT instead of POST * update import ui tests * Add 413 as a possible response for /config/import * Options/Settings type conversion tests and related bugfixes * Fixes for proto type conversion and tests * Update core-zero import client * Update core-zero import client * Update import api and environment detection * update go.mod * remove old testdata * Remove usage of deleted setting after merge * remove extra newline from --version output
This commit is contained in:
parent
5b4fe8969d
commit
0e13248685
22 changed files with 3193 additions and 700 deletions
71
internal/zero/cmd/command_root.go
Normal file
71
internal/zero/cmd/command_root.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
zero "github.com/pomerium/pomerium/internal/zero/api"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type zeroClientContextKeyType struct{}
|
||||
|
||||
var zeroClientContextKey zeroClientContextKeyType
|
||||
|
||||
func zeroClientFromContext(ctx context.Context) *zero.API {
|
||||
return ctx.Value(zeroClientContextKey).(*zero.API)
|
||||
}
|
||||
|
||||
func BuildRootCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "zero",
|
||||
Short: "Interact with the Pomerium Zero cloud service",
|
||||
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
||||
configFlag := cmd.InheritedFlags().Lookup("config")
|
||||
var configFile string
|
||||
if configFlag != nil {
|
||||
configFile = configFlag.Value.String()
|
||||
}
|
||||
|
||||
if err := setupLogger(); err != nil {
|
||||
return err
|
||||
}
|
||||
var token string
|
||||
if tokenFlag := cmd.InheritedFlags().Lookup("token"); tokenFlag != nil && tokenFlag.Changed {
|
||||
token = tokenFlag.Value.String()
|
||||
} else {
|
||||
token = getToken(configFile)
|
||||
}
|
||||
if token == "" {
|
||||
return errors.New("no token provided")
|
||||
}
|
||||
|
||||
var clusterAPIEndpoint string
|
||||
if endpointFlag := cmd.InheritedFlags().Lookup("cluster-api-endpoint"); endpointFlag != nil && endpointFlag.Changed {
|
||||
clusterAPIEndpoint = endpointFlag.Value.String()
|
||||
} else {
|
||||
clusterAPIEndpoint = getClusterAPIEndpoint()
|
||||
}
|
||||
|
||||
client, err := zero.NewAPI(cmd.Context(),
|
||||
zero.WithAPIToken(token),
|
||||
zero.WithClusterAPIEndpoint(clusterAPIEndpoint),
|
||||
zero.WithConnectAPIEndpoint(getConnectAPIEndpoint()),
|
||||
zero.WithOTELEndpoint(getOTELAPIEndpoint()),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmd.SetContext(context.WithValue(cmd.Context(), zeroClientContextKey, client))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.AddCommand(BuildImportCmd())
|
||||
cmd.PersistentFlags().String("config", "", "Specify configuration file location")
|
||||
cmd.PersistentFlags().String("token", "", "Pomerium Zero Token (default: $POMERIUM_ZERO_TOKEN)")
|
||||
cmd.PersistentFlags().String("cluster-api-endpoint", "", "Pomerium Zero Cluster API Endpoint (default: $CLUSTER_API_ENDPOINT)")
|
||||
cmd.PersistentFlags().Lookup("cluster-api-endpoint").Hidden = true
|
||||
|
||||
return cmd
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue