Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the go-topaz-ui v0.0.1 #157

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ env:
GO_RELEASER_VERSION: "v1.20.0"
GO_LANGCI_LINT_VERSION: "v1.53.3"
GO_TESTSUM_VERSION: "1.10.1"
CONSOLE_VERSION: "0.0.0-20231109070717.0.gaae6c0a2"

jobs:
test:
Expand Down
5 changes: 0 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ env:
- ORG=aserto-dev
- REPO=topaz

before:
# https://goreleaser.com/customization/hooks/
hooks:
- ./pre-build.sh {{ .Env.CONSOLE_VERSION }}

builds:
# https://goreleaser.com/customization/build/
- id: topazd
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ module github.com/aserto-dev/topaz

go 1.20

// replace github.com/aserto-dev/azm => ../azm
// replace github.com/aserto-dev/go-directory => ../go-directory
// replace github.com/aserto-dev/go-directory-cli => ../go-directory-cli
// replace github.com/aserto-dev/go-edge-ds => ../go-edge-ds
// replace github.com/aserto-dev/go-topaz-ui => ../go-topaz-ui
// replace github.com/aserto-dev/service-host => ../service-host
// replace github.com/aserto-dev/runtime => ../runtime

Expand All @@ -18,10 +17,11 @@ require (
github.com/aserto-dev/errors v0.0.6
github.com/aserto-dev/go-aserto v0.30.0
github.com/aserto-dev/go-authorizer v0.20.3
github.com/aserto-dev/go-directory v0.30.3
github.com/aserto-dev/go-directory v0.30.4
github.com/aserto-dev/go-directory-cli v0.30.1
github.com/aserto-dev/go-edge-ds v0.30.2
github.com/aserto-dev/go-grpc v0.8.59
github.com/aserto-dev/go-topaz-ui v0.0.1
github.com/aserto-dev/header v0.0.5
github.com/aserto-dev/logger v0.0.4
github.com/aserto-dev/openapi-authorizer v0.20.3
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ github.com/aserto-dev/go-authorizer v0.20.3 h1:Jm3CzUKo4WZKt6XV/N1WLwXxCBCHvsLwp
github.com/aserto-dev/go-authorizer v0.20.3/go.mod h1:cwuPKELMmzTwLMYYoIKFwtf9psNYsDXefOGywtTm094=
github.com/aserto-dev/go-decision-logs v0.0.4 h1:beu/mhqZ92ovhSIPOv2f4q0Ci7HWNLla/j/x+ZD5eHw=
github.com/aserto-dev/go-decision-logs v0.0.4/go.mod h1:W50DNu4HPCk+iyI39cP3+KBytdrQYVieSPXh9StuRzA=
github.com/aserto-dev/go-directory v0.30.3 h1:agzqBvC1biaJUBzkJYCqUiKnmNXRQ67JVlxlLFsxu2c=
github.com/aserto-dev/go-directory v0.30.3/go.mod h1:jHn6ckERuci6nWz9vCzAbYoF2UnbOwEzl++sA1L3nyc=
github.com/aserto-dev/go-directory v0.30.4 h1:MifQgaA2ino54mWcmJAbJZSmUPNqat0V/u60EpFd9Vs=
github.com/aserto-dev/go-directory v0.30.4/go.mod h1:jHn6ckERuci6nWz9vCzAbYoF2UnbOwEzl++sA1L3nyc=
github.com/aserto-dev/go-directory-cli v0.30.1 h1:5tEDG7uj//NXEzKkF4cbQbsvPuZzn/3hrhTA0GuG/7A=
github.com/aserto-dev/go-directory-cli v0.30.1/go.mod h1:EvTAQdfREB8Wq5aRJxk3krkBz6/4LUwJjfbc0MjVUl8=
github.com/aserto-dev/go-edge-ds v0.30.2 h1:7ltut961B583/ix9AwmkO1M8qh0Wedy+3Wfdzhk/PVU=
Expand All @@ -440,6 +440,8 @@ github.com/aserto-dev/go-grpc v0.8.59 h1:GWNgYUYPdLy6F1tMktSQWfls82nhrQXAY2NBM9z
github.com/aserto-dev/go-grpc v0.8.59/go.mod h1:2FcclMDheTsEvYCY72o+EwTaoO0ti3/it4G6xIlzNIM=
github.com/aserto-dev/go-http-metrics v0.10.1-20221024-1 h1:nONd24V5nyJ0IIw8QE+OKv30YuHOTNbJ4FsvczLaM8o=
github.com/aserto-dev/go-http-metrics v0.10.1-20221024-1/go.mod h1:QnWF5/X2U/kmbu7GEw+zupvqX2hIthDjyXlRTwt2zEI=
github.com/aserto-dev/go-topaz-ui v0.0.1 h1:Z6tkKrfXIEwVICGQmHNT8kxZJIwEo5SrZugUWMhi7fE=
github.com/aserto-dev/go-topaz-ui v0.0.1/go.mod h1:BdW4vOhuG0HkjNH4L4omcNa/RJJ4LaxFzbw92qc+pc8=
github.com/aserto-dev/header v0.0.5 h1:nEvYNgBoIwomxuvo14JuQ/ZqGGHU67NKuZyNdW4n4FU=
github.com/aserto-dev/header v0.0.5/go.mod h1:LNgRo3gStS71lO1d9Oue9e9kfVvirvUHvdZClzDmNwo=
github.com/aserto-dev/logger v0.0.4 h1:GF+17mhn03ZnE5KHCszrzGRcZULgczsql+y+PCHjgpI=
Expand Down
1 change: 0 additions & 1 deletion magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const containerImage string = "topaz"
func init() {
os.Setenv("GO_VERSION", "1.20")
os.Setenv("DOCKER_BUILDKIT", "1")
os.Setenv("CONSOLE_VERSION", "0.0.0-20231109070717.0.gaae6c0a2")
}

// Generate generates all code.
Expand Down
1 change: 0 additions & 1 deletion pkg/app/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type Authorizer struct {

const (
authorizerService = "authorizer"
consoleService = "console"
)

func NewAuthorizer(cfg *builder.API, commonConfig *config.Common, authorizerOpts []grpc.ServerOption, logger *zerolog.Logger) (ServiceTypes, error) {
Expand Down
53 changes: 48 additions & 5 deletions pkg/app/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ package app

import (
"context"
"embed"
"fmt"
"strings"

"github.com/aserto-dev/go-topaz-ui/ui"
builder "github.com/aserto-dev/service-host"
"github.com/aserto-dev/topaz/pkg/cc/config"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
)

//nolint:all
//go:embed console
var console embed.FS

type ConsoleService struct{}

const (
consoleService = "console"
)

func NewConsole() ServiceTypes {
return &ConsoleService{}
}
Expand All @@ -37,3 +40,43 @@ func (e *ConsoleService) GetGatewayRegistration(services ...string) builder.Hand
func (e *ConsoleService) Cleanups() []func() {
return nil
}

func (e *ConsoleService) PrepareConfig(cfg *config.Config) *ui.ConsoleCfg {
authorizerURL := ""
if serviceConfig, ok := cfg.APIConfig.Services[authorizerService]; ok {
authorizerURL = getGatewayAddress(serviceConfig)
}
readerURL := ""
if serviceConfig, ok := cfg.APIConfig.Services[readerService]; ok {
readerURL = getGatewayAddress(serviceConfig)
}
if readerURL == "" {
host := strings.Split(cfg.DirectoryResolver.Address, ":")[0]
readerURL = fmt.Sprintf("https://%s", host)
}
writerURL := ""
if serviceConfig, ok := cfg.APIConfig.Services[writerService]; ok {
readerURL = getGatewayAddress(serviceConfig)
}
modelURL := ""
if serviceConfig, ok := cfg.APIConfig.Services[modelService]; ok {
readerURL = getGatewayAddress(serviceConfig)
}
return &ui.ConsoleCfg{
AsertoDirectoryURL: readerURL,
DirectoryAPIKey: cfg.DirectoryResolver.APIKey,
DirectoryTenantID: cfg.DirectoryResolver.TenantID,
AuthorizerServiceURL: authorizerURL,
AsertoDirectoryReaderURL: &readerURL,
AsertoDirectoryWriterURL: &writerURL,
AsertoDirectoryModelURL: &modelURL,
}
}

func getGatewayAddress(serviceConfig *builder.API) string {
if serviceConfig.Gateway.HTTP {
return fmt.Sprintf("http://%s", serviceConfig.Gateway.ListenAddress)
} else {
return fmt.Sprintf("https://%s", serviceConfig.Gateway.ListenAddress)
}
}
23 changes: 15 additions & 8 deletions pkg/app/topaz.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/aserto-dev/topaz/decision_log/logger/file"
"github.com/aserto-dev/topaz/decision_log/logger/nop"
"github.com/aserto-dev/topaz/pkg/app/middlewares"
"github.com/aserto-dev/topaz/pkg/app/ui"

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"

Expand All @@ -24,6 +23,8 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/health/grpc_health_v1"

console "github.com/aserto-dev/go-topaz-ui"
"github.com/aserto-dev/go-topaz-ui/ui"
builder "github.com/aserto-dev/service-host"
)

Expand Down Expand Up @@ -145,11 +146,15 @@ func (e *Topaz) ConfigServices() error {
return err
}

if contains(serviceConfig.registeredServices, "console") {
server.Gateway.Mux.Handle("/ui/", ui.UIHandler(http.FS(console)))
server.Gateway.Mux.Handle("/public/", ui.UIHandler(http.FS(console)))
server.Gateway.Mux.HandleFunc("/api/v1/config", ui.ConfigHandler(e.Configuration))
server.Gateway.Mux.HandleFunc("/api/v1/authorizers", ui.AuthorizersHandler(e.Configuration))
if con, ok := e.Services[consoleService]; ok {
consoleConfig := con.(*ConsoleService).PrepareConfig(e.Configuration)

if contains(serviceConfig.registeredServices, "console") {
server.Gateway.Mux.Handle("/ui/", ui.UIHandler(http.FS(console.FS)))
server.Gateway.Mux.Handle("/public/", ui.UIHandler(http.FS(console.FS)))
server.Gateway.Mux.HandleFunc("/api/v1/config", ui.ConfigHandler(consoleConfig))
server.Gateway.Mux.HandleFunc("/api/v1/authorizers", ui.AuthorizersHandler(consoleConfig))
}
}

err = e.Manager.AddGRPCServer(server)
Expand Down Expand Up @@ -299,8 +304,10 @@ func (e *Topaz) validateConfig() error {
}

if _, ok := e.Configuration.APIConfig.Services["console"]; ok {
if _, ok := e.Configuration.APIConfig.Services["model"]; !ok {
return errors.New("console needs the model service to be configured")
if _, ok := e.Configuration.APIConfig.Services["reader"]; ok {
if _, ok := e.Configuration.APIConfig.Services["model"]; !ok {
return errors.New("console needs the model service to be configured")
}
}
}

Expand Down
162 changes: 0 additions & 162 deletions pkg/app/ui/handler.go

This file was deleted.

7 changes: 0 additions & 7 deletions pre-build.sh

This file was deleted.

Loading