-
Notifications
You must be signed in to change notification settings - Fork 26
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
oanatmaria
committed
Sep 25, 2023
1 parent
4f9ac98
commit f0f761f
Showing
15 changed files
with
213 additions
and
39 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,16 @@ | ||
ARG GO_VERSION | ||
FROM golang:$GO_VERSION-alpine AS build-dev | ||
RUN apk add --no-cache bash build-base git tree curl protobuf openssh | ||
WORKDIR /src | ||
|
||
ENV GOBIN=/bin | ||
ENV ROOT_DIR=/src | ||
|
||
# generate & build | ||
ARG VERSION | ||
ARG COMMIT | ||
|
||
COPY . . | ||
RUN --mount=type=cache,target=/go/pkg/mod \ | ||
--mount=type=cache,target=/root/.cache/go-build \ | ||
--mount=type=ssh \ | ||
go run mage.go deps build | ||
|
||
FROM alpine | ||
ARG VERSION | ||
ARG COMMIT | ||
|
||
LABEL org.opencontainers.image.version=$VERSION | ||
LABEL org.opencontainers.image.source=https://github.com/aserto-dev/topaz | ||
LABEL org.opencontainers.image.title="Topaz" | ||
LABEL org.opencontainers.image.revision=$COMMIT | ||
LABEL org.opencontainers.image.url=https://aserto.com | ||
|
||
RUN apk add --no-cache bash tzdata | ||
WORKDIR /app | ||
COPY --from=build-dev /src/dist/topazd_linux_amd64_v1/topazd /app/ | ||
|
||
EXPOSE 8282 | ||
EXPOSE 8383 | ||
EXPOSE 8484 | ||
EXPOSE 8585 | ||
EXPOSE 9292 | ||
EXPOSE 8080 | ||
|
||
WORKDIR /app | ||
|
||
COPY dist/topazd_linux_amd64_v1/topazd /app/ | ||
|
||
ENTRYPOINT ["./topazd"] |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ EXPOSE 8383 | |
EXPOSE 8484 | ||
EXPOSE 8585 | ||
EXPOSE 9292 | ||
EXPOSE 8080 | ||
|
||
WORKDIR /app | ||
|
||
|
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
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,35 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
"embed" | ||
|
||
builder "github.com/aserto-dev/service-host" | ||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
//nolint:all | ||
//go:embed console | ||
var console embed.FS | ||
|
||
type ConsoleService struct{} | ||
|
||
func NewConsole() ServiceTypes { | ||
return &ConsoleService{} | ||
} | ||
|
||
func (e *ConsoleService) AvailableServices() []string { | ||
return []string{"console"} | ||
} | ||
|
||
func (e *ConsoleService) GetGRPCRegistrations(services ...string) builder.GRPCRegistrations { | ||
return func(server *grpc.Server) { | ||
} | ||
} | ||
|
||
func (e *ConsoleService) GetGatewayRegistration(services ...string) builder.HandlerRegistrations { | ||
return func(ctx context.Context, mux *runtime.ServeMux, grpcEndpoint string, opts []grpc.DialOption) error { | ||
return nil | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package ui | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/aserto-dev/topaz/pkg/cc/config" | ||
) | ||
|
||
type fsWithDefinition struct { | ||
consoleFS http.FileSystem | ||
} | ||
|
||
func (f *fsWithDefinition) Open(name string) (http.File, error) { | ||
if strings.HasPrefix(name, "/ui/") { | ||
return f.consoleFS.Open("console/build/index.html") | ||
} | ||
|
||
name = strings.TrimPrefix(name, "/public") | ||
return f.consoleFS.Open(fmt.Sprintf("console/build%s", name)) | ||
} | ||
|
||
func UIHandler(consoleFS http.FileSystem) http.Handler { | ||
return http.FileServer(&fsWithDefinition{consoleFS: consoleFS}) | ||
} | ||
|
||
func ConfigHandler(confServices *config.Config) func(w http.ResponseWriter, r *http.Request) { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
type consoleCfg struct { | ||
AsertoDirectoryUrl string `json:"asertoDirectoryUrl"` | ||
AuthorizerServiceUrl string `json:"authorizerServiceUrl"` | ||
AuthorizerApiKey string `json:"authorizerApiKey"` | ||
DirectoryApiKey string `json:"directoryApiKey"` | ||
DirectoryTenantId string `json:"directoryTenantId"` | ||
} | ||
|
||
var apiKey string | ||
for key := range confServices.Auth.APIKeys { | ||
apiKey = key | ||
break | ||
} | ||
|
||
cfg := &consoleCfg{} | ||
if serviceConfig, ok := confServices.Services["authorizer"]; ok { | ||
cfg.AuthorizerServiceUrl = fmt.Sprintf("https://%s", serviceConfig.Gateway.ListenAddress) | ||
cfg.AuthorizerApiKey = apiKey | ||
} | ||
|
||
if serviceConfig, ok := confServices.Services["reader"]; ok { | ||
cfg.AsertoDirectoryUrl = fmt.Sprintf("https://%s", serviceConfig.Gateway.ListenAddress) | ||
} else { | ||
host := strings.Split(confServices.DirectoryResolver.Address, ":")[0] | ||
cfg.AsertoDirectoryUrl = fmt.Sprintf("https://%s", host) | ||
if confServices.DirectoryResolver.TenantID != "" { | ||
cfg.DirectoryTenantId = confServices.DirectoryResolver.TenantID | ||
} | ||
} | ||
|
||
if confServices.DirectoryResolver.APIKey != "" { | ||
cfg.DirectoryApiKey = confServices.DirectoryResolver.APIKey | ||
} | ||
|
||
buf, _ := json.Marshal(cfg) | ||
writeFile(buf, w, r) | ||
} | ||
} | ||
|
||
func AuthorizersHandler(confServices *config.Config) func(w http.ResponseWriter, r *http.Request) { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
type AuthorizerInstance struct { | ||
Name string `json:"name"` | ||
URL string `json:"url"` | ||
APIKey string `json:"apiKey"` | ||
} | ||
type authorizersResult struct { | ||
Results []AuthorizerInstance `json:"results"` | ||
} | ||
|
||
var apiKey string | ||
for key := range confServices.Auth.APIKeys { | ||
apiKey = key | ||
break | ||
} | ||
|
||
var cfg *authorizersResult | ||
if serviceConfig, ok := confServices.Services["authorizer"]; ok { | ||
cfg = &authorizersResult{ | ||
Results: []AuthorizerInstance{{URL: fmt.Sprintf("https://%s", serviceConfig.Gateway.ListenAddress), Name: "authorizer", APIKey: apiKey}}, | ||
} | ||
} else { | ||
cfg = &authorizersResult{} | ||
} | ||
|
||
buf, _ := json.Marshal(cfg) | ||
writeFile(buf, w, r) | ||
} | ||
} | ||
|
||
func writeFile(buf []byte, w http.ResponseWriter, _ *http.Request) { | ||
w.Header().Add("Content-Type", "application/json") | ||
w.Header().Add("Content-Length", strconv.FormatInt(int64(len(buf)), 10)) | ||
_, _ = w.Write(buf) | ||
} |
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
Oops, something went wrong.