Documentation ¶
Overview ¶
module defining the fileserver. this holds all the structs and configuration functions needed to get the sever up and running.
Index ¶
- func RunServer(srv *FServer, cfg *GrpcConfig) (err error)
- type BytesEncryptor
- type FServer
- func (fsrv *FServer) DecryptFile(ctx context.Context, fr *filehandler.FileRequest) (response *protocommon.StatusMessage, err error)
- func (fsrv *FServer) DeleteFile(ctx context.Context, req *filehandler.FileRequest) (resp *protocommon.StatusMessage, err error)
- func (fsrv *FServer) DownloadFile(srv filehandler.Fileservice_DownloadFileServer) (err error)
- func (fsrv *FServer) EncryptFile(ctx context.Context, fr *filehandler.FileRequest) (response *protocommon.StatusMessage, err error)
- func (fsrv *FServer) ListFiles(mpty *protocommon.Empty, srv filehandler.Fileservice_ListFilesServer) (err error)
- func (fsrv *FServer) MakeDirectory(ctx context.Context, dirreq *filehandler.MakeDirectoryRequest) (retstatus *protocommon.StatusMessage, err error)
- func (fsrv *FServer) Ping(ctx context.Context, ping *pingpong.Ping) (pong *pingpong.Pong, err error)
- func (fsrv *FServer) RenameFile(ctx context.Context, rnreq *filehandler.RenameFileRequest) (resp *protocommon.StatusMessage, err error)
- func (fsrv *FServer) StorageBreakdown(ctx context.Context, mpty *protocommon.Empty) (consumption *filehandler.StorageInfo, err error)
- func (fsrv *FServer) UploadFile(req *filehandler.FileRequest, srv filehandler.Fileservice_UploadFileServer) (err error)
- type FServerOption
- type FSrvOptFunc
- func WithAuthenticator(authenticator ofsauthenticators.OFSAuthenticator) FSrvOptFunc
- func WithDebug() FSrvOptFunc
- func WithDirRoot(dirpath string) FSrvOptFunc
- func WithDownloadsDir(dirname string) FSrvOptFunc
- func WithEncryptor(encryptor OFSEncryptor) FSrvOptFunc
- func WithMaxDownloads(max int) FSrvOptFunc
- func WithMaxUploads(max int) FSrvOptFunc
- func WithTransferTimeout(timeout time.Duration) FSrvOptFunc
- func WithUploadsDir(dirname string) FSrvOptFunc
- type GrpcConfig
- type GrpcConfigOpt
- type GrpcOptFunc
- type OFSEncryptor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunServer ¶
func RunServer(srv *FServer, cfg *GrpcConfig) (err error)
function designed to start the gRPC file server using the specified gRPC configuration.
Types ¶
type BytesEncryptor ¶ added in v0.4.0
type BytesEncryptor interface { // decrypt provided ciphertext and return the // resulting plaintext. DecryptBytes([]byte) ([]byte, error) // encrypt provided plaintext and return the // resulting ciphertext. EncryptBytes([]byte) ([]byte, error) }
interface defining an object that can perform vaious encryption methods on bytes.
type FServer ¶
type FServer struct { filehandler.UnimplementedFileserviceServer // contains filtered or unexported fields }
fileserver object. this can be added to an existing grpc server by registering it with the filehandler service via "filehandler.RegisterFileserviceServer".
func NewOFS ¶
func NewOFS(opts ...FSrvOptFunc) (srv *FServer, err error)
create, initialize and return a new instance of a file server object.
for Rootdir: if no rootdir is specified, the root directory will be set to the current working directory. this can be set using the WithDirRoot function. the WithDirRoot function will automatically detect if the specified directory is an absolute or relative path. if the path is relative it will be prepended with the current working directory.
for Uploadsdir and Downloadsdir: if no value is specified, no subdirectory will be created within the server's root directory. these can be set using the WithDownloadsDir and WithUploadsDir functions.
func (*FServer) DecryptFile ¶ added in v0.4.0
func (fsrv *FServer) DecryptFile(ctx context.Context, fr *filehandler.FileRequest) (response *protocommon.StatusMessage, err error)
function designed to encrypt a file as requested by the client.
func (*FServer) DeleteFile ¶ added in v0.1.0
func (fsrv *FServer) DeleteFile(ctx context.Context, req *filehandler.FileRequest) (resp *protocommon.StatusMessage, err error)
function designed to delete a file in the uploads directory as requested by the client.
func (*FServer) DownloadFile ¶
func (fsrv *FServer) DownloadFile(srv filehandler.Fileservice_DownloadFileServer) (err error)
function designed to download a file from a client to the server.
this will save the file uploaded by the client to the root directory or downloads directory (if one has been set).
func (*FServer) EncryptFile ¶ added in v0.4.0
func (fsrv *FServer) EncryptFile(ctx context.Context, fr *filehandler.FileRequest) (response *protocommon.StatusMessage, err error)
function designed to encrypt a file as requested by the client.
func (*FServer) ListFiles ¶ added in v0.1.0
func (fsrv *FServer) ListFiles(mpty *protocommon.Empty, srv filehandler.Fileservice_ListFilesServer) (err error)
function designed to list out the files in the directory the client has the ability to download files from. if there are separate upload and download directories, only the "uploads" (files that can be uploaded from the server to client) directory will be listed.
func (*FServer) MakeDirectory ¶ added in v0.1.0
func (fsrv *FServer) MakeDirectory(ctx context.Context, dirreq *filehandler.MakeDirectoryRequest) (retstatus *protocommon.StatusMessage, err error)
function designed to create a new sub-directory within the uploads directory. if the sub-directory has sub-directories, this function will attempt to create all directories.
successful code: 201 Created
failure code: 500 Internal Server Error
func (*FServer) Ping ¶ added in v0.2.0
func (fsrv *FServer) Ping(ctx context.Context, ping *pingpong.Ping) (pong *pingpong.Pong, err error)
function designed to let the client know that the server is up and able to be contacted.
func (*FServer) RenameFile ¶ added in v0.1.0
func (fsrv *FServer) RenameFile(ctx context.Context, rnreq *filehandler.RenameFileRequest) (resp *protocommon.StatusMessage, err error)
function designed to rename a file in the uploads directory. this will move the source file to the destination.
if the file does not already exist, the success or failure status will be transmitted to the client using a StatusMessage object. the code should be used to determine whether the copy was successful or not.
success status code: 200 OK
failure status code: 500 Internal Server Error
note: if the destination file already exists, or if there is an issue related to permissions, an error will be returned.
func (*FServer) StorageBreakdown ¶ added in v0.3.0
func (fsrv *FServer) StorageBreakdown(ctx context.Context, mpty *protocommon.Empty) (consumption *filehandler.StorageInfo, err error)
function designed to calculate and return the amount of storage (in bytes) consumed by the uploads and downloads directories.
func (*FServer) UploadFile ¶
func (fsrv *FServer) UploadFile(req *filehandler.FileRequest, srv filehandler.Fileservice_UploadFileServer) (err error)
function designed to upload a requested file from the server to the client.
the specified file must exist in the root directory (or the uploads directory if one is specified) for a successful (nil error) return.
type FServerOption ¶
type FServerOption struct { // authenticator to use while processing requests. Authenticator ofsauthenticators.OFSAuthenticator // if this is set to true, output will be printed to // STDOUT while the server is running. Debug bool // subdirectory within the rootdir where uploaded // files will be saved. Downloadsdir string // encryptor the fileserver will use. Encryptor OFSEncryptor // number of maximum concurrent downloads the server is // allowed to have active at one time. MaxDownloads int // number of maximum concurrent uploads the server is // allowed to have active at one time. MaxUploads int // fileserver root directory. Rootdir string // maximum allowed time a file upload or download can take. TransferTimeout time.Duration // subdirectory within the rootdir where files that // can be downloaded to a client are stored. Uploadsdir string }
object used to set the confiruation options for a new fileserver.
type FSrvOptFunc ¶
type FSrvOptFunc func(*FServerOption) error
func WithAuthenticator ¶ added in v0.5.0
func WithAuthenticator(authenticator ofsauthenticators.OFSAuthenticator) FSrvOptFunc
set the authenticator to use while processing requests from clients.
func WithDebug ¶
func WithDebug() FSrvOptFunc
turn server debug mode on. this will cause messages to be printed to STDOUT while the server runs.
func WithDirRoot ¶
func WithDirRoot(dirpath string) FSrvOptFunc
specify root directory for files.
this will automatically detect whether a path is relative or absolute.
func WithDownloadsDir ¶
func WithDownloadsDir(dirname string) FSrvOptFunc
set the downloads directory within the root directory.
func WithEncryptor ¶ added in v0.4.0
func WithEncryptor(encryptor OFSEncryptor) FSrvOptFunc
set the encryptor the fileserver will use.
func WithMaxDownloads ¶ added in v0.3.0
func WithMaxDownloads(max int) FSrvOptFunc
set the maximum number of concurrent downloads allowed at one time.
func WithMaxUploads ¶ added in v0.3.0
func WithMaxUploads(max int) FSrvOptFunc
set the maximum number of concurrent uploads allowed at one time.
func WithTransferTimeout ¶ added in v0.3.0
func WithTransferTimeout(timeout time.Duration) FSrvOptFunc
set the transfer timeout value for the server.
func WithUploadsDir ¶
func WithUploadsDir(dirname string) FSrvOptFunc
set the uploads directory within the root directory.
type GrpcConfig ¶
type GrpcConfig struct {
// contains filtered or unexported fields
}
func NewGrpcConfiguration ¶
func NewGrpcConfiguration(opts ...GrpcOptFunc) (config *GrpcConfig, err error)
create, initialize and return a new grpc server configuration.
type GrpcConfigOpt ¶
type GrpcConfigOpt struct { Listenaddr string Listenport int Options []grpc.ServerOption TLSCert tls.Certificate }
type GrpcOptFunc ¶
type GrpcOptFunc func(*GrpcConfigOpt) error
func WithGrpcOptions ¶
func WithGrpcOptions(opts []grpc.ServerOption) GrpcOptFunc
set the grpc server options.
func WithListenaddr ¶
func WithListenaddr(addr string) GrpcOptFunc
set the listen address the gRPC server will listen on.
func WithListenport ¶
func WithListenport(portno int) GrpcOptFunc
set the port the gRPC server will listen on.
must be within range 1 - 65535.
func WithTLSCert ¶
func WithTLSCert(cert tls.Certificate) GrpcOptFunc
add a TLS cert to the server configuration.
type OFSEncryptor ¶ added in v0.4.0
type OFSEncryptor interface { // decrypt a given encrypted file. DecryptFile(string) error // encrypt a given file. EncryptFile(string) error }
interface defining an object that can perform various encryption methods on files.
this can be used to encrypt and decrypt files on the server.