github.com/mendersoftware/go-lib-micro@v0.0.0-20240304135804-e8e39c59b148/ws/filetransfer/model.go (about)

     1  // Copyright 2023 Northern.tech AS
     2  //
     3  //    Licensed under the Apache License, Version 2.0 (the "License");
     4  //    you may not use this file except in compliance with the License.
     5  //    You may obtain a copy of the License at
     6  //
     7  //        http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  //    Unless required by applicable law or agreed to in writing, software
    10  //    distributed under the License is distributed on an "AS IS" BASIS,
    11  //    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  //    See the License for the specific language governing permissions and
    13  //    limitations under the License.
    14  
    15  package filetransfer
    16  
    17  import "time"
    18  
    19  const (
    20  	// MessageTypeGet requests a file from the device.
    21  	MessageTypeGet = "get_file"
    22  	// MessageTypePut requests a file upload to the device. The body MUST
    23  	// contain a FileInfo object.
    24  	MessageTypePut = "put_file"
    25  	// MessageTypeACK messages MUST be sent in response to a
    26  	// file_chunk or put_file message.
    27  	MessageTypeACK = "ack"
    28  	// MessageTypeStat requests file information from the device. The body
    29  	// MUST contain a StatFile object.
    30  	MessageTypeStat = "stat"
    31  	// MessageTypeFileInfo is a response to a MessageTypeStat request.
    32  	// The body MUST contain a FileInfo object.
    33  	MessageTypeFileInfo = "file_info"
    34  	// MessageTypeChunk is the message type for streaming file chunks. The
    35  	// body contains a binary slice of the file, and optional "offset" property
    36  	// can be passed in the header.
    37  	MessageTypeChunk = "file_chunk"
    38  	// MessageTypeError is returned on internal or protocol errors. The
    39  	// body MUST contain an Error object.
    40  	MessageTypeError = "error"
    41  )
    42  
    43  // The Error struct is passed in the Body of MsgProto in case the message type is ErrorMessage
    44  type Error struct {
    45  	// The error description, as in "Permission denied while opening a file"
    46  	Error *string `msgpack:"err" json:"error"`
    47  	// Type of message that raised the error
    48  	MessageType *string `msgpack:"msgtype,omitempty" json:"message_type,omitempty"`
    49  	// Message id is passed in the MsgProto Properties, and in case it is available and
    50  	// error occurs it is passed for reference in the Body of the error message
    51  	MessageID *string `msgpack:"msgid,omitempty" json:"message_id,omitempty"`
    52  }
    53  
    54  // Get file requests the flow of MessageTypeFileChunk messages to be started from the remote end
    55  type GetFile struct {
    56  	// The file path to the file we are requesting
    57  	Path *string `msgpack:"path,omitempty" json:"path,omitempty"`
    58  }
    59  
    60  // Stat file requests the file stat structure from the remote end
    61  type StatFile struct {
    62  	// The file path to the file we are requesting
    63  	Path *string `msgpack:"path" json:"path,omitempty"`
    64  }
    65  
    66  // FileInfo is the object returned from a StatFile request and is also used
    67  // for "put_file" requests for specifying the target file.
    68  type FileInfo struct {
    69  	// The file path to the file we are sending status for
    70  	Path *string `msgpack:"path" json:"path"`
    71  	// The file size
    72  	Size *int64 `msgpack:"size,omitempty" json:"size,omitempty"`
    73  	// The file owner
    74  	UID *uint32 `msgpack:"uid,omitempty" json:"uid,omitempty"`
    75  	// The file group
    76  	GID *uint32 `msgpack:"gid,omitempty" json:"gid,omitempty"`
    77  	// Mode contains the file mode and permission bits.
    78  	Mode *uint32 `msgpack:"mode,omitempty" json:"mode,omitempty"`
    79  	// ModTime is the last modification time for the file.
    80  	ModTime *time.Time `msgpack:"modtime,omitempty" json:"modification_time,omitempty"`
    81  }
    82  
    83  type UploadRequest struct {
    84  	// SrcPath is the (optional) source filename which will be appended
    85  	// to the target path if it points to a directory.
    86  	SrcPath *string `msgpack:"src_path,omitempty" json:"src_path,omitempty"`
    87  	// The file path to the file we are sending status for
    88  	Path *string `msgpack:"path" json:"path"`
    89  	// The file size
    90  	Size *int64 `msgpack:"size,omitempty" json:"size,omitempty"`
    91  	// The file owner
    92  	UID *uint32 `msgpack:"uid,omitempty" json:"uid,omitempty"`
    93  	// The file group
    94  	GID *uint32 `msgpack:"gid,omitempty" json:"gid,omitempty"`
    95  	// Mode contains the file mode and permission bits.
    96  	Mode *uint32 `msgpack:"mode,omitempty" json:"mode,omitempty"`
    97  	// ModTime is the last modification time for the file.
    98  	ModTime *time.Time `msgpack:"modtime,omitempty" json:"modification_time,omitempty"`
    99  }