files

package
v0.0.0-...-966d904 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = models.Command{
	Name:      "files",
	ShortHelp: "Tasks for managing service files",
	LongHelp: "The <code>files</code> command gives access to service files on your environment's services. " +
		"Service files can include Nginx configs, SSL certificates, and any other file that might be injected into your running service. " +
		"The files command can not be run directly but has subcommands.",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(cmd *cli.Cmd) {
			cmd.CommandLong(DownloadSubCmd.Name, DownloadSubCmd.ShortHelp, DownloadSubCmd.LongHelp, DownloadSubCmd.CmdFunc(settings))
			cmd.CommandLong(ListSubCmd.Name, ListSubCmd.ShortHelp, ListSubCmd.LongHelp, ListSubCmd.CmdFunc(settings))
		}
	},
}

Cmd is the contract between the user and the CLI. This specifies the command name, arguments, and required/optional arguments and flags for the command.

View Source
var DownloadSubCmd = models.Command{
	Name:      "download",
	ShortHelp: "Download a file to your localhost with the same file permissions as on the remote host or print it to stdout",
	LongHelp: "<code>files download</code> allows you to view the contents of a service file and save it to your local machine. " +
		"Most service files are stored on your service_proxy and therefore you should not have to specify the <code>SERVICE_NAME</code> argument. " +
		"Simply supply the <code>FILE_NAME</code> found from the files list command and the contents of the file, as well as the permissions string, will be printed to your console. " +
		"You can always store the file locally, applying the same permissions as those on the remote server, by specifying an output file with the <code>-o</code> flag. Here is a sample command\n\n" +
		"<pre>\ndatica -E \"<your_env_name>\" files download /etc/nginx/sites-enabled/mywebsite.com\n</pre>",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			serviceName := subCmd.StringArg("SERVICE_NAME", "service_proxy", "The name of the service to download a file from")
			fileName := subCmd.StringArg("FILE_NAME", "", "The name of the service file from running \"datica files list\"")
			output := subCmd.StringOpt("o output", "", "The downloaded file will be saved to the given location with the same file permissions as it has on the remote host. If those file permissions cannot be applied, a warning will be printed and default 0644 permissions applied. If no output is specified, stdout is used.")
			force := subCmd.BoolOpt("f force", false, "If the specified output file already exists, automatically overwrite it")
			subCmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdDownload(*serviceName, *fileName, *output, *force, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "[SERVICE_NAME] FILE_NAME [-o] [-f]"
		}
	},
}
View Source
var ListSubCmd = models.Command{
	Name:      "list",
	ShortHelp: "List all files available for a given service",
	LongHelp: "<code>files list</code> prints out a listing of all service files available for download. " +
		"Nearly all service files are stored on the service_proxy and therefore you should not have to specify the <code>SERVICE_NAME</code> argument. " +
		"Here is a sample command\n\n" +
		"<pre>\ndatica -E \"<your_env_name>\" files list\n</pre>",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			svcName := subCmd.StringArg("SERVICE_NAME", "service_proxy", "The name of the service to list files for")
			showTimestamps := subCmd.BoolOpt("t showTimestamps", false, "Show when each file was created and most recently updated")
			subCmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdList(*svcName, *showTimestamps, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "[SERVICE_NAME] [-t]"
		}
	},
}

Functions

func CmdDownload

func CmdDownload(svcName, fileName, output string, force bool, ifiles IFiles, is services.IServices) error

CmdDownload downloads a service file by its name (taken from listing service files) to the local machine matching the file's assigned permissions. If those permissions cannot be applied, the default 0644 permissions are applied. If not output file is specified, the file and permissions are printed to stdout.

func CmdList

func CmdList(svcName string, showTimestamps bool, ifiles IFiles, is services.IServices) error

CmdList lists all service files that are able to be downloaded by a member of the environment. Typically service files of interest will be on the service_proxy.

Types

type IFiles

type IFiles interface {
	Create(svcID, filePath, name, mode string) (*models.ServiceFile, error)
	List(svcID string) (*[]models.ServiceFile, error)
	Retrieve(fileName string, svcID string) (*models.ServiceFile, error)
	Save(output string, force bool, file *models.ServiceFile) error
}

IFiles

func New

func New(settings *models.Settings) IFiles

New generates a new instance of IFiles

type SFiles

type SFiles struct {
	Settings *models.Settings
}

SFiles is a concrete implementation of IFiles

func (*SFiles) Create

func (f *SFiles) Create(svcID, filePath, name, mode string) (*models.ServiceFile, error)

func (*SFiles) List

func (f *SFiles) List(svcID string) (*[]models.ServiceFile, error)

func (*SFiles) Retrieve

func (f *SFiles) Retrieve(fileName string, svcID string) (*models.ServiceFile, error)

func (*SFiles) Save

func (f *SFiles) Save(output string, force bool, file *models.ServiceFile) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL