Skip to content

feat(plugin): Add support for remote grpc plugins #2938

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

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 9 additions & 0 deletions internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
Expand All @@ -15,6 +16,7 @@ import (

"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/status"

"github.com/sqlc-dev/sqlc/internal/codegen/golang"
Expand Down Expand Up @@ -406,6 +408,13 @@ func codegen(ctx context.Context, combo config.CombinedSettings, sql outPair, re
SHA256: plug.WASM.SHA256,
Env: plug.Env,
}
case plug.Remote != nil:
handler, err = grpc.DialContext(ctx, plug.Remote.Target,
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
if err != nil {
return "", nil, err
}

default:
return "", nil, fmt.Errorf("unsupported plugin type")
}
Expand Down
5 changes: 4 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ type Plugin struct {
URL string `json:"url" yaml:"url"`
SHA256 string `json:"sha256" yaml:"sha256"`
} `json:"wasm" yaml:"wasm"`
Remote *struct {
Target string `json:"target" yaml:"target"`
} `json:"remote" yaml:"remote"`
}

type Rule struct {
Expand Down Expand Up @@ -151,7 +154,7 @@ var ErrPluginBuiltin = errors.New("a built-in plugin with that name already exis
var ErrPluginNoName = errors.New("missing plugin name")
var ErrPluginExists = errors.New("a plugin with that name already exists")
var ErrPluginNotFound = errors.New("no plugin found")
var ErrPluginNoType = errors.New("plugin: field `process` or `wasm` required")
var ErrPluginNoType = errors.New("plugin: field `process`, `wasm` or `remote` required")
var ErrPluginBothTypes = errors.New("plugin: `process` and `wasm` cannot both be defined")
var ErrPluginProcessNoCmd = errors.New("plugin: missing process command")

Expand Down
2 changes: 1 addition & 1 deletion internal/config/v_two.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func v2ParseConfig(rd io.Reader) (Config, error) {
if _, ok := plugins[conf.Plugins[i].Name]; ok {
return conf, ErrPluginExists
}
if conf.Plugins[i].Process == nil && conf.Plugins[i].WASM == nil {
if conf.Plugins[i].Process == nil && conf.Plugins[i].WASM == nil && conf.Plugins[i].Remote == nil {
return conf, ErrPluginNoType
}
if conf.Plugins[i].Process != nil && conf.Plugins[i].WASM != nil {
Expand Down