cmd

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: MIT Imports: 86 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ConfigDir string

	AgentCmd = &cobra.Command{
		Use:   "agent",
		Short: "Start Files.com Agent",
		Long: `To serve the current working directory with auto generated credentials simply
use:

$ files-cli agent

Please take a look at the usage below to customize the serving parameters`,
		Run: func(cmd *cobra.Command, args []string) {
			portableDir := directoryToServe
			fsProvider := sdk.GetProviderByName(portableFsProvider)
			if !filepath.IsAbs(portableDir) {
				if fsProvider == sdk.LocalFilesystemProvider {
					portableDir, _ = filepath.Abs(portableDir)
				} else {
					portableDir = os.TempDir()
				}
			}
			permissions := make(map[string][]string)
			permissions["/"] = portablePermissions
			portableSFTPPrivateKey := ""
			if portableSFTPPrivateKeyPath != "" {
				contents, err := getFileContents(portableSFTPPrivateKeyPath)
				if err != nil {
					fmt.Printf("Unable to get SFTP private key: %v\n", err)
					os.Exit(1)
				}
				portableSFTPPrivateKey = contents
			}
			if portableFTPDPort >= 0 && portableFTPSCert != "" && portableFTPSKey != "" {
				keyPairs := []common.TLSKeyPair{
					{
						Cert: portableFTPSCert,
						Key:  portableFTPSKey,
						ID:   common.DefaultTLSKeyPaidID,
					},
				}
				_, err := common.NewCertManager(keyPairs, filepath.Clean(defaultConfigDir),
					"FTP portable")
				if err != nil {
					fmt.Printf("Unable to load FTPS key pair, cert file %#v key file %#v error: %v\n",
						portableFTPSCert, portableFTPSKey, err)
					os.Exit(1)
				}
			}
			service := service.Service{
				ConfigDir:     filepath.Clean(defaultConfigDir),
				ConfigFile:    defaultConfigFile,
				LogFilePath:   portableLogFile,
				LogMaxSize:    defaultLogMaxSize,
				LogMaxBackups: defaultLogMaxBackup,
				LogMaxAge:     defaultLogMaxAge,
				LogCompress:   defaultLogCompress,
				LogVerbose:    portableLogVerbose,
				LogUTCTime:    portableLogUTCTime,
				Shutdown:      make(chan bool),
				PortableMode:  1,
				PortableUser: dataprovider.User{
					BaseUser: sdk.BaseUser{
						Username:    portableUsername,
						Password:    portablePassword,
						PublicKeys:  portablePublicKeys,
						Permissions: permissions,
						HomeDir:     portableDir,
						Status:      1,
					},
					Filters: dataprovider.UserFilters{
						BaseUserFilters: sdk.BaseUserFilters{
							FilePatterns:   parsePatternsFilesFilters(),
							StartDirectory: portableStartDir,
						},
					},
					FsConfig: vfs.Filesystem{
						Provider: sdk.GetProviderByName(portableFsProvider),
						CryptConfig: vfs.CryptFsConfig{
							Passphrase: kms.NewPlainSecret(portableCryptPassphrase),
						},
						SFTPConfig: vfs.SFTPFsConfig{
							BaseSFTPFsConfig: sdk.BaseSFTPFsConfig{
								Endpoint:                portableSFTPEndpoint,
								Username:                portableSFTPUsername,
								Fingerprints:            portableSFTPFingerprints,
								Prefix:                  portableSFTPPrefix,
								DisableCouncurrentReads: portableSFTPDisableConcurrentReads,
								BufferSize:              portableSFTPDBufferSize,
							},
							Password:   kms.NewPlainSecret(portableSFTPPassword),
							PrivateKey: kms.NewPlainSecret(portableSFTPPrivateKey),
						},
					},
				},
			}
			if err := service.StartPortableMode(portableSFTPDPort, portableFTPDPort, 0, portableSSHCommands, portableAdvertiseService,
				portableAdvertiseCredentials, "", "", "", ""); err == nil {
				service.Wait()
				if service.Error == nil {
					os.Exit(0)
				}
			}
			os.Exit(1)
		},
	}
)
View Source
var (
	Version      string
	ProfileValue string
	Environment  string
	APIKey       string

	OutputPath string
	RootCmd    = &cobra.Command{
		Use: "files-cli [resource]",
		PersistentPreRun: func(cmd *cobra.Command, args []string) {
			sdkConfig := cmd.Context().Value("config").(*files.Config)
			if APIKey != "" {
				sdkConfig.APIKey = APIKey
			}

			sdkConfig.Environment = files.NewEnvironment(Environment)
			debugFlag := cmd.Flag("debug")
			if debugFlag.Changed {
				logFile, err := os.Create(debug)
				if err != nil {
					fmt.Fprintf(cmd.ErrOrStderr(), "%v\n", err)
					os.Exit(1)
				}
				sdkConfig.SetLogger(log.New(logFile, "", log.LstdFlags))
			}
			profile := &lib.Profiles{}
			err := profile.Load(sdkConfig, ProfileValue)
			if err != nil {
				fmt.Fprintf(cmd.ErrOrStderr(), "%v\n", err)
				os.Exit(1)
			}
			cmd.SetContext(context.WithValue(cmd.Context(), "profile", profile))

			if OutputPath != "" {
				output, err := os.Create(OutputPath)
				if err != nil {
					lib.ClientError(cmd.Context(), Profile(cmd), err, cmd.ErrOrStderr())
				}
				cmd.SetOut(output)
			}

			if lib.Includes(cmd.Use, []string{"login", "logout"}) {
				return
			}

			if len(cmd.Aliases) != 0 && lib.Includes(cmd.Aliases[0], []string{"config-set", "config-reset", "config-show", "version"}) {
				return
			}

			if !ignoreVersionCheck {
				Profile(cmd).CheckVersion(Version, lib.FetchLatestVersionNumber(*sdkConfig, cmd.Context()), lib.InstalledViaBrew(), cmd.ErrOrStderr())
			}

			if Profile(cmd).Config.GetAPIKey() != "" {
				return
			}

			if Profile(cmd).ValidSession() {
				return
			}
			profile.Overrides = lib.Overrides{In: cmd.InOrStdin(), Out: cmd.OutOrStdout()}
			if Profile(cmd).SessionExpired() {
				fmt.Fprintf(cmd.ErrOrStderr(), "The session has expired, you must log in again.\n")
				err = lib.CreateSession(files.SessionCreateParams{}, Profile(cmd))
				if err != nil {
					fmt.Fprintf(cmd.ErrOrStderr(), "%v\n", err)
					os.Exit(1)
				}
				return
			}

			if Profile(cmd).Config.GetAPIKey() == "" {
				fmt.Fprintf(cmd.ErrOrStderr(), "No API Key found. Using session login.\n")
				err = lib.CreateSession(files.SessionCreateParams{}, Profile(cmd))
				if err != nil {
					fmt.Fprintf(cmd.ErrOrStderr(), "%v\n", err)
					os.Exit(1)
				}
			}
		},
	}
)
View Source
var (
	VersionCmd *cobra.Command
)

Functions

func AccountLineItems

func AccountLineItems() *cobra.Command

func ActionNotificationExportResults added in v1.0.843

func ActionNotificationExportResults() *cobra.Command

func ActionNotificationExports added in v1.0.843

func ActionNotificationExports() *cobra.Command

func ActionWebhookFailures added in v1.0.1483

func ActionWebhookFailures() *cobra.Command

func Actions

func Actions() *cobra.Command

func ApiKeys

func ApiKeys() *cobra.Command

func Apps

func Apps() *cobra.Command

func As2IncomingMessages added in v1.3.11

func As2IncomingMessages() *cobra.Command

func As2OutgoingMessages added in v1.3.11

func As2OutgoingMessages() *cobra.Command

func As2Partners added in v1.3.11

func As2Partners() *cobra.Command

func As2Stations added in v1.3.11

func As2Stations() *cobra.Command

func AutomationRuns added in v1.1.1672

func AutomationRuns() *cobra.Command

func Automations

func Automations() *cobra.Command

func Autos

func Autos() *cobra.Command

func BandwidthSnapshots added in v1.0.2

func BandwidthSnapshots() *cobra.Command

func Behaviors

func Behaviors() *cobra.Command

func BundleDownloads

func BundleDownloads() *cobra.Command

func BundleRecipients

func BundleRecipients() *cobra.Command

func BundleRegistrations added in v1.0.127

func BundleRegistrations() *cobra.Command

func Bundles

func Bundles() *cobra.Command

func Clickwraps

func Clickwraps() *cobra.Command

func Config added in v1.0.170

func Config() *cobra.Command

func DnsRecords

func DnsRecords() *cobra.Command

func Download added in v1.6.5

func Download() *cobra.Command

func Errors

func Errors() *cobra.Command

func ExternalEvents added in v1.0.18

func ExternalEvents() *cobra.Command

func FileActions

func FileActions() *cobra.Command

func FileCommentReactions

func FileCommentReactions() *cobra.Command

func FileComments

func FileComments() *cobra.Command

func FileMigrations added in v1.0.1504

func FileMigrations() *cobra.Command

func FileUploadParts added in v1.0.31

func FileUploadParts() *cobra.Command

func Files

func Files() *cobra.Command

func Folders

func Folders() *cobra.Command

func FormFieldSets added in v1.0.127

func FormFieldSets() *cobra.Command

func FormFields added in v1.0.127

func FormFields() *cobra.Command

func GroupUsers

func GroupUsers() *cobra.Command

func Groups

func Groups() *cobra.Command

func Histories

func Histories() *cobra.Command

func HistoryExportResults added in v1.0.5

func HistoryExportResults() *cobra.Command

func HistoryExports

func HistoryExports() *cobra.Command

func Images

func Images() *cobra.Command

func InboxRecipients added in v1.0.150

func InboxRecipients() *cobra.Command

func InboxRegistrations added in v1.0.127

func InboxRegistrations() *cobra.Command

func InboxUploads added in v1.0.127

func InboxUploads() *cobra.Command

func Init added in v1.6.5

func Init(version string, config *files.Config)

func InvoiceLineItems

func InvoiceLineItems() *cobra.Command

func Invoices

func Invoices() *cobra.Command

func IpAddresses

func IpAddresses() *cobra.Command

func Locks

func Locks() *cobra.Command

func LogOut added in v1.0.215

func LogOut() *cobra.Command

func Login added in v1.0.215

func Login() *cobra.Command

func MessageCommentReactions

func MessageCommentReactions() *cobra.Command

func MessageComments

func MessageComments() *cobra.Command

func MessageReactions

func MessageReactions() *cobra.Command

func Messages

func Messages() *cobra.Command

func Notifications

func Notifications() *cobra.Command

func PaymentLineItems

func PaymentLineItems() *cobra.Command

func Payments

func Payments() *cobra.Command

func Permissions

func Permissions() *cobra.Command

func Previews

func Previews() *cobra.Command

func Priorities added in v1.1.1668

func Priorities() *cobra.Command

func Profile added in v1.6.5

func Profile(cmd *cobra.Command) *lib.Profiles

func Projects

func Projects() *cobra.Command

func PublicIpAddresses

func PublicIpAddresses() *cobra.Command

func PublicKeys

func PublicKeys() *cobra.Command

func RemoteBandwidthSnapshots added in v1.3.23

func RemoteBandwidthSnapshots() *cobra.Command

func RemoteServers

func RemoteServers() *cobra.Command

func Requests

func Requests() *cobra.Command

func Sessions

func Sessions() *cobra.Command

func SettingsChanges

func SettingsChanges() *cobra.Command

func SftpHostKeys added in v1.5.13

func SftpHostKeys() *cobra.Command

func Sites

func Sites() *cobra.Command

func SsoStrategies

func SsoStrategies() *cobra.Command

func Statuses

func Statuses() *cobra.Command

func Styles

func Styles() *cobra.Command

func Sync added in v1.2.0

func Sync() *cobra.Command

func Upload added in v1.6.5

func Upload() *cobra.Command

func UsageDailySnapshots

func UsageDailySnapshots() *cobra.Command

func UsageSnapshots

func UsageSnapshots() *cobra.Command

func UserCipherUses

func UserCipherUses() *cobra.Command

func UserRequests

func UserRequests() *cobra.Command

func Users

func Users() *cobra.Command

func WebhookTests added in v1.0.502

func WebhookTests() *cobra.Command

Types

This section is empty.

Jump to

Keyboard shortcuts

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