From b489043a11b42ffae12a3a98dd01e122d89ce393 Mon Sep 17 00:00:00 2001 From: tomer-stripe <42354557+tomer-stripe@users.noreply.github.com> Date: Thu, 8 Aug 2019 14:16:27 -0700 Subject: [PATCH] Correctly read device name and profile for listen and http requests (#86) * Correctly read device name and profile for listen and http requests * Remove extra println --- pkg/cmd/delete.go | 2 +- pkg/cmd/get.go | 2 +- pkg/cmd/post.go | 2 +- pkg/config/profile.go | 7 ++++++- pkg/requests/base.go | 2 +- pkg/requests/examples.go | 4 ++-- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/delete.go b/pkg/cmd/delete.go index a966c5e57..0b5c2af7c 100644 --- a/pkg/cmd/delete.go +++ b/pkg/cmd/delete.go @@ -19,7 +19,7 @@ func newDeleteCmd() *deleteCmd { gc := &deleteCmd{} gc.reqs.Method = http.MethodDelete - gc.reqs.Profile = Config.Profile + gc.reqs.Profile = &Config.Profile gc.reqs.Cmd = &cobra.Command{ Use: "delete", Args: validators.ExactArgs(1), diff --git a/pkg/cmd/get.go b/pkg/cmd/get.go index 8938133d4..123886921 100644 --- a/pkg/cmd/get.go +++ b/pkg/cmd/get.go @@ -19,7 +19,7 @@ func newGetCmd() *getCmd { gc := &getCmd{} gc.reqs.Method = http.MethodGet - gc.reqs.Profile = Config.Profile + gc.reqs.Profile = &Config.Profile gc.reqs.Cmd = &cobra.Command{ Use: "get", Args: validators.ExactArgs(1), diff --git a/pkg/cmd/post.go b/pkg/cmd/post.go index 2210b47ab..65090135b 100644 --- a/pkg/cmd/post.go +++ b/pkg/cmd/post.go @@ -19,7 +19,7 @@ func newPostCmd() *postCmd { gc := &postCmd{} gc.reqs.Method = http.MethodPost - gc.reqs.Profile = Config.Profile + gc.reqs.Profile = &Config.Profile gc.reqs.Cmd = &cobra.Command{ Use: "post", Args: validators.ExactArgs(1), diff --git a/pkg/config/profile.go b/pkg/config/profile.go index d619ce661..da76cb40b 100644 --- a/pkg/config/profile.go +++ b/pkg/config/profile.go @@ -33,8 +33,13 @@ func (p *Profile) CreateProfile() error { // GetDeviceName returns the configured device name func (p *Profile) GetDeviceName() (string, error) { + deviceName := viper.GetString("device_name") + if deviceName != "" { + return deviceName, nil + } + if err := viper.ReadInConfig(); err == nil { - return viper.GetString("default.device_name"), nil + return viper.GetString(p.GetConfigField("device_name")), nil } return "", errors.New("your device name has not been configured. Use `stripe login` to set your device name") diff --git a/pkg/requests/base.go b/pkg/requests/base.go index a468b3266..c5c8b7b89 100644 --- a/pkg/requests/base.go +++ b/pkg/requests/base.go @@ -33,7 +33,7 @@ type Base struct { Cmd *cobra.Command Method string - Profile config.Profile + Profile *config.Profile Parameters RequestParameters diff --git a/pkg/requests/examples.go b/pkg/requests/examples.go index be96e3007..55c542c88 100644 --- a/pkg/requests/examples.go +++ b/pkg/requests/examples.go @@ -44,7 +44,7 @@ func (ex *Examples) buildRequest(method string, data []string) (*Base, *RequestP } base := &Base{ - Profile: ex.Profile, + Profile: &ex.Profile, Method: method, SuppressOutput: true, APIBaseURL: ex.APIBaseURL, @@ -472,7 +472,7 @@ func (ex *Examples) WebhookEndpointsList() WebhookEndpointList { } base := &Base{ - Profile: ex.Profile, + Profile: &ex.Profile, Method: http.MethodGet, SuppressOutput: true, }