diff --git a/internal/cmd/generate.go b/internal/cmd/generate.go index 0865705db7..bf7d687319 100644 --- a/internal/cmd/generate.go +++ b/internal/cmd/generate.go @@ -3,6 +3,7 @@ package cmd import ( "bytes" "context" + "crypto/tls" "encoding/json" "errors" "fmt" @@ -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" @@ -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") } diff --git a/internal/config/config.go b/internal/config/config.go index e11f40de48..d5a71dd161 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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 { @@ -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") diff --git a/internal/config/v_two.go b/internal/config/v_two.go index 30a8f58371..98e4cad50d 100644 --- a/internal/config/v_two.go +++ b/internal/config/v_two.go @@ -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 {