Skip to content

Commit

Permalink
Merge pull request #154 from mitre/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mattrbianchi authored Sep 13, 2019
2 parents eff3801 + 7a80693 commit dcd3bb5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
8 changes: 7 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package cmd

import (
"fmt"
"os"

"github.com/mattrbianchi/twig"
Expand Down Expand Up @@ -48,10 +49,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,
Expand All @@ -60,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)
Expand Down
10 changes: 6 additions & 4 deletions flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions sdl/sdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion sracp/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -148,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
Expand Down Expand Up @@ -298,6 +306,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)
Expand Down

0 comments on commit dcd3bb5

Please sign in to comment.