diff options
author | baude <bbaude@redhat.com> | 2019-01-27 09:57:44 -0600 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2019-02-05 10:05:41 -0600 |
commit | 64c8fb7c2460eb561c8496f781f26d65443eea59 (patch) | |
tree | 19a7bae6cd3bc117fa7b2e9dfe44d3534b4f75ed /vendor | |
parent | 3554bfce98bc643bd4724340bf2abbaa6373e70c (diff) | |
download | podman-64c8fb7c2460eb561c8496f781f26d65443eea59.tar.gz podman-64c8fb7c2460eb561c8496f781f26d65443eea59.tar.bz2 podman-64c8fb7c2460eb561c8496f781f26d65443eea59.zip |
podman-remote import|export
addition of import and export for the podman-remote client. This includes
the ability to send and receive files between the remote-client and the
"podman" host using an upgraded varlink connection.
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/github.com/varlink/go/varlink/bridge.go | 21 | ||||
-rw-r--r-- | vendor/github.com/varlink/go/varlink/bridge_windows.go | 17 | ||||
-rw-r--r-- | vendor/github.com/varlink/go/varlink/call.go | 21 | ||||
-rw-r--r-- | vendor/github.com/varlink/go/varlink/connection.go | 84 | ||||
-rw-r--r-- | vendor/github.com/varlink/go/varlink/orgvarlinkservice.go | 53 | ||||
-rw-r--r-- | vendor/github.com/varlink/go/varlink/service.go | 14 |
6 files changed, 159 insertions, 51 deletions
diff --git a/vendor/github.com/varlink/go/varlink/bridge.go b/vendor/github.com/varlink/go/varlink/bridge.go index b20c0925a..0ea5de682 100644 --- a/vendor/github.com/varlink/go/varlink/bridge.go +++ b/vendor/github.com/varlink/go/varlink/bridge.go @@ -5,13 +5,13 @@ package varlink import ( "bufio" "io" - "log" "net" "os/exec" ) type PipeCon struct { net.Conn + cmd *exec.Cmd reader *io.ReadCloser writer *io.WriteCloser } @@ -25,6 +25,8 @@ func (p PipeCon) Close() error { if err2 != nil { return err2 } + p.cmd.Wait() + return nil } @@ -42,18 +44,15 @@ func NewBridge(bridge string) (*Connection, error) { if err != nil { return nil, err } - c.conn = PipeCon{nil, &r, &w} + c.conn = PipeCon{nil, cmd, &r, &w} c.address = "" - c.reader = bufio.NewReader(r) - c.writer = bufio.NewWriter(w) + c.Reader = bufio.NewReader(r) + c.Writer = bufio.NewWriter(w) - go func() { - err := cmd.Run() - if err != nil { - log.Fatal(err) - } - }() + err = cmd.Start() + if err != nil { + return nil, err + } return &c, nil } - diff --git a/vendor/github.com/varlink/go/varlink/bridge_windows.go b/vendor/github.com/varlink/go/varlink/bridge_windows.go index 692367a1a..220ae3156 100644 --- a/vendor/github.com/varlink/go/varlink/bridge_windows.go +++ b/vendor/github.com/varlink/go/varlink/bridge_windows.go @@ -3,13 +3,13 @@ package varlink import ( "bufio" "io" - "log" "net" "os/exec" ) type PipeCon struct { net.Conn + cmd *exec.Cmd reader *io.ReadCloser writer *io.WriteCloser } @@ -23,6 +23,8 @@ func (p PipeCon) Close() error { if err2 != nil { return err2 } + p.cmd.Wait() + return nil } @@ -40,18 +42,15 @@ func NewBridge(bridge string) (*Connection, error) { if err != nil { return nil, err } - c.conn = PipeCon{nil, &r, &w} + c.conn = PipeCon{nil, cmd, &r, &w} c.address = "" c.reader = bufio.NewReader(r) c.writer = bufio.NewWriter(w) - go func() { - err := cmd.Run() - if err != nil { - log.Fatal(err) - } - }() + err = cmd.Start() + if err != nil { + return nil, err + } return &c, nil } - diff --git a/vendor/github.com/varlink/go/varlink/call.go b/vendor/github.com/varlink/go/varlink/call.go index 5e9249c0e..d6e046f1d 100644 --- a/vendor/github.com/varlink/go/varlink/call.go +++ b/vendor/github.com/varlink/go/varlink/call.go @@ -4,6 +4,7 @@ import ( "bufio" "encoding/json" "fmt" + "io" "strings" ) @@ -11,9 +12,11 @@ import ( // client can be terminated by returning an error from the call instead // of sending a reply or error reply. type Call struct { - writer *bufio.Writer + *bufio.Reader + *bufio.Writer in *serviceCall Continues bool + Upgrade bool } // WantsMore indicates if the calling client accepts more than one reply to this method call. @@ -21,6 +24,11 @@ func (c *Call) WantsMore() bool { return c.in.More } +// WantsUpgrade indicates that the calling client wants the connection to be upgraded. +func (c *Call) WantsUpgrade() bool { + return c.in.Upgrade +} + // IsOneway indicate that the calling client does not expect a reply. func (c *Call) IsOneway() bool { return c.in.Oneway @@ -45,11 +53,18 @@ func (c *Call) sendMessage(r *serviceReply) error { } b = append(b, 0) - _, e = c.writer.Write(b) + _, e = c.Writer.Write(b) if e != nil { + if e == io.EOF { + return io.ErrUnexpectedEOF + } return e } - return c.writer.Flush() + e = c.Writer.Flush() + if e == io.EOF { + return io.ErrUnexpectedEOF + } + return e } // Reply sends a reply to this method call. diff --git a/vendor/github.com/varlink/go/varlink/connection.go b/vendor/github.com/varlink/go/varlink/connection.go index ac9542408..596caa825 100644 --- a/vendor/github.com/varlink/go/varlink/connection.go +++ b/vendor/github.com/varlink/go/varlink/connection.go @@ -4,6 +4,7 @@ import ( "bufio" "encoding/json" "fmt" + "io" "net" "strings" ) @@ -15,15 +16,59 @@ const ( More = 1 << iota Oneway = 1 << iota Continues = 1 << iota + Upgrade = 1 << iota ) // Error is a varlink error returned from a method call. type Error struct { - error Name string Parameters interface{} } +func (e *Error) DispatchError() error { + errorRawParameters := e.Parameters.(*json.RawMessage) + + switch e.Name { + case "org.varlink.service.InterfaceNotFound": + var param InterfaceNotFound + if errorRawParameters != nil { + err := json.Unmarshal(*errorRawParameters, ¶m) + if err != nil { + return e + } + } + return ¶m + case "org.varlink.service.MethodNotFound": + var param MethodNotFound + if errorRawParameters != nil { + err := json.Unmarshal(*errorRawParameters, ¶m) + if err != nil { + return e + } + } + return ¶m + case "org.varlink.service.MethodNotImplemented": + var param MethodNotImplemented + if errorRawParameters != nil { + err := json.Unmarshal(*errorRawParameters, ¶m) + if err != nil { + return e + } + } + return ¶m + case "org.varlink.service.InvalidParameter": + var param InvalidParameter + if errorRawParameters != nil { + err := json.Unmarshal(*errorRawParameters, ¶m) + if err != nil { + return e + } + } + return ¶m + } + return e +} + // Error returns the fully-qualified varlink error name. func (e *Error) Error() string { return e.Name @@ -31,10 +76,11 @@ func (e *Error) Error() string { // Connection is a connection from a client to a service. type Connection struct { + io.Closer address string conn net.Conn - reader *bufio.Reader - writer *bufio.Writer + Reader *bufio.Reader + Writer *bufio.Writer } // Send sends a method call. It returns a receive() function which is called to retrieve the method reply. @@ -46,6 +92,7 @@ func (c *Connection) Send(method string, parameters interface{}, flags uint64) ( Parameters interface{} `json:"parameters,omitempty"` More bool `json:"more,omitempty"` Oneway bool `json:"oneway,omitempty"` + Upgrade bool `json:"upgrade,omitempty"` } if (flags&More != 0) && (flags&Oneway != 0) { @@ -55,11 +102,19 @@ func (c *Connection) Send(method string, parameters interface{}, flags uint64) ( } } + if (flags&More != 0) && (flags&Upgrade != 0) { + return nil, &Error{ + Name: "org.varlink.InvalidParameter", + Parameters: "more", + } + } + m := call{ Method: method, Parameters: parameters, More: flags&More != 0, Oneway: flags&Oneway != 0, + Upgrade: flags&Upgrade != 0, } b, err := json.Marshal(m) if err != nil { @@ -67,13 +122,19 @@ func (c *Connection) Send(method string, parameters interface{}, flags uint64) ( } b = append(b, 0) - _, err = c.writer.Write(b) + _, err = c.Writer.Write(b) if err != nil { + if err == io.EOF { + return nil, io.ErrUnexpectedEOF + } return nil, err } - err = c.writer.Flush() + err = c.Writer.Flush() if err != nil { + if err == io.EOF { + return nil, io.ErrUnexpectedEOF + } return nil, err } @@ -84,8 +145,11 @@ func (c *Connection) Send(method string, parameters interface{}, flags uint64) ( Error string `json:"error"` } - out, err := c.reader.ReadBytes('\x00') + out, err := c.Reader.ReadBytes('\x00') if err != nil { + if err == io.EOF { + return 0, io.ErrUnexpectedEOF + } return 0, err } @@ -96,11 +160,11 @@ func (c *Connection) Send(method string, parameters interface{}, flags uint64) ( } if m.Error != "" { - err = &Error{ + e := &Error{ Name: m.Error, Parameters: m.Parameters, } - return 0, err + return 0, e.DispatchError() } if m.Parameters != nil { @@ -220,8 +284,8 @@ func NewConnection(address string) (*Connection, error) { } c.address = address - c.reader = bufio.NewReader(c.conn) - c.writer = bufio.NewWriter(c.conn) + c.Reader = bufio.NewReader(c.conn) + c.Writer = bufio.NewWriter(c.conn) return &c, nil } diff --git a/vendor/github.com/varlink/go/varlink/orgvarlinkservice.go b/vendor/github.com/varlink/go/varlink/orgvarlinkservice.go index 39f843c31..600c99d34 100644 --- a/vendor/github.com/varlink/go/varlink/orgvarlinkservice.go +++ b/vendor/github.com/varlink/go/varlink/orgvarlinkservice.go @@ -1,5 +1,42 @@ package varlink +// The requested interface was not found. +type InterfaceNotFound struct { + Interface string `json:"interface"` +} + +func (e InterfaceNotFound) Error() string { + return "org.varlink.service.InterfaceNotFound" +} + +// The requested method was not found +type MethodNotFound struct { + Method string `json:"method"` +} + +func (e MethodNotFound) Error() string { + return "org.varlink.service.MethodNotFound" +} + +// The interface defines the requested method, but the service does not +// implement it. +type MethodNotImplemented struct { + Method string `json:"method"` +} + +func (e MethodNotImplemented) Error() string { + return "org.varlink.service.MethodNotImplemented" +} + +// One of the passed parameters is invalid. +type InvalidParameter struct { + Parameter string `json:"parameter"` +} + +func (e InvalidParameter) Error() string { + return "org.varlink.service.InvalidParameter" +} + func doReplyError(c *Call, name string, parameters interface{}) error { return c.sendMessage(&serviceReply{ Error: name, @@ -9,36 +46,28 @@ func doReplyError(c *Call, name string, parameters interface{}) error { // ReplyInterfaceNotFound sends a org.varlink.service errror reply to this method call func (c *Call) ReplyInterfaceNotFound(interfaceA string) error { - var out struct { - Interface string `json:"interface,omitempty"` - } + var out InterfaceNotFound out.Interface = interfaceA return doReplyError(c, "org.varlink.service.InterfaceNotFound", &out) } // ReplyMethodNotFound sends a org.varlink.service errror reply to this method call func (c *Call) ReplyMethodNotFound(method string) error { - var out struct { - Method string `json:"method,omitempty"` - } + var out MethodNotFound out.Method = method return doReplyError(c, "org.varlink.service.MethodNotFound", &out) } // ReplyMethodNotImplemented sends a org.varlink.service errror reply to this method call func (c *Call) ReplyMethodNotImplemented(method string) error { - var out struct { - Method string `json:"method,omitempty"` - } + var out MethodNotImplemented out.Method = method return doReplyError(c, "org.varlink.service.MethodNotImplemented", &out) } // ReplyInvalidParameter sends a org.varlink.service errror reply to this method call func (c *Call) ReplyInvalidParameter(parameter string) error { - var out struct { - Parameter string `json:"parameter,omitempty"` - } + var out InvalidParameter out.Parameter = parameter return doReplyError(c, "org.varlink.service.InvalidParameter", &out) } diff --git a/vendor/github.com/varlink/go/varlink/service.go b/vendor/github.com/varlink/go/varlink/service.go index cb461f917..abccffe6a 100644 --- a/vendor/github.com/varlink/go/varlink/service.go +++ b/vendor/github.com/varlink/go/varlink/service.go @@ -22,6 +22,7 @@ type serviceCall struct { Parameters *json.RawMessage `json:"parameters,omitempty"` More bool `json:"more,omitempty"` Oneway bool `json:"oneway,omitempty"` + Upgrade bool `json:"upgrade,omitempty"` } type serviceReply struct { @@ -50,7 +51,7 @@ type Service struct { } // ServiceTimoutError helps API users to special-case timeouts. -type ServiceTimeoutError struct {} +type ServiceTimeoutError struct{} func (ServiceTimeoutError) Error() string { return "service timeout" @@ -73,7 +74,7 @@ func (s *Service) getInterfaceDescription(c Call, name string) error { return c.replyGetInterfaceDescription(description) } -func (s *Service) handleMessage(writer *bufio.Writer, request []byte) error { +func (s *Service) handleMessage(reader *bufio.Reader, writer *bufio.Writer, request []byte) error { var in serviceCall err := json.Unmarshal(request, &in) @@ -83,7 +84,8 @@ func (s *Service) handleMessage(writer *bufio.Writer, request []byte) error { } c := Call{ - writer: writer, + Reader: reader, + Writer: writer, in: &in, } @@ -129,7 +131,7 @@ func (s *Service) handleConnection(conn net.Conn, wg *sync.WaitGroup) { break } - err = s.handleMessage(writer, request[:len(request)-1]) + err = s.handleMessage(reader, writer, request[:len(request)-1]) if err != nil { // FIXME: report error //fmt.Fprintf(os.Stderr, "handleMessage: %v", err) @@ -201,11 +203,11 @@ func getListener(protocol string, address string) (net.Listener, error) { func (s *Service) refreshTimeout(timeout time.Duration) error { switch l := s.listener.(type) { case *net.UnixListener: - if err:= l.SetDeadline(time.Now().Add(timeout)); err != nil { + if err := l.SetDeadline(time.Now().Add(timeout)); err != nil { return err } case *net.TCPListener: - if err:= l.SetDeadline(time.Now().Add(timeout)); err != nil { + if err := l.SetDeadline(time.Now().Add(timeout)); err != nil { return err } |