From e11be5012b5ff712878a217e32ae3c2d0854036c Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 28 Jun 2019 14:26:53 -0400 Subject: [PATCH 1/4] Change User-Agent to binary name and version for sdl req --- cmd/root.go | 3 ++- flags/flags.go | 10 ++++++---- sdl/sdl.go | 1 + sracp/cmd/root.go | 4 +++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index c7ac9ad..7b950b8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -48,10 +48,11 @@ func init() { viper.SetEnvPrefix(flags.EnvPrefix) viper.AutomaticEnv() + flags.BinaryName = "fusera" } var rootCmd = &cobra.Command{ - Use: "fusera", + Use: flags.BinaryName, Short: "A FUSE interface to the NCBI Sequence Read Archive (SRA) - " + flags.Version, Long: ``, Version: flags.Version, diff --git a/flags/flags.go b/flags/flags.go index 032a913..c3f3ad4 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -14,6 +14,8 @@ var ( EnvPrefix = "dbgap" // Version should be set at compile time to `git describe --tags --abbrev=0` Version string + // BinaryName should be set on init in order to know what binary is using the flags library. + BinaryName string LocationName = "location" AccessionName = "accession" @@ -50,10 +52,10 @@ var ( EndpointMsg = "ADVANCED: Change the endpoint used to communicate with SDL API.\nEnvironment Variable: [$DBGAP_ENDPOINT]" AwsBatchMsg = "ADVANCED: Adjust the amount of accessions put in one request to the SDL API when using an AWS location.\nEnvironment Variable: [$DBGAP_AWS-BATCH]" GcpBatchMsg = "ADVANCED: Adjust the amount of accessions put in one request to the SDL API when using a GCP location.\nEnvironment Variable: [$DBGAP_GCP-BATCH]" - AwsProfileMsg = "The desired AWS credentials profile in ~/.aws/credentials to use for instances when files require the requester (you) to pay for accessing the file.\nEnvironment Variable: [$DBGAP_AWS-PROFILE]\nNOTE: This account will be charged all cost accrued by accessing these certain files through fusera." - GcpProfileMsg = "The desired GCP credentials profile in ~/.aws/credentials to use for instances when files require the requester (you) to pay for accessing the file.\nEnvironment Variable: [$DBGAP_GCP-PROFILE]\nNOTE: This account will be charged all cost accrued by accessing these certain files through fusera. These credentials should be in the AWS supported format that Google provides in order to work with their AWS compatible API." - SilentMsg = "Fusera prints nothing, most useful for using fusera in scripts." - VerboseMsg = "Fusera prints everything, most useful for troubleshooting." + AwsProfileMsg = "The desired AWS credentials profile in ~/.aws/credentials to use for instances when files require the requester (you) to pay for accessing the file.\nEnvironment Variable: [$DBGAP_AWS-PROFILE]\nNOTE: This account will be charged all cost accrued by accessing these certain files." + GcpProfileMsg = "The desired GCP credentials profile in ~/.aws/credentials to use for instances when files require the requester (you) to pay for accessing the file.\nEnvironment Variable: [$DBGAP_GCP-PROFILE]\nNOTE: This account will be charged all cost accrued by accessing these certain files. These credentials should be in the AWS supported format that Google provides in order to work with their AWS compatible API." + SilentMsg = "Prints nothing, most useful when running in scripts." + VerboseMsg = "Prints everything, most useful for troubleshooting." ) // ResolveLocation attempts to resolve the location on GCP and AWS. diff --git a/sdl/sdl.go b/sdl/sdl.go index 89387c6..a815ec2 100644 --- a/sdl/sdl.go +++ b/sdl/sdl.go @@ -93,6 +93,7 @@ func (c *Client) makeRequest(accessions []string, meta bool) ([]*fuseralib.Acces if err != nil { return nil, errors.New("can't create request to SDL API") } + req.Header.Set("User-Agent", flags.BinaryName+"-"+flags.Version) req.Header.Set("Content-Type", writer.FormDataContentType()) if flags.Verbose { reqdump, err := httputil.DumpRequestOut(req, true) diff --git a/sracp/cmd/root.go b/sracp/cmd/root.go index 291a58e..f304597 100644 --- a/sracp/cmd/root.go +++ b/sracp/cmd/root.go @@ -93,10 +93,12 @@ func init() { viper.SetEnvPrefix("dbgap") viper.AutomaticEnv() + + flags.BinaryName = "sracp" } var rootCmd = &cobra.Command{ - Use: "sracp", + Use: flags.BinaryName, Short: "A tool similar to cp that allows a user to download accessions - " + flags.Version, Long: ``, Version: flags.Version, From 1cdc43f150212caea6b8915f9961be991a337d06 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 3 Jul 2019 16:40:31 -0400 Subject: [PATCH 2/4] Fusera won't run as root --- cmd/root.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index 7b950b8..5cf8af7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -16,6 +16,7 @@ package cmd import ( + "fmt" "os" "github.com/mattrbianchi/twig" @@ -61,6 +62,10 @@ var rootCmd = &cobra.Command{ // Execute runs the main command of fusera, which has no action of its own, // so it evaluates which subcommand should be executed. func Execute() { + if os.Geteuid() == 0 { + fmt.Println("Running Fusera as root is not supported. This causes problems with mounting the filesystem using FUSE.") + os.Exit(1) + } if err := rootCmd.Execute(); err != nil { prettyPrintError(err) os.Exit(1) From ae7b94bdc13994c5255a017d5b3b2ed20e46dca5 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 8 Jul 2019 08:59:20 -0400 Subject: [PATCH 3/4] sracp won't run as root --- sracp/cmd/root.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sracp/cmd/root.go b/sracp/cmd/root.go index f304597..f11b929 100644 --- a/sracp/cmd/root.go +++ b/sracp/cmd/root.go @@ -300,6 +300,10 @@ var rootCmd = &cobra.Command{ // Execute runs the root command of sracp, which copies files from the cloud to a local file system. func Execute() { + if os.Geteuid() == 0 { + fmt.Println("Running sracp as root is not supported. The tool should not require root.") + os.Exit(1) + } if err := rootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) From 7a8069332a383e687092737d3b26875cf6ec0b1b Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 10 Jul 2019 13:43:15 -0400 Subject: [PATCH 4/4] Fail if not able to write to destination --- sracp/cmd/root.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sracp/cmd/root.go b/sracp/cmd/root.go index f11b929..8fa9b48 100644 --- a/sracp/cmd/root.go +++ b/sracp/cmd/root.go @@ -150,6 +150,12 @@ var rootCmd = &cobra.Command{ } } path := args[0] + // Test whether we can write to this location. If not, fail here. + err = os.MkdirAll(filepath.Join(path, ".test"), 0755) + if err != nil { + fmt.Printf("It seems like sracp cannot make directories under %s. Please check that you have correct permissions to write to that path.\n", path) + os.Exit(1) + } batch := flags.ResolveBatch(platform.Name, awsBatch, gcpBatch) var accessions []*fuseralib.Accession