Skip to content

Commit

Permalink
feat(KRY-634): Add sidekick local run to support local bolt endpoint (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
avasani committed Jul 20, 2023
1 parent 1397abc commit 7bf67c7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
14 changes: 13 additions & 1 deletion boltrouter/bolt_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func (br *BoltRouter) SelectBoltEndpoint(ctx context.Context, reqMethod string)
if ok && len(availableEndpointsStr) > 0 {
randomIndex := rand.Intn(len(availableEndpointsStr))
selectedEndpoint := availableEndpointsStr[randomIndex]
if br.config.Local {
return url.Parse(fmt.Sprintf("http://%s", selectedEndpoint))
}
return url.Parse(fmt.Sprintf("https://%s", selectedEndpoint))
}
}
Expand Down Expand Up @@ -86,7 +89,16 @@ func (br *BoltRouter) RefreshBoltInfo(ctx context.Context) error {
func (br *BoltRouter) getBoltInfo(ctx context.Context) (BoltInfo, error) {
// If running locally, we can't connect to quicksilver.
if br.config.Local {
return BoltInfo{}, nil
if br.config.BoltEndpointOverride == "" {
return BoltInfo{}, nil
}
endpoints := make(BoltInfo)
endpoints["main_write_endpoints"] = []interface{}{br.config.BoltEndpointOverride}
endpoints["failover_write_endpoints"] = []interface{}{br.config.BoltEndpointOverride}
endpoints["main_read_endpoints"] = []interface{}{br.config.BoltEndpointOverride}
endpoints["failover_read_endpoints"] = []interface{}{br.config.BoltEndpointOverride}
endpoints["cluster_healthy"] = true
return endpoints, nil
}

if br.boltVars.QuicksilverURL.Get() == "" || br.boltVars.Region.Get() == "" {
Expand Down
8 changes: 6 additions & 2 deletions boltrouter/bolt_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -61,8 +62,11 @@ func (br *BoltRouter) NewBoltRequest(ctx context.Context, logger *zap.Logger, re
BoltURL.Path = "/" + BoltURL.Path
BoltURL.RawQuery = req.URL.RawQuery
req.URL = BoltURL
req.URL.Scheme = "https"

if strings.Contains(BoltURL.Path, "https") {
req.URL.Scheme = "https"
} else {
req.URL.Scheme = "http"
}
if v := headReq.Header.Get("X-Amz-Security-Token"); v != "" {
req.Header.Set("X-Amz-Security-Token", v)
}
Expand Down
10 changes: 7 additions & 3 deletions boltrouter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ type Config struct {
// For example, boultrouter will not query quicksilver to get endpoints.
Local bool `yaml:"Local"`

// Set the BoltEndpointOverride while running from local mode.
BoltEndpointOverride string `yaml:"BoltEndpointOverride"`

// Enable pass through in Bolt.
Passthrough bool `yaml:"Passthrough"`

Expand All @@ -14,8 +17,9 @@ type Config struct {

func NewConfig() Config {
return Config{
Local: false,
Passthrough: false,
Failover: true,
Local: false,
Passthrough: false,
Failover: true,
BoltEndpointOverride: "",
}
}
4 changes: 4 additions & 0 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func init() {
func initServerFlags(cmd *cobra.Command) {
cmd.Flags().IntP("port", "p", DEFAULT_PORT, "The port for sidekick to listen on.")
cmd.Flags().BoolP("local", "l", false, "Run sidekick in local (non cloud) mode. This is mostly use for testing locally.")
cmd.Flags().String("bolt-endpoint-override", "", "Specify the local bolt endpoint to override in local mode.")
cmd.Flags().Bool("passthrough", false, "Set passthrough flag to bolt requests.")
cmd.Flags().BoolP("failover", "f", true, "Enables aws request failover if bolt request fails.")
}
Expand Down Expand Up @@ -71,6 +72,9 @@ func getBoltRouterConfig(cmd *cobra.Command) boltrouter.Config {
if cmd.Flags().Lookup("local").Changed {
boltRouterConfig.Local, _ = cmd.Flags().GetBool("local")
}
if cmd.Flags().Lookup("bolt-endpoint-override").Changed {
boltRouterConfig.BoltEndpointOverride, _ = cmd.Flags().GetString("bolt-endpoint-override")
}
if cmd.Flags().Lookup("passthrough").Changed {
boltRouterConfig.Passthrough, _ = cmd.Flags().GetBool("passthrough")
}
Expand Down

0 comments on commit 7bf67c7

Please sign in to comment.