( ctx context.Context, e *echo.Echo, stores *store.Store, sheetManager *sheet.Manager, dbFactory *dbfactory.DBFactory, licenseService *enterprise.LicenseService, profile *config.Profile, bus *bus.Bus, schemaSyncer *schemasync.Syncer, webhookManager *webhook.Manager, iamManager *iam.Manager, secret string, sampleInstanceManager *sampleinstance.Manager, )
| 38 | ) |
| 39 | |
| 40 | func configureGrpcRouters( |
| 41 | ctx context.Context, |
| 42 | e *echo.Echo, |
| 43 | stores *store.Store, |
| 44 | sheetManager *sheet.Manager, |
| 45 | dbFactory *dbfactory.DBFactory, |
| 46 | licenseService *enterprise.LicenseService, |
| 47 | profile *config.Profile, |
| 48 | bus *bus.Bus, |
| 49 | schemaSyncer *schemasync.Syncer, |
| 50 | webhookManager *webhook.Manager, |
| 51 | iamManager *iam.Manager, |
| 52 | secret string, |
| 53 | sampleInstanceManager *sampleinstance.Manager, |
| 54 | ) error { |
| 55 | // Note: the gateway response modifier takes the token duration on server startup. If the value is changed, |
| 56 | // the user has to restart the server to take the latest value. |
| 57 | gatewayMarshaler := &grpcruntime.HTTPBodyMarshaler{ |
| 58 | Marshaler: newSuggestingMarshaler(&grpcruntime.JSONPb{ |
| 59 | MarshalOptions: protojson.MarshalOptions{}, |
| 60 | //nolint:forbidigo |
| 61 | UnmarshalOptions: protojson.UnmarshalOptions{}, |
| 62 | }), |
| 63 | } |
| 64 | mux := grpcruntime.NewServeMux( |
| 65 | grpcruntime.WithMarshalerOption(grpcruntime.MIMEWildcard, gatewayMarshaler), |
| 66 | // pass through request headers that need to be used by connect rpc handlers. |
| 67 | grpcruntime.WithIncomingHeaderMatcher(func(key string) (string, bool) { |
| 68 | switch strings.ToLower(key) { |
| 69 | // grpc-gateway hard codes authorization pass-through already, we do it again anyways. |
| 70 | // https://github.com/grpc-ecosystem/grpc-gateway/blob/2cca0efe61de30f05068b9e3b4eb4801b1b2c1aa/runtime/context.go#L160 |
| 71 | case "authorization", "cookie", "origin": |
| 72 | return key, true |
| 73 | default: |
| 74 | return "", false |
| 75 | } |
| 76 | }), |
| 77 | grpcruntime.WithOutgoingHeaderMatcher(func(key string) (string, bool) { |
| 78 | switch strings.ToLower(key) { |
| 79 | case "set-cookie": |
| 80 | return key, true |
| 81 | default: |
| 82 | return "", false |
| 83 | } |
| 84 | }), |
| 85 | grpcruntime.WithRoutingErrorHandler(func(ctx context.Context, sm *grpcruntime.ServeMux, m grpcruntime.Marshaler, w http.ResponseWriter, r *http.Request, httpStatus int) { |
| 86 | err := &grpcruntime.HTTPStatusError{ |
| 87 | HTTPStatus: httpStatus, |
| 88 | Err: connect.NewError(connect.CodeNotFound, errors.Errorf("gateway routing error %d: request method %v, URI %v", httpStatus, r.Method, r.RequestURI)), |
| 89 | } |
| 90 | grpcruntime.DefaultHTTPErrorHandler(ctx, sm, m, w, r, err) |
| 91 | }), |
| 92 | ) |
| 93 | aiService := apiv1.NewAIService(stores) |
| 94 | accessGrantService := apiv1.NewAccessGrantService(stores, licenseService, webhookManager, bus) |
| 95 | actuatorService := apiv1.NewActuatorService(stores, profile, schemaSyncer, licenseService, sampleInstanceManager) |
| 96 | auditLogService := apiv1.NewAuditLogService(stores, licenseService) |
| 97 | authService := apiv1.NewAuthService(stores, secret, licenseService, profile, iamManager) |
no test coverage detected