diff --git a/cli/export.go b/cli/export.go index 48020890..3e688d42 100644 --- a/cli/export.go +++ b/cli/export.go @@ -61,11 +61,20 @@ var exportCmd = &cobra.Command{ defer fle.Close() + // Check to see if the http request type has + // been specified as eith 'http' or 'https' + // as these are the only supported schemes. + + if opts.DB.Type != "http" && opts.DB.Type != "https" { + log.Fatalln("Connection failed - please specify 'http' or 'https' for the scheme.") + return + } + // Configure the export connection endpoint url // and specify the authentication header using // basic auth for root login. - url := fmt.Sprintf("https://%s@%s:%s/export", opts.Auth.Auth, opts.DB.Host, opts.DB.Port) + url := fmt.Sprintf("%s://%s@%s:%s/export", opts.DB.Type, opts.Auth.Auth, opts.DB.Host, opts.DB.Port) // Create a new http request object that we // can use to connect to the export endpoint @@ -133,6 +142,7 @@ var exportCmd = &cobra.Command{ func init() { exportCmd.PersistentFlags().StringVarP(&opts.Auth.Auth, "auth", "a", "root:root", "Master authentication details to use when connecting.") + exportCmd.PersistentFlags().StringVar(&opts.DB.Type, "scheme", "https", "HTTP connection scheme to use to connect to the database.") exportCmd.PersistentFlags().StringVar(&opts.DB.Host, "host", "surreal.io", "Database server host to connect to.") exportCmd.PersistentFlags().StringVar(&opts.DB.Port, "port", "80", "Database server port to connect to.") diff --git a/cli/import.go b/cli/import.go index 3bd472ce..f2ef5c07 100644 --- a/cli/import.go +++ b/cli/import.go @@ -60,11 +60,20 @@ var importCmd = &cobra.Command{ defer fle.Close() + // Check to see if the http request type has + // been specified as eith 'http' or 'https' + // as these are the only supported schemes. + + if opts.DB.Type != "http" && opts.DB.Type != "https" { + log.Fatalln("Connection failed - please specify 'http' or 'https' for the scheme.") + return + } + // Configure the export connection endpoint url // and specify the authentication header using // basic auth for root login. - url := fmt.Sprintf("https://%s@%s:%s/import", opts.Auth.Auth, opts.DB.Host, opts.DB.Port) + url := fmt.Sprintf("%s://%s@%s:%s/import", opts.DB.Type, opts.Auth.Auth, opts.DB.Host, opts.DB.Port) // Create a new http request object that we // can use to connect to the import endpoint @@ -123,6 +132,7 @@ var importCmd = &cobra.Command{ func init() { importCmd.PersistentFlags().StringVarP(&opts.Auth.Auth, "auth", "a", "root:root", "Master authentication details to use when connecting.") + importCmd.PersistentFlags().StringVar(&opts.DB.Type, "scheme", "https", "HTTP connection scheme to use to connect to the database.") importCmd.PersistentFlags().StringVar(&opts.DB.Host, "host", "surreal.io", "Database server host to connect to.") importCmd.PersistentFlags().StringVar(&opts.DB.Port, "port", "80", "Database server port to connect to.") diff --git a/cli/sql.go b/cli/sql.go index 496cca4e..7dedc3b6 100644 --- a/cli/sql.go +++ b/cli/sql.go @@ -50,7 +50,7 @@ var sqlCmd = &cobra.Command{ // creating the file, then return an error. if fle, err = os.OpenFile(args[0], os.O_RDONLY, 0644); err != nil { - log.Fatalln("Import failed - please check the filepath and try again.") + log.Fatalln("SQL failed - please check the filepath and try again.") return } @@ -60,11 +60,20 @@ var sqlCmd = &cobra.Command{ defer fle.Close() + // Check to see if the http request type has + // been specified as eith 'http' or 'https' + // as these are the only supported schemes. + + if opts.DB.Type != "http" && opts.DB.Type != "https" { + log.Fatalln("Connection failed - please specify 'http' or 'https' for the scheme.") + return + } + // Configure the export connection endpoint url // and specify the authentication header using // basic auth for root login. - url := fmt.Sprintf("http://%s@%s:%s/sql", opts.Auth.Auth, opts.DB.Host, opts.DB.Port) + url := fmt.Sprintf("%s://%s@%s:%s/sql", opts.DB.Type, opts.Auth.Auth, opts.DB.Host, opts.DB.Port) // Create a new http request object that we // can use to connect to the import endpoint @@ -141,6 +150,7 @@ var sqlCmd = &cobra.Command{ func init() { sqlCmd.PersistentFlags().StringVarP(&opts.Auth.Auth, "auth", "a", "root:root", "Master authentication details to use when connecting.") + sqlCmd.PersistentFlags().StringVar(&opts.DB.Type, "scheme", "https", "HTTP connection scheme to use to connect to the database.") sqlCmd.PersistentFlags().StringVar(&opts.DB.Host, "host", "surreal.io", "Database server host to connect to.") sqlCmd.PersistentFlags().StringVar(&opts.DB.Port, "port", "80", "Database server port to connect to.") diff --git a/cnf/cnf.go b/cnf/cnf.go index 78745d64..26ba2b2d 100644 --- a/cnf/cnf.go +++ b/cnf/cnf.go @@ -79,6 +79,7 @@ type Options struct { Key []byte // Data encryption key Code string // Data encryption key string Path string // Path to store the data file + Type string // HTTP scheme type to use Host string // Surreal host to connect to Port string // Surreal port to connect to Base string // Base key to use in KV stores