Skip to content

Commit

Permalink
Merge pull request #142 from aserto-dev/console-config
Browse files Browse the repository at this point in the history
Replace 0.0.0.0 with localhost
  • Loading branch information
oanatmaria authored Oct 3, 2023
2 parents 1784418 + 38d2496 commit 577173a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const containerImage string = "topaz"
func init() {
os.Setenv("GO_VERSION", "1.20")
os.Setenv("DOCKER_BUILDKIT", "1")
os.Setenv("CONSOLE_VERSION", "0.8.66-20231002144058.64.g51d1cc0c.v3")
os.Setenv("CONSOLE_VERSION", "0.0.0-20231002232018.0.gef5db259")
}

// Generate generates all code.
Expand Down
25 changes: 20 additions & 5 deletions pkg/app/ui/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ func ConfigHandler(confServices *config.Config) func(w http.ResponseWriter, r *h

func composeConfig(confServices *config.Config, apiKey string) *consoleCfg {
cfg := &consoleCfg{}
cfg.AsertoDirectoryReaderURL = fmt.Sprintf("https://%s", confServices.Services["reader"].Gateway.ListenAddress)
cfg.AsertoDirectoryURL = fmt.Sprintf("https://%s", confServices.Services["reader"].Gateway.ListenAddress)
cfg.AsertoDirectoryReaderURL = fmt.Sprintf("https://%s", serviceAddress(confServices.Services["reader"].Gateway.ListenAddress))
cfg.AsertoDirectoryURL = fmt.Sprintf("https://%s", serviceAddress(confServices.Services["reader"].Gateway.ListenAddress))

if confServices.Services["writer"] != nil {
cfg.AsertoDirectoryWriterURL = fmt.Sprintf("https://%s", confServices.Services["writer"].Gateway.ListenAddress)
cfg.AsertoDirectoryWriterURL = fmt.Sprintf("https://%s", serviceAddress(confServices.Services["writer"].Gateway.ListenAddress))
}

if confServices.Services["model"] != nil {
cfg.AsertoDirectoryModelURL = fmt.Sprintf("https://%s", confServices.Services["model"].Gateway.ListenAddress)
cfg.AsertoDirectoryModelURL = fmt.Sprintf("https://%s", serviceAddress(confServices.Services["model"].Gateway.ListenAddress))
}

if serviceConfig, ok := confServices.Services["authorizer"]; ok {
cfg.AuthorizerServiceURL = fmt.Sprintf("https://%s", serviceConfig.Gateway.ListenAddress)
cfg.AuthorizerServiceURL = fmt.Sprintf("https://%s", serviceAddress(serviceConfig.Gateway.ListenAddress))
cfg.AuthorizerAPIKey = apiKey
}

Expand All @@ -91,6 +91,21 @@ func composeConfig(confServices *config.Config, apiKey string) *consoleCfg {
return cfg
}

func serviceAddress(listenAddress string) string {
addr, port, found := strings.Cut(listenAddress, ":")
if addr == "0.0.0.0" {
addr = "localhost"
}

fmt.Println("addr: ", addr)

if found {
return fmt.Sprintf("%s:%s", addr, port)
}

return addr
}

func composeRemoteDiretoryConfig(confServices *config.Config, apiKey string) *consoleCfgWithRemoteDirectory {
cfg := &consoleCfgWithRemoteDirectory{}
host := strings.Split(confServices.DirectoryResolver.Address, ":")[0]
Expand Down

0 comments on commit 577173a

Please sign in to comment.