forked from raystack/frontier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3462887
commit 0a2711c
Showing
5 changed files
with
146 additions
and
36 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,94 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/MakeNowJust/heredoc" | ||
"github.com/goto/shield/config" | ||
"github.com/goto/shield/internal/proxy/envoy/xds" | ||
"github.com/goto/shield/internal/store/postgres" | ||
shieldlogger "github.com/goto/shield/pkg/logger" | ||
"github.com/spf13/cobra" | ||
cli "github.com/spf13/cobra" | ||
) | ||
|
||
func ProxyCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "proxy <command>", | ||
Short: "Proxy management", | ||
Long: "Server management commands.", | ||
Example: heredoc.Doc(` | ||
$ shield proxy envoy-xds start -c ./config.yaml | ||
`), | ||
} | ||
|
||
cmd.AddCommand(proxyEnvoyXDSCommand()) | ||
|
||
return cmd | ||
} | ||
|
||
func proxyEnvoyXDSCommand() *cobra.Command { | ||
c := &cli.Command{ | ||
Use: "envoy-xds", | ||
Short: "Envoy Agent xDS management", | ||
Long: "Envoy Agent xDS management commands.", | ||
Example: heredoc.Doc(` | ||
$ shield proxy envoy-xds start | ||
`), | ||
} | ||
|
||
c.AddCommand(envoyXDSStartCommand()) | ||
|
||
return c | ||
} | ||
|
||
func envoyXDSStartCommand() *cobra.Command { | ||
var configFile string | ||
|
||
c := &cli.Command{ | ||
Use: "start", | ||
Short: "Start Envoy Agent xDS server", | ||
Long: "Start Envoy Agent xDS server commands.", | ||
Example: "shield proxy envoy-xds start", | ||
RunE: func(cmd *cli.Command, args []string) error { | ||
appConfig, err := config.Load(configFile) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
logger := shieldlogger.InitLogger(shieldlogger.Config{Level: appConfig.Log.Level}) | ||
|
||
dbClient, err := setupDB(appConfig.DB, logger) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
logger.Info("cleaning up db") | ||
dbClient.Close() | ||
}() | ||
|
||
ctx := cmd.Context() | ||
|
||
pgRuleRepository := postgres.NewRuleRepository(dbClient) | ||
if err := pgRuleRepository.InitCache(ctx); err != nil { | ||
return err | ||
} | ||
|
||
cbs, repositories, err := buildXDSDependencies(ctx, logger, appConfig.Proxy, pgRuleRepository) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
logger.Info("cleaning up rules proxy blob") | ||
for _, f := range cbs { | ||
if err := f(); err != nil { | ||
logger.Warn("error occurred during shutdown rules proxy blob storages", "err", err) | ||
} | ||
} | ||
}() | ||
|
||
return xds.Serve(ctx, logger, appConfig.Proxy, repositories) | ||
}, | ||
} | ||
|
||
c.Flags().StringVarP(&configFile, "config", "c", "", "Config file path") | ||
return c | ||
} |
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