Skip to content

Commit

Permalink
Update UI Server
Browse files Browse the repository at this point in the history
  • Loading branch information
temporal-data committed Jan 29, 2024
1 parent 51d2aa1 commit 8a76156
Show file tree
Hide file tree
Showing 138 changed files with 304 additions and 243 deletions.
24 changes: 11 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ go 1.20

require (
github.com/coreos/go-oidc/v3 v3.1.0
github.com/gogo/gateway v1.1.0
github.com/gorilla/securecookie v1.1.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1
github.com/labstack/echo/v4 v4.9.1
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.3.0
go.temporal.io/api v1.24.1-0.20231020155655-224b196919ea
golang.org/x/net v0.17.0
golang.org/x/oauth2 v0.11.0
go.temporal.io/api v1.26.2-0.20231129165614-630d88440548
golang.org/x/net v0.19.0
golang.org/x/oauth2 v0.13.0
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
gopkg.in/validator.v2 v2.0.0-20210331031555-b37d688a7fb0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/labstack/gommon v0.4.0 // indirect
Expand All @@ -31,15 +30,14 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/genproto v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
)

Expand Down
123 changes: 25 additions & 98 deletions go.sum

Large diffs are not rendered by default.

54 changes: 44 additions & 10 deletions server/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
"fmt"
"net/http"

"github.com/gogo/gateway"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/labstack/echo/v4"
"golang.org/x/net/context"
"google.golang.org/grpc"
Expand All @@ -37,7 +36,12 @@ import (
"github.com/temporalio/ui-server/v2/server/rpc"
"github.com/temporalio/ui-server/v2/server/version"
"go.temporal.io/api/operatorservice/v1"
"go.temporal.io/api/serviceerror"
"go.temporal.io/api/temporalproto"
"go.temporal.io/api/workflowservice/v1"

// DO NOT REMOVE
_ "go.temporal.io/api/temporalproto"
)

type Auth struct {
Expand Down Expand Up @@ -142,6 +146,36 @@ func GetSettings(cfgProvider *config.ConfigProviderWithRefresh) func(echo.Contex
}
}

func errorHandler(
ctx context.Context,
mux *runtime.ServeMux,
marshaler runtime.Marshaler,
w http.ResponseWriter,
r *http.Request,
err error,
) {
// Convert the error using serviceerror. The result does not conform to Google
// gRPC status directly (it conforms to gogo gRPC status), but Err() does
// based on internal code reading. However, Err() uses Google proto Any
// which our marshaler is not expecting. So instead we are embedding similar
// logic to runtime.DefaultHTTPProtoErrorHandler in here but with gogo
// support. We don't implement custom content type marshaler or trailers at
// this time.
s := serviceerror.ToStatus(err)
w.Header().Set("Content-Type", marshaler.ContentType(struct{}{}))

buf, merr := marshaler.Marshal(s.Proto())
if merr != nil {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(`{"code": 13, "message": "failed to marshal error message"}`))
return
}

w.WriteHeader(runtime.HTTPStatusFromCode(s.Code()))
_, _ = w.Write(buf)
}

func getTemporalClientMux(c echo.Context, temporalConn *grpc.ClientConn, apiMiddleware []Middleware) (*runtime.ServeMux, error) {
var muxOpts []runtime.ServeMuxOption
for _, m := range apiMiddleware {
Expand All @@ -152,9 +186,10 @@ func getTemporalClientMux(c echo.Context, temporalConn *grpc.ClientConn, apiMidd
append(muxOpts,
withMarshaler(),
version.WithVersionHeader(c),
runtime.WithUnescapingMode(runtime.UnescapingModeAllExceptReserved),
// This is necessary to get error details properly
// marshalled in unary requests.
runtime.WithProtoErrorHandler(runtime.DefaultHTTPProtoErrorHandler),
runtime.WithErrorHandler(errorHandler),
)...,
)

Expand All @@ -169,11 +204,10 @@ func getTemporalClientMux(c echo.Context, temporalConn *grpc.ClientConn, apiMidd
}

func withMarshaler() runtime.ServeMuxOption {
jsonpb := &gateway.JSONPb{
EmitDefaults: true,
Indent: " ",
OrigName: false,
}

return runtime.WithMarshalerOption(runtime.MIMEWildcard, jsonpb)
return runtime.WithMarshalerOption(runtime.MIMEWildcard, temporalProtoMarshaler{
contentType: runtime.MIMEWildcard,
mOpts: temporalproto.CustomJSONMarshalOptions{
Indent: " ",
},
})
}
101 changes: 101 additions & 0 deletions server/api/marshaler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package api

import (
"encoding/json"
"io"

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"go.temporal.io/api/temporalproto"
"google.golang.org/protobuf/proto"
)

type temporalProtoMarshaler struct {
contentType string
mOpts temporalproto.CustomJSONMarshalOptions
uOpts temporalproto.CustomJSONUnmarshalOptions
}

type temporalProtoEncoder struct {
mOpts temporalproto.CustomJSONMarshalOptions
writer io.Writer
json *json.Encoder
}

type temporalProtoDecoder struct {
uOpts temporalproto.CustomJSONUnmarshalOptions
reader io.Reader
json *json.Decoder
}

func (p temporalProtoMarshaler) Marshal(v any) ([]byte, error) {
if m, ok := v.(proto.Message); ok {
return p.mOpts.Marshal(m)
}

if p.mOpts.Indent != "" {
return json.MarshalIndent(v, "", p.mOpts.Indent)
}

return json.Marshal(v)
}

func (p temporalProtoMarshaler) Unmarshal(data []byte, v interface{}) error {
if m, ok := v.(proto.Message); ok {
return p.uOpts.Unmarshal(data, m)
}

return json.Unmarshal(data, v)
}

func (p temporalProtoMarshaler) NewDecoder(r io.Reader) runtime.Decoder {
return temporalProtoDecoder{
p.uOpts,
r,
json.NewDecoder(r),
}
}

func (p temporalProtoMarshaler) NewEncoder(w io.Writer) runtime.Encoder {
return temporalProtoEncoder{
p.mOpts,
w,
json.NewEncoder(w),
}
}

func (p temporalProtoMarshaler) ContentType(_ any) string {
return p.contentType
}

func (d temporalProtoDecoder) Decode(v any) error {
m, ok := v.(proto.Message)
if !ok {
return d.json.Decode(v)
}

var bs json.RawMessage
if err := d.json.Decode(&bs); err != nil {
return err
}

return d.uOpts.Unmarshal([]byte(bs), m)
}

func (e temporalProtoEncoder) Encode(v any) error {
m, ok := v.(proto.Message)
if !ok {
return e.json.Encode(v)
}

bs, err := e.mOpts.Marshal(m)
if err != nil {
return err
}

_, err = e.writer.Write(bs)
if err != nil {
return err
}
_, err = e.writer.Write([]byte{'\n'})
return err
}
2 changes: 1 addition & 1 deletion server/api/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package api

import (
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/labstack/echo/v4"
)

Expand Down
2 changes: 1 addition & 1 deletion server/headers/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"context"
"net/http"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/labstack/echo/v4"
"github.com/temporalio/ui-server/v2/server/api"
"google.golang.org/grpc/metadata"
Expand Down
2 changes: 1 addition & 1 deletion server/version/with_version_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"context"
"net/http"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/labstack/echo/v4"
"google.golang.org/grpc/metadata"
)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8a76156

Please sign in to comment.