mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2024-11-26 06:00:18 +01:00
Upgrade github.com/urfave/cli to v2 (#551)
`urfave/cli` v2 was released in 2019, and it doesn't introduce relevant user-facing breaking changes. Migration guide from v1 can be found at: https://cli.urfave.org/migrate-v1-to-v2/ The only user-facing change is within the "Flags before args" section, but I haven't found that to affect `transfer.sh` as arguments are not used. Co-authored-by: Stefan Benten <mail@stefan-benten.de> Co-authored-by: Andrea Spacca <andrea.spacca@gmail.com>
This commit is contained in:
parent
2a11ca13a3
commit
df0d04f0da
5 changed files with 258 additions and 256 deletions
233
cmd/cmd.go
233
cmd/cmd.go
|
@ -1,6 +1,7 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -10,7 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/dutchcoders/transfer.sh/server"
|
"github.com/dutchcoders/transfer.sh/server"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli/v2"
|
||||||
"google.golang.org/api/googleapi"
|
"google.golang.org/api/googleapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -36,275 +37,275 @@ VERSION:
|
||||||
`{{ "\n"}}`
|
`{{ "\n"}}`
|
||||||
|
|
||||||
var globalFlags = []cli.Flag{
|
var globalFlags = []cli.Flag{
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "listener",
|
Name: "listener",
|
||||||
Usage: "127.0.0.1:8080",
|
Usage: "127.0.0.1:8080",
|
||||||
Value: "127.0.0.1:8080",
|
Value: "127.0.0.1:8080",
|
||||||
EnvVar: "LISTENER",
|
EnvVars: []string{"LISTENER"},
|
||||||
},
|
},
|
||||||
// redirect to https?
|
// redirect to https?
|
||||||
// hostnames
|
// hostnames
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "profile-listener",
|
Name: "profile-listener",
|
||||||
Usage: "127.0.0.1:6060",
|
Usage: "127.0.0.1:6060",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "PROFILE_LISTENER",
|
EnvVars: []string{"PROFILE_LISTENER"},
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "force-https",
|
Name: "force-https",
|
||||||
Usage: "",
|
Usage: "",
|
||||||
EnvVar: "FORCE_HTTPS",
|
EnvVars: []string{"FORCE_HTTPS"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "tls-listener",
|
Name: "tls-listener",
|
||||||
Usage: "127.0.0.1:8443",
|
Usage: "127.0.0.1:8443",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "TLS_LISTENER",
|
EnvVars: []string{"TLS_LISTENER"},
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "tls-listener-only",
|
Name: "tls-listener-only",
|
||||||
Usage: "",
|
Usage: "",
|
||||||
EnvVar: "TLS_LISTENER_ONLY",
|
EnvVars: []string{"TLS_LISTENER_ONLY"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "tls-cert-file",
|
Name: "tls-cert-file",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "TLS_CERT_FILE",
|
EnvVars: []string{"TLS_CERT_FILE"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "tls-private-key",
|
Name: "tls-private-key",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "TLS_PRIVATE_KEY",
|
EnvVars: []string{"TLS_PRIVATE_KEY"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "temp-path",
|
Name: "temp-path",
|
||||||
Usage: "path to temp files",
|
Usage: "path to temp files",
|
||||||
Value: os.TempDir(),
|
Value: os.TempDir(),
|
||||||
EnvVar: "TEMP_PATH",
|
EnvVars: []string{"TEMP_PATH"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "web-path",
|
Name: "web-path",
|
||||||
Usage: "path to static web files",
|
Usage: "path to static web files",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "WEB_PATH",
|
EnvVars: []string{"WEB_PATH"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "proxy-path",
|
Name: "proxy-path",
|
||||||
Usage: "path prefix when service is run behind a proxy",
|
Usage: "path prefix when service is run behind a proxy",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "PROXY_PATH",
|
EnvVars: []string{"PROXY_PATH"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "proxy-port",
|
Name: "proxy-port",
|
||||||
Usage: "port of the proxy when the service is run behind a proxy",
|
Usage: "port of the proxy when the service is run behind a proxy",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "PROXY_PORT",
|
EnvVars: []string{"PROXY_PORT"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "email-contact",
|
Name: "email-contact",
|
||||||
Usage: "email address to link in Contact Us (front end)",
|
Usage: "email address to link in Contact Us (front end)",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "EMAIL_CONTACT",
|
EnvVars: []string{"EMAIL_CONTACT"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "ga-key",
|
Name: "ga-key",
|
||||||
Usage: "key for google analytics (front end)",
|
Usage: "key for google analytics (front end)",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "GA_KEY",
|
EnvVars: []string{"GA_KEY"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "uservoice-key",
|
Name: "uservoice-key",
|
||||||
Usage: "key for user voice (front end)",
|
Usage: "key for user voice (front end)",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "USERVOICE_KEY",
|
EnvVars: []string{"USERVOICE_KEY"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "provider",
|
Name: "provider",
|
||||||
Usage: "s3|gdrive|local",
|
Usage: "s3|gdrive|local",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "PROVIDER",
|
EnvVars: []string{"PROVIDER"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "s3-endpoint",
|
Name: "s3-endpoint",
|
||||||
Usage: "",
|
Usage: "",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "S3_ENDPOINT",
|
EnvVars: []string{"S3_ENDPOINT"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "s3-region",
|
Name: "s3-region",
|
||||||
Usage: "",
|
Usage: "",
|
||||||
Value: "eu-west-1",
|
Value: "eu-west-1",
|
||||||
EnvVar: "S3_REGION",
|
EnvVars: []string{"S3_REGION"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "aws-access-key",
|
Name: "aws-access-key",
|
||||||
Usage: "",
|
Usage: "",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "AWS_ACCESS_KEY",
|
EnvVars: []string{"AWS_ACCESS_KEY"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "aws-secret-key",
|
Name: "aws-secret-key",
|
||||||
Usage: "",
|
Usage: "",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "AWS_SECRET_KEY",
|
EnvVars: []string{"AWS_SECRET_KEY"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "bucket",
|
Name: "bucket",
|
||||||
Usage: "",
|
Usage: "",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "BUCKET",
|
EnvVars: []string{"BUCKET"},
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "s3-no-multipart",
|
Name: "s3-no-multipart",
|
||||||
Usage: "Disables S3 Multipart Puts",
|
Usage: "Disables S3 Multipart Puts",
|
||||||
EnvVar: "S3_NO_MULTIPART",
|
EnvVars: []string{"S3_NO_MULTIPART"},
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "s3-path-style",
|
Name: "s3-path-style",
|
||||||
Usage: "Forces path style URLs, required for Minio.",
|
Usage: "Forces path style URLs, required for Minio.",
|
||||||
EnvVar: "S3_PATH_STYLE",
|
EnvVars: []string{"S3_PATH_STYLE"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "gdrive-client-json-filepath",
|
Name: "gdrive-client-json-filepath",
|
||||||
Usage: "",
|
Usage: "",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "GDRIVE_CLIENT_JSON_FILEPATH",
|
EnvVars: []string{"GDRIVE_CLIENT_JSON_FILEPATH"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "gdrive-local-config-path",
|
Name: "gdrive-local-config-path",
|
||||||
Usage: "",
|
Usage: "",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "GDRIVE_LOCAL_CONFIG_PATH",
|
EnvVars: []string{"GDRIVE_LOCAL_CONFIG_PATH"},
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "gdrive-chunk-size",
|
Name: "gdrive-chunk-size",
|
||||||
Usage: "",
|
Usage: "",
|
||||||
Value: googleapi.DefaultUploadChunkSize / 1024 / 1024,
|
Value: googleapi.DefaultUploadChunkSize / 1024 / 1024,
|
||||||
EnvVar: "GDRIVE_CHUNK_SIZE",
|
EnvVars: []string{"GDRIVE_CHUNK_SIZE"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "storj-access",
|
Name: "storj-access",
|
||||||
Usage: "Access for the project",
|
Usage: "Access for the project",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "STORJ_ACCESS",
|
EnvVars: []string{"STORJ_ACCESS"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "storj-bucket",
|
Name: "storj-bucket",
|
||||||
Usage: "Bucket to use within the project",
|
Usage: "Bucket to use within the project",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "STORJ_BUCKET",
|
EnvVars: []string{"STORJ_BUCKET"},
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "rate-limit",
|
Name: "rate-limit",
|
||||||
Usage: "requests per minute",
|
Usage: "requests per minute",
|
||||||
Value: 0,
|
Value: 0,
|
||||||
EnvVar: "RATE_LIMIT",
|
EnvVars: []string{"RATE_LIMIT"},
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "purge-days",
|
Name: "purge-days",
|
||||||
Usage: "number of days after uploads are purged automatically",
|
Usage: "number of days after uploads are purged automatically",
|
||||||
Value: 0,
|
Value: 0,
|
||||||
EnvVar: "PURGE_DAYS",
|
EnvVars: []string{"PURGE_DAYS"},
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "purge-interval",
|
Name: "purge-interval",
|
||||||
Usage: "interval in hours to run the automatic purge for",
|
Usage: "interval in hours to run the automatic purge for",
|
||||||
Value: 0,
|
Value: 0,
|
||||||
EnvVar: "PURGE_INTERVAL",
|
EnvVars: []string{"PURGE_INTERVAL"},
|
||||||
},
|
},
|
||||||
cli.Int64Flag{
|
&cli.Int64Flag{
|
||||||
Name: "max-upload-size",
|
Name: "max-upload-size",
|
||||||
Usage: "max limit for upload, in kilobytes",
|
Usage: "max limit for upload, in kilobytes",
|
||||||
Value: 0,
|
Value: 0,
|
||||||
EnvVar: "MAX_UPLOAD_SIZE",
|
EnvVars: []string{"MAX_UPLOAD_SIZE"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "lets-encrypt-hosts",
|
Name: "lets-encrypt-hosts",
|
||||||
Usage: "host1, host2",
|
Usage: "host1, host2",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "HOSTS",
|
EnvVars: []string{"HOSTS"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "log",
|
Name: "log",
|
||||||
Usage: "/var/log/transfersh.log",
|
Usage: "/var/log/transfersh.log",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "LOG",
|
EnvVars: []string{"LOG"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "basedir",
|
Name: "basedir",
|
||||||
Usage: "path to storage",
|
Usage: "path to storage",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "BASEDIR",
|
EnvVars: []string{"BASEDIR"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "clamav-host",
|
Name: "clamav-host",
|
||||||
Usage: "clamav-host",
|
Usage: "clamav-host",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "CLAMAV_HOST",
|
EnvVars: []string{"CLAMAV_HOST"},
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "perform-clamav-prescan",
|
Name: "perform-clamav-prescan",
|
||||||
Usage: "perform-clamav-prescan",
|
Usage: "perform-clamav-prescan",
|
||||||
EnvVar: "PERFORM_CLAMAV_PRESCAN",
|
EnvVars: []string{"PERFORM_CLAMAV_PRESCAN"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "virustotal-key",
|
Name: "virustotal-key",
|
||||||
Usage: "virustotal-key",
|
Usage: "virustotal-key",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "VIRUSTOTAL_KEY",
|
EnvVars: []string{"VIRUSTOTAL_KEY"},
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "profiler",
|
Name: "profiler",
|
||||||
Usage: "enable profiling",
|
Usage: "enable profiling",
|
||||||
EnvVar: "PROFILER",
|
EnvVars: []string{"PROFILER"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "http-auth-user",
|
Name: "http-auth-user",
|
||||||
Usage: "user for http basic auth",
|
Usage: "user for http basic auth",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "HTTP_AUTH_USER",
|
EnvVars: []string{"HTTP_AUTH_USER"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "http-auth-pass",
|
Name: "http-auth-pass",
|
||||||
Usage: "pass for http basic auth",
|
Usage: "pass for http basic auth",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "HTTP_AUTH_PASS",
|
EnvVars: []string{"HTTP_AUTH_PASS"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "http-auth-htpasswd",
|
Name: "http-auth-htpasswd",
|
||||||
Usage: "htpasswd file http basic auth",
|
Usage: "htpasswd file http basic auth",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "HTTP_AUTH_HTPASSWD",
|
EnvVars: []string{"HTTP_AUTH_HTPASSWD"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "http-auth-ip-whitelist",
|
Name: "http-auth-ip-whitelist",
|
||||||
Usage: "comma separated list of ips allowed to upload without being challenged an http auth",
|
Usage: "comma separated list of ips allowed to upload without being challenged an http auth",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "HTTP_AUTH_IP_WHITELIST",
|
EnvVars: []string{"HTTP_AUTH_IP_WHITELIST"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "ip-whitelist",
|
Name: "ip-whitelist",
|
||||||
Usage: "comma separated list of ips allowed to connect to the service",
|
Usage: "comma separated list of ips allowed to connect to the service",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "IP_WHITELIST",
|
EnvVars: []string{"IP_WHITELIST"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "ip-blacklist",
|
Name: "ip-blacklist",
|
||||||
Usage: "comma separated list of ips not allowed to connect to the service",
|
Usage: "comma separated list of ips not allowed to connect to the service",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "IP_BLACKLIST",
|
EnvVars: []string{"IP_BLACKLIST"},
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "cors-domains",
|
Name: "cors-domains",
|
||||||
Usage: "comma separated list of domains allowed for CORS requests",
|
Usage: "comma separated list of domains allowed for CORS requests",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "CORS_DOMAINS",
|
EnvVars: []string{"CORS_DOMAINS"},
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "random-token-length",
|
Name: "random-token-length",
|
||||||
Usage: "",
|
Usage: "",
|
||||||
Value: 10,
|
Value: 10,
|
||||||
EnvVar: "RANDOM_TOKEN_LENGTH",
|
EnvVars: []string{"RANDOM_TOKEN_LENGTH"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,8 +314,9 @@ type Cmd struct {
|
||||||
*cli.App
|
*cli.App
|
||||||
}
|
}
|
||||||
|
|
||||||
func versionCommand(_ *cli.Context) {
|
func versionCommand(_ *cli.Context) error {
|
||||||
fmt.Println(color.YellowString("transfer.sh %s: Easy file sharing from the command line", Version))
|
fmt.Println(color.YellowString("transfer.sh %s: Easy file sharing from the command line", Version))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// New is the factory for transfer.sh
|
// New is the factory for transfer.sh
|
||||||
|
@ -323,13 +325,13 @@ func New() *Cmd {
|
||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "transfer.sh"
|
app.Name = "transfer.sh"
|
||||||
app.Author = ""
|
app.Authors = []*cli.Author{}
|
||||||
app.Usage = "transfer.sh"
|
app.Usage = "transfer.sh"
|
||||||
app.Description = `Easy file sharing from the command line`
|
app.Description = `Easy file sharing from the command line`
|
||||||
app.Version = Version
|
app.Version = Version
|
||||||
app.Flags = globalFlags
|
app.Flags = globalFlags
|
||||||
app.CustomAppHelpTemplate = helpTemplate
|
app.CustomAppHelpTemplate = helpTemplate
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []*cli.Command{
|
||||||
{
|
{
|
||||||
Name: "version",
|
Name: "version",
|
||||||
Action: versionCommand,
|
Action: versionCommand,
|
||||||
|
@ -340,7 +342,7 @@ func New() *Cmd {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Action = func(c *cli.Context) {
|
app.Action = func(c *cli.Context) error {
|
||||||
var options []server.OptionFn
|
var options []server.OptionFn
|
||||||
if v := c.String("listener"); v != "" {
|
if v := c.String("listener"); v != "" {
|
||||||
options = append(options, server.Listener(v))
|
options = append(options, server.Listener(v))
|
||||||
|
@ -409,7 +411,7 @@ func New() *Cmd {
|
||||||
|
|
||||||
if v := c.Bool("perform-clamav-prescan"); v {
|
if v := c.Bool("perform-clamav-prescan"); v {
|
||||||
if c.String("clamav-host") == "" {
|
if c.String("clamav-host") == "" {
|
||||||
panic("clamav-host not set")
|
return errors.New("clamav-host not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
options = append(options, server.PerformClamavPrescan(v))
|
options = append(options, server.PerformClamavPrescan(v))
|
||||||
|
@ -483,13 +485,13 @@ func New() *Cmd {
|
||||||
switch provider := c.String("provider"); provider {
|
switch provider := c.String("provider"); provider {
|
||||||
case "s3":
|
case "s3":
|
||||||
if accessKey := c.String("aws-access-key"); accessKey == "" {
|
if accessKey := c.String("aws-access-key"); accessKey == "" {
|
||||||
panic("access-key not set.")
|
return errors.New("access-key not set.")
|
||||||
} else if secretKey := c.String("aws-secret-key"); secretKey == "" {
|
} else if secretKey := c.String("aws-secret-key"); secretKey == "" {
|
||||||
panic("secret-key not set.")
|
return errors.New("secret-key not set.")
|
||||||
} else if bucket := c.String("bucket"); bucket == "" {
|
} else if bucket := c.String("bucket"); bucket == "" {
|
||||||
panic("bucket not set.")
|
return errors.New("bucket not set.")
|
||||||
} else if store, err := storage.NewS3Storage(accessKey, secretKey, bucket, purgeDays, c.String("s3-region"), c.String("s3-endpoint"), c.Bool("s3-no-multipart"), c.Bool("s3-path-style"), logger); err != nil {
|
} else if store, err := storage.NewS3Storage(accessKey, secretKey, bucket, purgeDays, c.String("s3-region"), c.String("s3-endpoint"), c.Bool("s3-no-multipart"), c.Bool("s3-path-style"), logger); err != nil {
|
||||||
panic(err)
|
return err
|
||||||
} else {
|
} else {
|
||||||
options = append(options, server.UseStorage(store))
|
options = append(options, server.UseStorage(store))
|
||||||
}
|
}
|
||||||
|
@ -497,36 +499,36 @@ func New() *Cmd {
|
||||||
chunkSize := c.Int("gdrive-chunk-size") * 1024 * 1024
|
chunkSize := c.Int("gdrive-chunk-size") * 1024 * 1024
|
||||||
|
|
||||||
if clientJSONFilepath := c.String("gdrive-client-json-filepath"); clientJSONFilepath == "" {
|
if clientJSONFilepath := c.String("gdrive-client-json-filepath"); clientJSONFilepath == "" {
|
||||||
panic("gdrive-client-json-filepath not set.")
|
return errors.New("gdrive-client-json-filepath not set.")
|
||||||
} else if localConfigPath := c.String("gdrive-local-config-path"); localConfigPath == "" {
|
} else if localConfigPath := c.String("gdrive-local-config-path"); localConfigPath == "" {
|
||||||
panic("gdrive-local-config-path not set.")
|
return errors.New("gdrive-local-config-path not set.")
|
||||||
} else if basedir := c.String("basedir"); basedir == "" {
|
} else if basedir := c.String("basedir"); basedir == "" {
|
||||||
panic("basedir not set.")
|
return errors.New("basedir not set.")
|
||||||
} else if store, err := storage.NewGDriveStorage(clientJSONFilepath, localConfigPath, basedir, chunkSize, logger); err != nil {
|
} else if store, err := storage.NewGDriveStorage(c.Context, clientJSONFilepath, localConfigPath, basedir, chunkSize, logger); err != nil {
|
||||||
panic(err)
|
return err
|
||||||
} else {
|
} else {
|
||||||
options = append(options, server.UseStorage(store))
|
options = append(options, server.UseStorage(store))
|
||||||
}
|
}
|
||||||
case "storj":
|
case "storj":
|
||||||
if access := c.String("storj-access"); access == "" {
|
if access := c.String("storj-access"); access == "" {
|
||||||
panic("storj-access not set.")
|
return errors.New("storj-access not set.")
|
||||||
} else if bucket := c.String("storj-bucket"); bucket == "" {
|
} else if bucket := c.String("storj-bucket"); bucket == "" {
|
||||||
panic("storj-bucket not set.")
|
return errors.New("storj-bucket not set.")
|
||||||
} else if store, err := storage.NewStorjStorage(access, bucket, purgeDays, logger); err != nil {
|
} else if store, err := storage.NewStorjStorage(c.Context, access, bucket, purgeDays, logger); err != nil {
|
||||||
panic(err)
|
return err
|
||||||
} else {
|
} else {
|
||||||
options = append(options, server.UseStorage(store))
|
options = append(options, server.UseStorage(store))
|
||||||
}
|
}
|
||||||
case "local":
|
case "local":
|
||||||
if v := c.String("basedir"); v == "" {
|
if v := c.String("basedir"); v == "" {
|
||||||
panic("basedir not set.")
|
return errors.New("basedir not set.")
|
||||||
} else if store, err := storage.NewLocalStorage(v, logger); err != nil {
|
} else if store, err := storage.NewLocalStorage(v, logger); err != nil {
|
||||||
panic(err)
|
return err
|
||||||
} else {
|
} else {
|
||||||
options = append(options, server.UseStorage(store))
|
options = append(options, server.UseStorage(store))
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
panic("Provider not set or invalid.")
|
return errors.New("Provider not set or invalid.")
|
||||||
}
|
}
|
||||||
|
|
||||||
srvr, err := server.New(
|
srvr, err := server.New(
|
||||||
|
@ -535,10 +537,11 @@ func New() *Cmd {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Println(color.RedString("Error starting server: %s", err.Error()))
|
logger.Println(color.RedString("Error starting server: %s", err.Error()))
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
srvr.Run()
|
srvr.Run()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Cmd{
|
return &Cmd{
|
||||||
|
|
4
go.mod
4
go.mod
|
@ -21,7 +21,7 @@ require (
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
github.com/tg123/go-htpasswd v1.2.1
|
github.com/tg123/go-htpasswd v1.2.1
|
||||||
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce
|
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce
|
||||||
github.com/urfave/cli v1.22.12
|
github.com/urfave/cli/v2 v2.25.3
|
||||||
golang.org/x/crypto v0.6.0
|
golang.org/x/crypto v0.6.0
|
||||||
golang.org/x/net v0.8.0
|
golang.org/x/net v0.8.0
|
||||||
golang.org/x/oauth2 v0.5.0
|
golang.org/x/oauth2 v0.5.0
|
||||||
|
@ -62,6 +62,7 @@ require (
|
||||||
github.com/rogpeppe/go-internal v1.9.0 // indirect
|
github.com/rogpeppe/go-internal v1.9.0 // indirect
|
||||||
github.com/spacemonkeygo/monkit/v3 v3.0.19 // indirect
|
github.com/spacemonkeygo/monkit/v3 v3.0.19 // indirect
|
||||||
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3 // indirect
|
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3 // indirect
|
||||||
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||||
github.com/zeebo/blake3 v0.2.3 // indirect
|
github.com/zeebo/blake3 v0.2.3 // indirect
|
||||||
github.com/zeebo/errs v1.3.0 // indirect
|
github.com/zeebo/errs v1.3.0 // indirect
|
||||||
go.opencensus.io v0.24.0 // indirect
|
go.opencensus.io v0.24.0 // indirect
|
||||||
|
@ -72,6 +73,7 @@ require (
|
||||||
google.golang.org/genproto v0.0.0-20230227214838-9b19f0bdc514 // indirect
|
google.golang.org/genproto v0.0.0-20230227214838-9b19f0bdc514 // indirect
|
||||||
google.golang.org/grpc v1.53.0 // indirect
|
google.golang.org/grpc v1.53.0 // indirect
|
||||||
google.golang.org/protobuf v1.28.1 // indirect
|
google.golang.org/protobuf v1.28.1 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
storj.io/drpc v0.0.33-0.20230204035225-c9649dee8f2a // indirect
|
storj.io/drpc v0.0.33-0.20230204035225-c9649dee8f2a // indirect
|
||||||
storj.io/picobuf v0.0.1 // indirect
|
storj.io/picobuf v0.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
7
go.sum
7
go.sum
|
@ -7,7 +7,6 @@ cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGB
|
||||||
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
|
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
|
||||||
cloud.google.com/go/longrunning v0.4.1 h1:v+yFJOfKC3yZdY6ZUI933pIYdhyhV8S3NpWrXWmg7jM=
|
cloud.google.com/go/longrunning v0.4.1 h1:v+yFJOfKC3yZdY6ZUI933pIYdhyhV8S3NpWrXWmg7jM=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
|
||||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||||
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962 h1:KeNholpO2xKjgaaSyd+DyQRrsQjhbSeS7qe4nEw8aQw=
|
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962 h1:KeNholpO2xKjgaaSyd+DyQRrsQjhbSeS7qe4nEw8aQw=
|
||||||
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962/go.mod h1:kC29dT1vFpj7py2OvG1khBdQpo3kInWP+6QipLbdngo=
|
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962/go.mod h1:kC29dT1vFpj7py2OvG1khBdQpo3kInWP+6QipLbdngo=
|
||||||
|
@ -186,10 +185,12 @@ github.com/tg123/go-htpasswd v1.2.1 h1:i4wfsX1KvvkyoMiHZzjS0VzbAPWfxzI8INcZAKtut
|
||||||
github.com/tg123/go-htpasswd v1.2.1/go.mod h1:erHp1B86KXdwQf1X5ZrLb7erXZnWueEQezb2dql4q58=
|
github.com/tg123/go-htpasswd v1.2.1/go.mod h1:erHp1B86KXdwQf1X5ZrLb7erXZnWueEQezb2dql4q58=
|
||||||
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce h1:fb190+cK2Xz/dvi9Hv8eCYJYvIGUTN2/KLq1pT6CjEc=
|
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce h1:fb190+cK2Xz/dvi9Hv8eCYJYvIGUTN2/KLq1pT6CjEc=
|
||||||
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce/go.mod h1:o8v6yHRoik09Xen7gje4m9ERNah1d1PPsVq1VEx9vE4=
|
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce/go.mod h1:o8v6yHRoik09Xen7gje4m9ERNah1d1PPsVq1VEx9vE4=
|
||||||
github.com/urfave/cli v1.22.12 h1:igJgVw1JdKH+trcLWLeLwZjU9fEfPesQ+9/e4MQ44S8=
|
github.com/urfave/cli/v2 v2.25.3 h1:VJkt6wvEBOoSjPFQvOkv6iWIrsJyCrKGtCtxXWwmGeY=
|
||||||
github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8=
|
github.com/urfave/cli/v2 v2.25.3/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
||||||
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3 h1:zMsHhfK9+Wdl1F7sIKLyx3wrOFofpb3rWFbA4HgcK5k=
|
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3 h1:zMsHhfK9+Wdl1F7sIKLyx3wrOFofpb3rWFbA4HgcK5k=
|
||||||
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3/go.mod h1:R0Gbuw7ElaGSLOZUSwBm/GgVwMd30jWxBDdAyMOeTuc=
|
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3/go.mod h1:R0Gbuw7ElaGSLOZUSwBm/GgVwMd30jWxBDdAyMOeTuc=
|
||||||
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||||
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
|
|
|
@ -35,9 +35,7 @@ const gDriveTokenJSONFile = "token.json"
|
||||||
const gDriveDirectoryMimeType = "application/vnd.google-apps.folder"
|
const gDriveDirectoryMimeType = "application/vnd.google-apps.folder"
|
||||||
|
|
||||||
// NewGDriveStorage is the factory for GDrive
|
// NewGDriveStorage is the factory for GDrive
|
||||||
func NewGDriveStorage(clientJSONFilepath string, localConfigPath string, basedir string, chunkSize int, logger *log.Logger) (*GDrive, error) {
|
func NewGDriveStorage(ctx context.Context, clientJSONFilepath string, localConfigPath string, basedir string, chunkSize int, logger *log.Logger) (*GDrive, error) {
|
||||||
|
|
||||||
ctx := context.TODO()
|
|
||||||
|
|
||||||
b, err := ioutil.ReadFile(clientJSONFilepath)
|
b, err := ioutil.ReadFile(clientJSONFilepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -22,13 +22,11 @@ type StorjStorage struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStorjStorage is the factory for StorjStorage
|
// NewStorjStorage is the factory for StorjStorage
|
||||||
func NewStorjStorage(access, bucket string, purgeDays int, logger *log.Logger) (*StorjStorage, error) {
|
func NewStorjStorage(ctx context.Context, access, bucket string, purgeDays int, logger *log.Logger) (*StorjStorage, error) {
|
||||||
var instance StorjStorage
|
var instance StorjStorage
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
pCtx := context.TODO()
|
ctx = fpath.WithTempData(ctx, "", true)
|
||||||
|
|
||||||
ctx := fpath.WithTempData(pCtx, "", true)
|
|
||||||
|
|
||||||
uplConf := &uplink.Config{
|
uplConf := &uplink.Config{
|
||||||
UserAgent: "transfer-sh",
|
UserAgent: "transfer-sh",
|
||||||
|
|
Loading…
Reference in a new issue