mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
7c260f88d1
* feat: Create provisioner abstraction Creates a provisioner abstraction that takes prior art from the Terraform plugin system. It's safe to assume this code will change a lot when it becomes integrated with provisionerd. Closes #10. * Ignore generated files in diff view * Check for unstaged file changes * Install protoc-gen-go * Use proper drpc plugin version * Fix serve closed pipe * Install sqlc with curl for speed * Fix install command * Format CI action * Add linguist-generated and closed pipe test * Cleanup code from comments * Add dRPC comment * Add Terraform installer for cross-platform * Build provisioner tests on Linux only
45 lines
928 B
Go
45 lines
928 B
Go
package provisionersdk
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"storj.io/drpc"
|
|
)
|
|
|
|
// Transport creates a dRPC transport using stdin and stdout.
|
|
func TransportStdio() drpc.Transport {
|
|
return &transport{
|
|
in: os.Stdin,
|
|
out: os.Stdout,
|
|
}
|
|
}
|
|
|
|
// TransportPipe creates an in-memory pipe for dRPC transport.
|
|
func TransportPipe() (drpc.Transport, drpc.Transport) {
|
|
clientReader, serverWriter := io.Pipe()
|
|
serverReader, clientWriter := io.Pipe()
|
|
clientTransport := &transport{clientReader, clientWriter}
|
|
serverTransport := &transport{serverReader, serverWriter}
|
|
|
|
return clientTransport, serverTransport
|
|
}
|
|
|
|
// transport wraps an input and output to pipe data.
|
|
type transport struct {
|
|
in io.ReadCloser
|
|
out io.Writer
|
|
}
|
|
|
|
func (s *transport) Read(data []byte) (int, error) {
|
|
return s.in.Read(data)
|
|
}
|
|
|
|
func (s *transport) Write(data []byte) (int, error) {
|
|
return s.out.Write(data)
|
|
}
|
|
|
|
func (s *transport) Close() error {
|
|
return s.in.Close()
|
|
}
|