Add ability to specific http scheme when connecting
Add ability to specific http scheme when connecting to a remote database, when import / exporting / running sql.
This commit is contained in:
parent
f1e4e3961a
commit
17cecae390
4 changed files with 35 additions and 4 deletions
|
@ -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.")
|
||||
|
||||
|
|
|
@ -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.")
|
||||
|
||||
|
|
14
cli/sql.go
14
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.")
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue