Skip to content

Commit

Permalink
Remove the use_rest_api setting
Browse files Browse the repository at this point in the history
After discussing this, we've decided to just take the minor perf hit on
server for now. We can speed up the openapi spec request to make this
less of an issue.

Aslo changed `restClient.Test()` -> `restClient.EnsureExists()`
  • Loading branch information
johnswanson committed Aug 12, 2020
1 parent 4c4c75c commit c4a8029
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 40 deletions.
2 changes: 1 addition & 1 deletion api/context_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func (c *ContextRestClient) newHTTPRequest(method, url string, body io.Reader) (
return req, nil
}

func (c *ContextRestClient) Test() error {
func (c *ContextRestClient) EnsureExists() error {
queryURL, err := url.Parse(c.server)
if err != nil {
return err
Expand Down
29 changes: 2 additions & 27 deletions cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,6 @@ import (
"github.com/spf13/cobra"
)

var TestRestAPIWarningFormatStr = `
The Rest API has been tested and is functional.
To avoid unnecessarily testing the Rest API in the future you can either:
- run "%s setup" from the command line
- add "use_rest_api: true" to your config file (%s)
`

func alwaysUseRestAPI(config *settings.Config) bool {
// set to true explicitly
if config.UseRestAPI != nil && *config.UseRestAPI {
return true
}

// not set, but using cloud
if config.UseRestAPI == nil && config.Host == defaultHost {
return true
}

return false
}

func newContextCommand(config *settings.Config) *cobra.Command {
var contextClient api.ContextInterface

Expand All @@ -46,12 +24,9 @@ func newContextCommand(config *settings.Config) *cobra.Command {
if e != nil {
return e
}
if alwaysUseRestAPI(config) {
return validateToken(config)
}

if contextClient.(*api.ContextRestClient).Test() == nil {
fmt.Printf(TestRestAPIWarningFormatStr, cmd.Root().CommandPath(), config.FileUsed)
// If we're on cloud, we're good.
if (config.Host == defaultHost || contextClient.(*api.ContextRestClient).EnsureExists() == nil) {
return validateToken(config)
}

Expand Down
11 changes: 0 additions & 11 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,6 @@ func setup(opts setupOptions) error {
opts.cfg.Endpoint = defaultEndpoint
}

// Test the rest client, if it works then record it so we know we can use it
// client, err := api.NewContextRestClient(opts.cfg.Host, opts.cfg.RestEndpoint, opts.cfg.Token)
// if err == nil {
// err = client.Test()
// // only set UseRestAPI to true if it was not originally set (allow
// // explicit `false`)
// if err == nil && opts.cfg.UseRestAPI == nil {
// *opts.cfg.UseRestAPI = true
// }
// }

if err := opts.cfg.WriteToDisk(); err != nil {
return errors.Wrap(err, "Failed to save config file")
}
Expand Down
1 change: 0 additions & 1 deletion settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type Config struct {
Endpoint string
Token string
RestEndpoint string `yaml:"rest_endpoint"`
UseRestAPI *bool `yaml:"use_rest_api,omitempty"`
Data *data.YML `yaml:"-"`
Debug bool `yaml:"-"`
Address string `yaml:"-"`
Expand Down

0 comments on commit c4a8029

Please sign in to comment.