From 48cb805f529cbc617d915e288b6157b83595d24a Mon Sep 17 00:00:00 2001 From: Anupam Pokharel <120498245+tonystarkjr3@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:35:14 -0500 Subject: [PATCH 1/6] Feat: Add config SSO option (#377) * added sso style entry * style to type for SSO * setBasicAuth * Win unit test (#355) * Fixed unit tests so they work in windows environments * Removed dead imports * adding Connection close header in http requests of our golang client (#372) Co-authored-by: Anupam Pokharel * Adds PrintCsv() function and unit tests to bluemix/terminal/table (#352) * added PrintCsv() function and unit tests to bluemix/terminal/table * Added handled errors to function PrintCsv * Added unit test for empty table in function PrintCsv * Added translations for error message and returned it --------- Co-authored-by: Aerex * chore: add csv messages to i18n (#373) * chore: bump version to 1.1.0 (#374) * Add recommendation to use Cobra (#368) * Add recommendation to use Cobra * dummy commit --------- Co-authored-by: steveclay * chore: bump packages for vulnerabilities (#376) * docs: added building section for building architectures * docs: improved description on building architectures * docs: Removed extraneous info for architecture requirements * chore(security): resolved vulnerability by updating golang.org/x/net * chore: bumped to 1.1.1 (#380) --------- Co-authored-by: Anupam Pokharel Co-authored-by: Christopher Gallo Co-authored-by: edsonarios Co-authored-by: Aerex Co-authored-by: steveclay Co-authored-by: lmosca --- .../configuration/core_config/bx_config.go | 14 ++++ .../configuration/core_config/repository.go | 2 + common/rest/request.go | 84 ++++++++++++------- 3 files changed, 68 insertions(+), 32 deletions(-) diff --git a/bluemix/configuration/core_config/bx_config.go b/bluemix/configuration/core_config/bx_config.go index 907740f..40b3d36 100644 --- a/bluemix/configuration/core_config/bx_config.go +++ b/bluemix/configuration/core_config/bx_config.go @@ -55,6 +55,7 @@ type BXConfigData struct { Trace string ColorEnabled string HTTPTimeout int + TypeOfSSO string CLIInfoEndpoint string // overwrite the cli info endpoint CheckCLIVersionDisabled bool UsageStatsDisabled bool // deprecated: use UsageStatsEnabled @@ -412,6 +413,13 @@ func (c *bxConfig) ColorEnabled() (enabled string) { return } +func (c *bxConfig) TypeOfSSO() (style string) { + c.read(func() { + style = c.data.TypeOfSSO + }) + return +} + func (c *bxConfig) HTTPTimeout() (timeout int) { c.read(func() { timeout = c.data.HTTPTimeout @@ -639,6 +647,12 @@ func (c *bxConfig) SetHTTPTimeout(timeout int) { }) } +func (c *bxConfig) SetTypeOfSSO(style string) { + c.write(func() { + c.data.TypeOfSSO = style + }) +} + func (c *bxConfig) SetCheckCLIVersionDisabled(disabled bool) { c.write(func() { c.data.CheckCLIVersionDisabled = disabled diff --git a/bluemix/configuration/core_config/repository.go b/bluemix/configuration/core_config/repository.go index 8c035e6..dd9d502 100644 --- a/bluemix/configuration/core_config/repository.go +++ b/bluemix/configuration/core_config/repository.go @@ -51,6 +51,7 @@ type Repository interface { PluginRepos() []models.PluginRepo PluginRepo(string) (models.PluginRepo, bool) IsSSLDisabled() bool + TypeOfSSO() string HTTPTimeout() int CLIInfoEndpoint() string CheckCLIVersionDisabled() bool @@ -99,6 +100,7 @@ type Repository interface { SetPluginRepo(models.PluginRepo) UnsetPluginRepo(string) SetSSLDisabled(bool) + SetTypeOfSSO(string) SetHTTPTimeout(int) // SetUsageSatsDisabled disable or enable usage statistics data collection // Deprecated: use SetUsageSatsEnabled instead diff --git a/common/rest/request.go b/common/rest/request.go index f1badd9..cd37ab6 100644 --- a/common/rest/request.go +++ b/common/rest/request.go @@ -1,44 +1,45 @@ // Request examples: -// // create a simple GET request -// req := GetRequest("http://www.example.com") // -// // set header -// req.Set("Accept", "application/json") +// // create a simple GET request +// req := GetRequest("http://www.example.com") // -// // set query parameters -// req.Query("foo1", "bar1") -// req.Query("foo2", "bar2") +// // set header +// req.Set("Accept", "application/json") // -// // Build to a HTTP request -// req.Build() +// // set query parameters +// req.Query("foo1", "bar1") +// req.Query("foo2", "bar2") // -// // method chaining is also supported -// // the above is equal to: -// GetRequest("http://www.example.com"). -// Set("Accept", "application/json"). -// Query("foo1", "bar1"). -// Query("foo2", "bar2"). -// Build() +// // Build to a HTTP request +// req.Build() // -// // struct body -// foo = Foo{Bar: "val"} -// PostRequest("http://www.example.com"). -// Body(foo) +// // method chaining is also supported +// // the above is equal to: +// GetRequest("http://www.example.com"). +// Set("Accept", "application/json"). +// Query("foo1", "bar1"). +// Query("foo2", "bar2"). +// Build() // -// // String body -// PostRequest("http://www.example.com"). -// Body("{\"bar\": \"val\"}") +// // struct body +// foo = Foo{Bar: "val"} +// PostRequest("http://www.example.com"). +// Body(foo) // -// // Stream body -// PostRequest("http://www.example.com"). -// Body(strings.NewReader("abcde")) +// // String body +// PostRequest("http://www.example.com"). +// Body("{\"bar\": \"val\"}") // -// // Multipart POST request -// var f *os.File -// PostRequest("http://www.example.com"). -// Field("foo", "bar"). -// File("file1", File{Name: f.Name(), Content: f}). -// File("file2", File{Name: "1.txt", Content: []byte("abcde"), Type: "text/plain"}) +// // Stream body +// PostRequest("http://www.example.com"). +// Body(strings.NewReader("abcde")) +// +// // Multipart POST request +// var f *os.File +// PostRequest("http://www.example.com"). +// Field("foo", "bar"). +// File("file1", File{Name: f.Name(), Content: f}). +// File("file2", File{Name: "1.txt", Content: []byte("abcde"), Type: "text/plain"}) package rest import ( @@ -79,6 +80,8 @@ type Request struct { queryParams url.Values formParams url.Values + basicAuthn *BasicAuthInfo + // files to upload files map[string][]File @@ -86,6 +89,11 @@ type Request struct { body interface{} } +type BasicAuthInfo struct { + user string + pass string +} + // NewRequest creates a new request with a given rawUrl. func NewRequest(rawUrl string) *Request { return &Request{ @@ -165,6 +173,14 @@ func (r *Request) Set(key string, value string) *Request { return r } +func (r *Request) SetBasicAuth(user string, pass string) *Request { + r.basicAuthn = &BasicAuthInfo{ + user: user, + pass: pass, + } + return r +} + // Query appends the key, value pair to the request query which will be // encoded as url query parameters on HTTP request's url. func (r *Request) Query(key string, value string) *Request { @@ -210,6 +226,10 @@ func (r *Request) Build() (*http.Request, error) { return req, err } + if r.basicAuthn != nil { + req.SetBasicAuth(r.basicAuthn.user, r.basicAuthn.pass) + } + for k, vs := range r.header { for _, v := range vs { req.Header.Add(k, v) From 8987d5ba34489285383dd40ee43d9e0643093e60 Mon Sep 17 00:00:00 2001 From: Anupam Pokharel <120498245+tonystarkjr3@users.noreply.github.com> Date: Thu, 14 Mar 2024 08:06:47 -0500 Subject: [PATCH 2/6] bump version (#398) --- bluemix/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bluemix/version.go b/bluemix/version.go index 0c17f77..74497e4 100644 --- a/bluemix/version.go +++ b/bluemix/version.go @@ -3,7 +3,7 @@ package bluemix import "fmt" // Version is the SDK version -var Version = VersionType{Major: 1, Minor: 2, Build: 0} +var Version = VersionType{Major: 1, Minor: 3, Build: 0} // VersionType describe version info type VersionType struct { From b24ed86511ffda55bdd98c0bb9c07ddbccee6e1e Mon Sep 17 00:00:00 2001 From: Aerex Date: Tue, 14 May 2024 10:39:20 -0400 Subject: [PATCH 3/6] refactor: removed all Cloud Foundry related logic and documentation (#400) --- bluemix/authentication/iam/iam.go | 28 +- bluemix/authentication/uaa/uaa.go | 193 --- .../configuration/config_helpers/helpers.go | 12 - .../configuration/core_config/bx_config.go | 34 +- .../core_config/bx_config_test.go | 4 +- .../configuration/core_config/cf_config.go | 528 ------ .../core_config/cf_config_test.go | 170 -- .../core_config/iam_token_test.go | 8 - .../configuration/core_config/repository.go | 111 +- .../configuration/core_config/uaa_token.go | 53 - .../core_config/uaa_token_test.go | 45 - bluemix/crn/crn.go | 7 - bluemix/models/region.go | 3 +- docs/interface_summary.md | 55 +- docs/plugin_developer_guide.md | 91 +- plugin/plugin.go | 78 +- plugin/plugin_context.go | 32 - plugin/pluginfakes/fake_cfcontext.go | 855 ---------- plugin/pluginfakes/fake_plugin.go | 146 -- plugin/pluginfakes/fake_plugin_config.go | 1428 ----------------- plugin/pluginfakes/fake_plugin_context.go | 586 ++----- plugin_examples/auto_complete_delegation.go | 84 - plugin_examples/context.go | 66 - plugin_examples/hello.go | 36 - .../list_plugin/api/api_suite_test.go | 13 - plugin_examples/list_plugin/api/cc_client.go | 62 - .../list_plugin/api/cc_client_test.go | 215 --- .../list_plugin/api/container_client.go | 65 - .../list_plugin/api/container_client_test.go | 209 --- .../list_plugin/api/fakes/fake_ccclient.go | 98 -- .../api/fakes/fake_container_client.go | 98 -- .../list_plugin/bin/generate-i18n-resources | 9 - .../commands/commands_suite_test.go | 18 - plugin_examples/list_plugin/commands/list.go | 190 --- .../list_plugin/commands/list_test.go | 216 --- plugin_examples/list_plugin/i18n/i18n.go | 110 -- .../list_plugin/i18n/i18n_suite_test.go | 13 - plugin_examples/list_plugin/i18n/i18n_test.go | 187 --- .../list_plugin/i18n/resources/all.en_US.json | 86 - .../i18n/resources/all.zh_Hans.json | 82 - plugin_examples/list_plugin/models/models.go | 101 -- plugin_examples/list_plugin/plugin.go | 110 -- .../list_plugin/resources/i18n_resources.go | 273 ---- plugin_examples/namespace.go | 66 - plugin_examples/stage.go | 56 - testhelpers/configuration/test_config.go | 3 +- 46 files changed, 250 insertions(+), 6683 deletions(-) delete mode 100644 bluemix/authentication/uaa/uaa.go delete mode 100644 bluemix/configuration/core_config/cf_config.go delete mode 100644 bluemix/configuration/core_config/cf_config_test.go delete mode 100644 bluemix/configuration/core_config/uaa_token.go delete mode 100644 bluemix/configuration/core_config/uaa_token_test.go delete mode 100644 plugin/pluginfakes/fake_cfcontext.go delete mode 100644 plugin/pluginfakes/fake_plugin.go delete mode 100644 plugin/pluginfakes/fake_plugin_config.go delete mode 100644 plugin_examples/auto_complete_delegation.go delete mode 100644 plugin_examples/context.go delete mode 100644 plugin_examples/hello.go delete mode 100644 plugin_examples/list_plugin/api/api_suite_test.go delete mode 100644 plugin_examples/list_plugin/api/cc_client.go delete mode 100644 plugin_examples/list_plugin/api/cc_client_test.go delete mode 100644 plugin_examples/list_plugin/api/container_client.go delete mode 100644 plugin_examples/list_plugin/api/container_client_test.go delete mode 100644 plugin_examples/list_plugin/api/fakes/fake_ccclient.go delete mode 100644 plugin_examples/list_plugin/api/fakes/fake_container_client.go delete mode 100755 plugin_examples/list_plugin/bin/generate-i18n-resources delete mode 100644 plugin_examples/list_plugin/commands/commands_suite_test.go delete mode 100644 plugin_examples/list_plugin/commands/list.go delete mode 100644 plugin_examples/list_plugin/commands/list_test.go delete mode 100644 plugin_examples/list_plugin/i18n/i18n.go delete mode 100644 plugin_examples/list_plugin/i18n/i18n_suite_test.go delete mode 100644 plugin_examples/list_plugin/i18n/i18n_test.go delete mode 100644 plugin_examples/list_plugin/i18n/resources/all.en_US.json delete mode 100644 plugin_examples/list_plugin/i18n/resources/all.zh_Hans.json delete mode 100644 plugin_examples/list_plugin/models/models.go delete mode 100644 plugin_examples/list_plugin/plugin.go delete mode 100644 plugin_examples/list_plugin/resources/i18n_resources.go delete mode 100644 plugin_examples/namespace.go delete mode 100644 plugin_examples/stage.go diff --git a/bluemix/authentication/iam/iam.go b/bluemix/authentication/iam/iam.go index 246f61c..4e3e8a8 100644 --- a/bluemix/authentication/iam/iam.go +++ b/bluemix/authentication/iam/iam.go @@ -14,14 +14,12 @@ import ( ) const ( - defaultClientID = "bx" - defaultClientSecret = "bx" - defaultUAAClientID = "cf" - defaultUAAClientSecret = "" - crTokenParam = "cr_token" - profileIDParam = "profile_id" - profileNameParam = "profile_name" - profileCRNParam = "profile_crn" + defaultClientID = "bx" + defaultClientSecret = "bx" + crTokenParam = "cr_token" + profileIDParam = "profile_id" + profileNameParam = "profile_name" + profileCRNParam = "profile_crn" ) // Grant types @@ -40,7 +38,6 @@ const ( // Response types const ( ResponseTypeIAM authentication.ResponseType = "cloud_iam" - ResponseTypeUAA authentication.ResponseType = "uaa" ResponseTypeIMS authentication.ResponseType = "ims_portal" ResponseTypeDelegatedRefreshToken authentication.ResponseType = "delegated_refresh_token" // #nosec G101 - this the API response grant type. Not a credential ) @@ -191,10 +188,6 @@ type Token struct { Scope string `json:"scope"` Expiry time.Time `json:"expiration"` - // Fields present when ResponseTypeUAA is set - UAAToken string `json:"uaa_token"` - UAARefreshToken string `json:"uaa_refresh_token"` - // Fields present when ResponseTypeIMS is set IMSUserID int64 `json:"ims_user_id"` IMSToken string `json:"ims_token"` @@ -263,8 +256,6 @@ func DefaultConfig(iamEndpoint string) Config { SessionEndpoint: iamEndpoint + "/v1/sessions", ClientID: defaultClientID, ClientSecret: defaultClientSecret, - UAAClientID: defaultUAAClientID, - UAAClientSecret: defaultUAAClientSecret, } } @@ -285,13 +276,6 @@ func (c *client) GetToken(tokenReq *authentication.TokenRequest) (*Token, error) tokenReq.SetValue(v) responseTypes := tokenReq.ResponseTypes() - for _, t := range responseTypes { - if t == ResponseTypeUAA { - v.Set("uaa_client_id", c.config.UAAClientID) - v.Set("uaa_client_secret", c.config.UAAClientSecret) - break - } - } if len(responseTypes) == 0 { v.Set("response_type", ResponseTypeIAM.String()) } diff --git a/bluemix/authentication/uaa/uaa.go b/bluemix/authentication/uaa/uaa.go deleted file mode 100644 index 9db61e5..0000000 --- a/bluemix/authentication/uaa/uaa.go +++ /dev/null @@ -1,193 +0,0 @@ -package uaa - -import ( - "encoding/base64" - "encoding/json" - "fmt" - "net/url" - "time" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/authentication" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/common/rest" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/common/types" -) - -const ( - defaultClientID = "cf" - defaultClientSecret = "" -) - -// Grant types -const ( - GrantTypePassword authentication.GrantType = "password" - GrantTypeRefreshToken authentication.GrantType = "refresh_token" - GrantTypeAuthorizationCode authentication.GrantType = "authorization_code" - GrantTypeIAMToken authentication.GrantType = "iam_token" -) - -// Response types -const ( - ResponseTypeUAA authentication.ResponseType = "uaa" -) - -type APIError struct { - ErrorCode string `json:"error"` - Description string `json:"error_description"` -} - -func PasswordTokenRequest(username, password string, opts ...authentication.TokenOption) *authentication.TokenRequest { - r := authentication.NewTokenRequest(GrantTypePassword) - r.SetTokenParam("username", username) - r.SetTokenParam("password", password) - for _, o := range opts { - r.WithOption(o) - } - return r -} - -func OnetimePasscodeTokenRequest(passcode string, opts ...authentication.TokenOption) *authentication.TokenRequest { - r := authentication.NewTokenRequest(GrantTypePassword) - r.SetTokenParam("passcode", passcode) - for _, o := range opts { - r.WithOption(o) - } - return r -} - -func APIKeyTokenRequest(apiKey string, opts ...authentication.TokenOption) *authentication.TokenRequest { - r := authentication.NewTokenRequest(GrantTypePassword) - r.SetTokenParam("username", "apikey") - r.SetTokenParam("password", apiKey) - for _, o := range opts { - r.WithOption(o) - } - return r -} - -func AuthorizationTokenRequest(code string, redirectURI string, opts ...authentication.TokenOption) *authentication.TokenRequest { - r := authentication.NewTokenRequest(GrantTypeAuthorizationCode) - r.SetTokenParam("code", code) - r.SetTokenParam("redirect_uri", redirectURI) - for _, o := range opts { - r.WithOption(o) - } - return r -} - -func RefreshTokenRequest(refreshToken string, opts ...authentication.TokenOption) *authentication.TokenRequest { - r := authentication.NewTokenRequest(GrantTypeRefreshToken) - r.SetTokenParam("refresh_token", refreshToken) - for _, o := range opts { - r.WithOption(o) - } - return r -} - -func ConnectToIAM(iamAccessToken string) authentication.TokenOption { - return func(r *authentication.TokenRequest) { - r.SetTokenParam("connect_to_iam_token", iamAccessToken) - } -} - -type Token struct { - AccessToken string `json:"access_token"` - RefreshToken string `json:"refresh_token"` - TokenType string `json:"token_type"` - Expiry time.Time `json:"expires_in"` - Scope string `json:"scope"` -} - -type Interface interface { - GetToken(req *authentication.TokenRequest) (*Token, error) - ConnectToIAM(iamAccessToken string) (*Token, error) - DisconnectIAM(uaaToken string) error -} - -type Config struct { - UAAEndpoint string - ClientID string - ClientSecret string -} - -func DefaultConfig(uaaEndpoint string) Config { - return Config{ - UAAEndpoint: uaaEndpoint, - ClientID: defaultClientID, - ClientSecret: defaultClientSecret, - } -} - -type client struct { - config Config - client *rest.Client -} - -func NewClient(config Config, restClient *rest.Client) Interface { - return &client{ - config: config, - client: restClient, - } -} - -func (c *client) GetToken(tokenReq *authentication.TokenRequest) (*Token, error) { - v := make(url.Values) - tokenReq.SetValue(v) - - if len(tokenReq.ResponseTypes()) == 0 { - v.Set("response_type", ResponseTypeUAA.String()) - } - - r := rest.PostRequest(c.config.UAAEndpoint+"/oauth/token"). - Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", c.config.ClientID, c.config.ClientSecret)))). - Field("scope", "") - - for k, ss := range v { - for _, s := range ss { - r.Field(k, s) - } - } - - var tokenResponse struct { - Token - Expiry types.UnixTime `json:"expires_in"` - } - if err := c.doRequest(r, &tokenResponse); err != nil { - return nil, err - } - - ret := tokenResponse.Token - ret.Expiry = time.Time(tokenResponse.Expiry) - return &ret, nil -} - -func (c *client) ConnectToIAM(iamAccessToken string) (*Token, error) { - r := authentication.NewTokenRequest(GrantTypeIAMToken) - r.SetTokenParam("iam_token", iamAccessToken) - return c.GetToken(r) -} - -func (c *client) DisconnectIAM(uaaToken string) error { - r := rest.PostRequest(c.config.UAAEndpoint+"/oauth/token/disconnect"). - Set("Authorization", uaaToken) - return c.doRequest(r, nil) -} - -func (c *client) doRequest(req *rest.Request, respV interface{}) error { - _, err := c.client.Do(req, respV, nil) - switch err := err.(type) { - case *rest.ErrorResponse: - var apiErr APIError - if e := json.Unmarshal([]byte(err.Message), &apiErr); e == nil { - switch apiErr.ErrorCode { - case "": - case "invalid_grant": - return authentication.NewInvalidGrantTypeError(apiErr.Description) - case "invalid-token": - return authentication.NewInvalidTokenError(apiErr.Description) - default: - return authentication.NewServerError(err.StatusCode, apiErr.ErrorCode, apiErr.Description) - } - } - } - return err -} diff --git a/bluemix/configuration/config_helpers/helpers.go b/bluemix/configuration/config_helpers/helpers.go index 0e5c2cf..a227d8b 100644 --- a/bluemix/configuration/config_helpers/helpers.go +++ b/bluemix/configuration/config_helpers/helpers.go @@ -70,18 +70,6 @@ func PluginBinaryLocation(pluginName string) string { return executable } -func CFHome() string { - return ConfigDir() -} - -func CFConfigDir() string { - return filepath.Join(CFHome(), ".cf") -} - -func CFConfigFilePath() string { - return filepath.Join(CFConfigDir(), "config.json") -} - func UserHomeDir() string { if runtime.GOOS == "windows" { home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH") diff --git a/bluemix/configuration/core_config/bx_config.go b/bluemix/configuration/core_config/bx_config.go index 40b3d36..693d9a0 100644 --- a/bluemix/configuration/core_config/bx_config.go +++ b/bluemix/configuration/core_config/bx_config.go @@ -45,8 +45,6 @@ type BXConfigData struct { Profile models.Profile ResourceGroup models.ResourceGroup LoginAt time.Time - CFEETargeted bool - CFEEEnvID string PluginRepos []models.PluginRepo SSLDisabled bool Locale string @@ -212,8 +210,7 @@ func (c *bxConfig) ConsoleEndpoints() (endpoints models.Endpoints) { func (c *bxConfig) CurrentRegion() (region models.Region) { c.read(func() { region = models.Region{ - MCCPID: c.data.RegionID, - Name: c.data.Region, + Name: c.data.Region, } }) return @@ -311,7 +308,7 @@ func (c *bxConfig) IsLoggedIn() bool { if token, refresh := c.IAMToken(), c.IAMRefreshToken(); token != "" || refresh != "" { iamTokenInfo := NewIAMTokenInfo(token) if iamTokenInfo.hasExpired() && refresh != "" { - repo := newRepository(c, nil) + repo := newRepository(c) if _, err := repo.RefreshIAMToken(); err != nil { return false } @@ -510,20 +507,6 @@ func (c *bxConfig) SDKVersion() (version string) { return } -func (c *bxConfig) HasTargetedCFEE() (targeted bool) { - c.read(func() { - targeted = c.data.CFEETargeted - }) - return -} - -func (c *bxConfig) CFEEEnvID() (envID string) { - c.read(func() { - envID = c.data.CFEEEnvID - }) - return -} - func (c *bxConfig) SetAPIEndpoint(endpoint string) { c.write(func() { c.data.APIEndpoint = endpoint @@ -553,7 +536,6 @@ func (c *bxConfig) SetConsoleEndpoints(endpoint models.Endpoints) { func (c *bxConfig) SetRegion(region models.Region) { c.write(func() { c.data.Region = region.Name - c.data.RegionID = region.MCCPID }) } @@ -714,18 +696,6 @@ func (c *bxConfig) SetTrace(trace string) { }) } -func (c *bxConfig) SetCFEETargeted(targeted bool) { - c.write(func() { - c.data.CFEETargeted = targeted - }) -} - -func (c *bxConfig) SetCFEEEnvID(envID string) { - c.write(func() { - c.data.CFEEEnvID = envID - }) -} - func (c *bxConfig) SetCloudType(ctype string) { c.write(func() { c.data.CloudType = ctype diff --git a/bluemix/configuration/core_config/bx_config_test.go b/bluemix/configuration/core_config/bx_config_test.go index 7a65474..79171a5 100644 --- a/bluemix/configuration/core_config/bx_config_test.go +++ b/bluemix/configuration/core_config/bx_config_test.go @@ -534,13 +534,11 @@ func checkUsageStats(enabled bool, timeStampExist bool, config core_config.Repos func prepareConfigForCLI(cliConfigContent string, t *testing.T) core_config.Repository { ioutil.WriteFile("config.json", []byte(cliConfigContent), 0644) - ioutil.WriteFile("cf_config.json", []byte(""), 0644) - return core_config.NewCoreConfigFromPath("cf_config.json", "config.json", func(err error) { + return core_config.NewCoreConfigFromPath("config.json", func(err error) { t.Fatal(err.Error()) }) } func cleanupConfigFiles() { os.Remove("config.json") - os.Remove("cf_config.json") } diff --git a/bluemix/configuration/core_config/cf_config.go b/bluemix/configuration/core_config/cf_config.go deleted file mode 100644 index 5e534f4..0000000 --- a/bluemix/configuration/core_config/cf_config.go +++ /dev/null @@ -1,528 +0,0 @@ -package core_config - -import ( - "encoding/json" - "errors" - "fmt" - "sync" - "time" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/authentication/uaa" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/configuration" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/models" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/common/rest" - "github.com/fatih/structs" -) - -type CFConfigData struct { - AccessToken string - APIVersion string - AsyncTimeout uint - AuthorizationEndpoint string - ColorEnabled string - ConfigVersion int - DopplerEndpoint string - Locale string - LogCacheEndPoint string - MinCLIVersion string - MinRecommendedCLIVersion string - OrganizationFields models.OrganizationFields - PluginRepos []models.PluginRepo - RefreshToken string - RoutingAPIEndpoint string - SpaceFields models.SpaceFields - SSHOAuthClient string - SSLDisabled bool - Target string - Trace string - UaaEndpoint string - LoginAt time.Time - UAAGrantType string - UAAOAuthClient string - UAAOAuthClientSecret string - raw raw -} - -func NewCFConfigData() *CFConfigData { - data := new(CFConfigData) - data.raw = make(map[string]interface{}) - - data.UAAOAuthClient = "cf" - data.UAAOAuthClientSecret = "" - - return data -} - -func (data *CFConfigData) Marshal() ([]byte, error) { - if data.ConfigVersion != 3 { - data.ConfigVersion = 4 - } - return json.MarshalIndent(data, "", " ") -} - -func (data *CFConfigData) Unmarshal(bytes []byte) error { - err := json.Unmarshal(bytes, data) - if err != nil { - return err - } - - // clear out config if version is not 3 or 4 - if data.ConfigVersion < 3 || data.ConfigVersion > 4 { - *data = CFConfigData{raw: make(map[string]interface{})} - return nil - } - - var raw raw - err = json.Unmarshal(bytes, &raw) - if err != nil { - return err - } - - data.raw = raw - return nil -} - -type cfConfig struct { - data *CFConfigData - persistor configuration.Persistor - initOnce *sync.Once - lock sync.Mutex - onError func(error) -} - -func createCFConfigFromPersistor(persistor configuration.Persistor, errHandler func(error)) *cfConfig { - data := NewCFConfigData() - if !persistor.Exists() { - data.PluginRepos = []models.PluginRepo{ - { - Name: "CF-Community", - URL: "https://plugins.cloudfoundry.org", - }, - } - } - - return &cfConfig{ - data: data, - persistor: persistor, - initOnce: new(sync.Once), - onError: errHandler, - } -} - -func (c *cfConfig) init() { - c.initOnce.Do(func() { - err := c.persistor.Load(c.data) - if err != nil { - c.onError(err) - } - }) -} - -func (c *cfConfig) read(cb func()) { - /* concurrency note: init() calls the persistor's Load(), which has a flock, - via lockedRead() and lockedWrite(), surrounding the critical sections */ - c.init() - - cb() -} - -func (c *cfConfig) write(cb func()) { - c.lock.Lock() - defer c.lock.Unlock() - - c.init() - - cb() - - c.data.raw = structs.Map(c.data) - - err := c.persistor.Save(c.data) - if err != nil { - c.onError(err) - } -} - -func (c *cfConfig) writeRaw(cb func()) { - c.lock.Lock() - defer c.lock.Unlock() - - c.init() - - cb() - - err := c.persistor.Save(c.data.raw) - if err != nil { - c.onError(err) - } -} - -func (c *cfConfig) refreshToken(refreshToken string) (uaa.Token, error) { - auth := uaa.NewClient(uaa.DefaultConfig(c.data.AuthorizationEndpoint), rest.NewClient()) - refreshedToken, err := auth.GetToken(uaa.RefreshTokenRequest(refreshToken)) - if err != nil { - return uaa.Token{}, err - } - - // return an error if refreshed token is invalid - refreshedTokenInfo := NewUAATokenInfo(refreshedToken.AccessToken) - if !refreshedTokenInfo.exists() { - return uaa.Token{}, errors.New("could not refresh token") - } - - return *refreshedToken, nil -} - -func (c *cfConfig) APIVersion() (version string) { - c.read(func() { - version = c.data.APIVersion - }) - return -} - -func (c *cfConfig) APIEndpoint() (endpoint string) { - c.read(func() { - endpoint = c.data.Target - }) - return -} - -func (c *cfConfig) AsyncTimeout() (timeout uint) { - c.read(func() { - timeout = c.data.AsyncTimeout - }) - return -} - -func (c *cfConfig) HasAPIEndpoint() (hasEndpoint bool) { - c.read(func() { - hasEndpoint = c.data.APIVersion != "" && c.data.Target != "" - }) - return -} - -func (c *cfConfig) AuthenticationEndpoint() (endpoint string) { - c.read(func() { - endpoint = c.data.AuthorizationEndpoint - }) - return -} - -func (c *cfConfig) DopplerEndpoint() (endpoint string) { - c.read(func() { - endpoint = c.data.DopplerEndpoint - }) - return -} - -func (c *cfConfig) UAAEndpoint() (endpoint string) { - c.read(func() { - endpoint = c.data.UaaEndpoint - }) - return -} - -func (c *cfConfig) RoutingAPIEndpoint() (endpoint string) { - c.read(func() { - endpoint = c.data.RoutingAPIEndpoint - }) - return -} - -// func (c *cfConfig) UAAOAuthClient() (client string) { -// c.read(func() { -// client = c.data.UAAOAuthClient -// }) -// return -// } - -// func (c *cfConfig) UAAOAuthClientSecret() (secret string) { -// c.read(func() { -// secret = c.data.UAAOAuthClientSecret -// }) -// return -// } - -func (c *cfConfig) SSHOAuthClient() (client string) { - c.read(func() { - client = c.data.SSHOAuthClient - }) - return -} - -func (c *cfConfig) MinCFCLIVersion() (version string) { - c.read(func() { - version = c.data.MinCLIVersion - }) - return -} - -func (c *cfConfig) MinRecommendedCFCLIVersion() (version string) { - c.read(func() { - version = c.data.MinRecommendedCLIVersion - }) - return -} - -func (c *cfConfig) UAAToken() (token string) { - c.read(func() { - token = c.data.AccessToken - }) - return -} - -func (c *cfConfig) UAARefreshToken() (token string) { - c.read(func() { - token = c.data.RefreshToken - }) - return -} - -func (c *cfConfig) UserEmail() (email string) { - c.read(func() { - email = NewUAATokenInfo(c.data.AccessToken).Email - }) - return -} - -func (c *cfConfig) UserGUID() (guid string) { - c.read(func() { - guid = NewUAATokenInfo(c.data.AccessToken).UserGUID - }) - return -} - -func (c *cfConfig) Username() (name string) { - c.read(func() { - name = NewUAATokenInfo(c.data.AccessToken).Username - }) - return -} - -// IsLoggedIn will check if the user is logged in. To determine if the user is logged in both the -// token and the refresh token will be checked -// If token is near expiration or expired, and a refresh token is present attempt to refresh the token. -// If token refresh was successful, check if the new UAA token is valid. If valid, user is logged in, -// otherwise user can be considered logged out. If refresh failed, then user is considered logged out. -// If no refresh token is present, and token is expired, then user is considered logged out. -func (c *cfConfig) IsLoggedIn() (loggedIn bool) { - if token, refresh := c.UAAToken(), c.UAARefreshToken(); token != "" || refresh != "" { - uaaTokenInfo := NewUAATokenInfo(token) - if uaaTokenInfo.hasExpired() && refresh != "" { - refreshedToken, err := c.refreshToken(token) - if err != nil { - return false - } - - // Check again to make sure that the new token has not expired - if uaaTokenInfo = NewUAATokenInfo(c.UAAToken()); uaaTokenInfo.hasExpired() { - return false - } - - uaaToken := fmt.Sprintf("%s %s", refreshedToken.TokenType, refreshedToken.AccessToken) - c.SetUAAToken(uaaToken) - c.SetUAARefreshToken(refreshedToken.RefreshToken) - - return true - } else if uaaTokenInfo.hasExpired() && refresh == "" { - return false - } else { - return true - } - } - - return false -} - -func (c *cfConfig) CurrentOrganization() (org models.OrganizationFields) { - c.read(func() { - org = c.data.OrganizationFields - }) - return -} - -func (c *cfConfig) HasTargetedOrganization() (hasOrg bool) { - c.read(func() { - hasOrg = c.data.OrganizationFields.GUID != "" && c.data.OrganizationFields.Name != "" - }) - return -} - -func (c *cfConfig) CurrentSpace() (space models.SpaceFields) { - c.read(func() { - space = c.data.SpaceFields - }) - return -} - -func (c *cfConfig) HasTargetedSpace() (hasSpace bool) { - c.read(func() { - hasSpace = c.data.SpaceFields.GUID != "" && c.data.SpaceFields.Name != "" - }) - return -} - -func (c *cfConfig) IsSSLDisabled() (isSSLDisabled bool) { - c.read(func() { - isSSLDisabled = c.data.SSLDisabled - }) - return -} - -func (c *cfConfig) Trace() (trace string) { - c.read(func() { - trace = c.data.Trace - }) - return -} - -func (c *cfConfig) ColorEnabled() (enabled string) { - c.read(func() { - enabled = c.data.ColorEnabled - }) - return -} - -func (c *cfConfig) Locale() (locale string) { - c.read(func() { - locale = c.data.Locale - }) - return -} - -func (c *cfConfig) SetAPIVersion(version string) { - c.write(func() { - c.data.APIVersion = version - }) -} - -func (c *cfConfig) SetAPIEndpoint(endpoint string) { - c.write(func() { - c.data.Target = endpoint - }) -} - -func (c *cfConfig) SetAuthenticationEndpoint(endpoint string) { - c.write(func() { - c.data.AuthorizationEndpoint = endpoint - }) -} - -func (c *cfConfig) SetDopplerEndpoint(endpoint string) { - c.write(func() { - c.data.DopplerEndpoint = endpoint - }) -} - -func (c *cfConfig) SetUAAEndpoint(endpoint string) { - c.write(func() { - c.data.UaaEndpoint = endpoint - }) -} - -func (c *cfConfig) SetRoutingAPIEndpoint(endpoint string) { - c.write(func() { - c.data.RoutingAPIEndpoint = endpoint - }) -} - -func (c *cfConfig) SetSSHOAuthClient(client string) { - c.write(func() { - c.data.SSHOAuthClient = client - }) -} - -func (c *cfConfig) SetMinCFCLIVersion(version string) { - c.write(func() { - c.data.MinCLIVersion = version - }) -} - -func (c *cfConfig) SetMinRecommendedCFCLIVersion(version string) { - c.write(func() { - c.data.MinRecommendedCLIVersion = version - }) -} - -func (c *cfConfig) SetUAAToken(token string) { - c.writeRaw(func() { - c.data.AccessToken = token - c.data.raw["AccessToken"] = token - }) -} - -func (c *cfConfig) SetUAARefreshToken(token string) { - c.writeRaw(func() { - c.data.RefreshToken = token - c.data.raw["RefreshToken"] = token - }) -} - -func (c *cfConfig) SetOrganization(org models.OrganizationFields) { - c.write(func() { - c.data.OrganizationFields = org - }) -} - -func (c *cfConfig) SetSpace(space models.SpaceFields) { - c.write(func() { - c.data.SpaceFields = space - }) -} - -func (c *cfConfig) SetLocale(locale string) { - c.write(func() { - c.data.Locale = locale - }) -} - -func (c *cfConfig) SetSSLDisabled(sslDisabled bool) { - c.write(func() { - c.data.SSLDisabled = sslDisabled - }) -} - -func (c *cfConfig) SetTrace(trace string) { - c.write(func() { - c.data.Trace = trace - }) -} - -func (c *cfConfig) SetColorEnabled(colorEnabled string) { - c.write(func() { - c.data.ColorEnabled = colorEnabled - }) -} - -func (c *cfConfig) UnsetAPI() { - c.write(func() { - c.data.APIVersion = "" - c.data.Target = "" - c.data.AuthorizationEndpoint = "" - c.data.UaaEndpoint = "" - c.data.RoutingAPIEndpoint = "" - c.data.DopplerEndpoint = "" - }) -} - -func (c *cfConfig) LoginAt() (loginAt time.Time) { - c.read(func() { - loginAt = c.data.LoginAt - }) - return -} - -func (c *cfConfig) SetLoginAt(loginAt time.Time) { - c.write(func() { - c.data.LoginAt = loginAt - }) -} - -func (c *cfConfig) ClearSession() { - c.write(func() { - c.data.AccessToken = "" - c.data.RefreshToken = "" - c.data.OrganizationFields = models.OrganizationFields{} - c.data.SpaceFields = models.SpaceFields{} - c.data.LoginAt = time.Time{} - }) -} diff --git a/bluemix/configuration/core_config/cf_config_test.go b/bluemix/configuration/core_config/cf_config_test.go deleted file mode 100644 index b91abf0..0000000 --- a/bluemix/configuration/core_config/cf_config_test.go +++ /dev/null @@ -1,170 +0,0 @@ -package core_config_test - -import ( - "testing" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/configuration/core_config" - "github.com/stretchr/testify/assert" -) - -func TestNewConfig(t *testing.T) { - c := core_config.NewCFConfigData() - - assert.Equal(t, "cf", c.UAAOAuthClient) - assert.Equal(t, "", c.UAAOAuthClientSecret) - -} - -var v4JSON = `{ - "AccessToken": "foo", - "APIVersion": "5", - "AsyncTimeout": 0, - "AuthorizationEndpoint": "iam.test.cloud.ibm.com", - "ColorEnabled": "", - "ConfigVersion": 4, - "DopplerEndpoint": "", - "Locale": "", - "LogCacheEndPoint": "", - "MinCLIVersion": "", - "MinRecommendedCLIVersion": "", - "OrganizationFields": { - "GUID": "", - "Name": "", - "QuotaDefinition": { - "name": "", - "memory_limit": 0, - "instance_memory_limit": 0, - "total_routes": 0, - "total_services": 0, - "non_basic_services_allowed": false, - "app_instance_limit": 0 - } - }, - "PluginRepos": null, - "RefreshToken": "", - "RoutingAPIEndpoint": "", - "SpaceFields": { - "GUID": "", - "Name": "", - "AllowSSH": false - }, - "SSHOAuthClient": "", - "SSLDisabled": false, - "Target": "", - "Trace": "", - "UaaEndpoint": "", - "LoginAt": "0001-01-01T00:00:00Z", - "UAAGrantType": "", - "UAAOAuthClient": "cf", - "UAAOAuthClientSecret": "" -}` - -func TestMarshal(t *testing.T) { - c := core_config.NewCFConfigData() - c.APIVersion = "5" - c.AccessToken = "foo" - c.AuthorizationEndpoint = "iam.test.cloud.ibm.com" - - bytes, err := c.Marshal() - assert.NoError(t, err) - assert.Equal(t, string(bytes), v4JSON) -} - -func TestUnmarshalV4(t *testing.T) { - c := core_config.NewCFConfigData() - assert.NoError(t, c.Unmarshal([]byte(v4JSON))) - - assert.Equal(t, 4, c.ConfigVersion) - assert.Equal(t, "5", c.APIVersion) - assert.Equal(t, "foo", c.AccessToken) - assert.Equal(t, "iam.test.cloud.ibm.com", c.AuthorizationEndpoint) -} - -func TestUnmarshalV3(t *testing.T) { - var v3JSON = `{ - "AccessToken": "bar", - "APIVersion": "4", - "AsyncTimeout": 0, - "AuthorizationEndpoint": "iam.test.cloud.ibm.com", - "ColorEnabled": "", - "ConfigVersion": 3, - "DopplerEndpoint": "", - "Locale": "", - "LogCacheEndPoint": "", - "MinCLIVersion": "", - "MinRecommendedCLIVersion": "", - "OrganizationFields": { - "GUID": "", - "Name": "", - "QuotaDefinition": { - "name": "", - "memory_limit": 0, - "instance_memory_limit": 0, - "total_routes": 0, - "total_services": 0, - "non_basic_services_allowed": false, - "app_instance_limit": 0 - } - }, - "PluginRepos": null, - "RefreshToken": "", - "RoutingAPIEndpoint": "", - "SpaceFields": { - "GUID": "", - "Name": "", - "AllowSSH": false - }, - "SSHOAuthClient": "", - "SSLDisabled": false, - "Target": "", - "Trace": "", - "UaaEndpoint": "", - "LoginAt": "0001-01-01T00:00:00Z", - "UAAGrantType": "", - "UAAOAuthClient": "cf", - "UAAOAuthClientSecret": "" -}` - - c := core_config.NewCFConfigData() - assert.NoError(t, c.Unmarshal([]byte(v3JSON))) - - assert.Equal(t, 3, c.ConfigVersion) - assert.Equal(t, "4", c.APIVersion) - assert.Equal(t, "bar", c.AccessToken) - assert.Equal(t, "iam.test.cloud.ibm.com", c.AuthorizationEndpoint) -} - -func TestUnmarshalV2(t *testing.T) { - var v2JSON = `{ - "AccessToken": "bar", - "APIVersion": "4", - "AsyncTimeout": 0, - "AuthorizationEndpoint": "iam.test.cloud.ibm.com", - "ColorEnabled": "", - "ConfigVersion": 2 -}` - c := core_config.NewCFConfigData() - assert.NoError(t, c.Unmarshal([]byte(v2JSON))) - - assert.Empty(t, 0, c) -} - -func TestUnmarshalV5(t *testing.T) { - var v2JSON = `{ - "AccessToken": "bar", - "APIVersion": "4", - "AsyncTimeout": 0, - "AuthorizationEndpoint": "iam.test.cloud.ibm.com", - "ColorEnabled": "", - "ConfigVersion": 5 -}` - c := core_config.NewCFConfigData() - assert.NoError(t, c.Unmarshal([]byte(v2JSON))) - - assert.Empty(t, 0, c) -} - -func TestUnmarshalError(t *testing.T) { - c := core_config.NewCFConfigData() - assert.Error(t, c.Unmarshal([]byte(`{"db":cf}`))) -} diff --git a/bluemix/configuration/core_config/iam_token_test.go b/bluemix/configuration/core_config/iam_token_test.go index aa71aa0..6cd3da9 100644 --- a/bluemix/configuration/core_config/iam_token_test.go +++ b/bluemix/configuration/core_config/iam_token_test.go @@ -94,14 +94,6 @@ func TestIATandEXP(t *testing.T) { assert.Equal(t, tokenInfo.Expiry.Unix(), int64(1516178203)) } -func TestUAATokenInfo(t *testing.T) { - for _, token := range TestUAATokenData { - tokenInfo := NewUAATokenInfo(token) - assert.Equal(t, tokenInfo.Username, "wangjunl@cn.ibm.com") - assert.Equal(t, tokenInfo.UserGUID, "6787b336-0075-4f0c-affb-e29fc2eaeb88") - } -} - func TestIAMTokenHasExpired(t *testing.T) { for _, testCase := range TestIAMTokenHasExpiredTestCases { t.Run(testCase.name, func(t *testing.T) { diff --git a/bluemix/configuration/core_config/repository.go b/bluemix/configuration/core_config/repository.go index dd9d502..b0fa563 100644 --- a/bluemix/configuration/core_config/repository.go +++ b/bluemix/configuration/core_config/repository.go @@ -114,14 +114,6 @@ type Repository interface { SetTrace(string) SetColorEnabled(string) - CFConfig() CFConfig - HasTargetedCF() bool - HasTargetedCFEE() bool - HasTargetedPublicCF() bool - SetCFEETargeted(bool) - CFEEEnvID() string - SetCFEEEnvID(string) - CheckMessageOfTheDay() bool SetMessageOfTheDayTime() @@ -139,76 +131,18 @@ type ReadWriter interface { Repository } -type CFConfig interface { - APIVersion() string - APIEndpoint() string - AsyncTimeout() uint - ColorEnabled() string - HasAPIEndpoint() bool - AuthenticationEndpoint() string - UAAEndpoint() string - DopplerEndpoint() string - RoutingAPIEndpoint() string - SSHOAuthClient() string - MinCFCLIVersion() string - MinRecommendedCFCLIVersion() string - Username() string - UserGUID() string - UserEmail() string - Locale() string - LoginAt() time.Time - IsLoggedIn() bool - SetLoginAt(loginAt time.Time) - Trace() string - UAAToken() string - UAARefreshToken() string - CurrentOrganization() models.OrganizationFields - HasTargetedOrganization() bool - CurrentSpace() models.SpaceFields - HasTargetedSpace() bool - - UnsetAPI() - SetAPIVersion(string) - SetAPIEndpoint(string) - SetAuthenticationEndpoint(string) - SetDopplerEndpoint(string) - SetUAAEndpoint(string) - SetRoutingAPIEndpoint(string) - SetSSHOAuthClient(string) - SetMinCFCLIVersion(string) - SetMinRecommendedCFCLIVersion(string) - SetUAAToken(string) - SetUAARefreshToken(string) - SetOrganization(models.OrganizationFields) - SetSpace(models.SpaceFields) - ClearSession() -} - type repository struct { *bxConfig - cfConfig cfConfigWrapper -} - -type cfConfigWrapper struct { - *cfConfig - bx *bxConfig } -func (wrapper cfConfigWrapper) UnsetAPI() { - wrapper.cfConfig.UnsetAPI() - wrapper.bx.SetCFEEEnvID("") - wrapper.bx.SetCFEETargeted(false) -} - -func newRepository(bx *bxConfig, cf *cfConfig) repository { +func newRepository(bx *bxConfig) repository { return repository{ bxConfig: bx, - cfConfig: cfConfigWrapper{cfConfig: cf, bx: bx}, } } func (c repository) IsLoggedIn() bool { - return c.bxConfig.IsLoggedIn() || c.cfConfig.IsLoggedIn() + return c.bxConfig.IsLoggedIn() } func (c repository) IsLoggedInWithServiceID() bool { @@ -312,59 +246,31 @@ func (c repository) fetchNewIAMTokenUsingVPCAuth() (*iam.Token, error) { } func (c repository) UserEmail() string { - email := c.bxConfig.UserEmail() - if email == "" { - email = c.cfConfig.UserEmail() - } - return email -} - -func (c repository) CFConfig() CFConfig { - return c.cfConfig -} - -func (c repository) HasTargetedCF() bool { - return c.cfConfig.HasAPIEndpoint() -} - -func (c repository) HasTargetedCFEE() bool { - return c.HasTargetedCF() && c.bxConfig.HasTargetedCFEE() -} - -func (c repository) HasTargetedPublicCF() bool { - return c.HasTargetedCF() && !c.bxConfig.HasTargetedCFEE() + return c.bxConfig.UserEmail() } func (c repository) SetSSLDisabled(disabled bool) { c.bxConfig.SetSSLDisabled(disabled) - c.cfConfig.SetSSLDisabled(disabled) } func (c repository) SetColorEnabled(enabled string) { c.bxConfig.SetColorEnabled(enabled) - c.cfConfig.SetColorEnabled(enabled) } func (c repository) SetTrace(trace string) { c.bxConfig.SetTrace(trace) - c.cfConfig.SetTrace(trace) } func (c repository) SetLocale(locale string) { c.bxConfig.SetLocale(locale) - c.cfConfig.SetLocale(locale) } func (c repository) UnsetAPI() { c.bxConfig.UnsetAPI() - c.bxConfig.SetCFEETargeted(false) - c.bxConfig.SetCFEEEnvID("") - c.cfConfig.UnsetAPI() } func (c repository) ClearSession() { c.bxConfig.ClearSession() - c.cfConfig.ClearSession() } func (c repository) LastSessionUpdateTime() (session int64) { @@ -392,14 +298,13 @@ func (c repository) ClearPaginationURLs() { } func NewCoreConfig(errHandler func(error)) ReadWriter { - // config_helpers.MigrateFromOldConfig() // error ignored - return NewCoreConfigFromPath(config_helpers.CFConfigFilePath(), config_helpers.ConfigFilePath(), errHandler) + return NewCoreConfigFromPath(config_helpers.ConfigFilePath(), errHandler) } -func NewCoreConfigFromPath(cfConfigPath string, bxConfigPath string, errHandler func(error)) ReadWriter { - return NewCoreConfigFromPersistor(configuration.NewDiskPersistor(cfConfigPath), configuration.NewDiskPersistor(bxConfigPath), errHandler) +func NewCoreConfigFromPath(bxConfigPath string, errHandler func(error)) ReadWriter { + return NewCoreConfigFromPersistor(configuration.NewDiskPersistor(bxConfigPath), errHandler) } -func NewCoreConfigFromPersistor(cfPersistor configuration.Persistor, bxPersistor configuration.Persistor, errHandler func(error)) ReadWriter { - return newRepository(createBluemixConfigFromPersistor(bxPersistor, errHandler), createCFConfigFromPersistor(cfPersistor, errHandler)) +func NewCoreConfigFromPersistor(bxPersistor configuration.Persistor, errHandler func(error)) ReadWriter { + return newRepository(createBluemixConfigFromPersistor(bxPersistor, errHandler)) } diff --git a/bluemix/configuration/core_config/uaa_token.go b/bluemix/configuration/core_config/uaa_token.go deleted file mode 100644 index 46dba9e..0000000 --- a/bluemix/configuration/core_config/uaa_token.go +++ /dev/null @@ -1,53 +0,0 @@ -package core_config - -import ( - "encoding/json" - "time" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/common/types" -) - -type UAATokenInfo struct { - Username string `json:"user_name"` - Email string `json:"email"` - UserGUID string `json:"user_id"` - Expiry time.Time - IssueAt time.Time -} - -func NewUAATokenInfo(token string) UAATokenInfo { - tokenJSON, err := DecodeAccessToken(token) - if err != nil { - return UAATokenInfo{} - } - - var t struct { - UAATokenInfo - Expiry types.UnixTime `json:"exp"` - IssueAt types.UnixTime `json:"iat"` - } - err = json.Unmarshal(tokenJSON, &t) - if err != nil { - return UAATokenInfo{} - } - - ret := t.UAATokenInfo - ret.Expiry = t.Expiry.Time() - ret.IssueAt = t.IssueAt.Time() - return ret -} - -func (t UAATokenInfo) exists() bool { - // UAA token without an UserGUID is invalid - return t.UserGUID != "" -} - -func (t UAATokenInfo) hasExpired() bool { - if !t.exists() { - return true - } - if t.Expiry.IsZero() { - return false - } - return t.Expiry.Before(time.Now().Add(expiryDelta)) -} diff --git a/bluemix/configuration/core_config/uaa_token_test.go b/bluemix/configuration/core_config/uaa_token_test.go deleted file mode 100644 index 547a137..0000000 --- a/bluemix/configuration/core_config/uaa_token_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package core_config - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -type uaaTokenTestCases struct { - token string - name string - isExpired bool -} - -var TestUAATokenHasExpiredTestCases = []uaaTokenTestCases{ - { - token: "", - name: "empty token", - isExpired: true, - }, - { - token: "eyJraWQiOiIyMDIxMTAxODA4MTkiLCJhbGciOiJSUzI1NiJ9.eyJpYW1faWQiOiJJQk1pZC02NjYwMDE1UktKIiwiaWQiOiJJQk1pZC02NjYwMDE1UktKIiwicmVhbG1pZCI6IklCTWlkIiwic2Vzc2lvbl9pZCI6IkMtMDBkNDIyYjAtYzcyZC00MzNmLWE0YmUtMzc2ZjkyZDEyNDliIiwianRpIjoiNzNmMzVmNGQtZmI2Ny00NTc3LThlNGMtNDE3YzA5MDYwNDU3IiwiaWRlbnRpZmllciI6IjY2NjAwMTVSS0oiLCJnaXZlbl9uYW1lIjoiTkFOQSIsImZhbWlseV9uYW1lIjoiQU1GTyIsIm5hbWUiOiJOQU5BIEFNRk8iLCJlbWFpbCI6Im5vYW1mb0BpYm0uY29tIiwic3ViIjoibm9hbWZvQGlibS5jb20iLCJhdXRobiI6eyJzdWIiOiJub2FtZm9AaWJtLmNvbSIsImlhbV9pZCI6IklCTWlkLTY2NjAwMTVSS0oiLCJuYW1lIjoiTkFOQSBBTUZPIiwiZ2l2ZW5fbmFtZSI6Ik5BTkEiLCJmYW1pbHlfbmFtZSI6IkFNRk8iLCJlbWFpbCI6Im5vYW1mb0BpYm0uY29tIn0sImFjY291bnQiOnsiYm91bmRhcnkiOiJnbG9iYWwiLCJ2YWxpZCI6dHJ1ZSwiYnNzIjoiMDY3OGUzOWY3ZWYxNDkyODk1OWM0YzFhOGY2YTdiYmYifSwiaWF0IjoxNjM1NDQyMDI3LCJleHAiOjE2MzU0NDI5MjcsImlzcyI6Imh0dHBzOi8vaWFtLmNsb3VkLmlibS5jb20vaWRlbnRpdHkiLCJncmFudF90eXBlIjoidXJuOmlibTpwYXJhbXM6b2F1dGg6Z3JhbnQtdHlwZTpwYXNzY29kZSIsInNjb3BlIjoiaWJtIG9wZW5pZCIsImNsaWVudF9pZCI6ImJ4IiwiYWNyIjozLCJhbXIiOlsidG90cCIsIm1mYSIsIm90cCIsInB3ZCJdfQ.RsBd371ACEKOlhkTJngqBVDCY90Z-MT-iYb1OiLA5OpLYPZunR0saHUzBLh2LxnV-Jo0oeitPBmIK38jDk8MCb-rZa3qYNB2qe0WgO50bCMLKgwhKqJwVM6jMMpg4vg6up8kH8Ftc61kivaa1GrJKmQkonnHrjgrLo5IB2yfkMEAbUAMPb_jcRfjEsSP44I-Vx3dYIVSZs8bIufkgmDbJjlMmdhRenh57iwtQ7uImFgK2d-qQ-7sWLvhfzj2VdBLRHPa-dWYlrVgOAMpk6SCMz8wh6LcDUx9LdNKHpxMGCXpGT_UUWvwYqBuLTI3nmkIWIb_Cqa6al7-gQKPTC00Fw", - name: "expired token", - isExpired: true, - }, - { - token: "ABCD.DEFG.HIGK", - name: "invalid token", - isExpired: true, - }, - { - token: "eyJhbGciOiJIUzI1NiIsImtpZCI6ImtleS0xIiwidHlwIjoiSldUIn0.eyJqdGkiOiJhZGFkNWYwYzQ0ZDI0ZDlkYmVhN2YyNGIzMDNmOWNhNyIsInN1YiI6IjY3ODdiMzM2LTAwNzUtNGYwYy1hZmZiLWUyOWZjMmVhZWI4OCIsInNjb3BlIjpbIm9wZW5pZCIsInVhYS51c2VyIiwiY2xvdWRfY29udHJvbGxlci5yZWFkIiwicGFzc3dvcmQud3JpdGUiLCJjbG91ZF9jb250cm9sbGVyLndyaXRlIl0sImNsaWVudF9pZCI6ImNmIiwiY2lkIjoiY2YiLCJhenAiOiJjZiIsImdyYW50X3R5cGUiOiJwYXNzd29yZCIsInVzZXJfaWQiOiI2Nzg3YjMzNi0wMDc1LTRmMGMtYWZmYi1lMjlmYzJlYWViODgiLCJvcmlnaW4iOiJ1YWEiLCJ1c2VyX25hbWUiOiJ3YW5nanVubEBjbi5pYm0uY29tIiwiZW1haWwiOiJ3YW5nanVubEBjbi5pYm0uY29tIiwiYXV0aF90aW1lIjoxNTE2MTczMjgxLCJpYXQiOjE4MTYxNzMyODEsImV4cCI6MjkyNjE3Njg4MCwiaXNzIjoiaHR0cHM6Ly91YWEubmcuYmx1ZW1peC5uZXQvb2F1dGgvdG9rZW4iLCJ6aWQiOiJ1YWEiLCJhdWQiOlsiY2xvdWRfY29udHJvbGxlciIsInBhc3N3b3JkIiwiY2YiLCJ1YWEiLCJvcGVuaWQiXX0.CPUPLMtDpGScEbK9pyD5pzOCWXUir7TX-gZSmFFSRLM", - name: "token expired in 2062", - isExpired: false, - }, -} - -func TestUAATokenHasExpired(t *testing.T) { - for _, testCase := range TestUAATokenHasExpiredTestCases { - t.Run(testCase.name, func(t *testing.T) { - tokenInfo := NewUAATokenInfo(testCase.token) - assert.Equal(t, testCase.isExpired, tokenInfo.hasExpired()) - }) - } -} diff --git a/bluemix/crn/crn.go b/bluemix/crn/crn.go index 846d071..954314b 100644 --- a/bluemix/crn/crn.go +++ b/bluemix/crn/crn.go @@ -24,10 +24,6 @@ var ( const ( ServiceBluemix = "bluemix" ServiceIAM = "iam" - // ServiceCF is the service name for public Cloudfoundry - ServiceCF = "cf" - // ServiceCFEE is the service name for CFEE Cloudfoundry - ServiceCFEE = "cfaas" // more services ... ScopeAccount = "a" @@ -35,9 +31,6 @@ const ( ScopeSpace = "s" ScopeProject = "p" - ResourceTypeCFSpace = "cf-space" - ResourceTypeCFApp = "cf-application" - ResourceTypeCFService = "cf-service-instance" ResourceTypeRole = "role" ResourceTypeDeployment = "deployment" // more resources ... diff --git a/bluemix/models/region.go b/bluemix/models/region.go index be26754..cf5a64c 100644 --- a/bluemix/models/region.go +++ b/bluemix/models/region.go @@ -1,6 +1,5 @@ package models type Region struct { - MCCPID string - Name string + Name string } diff --git a/docs/interface_summary.md b/docs/interface_summary.md index ef92b81..e134662 100644 --- a/docs/interface_summary.md +++ b/docs/interface_summary.md @@ -67,18 +67,18 @@ You are not logged in. Log in by running 'ibmcloud login'. ### Entity formatting in output messages: ([reference](https://github.com/IBM-Cloud/ibm-cloud-cli-sdk/blob/master/docs/plugin_developer_guide.md#23-entity-name)) -Add single quotation marks (') around entity names and keep the entity names in cyan with **bold**. For example: +Keep the entity names in cyan with **bold**. For example: ``` -Mapping route 'my-app.us-south.cf.cloud.ibm.com' to CF application 'my-app'... +Deleting service instance test in resource group GroupA under account TestAccount as user@ibm.com ``` ### Command Help ([reference](https://github.com/IBM-Cloud/ibm-cloud-cli-sdk/blob/master/docs/plugin_developer_guide.md#24-help-of-command)) - Use "-" for single letter flags, and "--" for multiple letter flags, e.g. `-c ACCOUNT_ID` and `--guid`. -- All user input values should be shown as capital letters, e.g. `ibmcloud scale RESOURCE_NAME` -- For optional parameters and flags, surround them with "[...]", e.g. `ibmcloud account orgs [--guid]`. +- All user input values should be shown as capital letters, e.g. `ibmcloud resource service-instance SERVICE_INSTANCE_NAME` +- For optional parameters and flags, surround them with "[...]", e.g. `ibmcloud iam service-id [--uuid]`. - For exclusive parameters and flags, group them together by "(...)" and separate by "|". - Example: `ibmcloud test create (NAME | --uuid ID)` - "[...]" and "(...)" can be nested. @@ -95,15 +95,16 @@ The following gives an example of the output of the `help` command: ``` NAME: - scale - Change the instance count for an app or container group. + group-update - Update an existing resource group + USAGE: - ibmcloud scale RESOURCE_NAME [-i INSTANCES] [-k DISK] [-m MEMORY] [-f] - RESOURCE_NAME is the name of the app or container group to be scaled. + icd resource group-update NAME [-n, --name NEW_NAME] [-f, --force] [--output FORMAT] [-q, --quiet] + OPTIONS: - -i value Number of instances. - -k value Disk limit (e.g. 256M, 1024M, 1G). Valid only for scaling an app, not a container group. - -m value Memory limit (e.g. 256M, 1024M, 1G). Valid only for scaling an app, not a container group. - -f Force restart of CF application without prompt. Valid only for scaling an app, not a container group. + -n value, --name value New name of the resource group + -f, --force Force update without confirmation + --output value Specify output format, only JSON is supported now. + -q, --quiet Suppress verbose output ``` ### Common options ([reference](https://github.com/IBM-Cloud/ibm-cloud-cli-sdk/blob/master/docs/plugin_developer_guide.md#212-common-options)) @@ -125,17 +126,20 @@ OPTIONS: When the user runs a command with the wrong usage (e.g. incorrect number of arguments, invalid option value, required options not specified, etc.), the message should be displayed and include help for the user for the command as below: ``` -Incorrect usage. +FAILED +Incorrect Usage. + NAME: - scale - Change the instance count for an app or container group. + group-update - Update an existing resource group + USAGE: - ibmcloud scale RESOURCE_NAME [-i INSTANCES] [-k DISK] [-m MEMORY] [-f] - RESOURCE_NAME is the name of the app or container group to be scaled. + icd resource group-update NAME [-n, --name NEW_NAME] [-f, --force] [--output FORMAT] [-q, --quiet] + OPTIONS: - -i value Number of instances. - -k value Disk limit (e.g. 256M, 1024M, 1G). Valid only for scaling an app, not a container group. - -m value Memory limit (e.g. 256M, 1024M, 1G). Valid only for scaling an app, not a container group. - -f Force restart of CF application without prompt. Valid only for scaling an app, not a container group. + -n value, --name value New name of the resource group + -f, --force Force update without confirmation + --output value Specify output format, only JSON is supported now. + -q, --quiet Suppress verbose output ``` Provide any details possible to guide and inform the users. For example: @@ -151,10 +155,11 @@ The failure message must start with "FAILED" in red with **bold**, followed by t In the message, explain the error and provide guidance on how to resolve the issue such as shown in the following output: ``` -Creating application 'my-app'... +Creating access policy role Editor under current account for service role as user@ibm.com... FAILED -An application with name 'my-app' already exists. -Use another name and try again. +Following errors returned from server: +Code Message Details +invalid_body The role name is conflicting with system define role, please choose another name. ``` #### Command Success ([reference](https://github.com/IBM-Cloud/ibm-cloud-cli-sdk/blob/master/docs/plugin_developer_guide.md#27-command-success)) @@ -162,9 +167,9 @@ Use another name and try again. When a command is successful, the success message should start with "OK" in green with **bold** and followed by the optional details in new line like the following example: ``` -Creating application 'my-app'... +Creating resource group Test under account TestAccount as user@ibm.com... OK -Application 'my-app' was created. +Resource group Test was created. ``` #### Warning Message ([reference](https://github.com/IBM-Cloud/ibm-cloud-cli-sdk/blob/master/docs/plugin_developer_guide.md#28-warning-message)) @@ -279,5 +284,5 @@ Service ID '15a15a0f-725e-453a-b3ac-755280ad7300' was not found. ### Globalization ([reference](https://github.com/IBM-Cloud/ibm-cloud-cli-sdk/blob/master/docs/plugin_developer_guide.md#7-globalization)) -IBM Cloud CLI tends to be used globally. Both IBM Cloud CLI and its plug-ins should support globalization. +IBM Cloud CLI tends to be used globally. Both IBM Cloud CLI and its plug-ins should support globalization. diff --git a/docs/plugin_developer_guide.md b/docs/plugin_developer_guide.md index 1e70821..2421fdb 100644 --- a/docs/plugin_developer_guide.md +++ b/docs/plugin_developer_guide.md @@ -96,7 +96,7 @@ IBM Cloud CLI SDK provides a set of APIs to register and manage plug-ins. It als } ``` -`PluginContext` provides the most useful methods which allow you to get command line properties from CF configuration as well as IBM Cloud specific properties. +`PluginContext` provides the most useful methods which allow you to get command line properties from IBM Cloud specific properties. ### 1.2. Namespace @@ -110,11 +110,9 @@ The following are shared namespaces are currently predefined in IBM Cloud CLI a | account | Manage accounts, orgs, spaces and users | | iam | Manage identities and accesses | | catalog | Manage IBM Cloud catalog | -| app | Manage IBM Cloud applications | | service | Manage IBM Cloud services | | resource | Manage the IBM cloud resources | | billing | Retrieve usage and billing information | -| cf | Run Cloud Foundry CLI with IBM Cloud context | | plugin | Manage plug-in repositories and plug-ins | For shared namespace, refer to the namespace in the plug-in: @@ -432,18 +430,20 @@ Incorrect description: ### 2.3. Entity Name -Add single quotation marks (') around entity names and keep the entity names in cyan with **bold**. For example: +Keep the entity names in cyan with **bold**. For example: ``` -Mapping route 'my-app.us-south.cf.cloud.ibm.com' to CF application 'my-app'... +Deleting service instance test in resource group Editors under account TestAccount as user@ibm.com... ``` The IBM Cloud CLI SDK also provides API to help you print the previous example message: ```go -ui.Say("Mapping route '%s' to CF application '%s'...", - terminal.EntityNameColor("my-app.cloud.ibm.com"), - terminal.EntityNameColor("my-app"), +ui.Say("Deleting service instance %s in resource group %s under account %s as %s...", + terminal.EntityNameColor("test"), + terminal.EntityNameColor("Editors"), + terminal.EntityNameColor("TestAccount"), + terminal.EntityNameColor("user@ibm.com"), ) ``` @@ -451,8 +451,8 @@ ui.Say("Mapping route '%s' to CF application '%s'...", Use the guidelines below to compose command help. - Use "-" for single letter flags, and "--" for multiple letter flags, e.g. `-c ACCOUNT_ID` and `--guid`. -- All user input values should be capital letters, e.g. `ibmcloud scale RESOURCE_NAME` -- For optional parameters and flags, surround them with "[...]", e.g. `ibmcloud account orgs [--guid]`. +- All user input values should be shown as capital letters, e.g. `ibmcloud resource service-instance SERVICE_INSTANCE_NAME` +- For optional parameters and flags, surround them with "[...]", e.g. `ibmcloud iam service-id [--uuid]`. - For exclusive parameters and flags, group them together by "(...)" and separate by "|". - Example: `ibmcloud test create (NAME | --uuid ID)` - "[...]" and "(...)" can be nested. @@ -469,40 +469,43 @@ The following gives an example of the output of the `help` command: ``` NAME: - scale - Change the instance count for an app or container group. + group-update - Update an existing resource group + USAGE: - ibmcloud scale RESOURCE_NAME [-i INSTANCES] [-k DISK] [-m MEMORY] [-f] - RESOURCE_NAME is the name of the app or container group to be scaled. + icd resource group-update NAME [-n, --name NEW_NAME] [-f, --force] [--output FORMAT] [-q, --quiet] + OPTIONS: - -i value Number of instances. - -k value Disk limit (e.g. 256M, 1024M, 1G). Valid only for scaling an app, not a container group. - -m value Memory limit (e.g. 256M, 1024M, 1G). Valid only for scaling an app, not a container group. - -f Force restart of CF application without prompt. Valid only for scaling an app, not a container group. + -n value, --name value New name of the resource group + -f, --force Force update without confirmation + --output value Specify output format, only JSON is supported now. + -q, --quiet Suppress verbose output ``` - ### 2.5. Incorrect Usage When users run a command with wrong usage (e.g. incorrect number of arguments, invalid option value, required options not specified and etc.), the message should be displayed in the following format: ``` -Incorrect usage. +FAILED +Incorrect Usage. + NAME: - scale - Change the instance count for an app or container group. + group-update - Update an existing resource group + USAGE: - ibmcloud scale RESOURCE_NAME [-i INSTANCES] [-k DISK] [-m MEMORY] [-f] - RESOURCE_NAME is the name of the app or container group to be scaled. + icd resource group-update NAME [-n, --name NEW_NAME] [-f, --force] [--output FORMAT] [-q, --quiet] + OPTIONS: - -i value Number of instances. - -k value Disk limit (e.g. 256M, 1024M, 1G). Valid only for scaling an app, not a container group. - -m value Memory limit (e.g. 256M, 1024M, 1G). Valid only for scaling an app, not a container group. - -f Force restart of CF application without prompt. Valid only for scaling an app, not a container group. + -n value, --name value New name of the resource group + -f, --force Force update without confirmation + --output value Specify output format, only JSON is supported now. + -q, --quiet Suppress verbose output ``` If possible, provide details to help the users figure out what was wrong with their usage. For example: ``` -Incorrect usage. The '-k' option is not valid for a container group. +Incorrect Usage: '--source-service-name' is only optional when '--source-resource-group-id' is specified ``` ### 2.6. Command Failure @@ -510,17 +513,17 @@ Incorrect usage. The '-k' option is not valid for a container group. If a command failed due to the client-side or server-side error, explain the error and provide guidance on how to resolve the issue, such as shown in the following output: ``` -Creating application 'my-app'... +Creating access policy role Editor under current account for service role as user@ibm.com... FAILED -An application with name 'my-app' already exists. -Use another name and try again. +Following errors returned from server: +Code Message Details +invalid_body The role name is conflicting with system define role, please choose another name. ``` ``` -Scaling container group 'xxx'... +Submitting request to delete resource reclamation d3a3941f-6582-4e1d-b156-694fe6169b66 under account b72850272cec44bfb139667342acb9f as user@ibm.com... FAILED -A server error occurred while scaling the container group. -Try again later. If the problem continues, contact IBM Cloud Support. +Cannot reclaim reclamation d3a3941f-6582-4e1d-b156-694fe6169b66 whose state is RECLAIMED ``` To summarize, the failure message must start with "FAILED" in red with **bold** and followed by the detailed error message in a new line as previously shown. A recovery solution must be provided, such as "Use another name and try again." or "Try again later." @@ -544,18 +547,21 @@ func Run() error { When command was successful, the success message should start with "OK" in green with **bold** and followed by the optional details in new line like the following examples: ``` -Creating application 'my-app'... +Creating resource group Test under account TestAccount as user@ibm.com... OK -Application 'my-app' was created. +Resource group Test was created. +Creating application 'my-app'... ``` The following code snippet can help you print the above message: ```go -ui.Say("Creating application '%s'...",terminal.EntityNameColor("my-app")) +ui.Say("Creating service ID %s bound to current account as %s...", + terminal.EntityNameColor("cloudant-user"), + terminal.EntityNameColor("user@ibm.com")) ... ui.Ok() -ui.Say("Application '%s' was created.", terminal.EntityNameColor("my-app")) +ui.Say("Service ID %s is created successfully", terminal.EntityNameColor("cloudant-user")) ``` ### 2.8. Warning Message @@ -906,7 +912,7 @@ if errorV != nil || err != nil { ### 5.1 Get Access Token -To access IBM Cloud back-end API, normally a token is required. You can get the IAM access token and UAA access token from IBM CLoud SDK as follows: +To access IBM Cloud back-end API, normally a token is required. You can get the IAM access token from IBM Cloud SDK as follows: ```go func (demo *DemoPlugin) Run(context plugin.PluginContext, args []string){ @@ -918,13 +924,6 @@ func (demo *DemoPlugin) Run(context plugin.PluginContext, args []string){ ui.Say("IAM token is not available. Have you logged in?") return } - - // get UAA access token - uaaToken := config.CFConfig().UAAToken() - if iamToken == "" { - ui.Say("UAA token is not available. Have you logged into Cloud Foundry?") - return - } ... } ``` @@ -938,7 +937,7 @@ h.Set("Authorization", token) For more details of the API, refer to docs of [core_config](https://godoc.org/github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/configuration/core_config). -If you want to fetch the token by yourselve, refer to API docs for [iam](https://godoc.org/github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/authentication/iam) and [uaa](https://godoc.org/github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/authentication/uaa). +If you want to fetch the token by yourself, refer to API docs for [iam](https://godoc.org/github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/authentication/iam) ### 5.2 Refresh Access Token on Expiry diff --git a/plugin/plugin.go b/plugin/plugin.go index c5ea10b..469789e 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -158,14 +158,13 @@ type Plugin interface { // PluginContext is a Bluemix CLI context passed to plugin's Run method. It // carries service endpoints info, login session, user configuration, plugin // configuration and provides utility methods. +// //go:generate counterfeiter . PluginContext type PluginContext interface { // APIEndpoint returns the targeted API endpoint of IBM Cloud APIEndpoint() string - // HasAPIEndpoint() returns whether an IBM Cloud has been targeted, does not - // necessarily mean the user has targeted a CF environment. - // Call HasTargetedCF() to return whether a CF environment has been targeted. + // HasAPIEndpoint() returns whether an IBM Cloud has been targeted HasAPIEndpoint() bool // IsPrivateEndpointEnabled returns whether use of the private endpoint has been chosen @@ -224,12 +223,10 @@ type PluginContext interface { // UserEmail returns the Email of the logged in user UserEmail() string - // IsLoggedIn returns if a user has logged into IBM cloud, does not - // necessarily mean the user has logged in a CF environment. - // Call CF().IsLoggedIn() to return whether user has been logged into the CF environment. + // IsLoggedIn returns if a user has logged into IBM Cloud IsLoggedIn() bool - // IsLoggedInWithServiceID returns if a user has logged into IBM cloud using service ID. + // IsLoggedInWithServiceID returns if a user has logged into IBM Cloud using service ID. IsLoggedInWithServiceID() bool // IsLoggedInAsProfile returns true if a user logged into IBM Cloud using an IAM token pertaining to a trusted profile @@ -263,21 +260,6 @@ type PluginContext interface { // HasTargetedResourceGroup returns whether a resource group has been targeted HasTargetedResourceGroup() bool - // CF returns the context of the targeted CloudFoundry environment - CF() CFContext - - // HasTargetedCF returns whether a CloudFoundry environment has been targeted - HasTargetedCF() bool - - // HasTargetedCF returns whether a enterprise CloudFoundry instance has been targeted - HasTargetedCFEE() bool - - // CFEEEnvID returns ID of targeted CFEE environment - CFEEEnvID() string - - // HasTargetedCF returns whether a public CloudFoundry instance has been targeted - HasTargetedPublicCF() bool - // Locale returns user specified locale Locale() string @@ -309,55 +291,3 @@ type PluginContext interface { // CLIName returns binary name of the Bluemix CLI that is invoking the plugin CLIName() string } - -// CFContext is a context of the targeted CloudFoundry environment into plugin -type CFContext interface { - // APIVersion returns the cloud controller API version - APIVersion() string - - // APIEndpoint returns the Cloud Foundry API endpoint - APIEndpoint() string - - // HasAPIEndpoint returns whether a Cloud Foundry API endpoint is set - HasAPIEndpoint() bool - - //DopplerEndpoint returns the Doppler endpoint - DopplerEndpoint() string - - // UAAEndpoint returns endpoint of UAA token service - UAAEndpoint() string - - // ISLoggedIn returns if a user has logged into the cloudfoundry instance - IsLoggedIn() bool - - // Username returns the name of the logged in user - Username() string - - // UserEmail returns the Email of the logged in user - UserEmail() string - - // UserGUID returns the GUID of the logged in user - UserGUID() string - - // UAAToken returns the UAA access token - // If the token is outdated, call RefreshUAAToken to refresh it - UAAToken() string - - // UAARefreshToken return the UAA refreshed token - UAARefreshToken() string - - // RefreshUAAToken refreshes and returns the UAA access token - RefreshUAAToken() (string, error) - - // CurrentOrganization returns the targeted organization - CurrentOrganization() models.OrganizationFields - - // HasTargetedOrganization returns if an organization has been targeted - HasTargetedOrganization() bool - - // CurrentSpace returns the targeted space - CurrentSpace() models.SpaceFields - - // HasTargetedSpace returns if a space has been targeted - HasTargetedSpace() bool -} diff --git a/plugin/plugin_context.go b/plugin/plugin_context.go index 8a7c7d6..ac2c6fe 100644 --- a/plugin/plugin_context.go +++ b/plugin/plugin_context.go @@ -7,53 +7,25 @@ import ( "strings" "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/authentication/uaa" "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/configuration/core_config" "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/endpoints" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/common/rest" ) type pluginContext struct { core_config.ReadWriter - cfConfig cfConfigWrapper pluginConfig PluginConfig pluginPath string } -type cfConfigWrapper struct { - core_config.CFConfig -} - -func (c cfConfigWrapper) RefreshUAAToken() (string, error) { - if !c.HasAPIEndpoint() { - return "", fmt.Errorf("CloudFoundry API endpoint is not set") - } - - auth := uaa.NewClient(uaa.DefaultConfig(c.AuthenticationEndpoint()), rest.NewClient()) - token, err := auth.GetToken(uaa.RefreshTokenRequest(c.UAARefreshToken())) - if err != nil { - return "", err - } - - ret := fmt.Sprintf("%s %s", token.TokenType, token.AccessToken) - c.SetUAAToken(ret) - c.SetUAARefreshToken(token.RefreshToken) - return ret, nil -} - func createPluginContext(pluginPath string, coreConfig core_config.ReadWriter) *pluginContext { return &pluginContext{ pluginPath: pluginPath, pluginConfig: loadPluginConfigFromPath(filepath.Join(pluginPath, "config.json")), ReadWriter: coreConfig, - cfConfig: cfConfigWrapper{coreConfig.CFConfig()}, } } func (c *pluginContext) APIEndpoint() string { - if compareVersion(c.SDKVersion(), "0.1.1") < 0 { - return c.ReadWriter.CFConfig().APIEndpoint() - } return c.ReadWriter.APIEndpoint() } @@ -144,10 +116,6 @@ func (c *pluginContext) VersionCheckEnabled() bool { return !c.CheckCLIVersionDisabled() } -func (c *pluginContext) CF() CFContext { - return c.cfConfig -} - func envOrConfig(env bluemix.Env, config string) string { if v := env.Get(); v != "" { return v diff --git a/plugin/pluginfakes/fake_cfcontext.go b/plugin/pluginfakes/fake_cfcontext.go deleted file mode 100644 index acbcc99..0000000 --- a/plugin/pluginfakes/fake_cfcontext.go +++ /dev/null @@ -1,855 +0,0 @@ -// This file was generated by counterfeiter -package pluginfakes - -import ( - "sync" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/models" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin" -) - -type FakeCFContext struct { - APIVersionStub func() string - aPIVersionMutex sync.RWMutex - aPIVersionArgsForCall []struct{} - aPIVersionReturns struct { - result1 string - } - aPIVersionReturnsOnCall map[int]struct { - result1 string - } - APIEndpointStub func() string - aPIEndpointMutex sync.RWMutex - aPIEndpointArgsForCall []struct{} - aPIEndpointReturns struct { - result1 string - } - aPIEndpointReturnsOnCall map[int]struct { - result1 string - } - HasAPIEndpointStub func() bool - hasAPIEndpointMutex sync.RWMutex - hasAPIEndpointArgsForCall []struct{} - hasAPIEndpointReturns struct { - result1 bool - } - hasAPIEndpointReturnsOnCall map[int]struct { - result1 bool - } - DopplerEndpointStub func() string - dopplerEndpointMutex sync.RWMutex - dopplerEndpointArgsForCall []struct{} - dopplerEndpointReturns struct { - result1 string - } - dopplerEndpointReturnsOnCall map[int]struct { - result1 string - } - UAAEndpointStub func() string - uAAEndpointMutex sync.RWMutex - uAAEndpointArgsForCall []struct{} - uAAEndpointReturns struct { - result1 string - } - uAAEndpointReturnsOnCall map[int]struct { - result1 string - } - IsLoggedInStub func() bool - isLoggedInMutex sync.RWMutex - isLoggedInArgsForCall []struct{} - isLoggedInReturns struct { - result1 bool - } - isLoggedInReturnsOnCall map[int]struct { - result1 bool - } - UsernameStub func() string - usernameMutex sync.RWMutex - usernameArgsForCall []struct{} - usernameReturns struct { - result1 string - } - usernameReturnsOnCall map[int]struct { - result1 string - } - UserEmailStub func() string - userEmailMutex sync.RWMutex - userEmailArgsForCall []struct{} - userEmailReturns struct { - result1 string - } - userEmailReturnsOnCall map[int]struct { - result1 string - } - UserGUIDStub func() string - userGUIDMutex sync.RWMutex - userGUIDArgsForCall []struct{} - userGUIDReturns struct { - result1 string - } - userGUIDReturnsOnCall map[int]struct { - result1 string - } - UAATokenStub func() string - uAATokenMutex sync.RWMutex - uAATokenArgsForCall []struct{} - uAATokenReturns struct { - result1 string - } - uAATokenReturnsOnCall map[int]struct { - result1 string - } - UAARefreshTokenStub func() string - uAARefreshTokenMutex sync.RWMutex - uAARefreshTokenArgsForCall []struct{} - uAARefreshTokenReturns struct { - result1 string - } - uAARefreshTokenReturnsOnCall map[int]struct { - result1 string - } - RefreshUAATokenStub func() (string, error) - refreshUAATokenMutex sync.RWMutex - refreshUAATokenArgsForCall []struct{} - refreshUAATokenReturns struct { - result1 string - result2 error - } - refreshUAATokenReturnsOnCall map[int]struct { - result1 string - result2 error - } - CurrentOrganizationStub func() models.OrganizationFields - currentOrganizationMutex sync.RWMutex - currentOrganizationArgsForCall []struct{} - currentOrganizationReturns struct { - result1 models.OrganizationFields - } - currentOrganizationReturnsOnCall map[int]struct { - result1 models.OrganizationFields - } - HasTargetedOrganizationStub func() bool - hasTargetedOrganizationMutex sync.RWMutex - hasTargetedOrganizationArgsForCall []struct{} - hasTargetedOrganizationReturns struct { - result1 bool - } - hasTargetedOrganizationReturnsOnCall map[int]struct { - result1 bool - } - CurrentSpaceStub func() models.SpaceFields - currentSpaceMutex sync.RWMutex - currentSpaceArgsForCall []struct{} - currentSpaceReturns struct { - result1 models.SpaceFields - } - currentSpaceReturnsOnCall map[int]struct { - result1 models.SpaceFields - } - HasTargetedSpaceStub func() bool - hasTargetedSpaceMutex sync.RWMutex - hasTargetedSpaceArgsForCall []struct{} - hasTargetedSpaceReturns struct { - result1 bool - } - hasTargetedSpaceReturnsOnCall map[int]struct { - result1 bool - } - invocations map[string][][]interface{} - invocationsMutex sync.RWMutex -} - -func (fake *FakeCFContext) APIVersion() string { - fake.aPIVersionMutex.Lock() - ret, specificReturn := fake.aPIVersionReturnsOnCall[len(fake.aPIVersionArgsForCall)] - fake.aPIVersionArgsForCall = append(fake.aPIVersionArgsForCall, struct{}{}) - fake.recordInvocation("APIVersion", []interface{}{}) - fake.aPIVersionMutex.Unlock() - if fake.APIVersionStub != nil { - return fake.APIVersionStub() - } - if specificReturn { - return ret.result1 - } - return fake.aPIVersionReturns.result1 -} - -func (fake *FakeCFContext) APIVersionCallCount() int { - fake.aPIVersionMutex.RLock() - defer fake.aPIVersionMutex.RUnlock() - return len(fake.aPIVersionArgsForCall) -} - -func (fake *FakeCFContext) APIVersionReturns(result1 string) { - fake.APIVersionStub = nil - fake.aPIVersionReturns = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) APIVersionReturnsOnCall(i int, result1 string) { - fake.APIVersionStub = nil - if fake.aPIVersionReturnsOnCall == nil { - fake.aPIVersionReturnsOnCall = make(map[int]struct { - result1 string - }) - } - fake.aPIVersionReturnsOnCall[i] = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) APIEndpoint() string { - fake.aPIEndpointMutex.Lock() - ret, specificReturn := fake.aPIEndpointReturnsOnCall[len(fake.aPIEndpointArgsForCall)] - fake.aPIEndpointArgsForCall = append(fake.aPIEndpointArgsForCall, struct{}{}) - fake.recordInvocation("APIEndpoint", []interface{}{}) - fake.aPIEndpointMutex.Unlock() - if fake.APIEndpointStub != nil { - return fake.APIEndpointStub() - } - if specificReturn { - return ret.result1 - } - return fake.aPIEndpointReturns.result1 -} - -func (fake *FakeCFContext) APIEndpointCallCount() int { - fake.aPIEndpointMutex.RLock() - defer fake.aPIEndpointMutex.RUnlock() - return len(fake.aPIEndpointArgsForCall) -} - -func (fake *FakeCFContext) APIEndpointReturns(result1 string) { - fake.APIEndpointStub = nil - fake.aPIEndpointReturns = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) APIEndpointReturnsOnCall(i int, result1 string) { - fake.APIEndpointStub = nil - if fake.aPIEndpointReturnsOnCall == nil { - fake.aPIEndpointReturnsOnCall = make(map[int]struct { - result1 string - }) - } - fake.aPIEndpointReturnsOnCall[i] = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) HasAPIEndpoint() bool { - fake.hasAPIEndpointMutex.Lock() - ret, specificReturn := fake.hasAPIEndpointReturnsOnCall[len(fake.hasAPIEndpointArgsForCall)] - fake.hasAPIEndpointArgsForCall = append(fake.hasAPIEndpointArgsForCall, struct{}{}) - fake.recordInvocation("HasAPIEndpoint", []interface{}{}) - fake.hasAPIEndpointMutex.Unlock() - if fake.HasAPIEndpointStub != nil { - return fake.HasAPIEndpointStub() - } - if specificReturn { - return ret.result1 - } - return fake.hasAPIEndpointReturns.result1 -} - -func (fake *FakeCFContext) HasAPIEndpointCallCount() int { - fake.hasAPIEndpointMutex.RLock() - defer fake.hasAPIEndpointMutex.RUnlock() - return len(fake.hasAPIEndpointArgsForCall) -} - -func (fake *FakeCFContext) HasAPIEndpointReturns(result1 bool) { - fake.HasAPIEndpointStub = nil - fake.hasAPIEndpointReturns = struct { - result1 bool - }{result1} -} - -func (fake *FakeCFContext) HasAPIEndpointReturnsOnCall(i int, result1 bool) { - fake.HasAPIEndpointStub = nil - if fake.hasAPIEndpointReturnsOnCall == nil { - fake.hasAPIEndpointReturnsOnCall = make(map[int]struct { - result1 bool - }) - } - fake.hasAPIEndpointReturnsOnCall[i] = struct { - result1 bool - }{result1} -} - -func (fake *FakeCFContext) DopplerEndpoint() string { - fake.dopplerEndpointMutex.Lock() - ret, specificReturn := fake.dopplerEndpointReturnsOnCall[len(fake.dopplerEndpointArgsForCall)] - fake.dopplerEndpointArgsForCall = append(fake.dopplerEndpointArgsForCall, struct{}{}) - fake.recordInvocation("DopplerEndpoint", []interface{}{}) - fake.dopplerEndpointMutex.Unlock() - if fake.DopplerEndpointStub != nil { - return fake.DopplerEndpointStub() - } - if specificReturn { - return ret.result1 - } - return fake.dopplerEndpointReturns.result1 -} - -func (fake *FakeCFContext) DopplerEndpointCallCount() int { - fake.dopplerEndpointMutex.RLock() - defer fake.dopplerEndpointMutex.RUnlock() - return len(fake.dopplerEndpointArgsForCall) -} - -func (fake *FakeCFContext) DopplerEndpointReturns(result1 string) { - fake.DopplerEndpointStub = nil - fake.dopplerEndpointReturns = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) DopplerEndpointReturnsOnCall(i int, result1 string) { - fake.DopplerEndpointStub = nil - if fake.dopplerEndpointReturnsOnCall == nil { - fake.dopplerEndpointReturnsOnCall = make(map[int]struct { - result1 string - }) - } - fake.dopplerEndpointReturnsOnCall[i] = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) UAAEndpoint() string { - fake.uAAEndpointMutex.Lock() - ret, specificReturn := fake.uAAEndpointReturnsOnCall[len(fake.uAAEndpointArgsForCall)] - fake.uAAEndpointArgsForCall = append(fake.uAAEndpointArgsForCall, struct{}{}) - fake.recordInvocation("UAAEndpoint", []interface{}{}) - fake.uAAEndpointMutex.Unlock() - if fake.UAAEndpointStub != nil { - return fake.UAAEndpointStub() - } - if specificReturn { - return ret.result1 - } - return fake.uAAEndpointReturns.result1 -} - -func (fake *FakeCFContext) UAAEndpointCallCount() int { - fake.uAAEndpointMutex.RLock() - defer fake.uAAEndpointMutex.RUnlock() - return len(fake.uAAEndpointArgsForCall) -} - -func (fake *FakeCFContext) UAAEndpointReturns(result1 string) { - fake.UAAEndpointStub = nil - fake.uAAEndpointReturns = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) UAAEndpointReturnsOnCall(i int, result1 string) { - fake.UAAEndpointStub = nil - if fake.uAAEndpointReturnsOnCall == nil { - fake.uAAEndpointReturnsOnCall = make(map[int]struct { - result1 string - }) - } - fake.uAAEndpointReturnsOnCall[i] = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) IsLoggedIn() bool { - fake.isLoggedInMutex.Lock() - ret, specificReturn := fake.isLoggedInReturnsOnCall[len(fake.isLoggedInArgsForCall)] - fake.isLoggedInArgsForCall = append(fake.isLoggedInArgsForCall, struct{}{}) - fake.recordInvocation("IsLoggedIn", []interface{}{}) - fake.isLoggedInMutex.Unlock() - if fake.IsLoggedInStub != nil { - return fake.IsLoggedInStub() - } - if specificReturn { - return ret.result1 - } - return fake.isLoggedInReturns.result1 -} - -func (fake *FakeCFContext) IsLoggedInCallCount() int { - fake.isLoggedInMutex.RLock() - defer fake.isLoggedInMutex.RUnlock() - return len(fake.isLoggedInArgsForCall) -} - -func (fake *FakeCFContext) IsLoggedInReturns(result1 bool) { - fake.IsLoggedInStub = nil - fake.isLoggedInReturns = struct { - result1 bool - }{result1} -} - -func (fake *FakeCFContext) IsLoggedInReturnsOnCall(i int, result1 bool) { - fake.IsLoggedInStub = nil - if fake.isLoggedInReturnsOnCall == nil { - fake.isLoggedInReturnsOnCall = make(map[int]struct { - result1 bool - }) - } - fake.isLoggedInReturnsOnCall[i] = struct { - result1 bool - }{result1} -} - -func (fake *FakeCFContext) Username() string { - fake.usernameMutex.Lock() - ret, specificReturn := fake.usernameReturnsOnCall[len(fake.usernameArgsForCall)] - fake.usernameArgsForCall = append(fake.usernameArgsForCall, struct{}{}) - fake.recordInvocation("Username", []interface{}{}) - fake.usernameMutex.Unlock() - if fake.UsernameStub != nil { - return fake.UsernameStub() - } - if specificReturn { - return ret.result1 - } - return fake.usernameReturns.result1 -} - -func (fake *FakeCFContext) UsernameCallCount() int { - fake.usernameMutex.RLock() - defer fake.usernameMutex.RUnlock() - return len(fake.usernameArgsForCall) -} - -func (fake *FakeCFContext) UsernameReturns(result1 string) { - fake.UsernameStub = nil - fake.usernameReturns = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) UsernameReturnsOnCall(i int, result1 string) { - fake.UsernameStub = nil - if fake.usernameReturnsOnCall == nil { - fake.usernameReturnsOnCall = make(map[int]struct { - result1 string - }) - } - fake.usernameReturnsOnCall[i] = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) UserEmail() string { - fake.userEmailMutex.Lock() - ret, specificReturn := fake.userEmailReturnsOnCall[len(fake.userEmailArgsForCall)] - fake.userEmailArgsForCall = append(fake.userEmailArgsForCall, struct{}{}) - fake.recordInvocation("UserEmail", []interface{}{}) - fake.userEmailMutex.Unlock() - if fake.UserEmailStub != nil { - return fake.UserEmailStub() - } - if specificReturn { - return ret.result1 - } - return fake.userEmailReturns.result1 -} - -func (fake *FakeCFContext) UserEmailCallCount() int { - fake.userEmailMutex.RLock() - defer fake.userEmailMutex.RUnlock() - return len(fake.userEmailArgsForCall) -} - -func (fake *FakeCFContext) UserEmailReturns(result1 string) { - fake.UserEmailStub = nil - fake.userEmailReturns = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) UserEmailReturnsOnCall(i int, result1 string) { - fake.UserEmailStub = nil - if fake.userEmailReturnsOnCall == nil { - fake.userEmailReturnsOnCall = make(map[int]struct { - result1 string - }) - } - fake.userEmailReturnsOnCall[i] = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) UserGUID() string { - fake.userGUIDMutex.Lock() - ret, specificReturn := fake.userGUIDReturnsOnCall[len(fake.userGUIDArgsForCall)] - fake.userGUIDArgsForCall = append(fake.userGUIDArgsForCall, struct{}{}) - fake.recordInvocation("UserGUID", []interface{}{}) - fake.userGUIDMutex.Unlock() - if fake.UserGUIDStub != nil { - return fake.UserGUIDStub() - } - if specificReturn { - return ret.result1 - } - return fake.userGUIDReturns.result1 -} - -func (fake *FakeCFContext) UserGUIDCallCount() int { - fake.userGUIDMutex.RLock() - defer fake.userGUIDMutex.RUnlock() - return len(fake.userGUIDArgsForCall) -} - -func (fake *FakeCFContext) UserGUIDReturns(result1 string) { - fake.UserGUIDStub = nil - fake.userGUIDReturns = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) UserGUIDReturnsOnCall(i int, result1 string) { - fake.UserGUIDStub = nil - if fake.userGUIDReturnsOnCall == nil { - fake.userGUIDReturnsOnCall = make(map[int]struct { - result1 string - }) - } - fake.userGUIDReturnsOnCall[i] = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) UAAToken() string { - fake.uAATokenMutex.Lock() - ret, specificReturn := fake.uAATokenReturnsOnCall[len(fake.uAATokenArgsForCall)] - fake.uAATokenArgsForCall = append(fake.uAATokenArgsForCall, struct{}{}) - fake.recordInvocation("UAAToken", []interface{}{}) - fake.uAATokenMutex.Unlock() - if fake.UAATokenStub != nil { - return fake.UAATokenStub() - } - if specificReturn { - return ret.result1 - } - return fake.uAATokenReturns.result1 -} - -func (fake *FakeCFContext) UAATokenCallCount() int { - fake.uAATokenMutex.RLock() - defer fake.uAATokenMutex.RUnlock() - return len(fake.uAATokenArgsForCall) -} - -func (fake *FakeCFContext) UAATokenReturns(result1 string) { - fake.UAATokenStub = nil - fake.uAATokenReturns = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) UAATokenReturnsOnCall(i int, result1 string) { - fake.UAATokenStub = nil - if fake.uAATokenReturnsOnCall == nil { - fake.uAATokenReturnsOnCall = make(map[int]struct { - result1 string - }) - } - fake.uAATokenReturnsOnCall[i] = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) UAARefreshToken() string { - fake.uAARefreshTokenMutex.Lock() - ret, specificReturn := fake.uAARefreshTokenReturnsOnCall[len(fake.uAARefreshTokenArgsForCall)] - fake.uAARefreshTokenArgsForCall = append(fake.uAARefreshTokenArgsForCall, struct{}{}) - fake.recordInvocation("UAARefreshToken", []interface{}{}) - fake.uAARefreshTokenMutex.Unlock() - if fake.UAARefreshTokenStub != nil { - return fake.UAARefreshTokenStub() - } - if specificReturn { - return ret.result1 - } - return fake.uAARefreshTokenReturns.result1 -} - -func (fake *FakeCFContext) UAARefreshTokenCallCount() int { - fake.uAARefreshTokenMutex.RLock() - defer fake.uAARefreshTokenMutex.RUnlock() - return len(fake.uAARefreshTokenArgsForCall) -} - -func (fake *FakeCFContext) UAARefreshTokenReturns(result1 string) { - fake.UAARefreshTokenStub = nil - fake.uAARefreshTokenReturns = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) UAARefreshTokenReturnsOnCall(i int, result1 string) { - fake.UAARefreshTokenStub = nil - if fake.uAARefreshTokenReturnsOnCall == nil { - fake.uAARefreshTokenReturnsOnCall = make(map[int]struct { - result1 string - }) - } - fake.uAARefreshTokenReturnsOnCall[i] = struct { - result1 string - }{result1} -} - -func (fake *FakeCFContext) RefreshUAAToken() (string, error) { - fake.refreshUAATokenMutex.Lock() - ret, specificReturn := fake.refreshUAATokenReturnsOnCall[len(fake.refreshUAATokenArgsForCall)] - fake.refreshUAATokenArgsForCall = append(fake.refreshUAATokenArgsForCall, struct{}{}) - fake.recordInvocation("RefreshUAAToken", []interface{}{}) - fake.refreshUAATokenMutex.Unlock() - if fake.RefreshUAATokenStub != nil { - return fake.RefreshUAATokenStub() - } - if specificReturn { - return ret.result1, ret.result2 - } - return fake.refreshUAATokenReturns.result1, fake.refreshUAATokenReturns.result2 -} - -func (fake *FakeCFContext) RefreshUAATokenCallCount() int { - fake.refreshUAATokenMutex.RLock() - defer fake.refreshUAATokenMutex.RUnlock() - return len(fake.refreshUAATokenArgsForCall) -} - -func (fake *FakeCFContext) RefreshUAATokenReturns(result1 string, result2 error) { - fake.RefreshUAATokenStub = nil - fake.refreshUAATokenReturns = struct { - result1 string - result2 error - }{result1, result2} -} - -func (fake *FakeCFContext) RefreshUAATokenReturnsOnCall(i int, result1 string, result2 error) { - fake.RefreshUAATokenStub = nil - if fake.refreshUAATokenReturnsOnCall == nil { - fake.refreshUAATokenReturnsOnCall = make(map[int]struct { - result1 string - result2 error - }) - } - fake.refreshUAATokenReturnsOnCall[i] = struct { - result1 string - result2 error - }{result1, result2} -} - -func (fake *FakeCFContext) CurrentOrganization() models.OrganizationFields { - fake.currentOrganizationMutex.Lock() - ret, specificReturn := fake.currentOrganizationReturnsOnCall[len(fake.currentOrganizationArgsForCall)] - fake.currentOrganizationArgsForCall = append(fake.currentOrganizationArgsForCall, struct{}{}) - fake.recordInvocation("CurrentOrganization", []interface{}{}) - fake.currentOrganizationMutex.Unlock() - if fake.CurrentOrganizationStub != nil { - return fake.CurrentOrganizationStub() - } - if specificReturn { - return ret.result1 - } - return fake.currentOrganizationReturns.result1 -} - -func (fake *FakeCFContext) CurrentOrganizationCallCount() int { - fake.currentOrganizationMutex.RLock() - defer fake.currentOrganizationMutex.RUnlock() - return len(fake.currentOrganizationArgsForCall) -} - -func (fake *FakeCFContext) CurrentOrganizationReturns(result1 models.OrganizationFields) { - fake.CurrentOrganizationStub = nil - fake.currentOrganizationReturns = struct { - result1 models.OrganizationFields - }{result1} -} - -func (fake *FakeCFContext) CurrentOrganizationReturnsOnCall(i int, result1 models.OrganizationFields) { - fake.CurrentOrganizationStub = nil - if fake.currentOrganizationReturnsOnCall == nil { - fake.currentOrganizationReturnsOnCall = make(map[int]struct { - result1 models.OrganizationFields - }) - } - fake.currentOrganizationReturnsOnCall[i] = struct { - result1 models.OrganizationFields - }{result1} -} - -func (fake *FakeCFContext) HasTargetedOrganization() bool { - fake.hasTargetedOrganizationMutex.Lock() - ret, specificReturn := fake.hasTargetedOrganizationReturnsOnCall[len(fake.hasTargetedOrganizationArgsForCall)] - fake.hasTargetedOrganizationArgsForCall = append(fake.hasTargetedOrganizationArgsForCall, struct{}{}) - fake.recordInvocation("HasTargetedOrganization", []interface{}{}) - fake.hasTargetedOrganizationMutex.Unlock() - if fake.HasTargetedOrganizationStub != nil { - return fake.HasTargetedOrganizationStub() - } - if specificReturn { - return ret.result1 - } - return fake.hasTargetedOrganizationReturns.result1 -} - -func (fake *FakeCFContext) HasTargetedOrganizationCallCount() int { - fake.hasTargetedOrganizationMutex.RLock() - defer fake.hasTargetedOrganizationMutex.RUnlock() - return len(fake.hasTargetedOrganizationArgsForCall) -} - -func (fake *FakeCFContext) HasTargetedOrganizationReturns(result1 bool) { - fake.HasTargetedOrganizationStub = nil - fake.hasTargetedOrganizationReturns = struct { - result1 bool - }{result1} -} - -func (fake *FakeCFContext) HasTargetedOrganizationReturnsOnCall(i int, result1 bool) { - fake.HasTargetedOrganizationStub = nil - if fake.hasTargetedOrganizationReturnsOnCall == nil { - fake.hasTargetedOrganizationReturnsOnCall = make(map[int]struct { - result1 bool - }) - } - fake.hasTargetedOrganizationReturnsOnCall[i] = struct { - result1 bool - }{result1} -} - -func (fake *FakeCFContext) CurrentSpace() models.SpaceFields { - fake.currentSpaceMutex.Lock() - ret, specificReturn := fake.currentSpaceReturnsOnCall[len(fake.currentSpaceArgsForCall)] - fake.currentSpaceArgsForCall = append(fake.currentSpaceArgsForCall, struct{}{}) - fake.recordInvocation("CurrentSpace", []interface{}{}) - fake.currentSpaceMutex.Unlock() - if fake.CurrentSpaceStub != nil { - return fake.CurrentSpaceStub() - } - if specificReturn { - return ret.result1 - } - return fake.currentSpaceReturns.result1 -} - -func (fake *FakeCFContext) CurrentSpaceCallCount() int { - fake.currentSpaceMutex.RLock() - defer fake.currentSpaceMutex.RUnlock() - return len(fake.currentSpaceArgsForCall) -} - -func (fake *FakeCFContext) CurrentSpaceReturns(result1 models.SpaceFields) { - fake.CurrentSpaceStub = nil - fake.currentSpaceReturns = struct { - result1 models.SpaceFields - }{result1} -} - -func (fake *FakeCFContext) CurrentSpaceReturnsOnCall(i int, result1 models.SpaceFields) { - fake.CurrentSpaceStub = nil - if fake.currentSpaceReturnsOnCall == nil { - fake.currentSpaceReturnsOnCall = make(map[int]struct { - result1 models.SpaceFields - }) - } - fake.currentSpaceReturnsOnCall[i] = struct { - result1 models.SpaceFields - }{result1} -} - -func (fake *FakeCFContext) HasTargetedSpace() bool { - fake.hasTargetedSpaceMutex.Lock() - ret, specificReturn := fake.hasTargetedSpaceReturnsOnCall[len(fake.hasTargetedSpaceArgsForCall)] - fake.hasTargetedSpaceArgsForCall = append(fake.hasTargetedSpaceArgsForCall, struct{}{}) - fake.recordInvocation("HasTargetedSpace", []interface{}{}) - fake.hasTargetedSpaceMutex.Unlock() - if fake.HasTargetedSpaceStub != nil { - return fake.HasTargetedSpaceStub() - } - if specificReturn { - return ret.result1 - } - return fake.hasTargetedSpaceReturns.result1 -} - -func (fake *FakeCFContext) HasTargetedSpaceCallCount() int { - fake.hasTargetedSpaceMutex.RLock() - defer fake.hasTargetedSpaceMutex.RUnlock() - return len(fake.hasTargetedSpaceArgsForCall) -} - -func (fake *FakeCFContext) HasTargetedSpaceReturns(result1 bool) { - fake.HasTargetedSpaceStub = nil - fake.hasTargetedSpaceReturns = struct { - result1 bool - }{result1} -} - -func (fake *FakeCFContext) HasTargetedSpaceReturnsOnCall(i int, result1 bool) { - fake.HasTargetedSpaceStub = nil - if fake.hasTargetedSpaceReturnsOnCall == nil { - fake.hasTargetedSpaceReturnsOnCall = make(map[int]struct { - result1 bool - }) - } - fake.hasTargetedSpaceReturnsOnCall[i] = struct { - result1 bool - }{result1} -} - -func (fake *FakeCFContext) Invocations() map[string][][]interface{} { - fake.invocationsMutex.RLock() - defer fake.invocationsMutex.RUnlock() - fake.aPIVersionMutex.RLock() - defer fake.aPIVersionMutex.RUnlock() - fake.aPIEndpointMutex.RLock() - defer fake.aPIEndpointMutex.RUnlock() - fake.hasAPIEndpointMutex.RLock() - defer fake.hasAPIEndpointMutex.RUnlock() - fake.dopplerEndpointMutex.RLock() - defer fake.dopplerEndpointMutex.RUnlock() - fake.uAAEndpointMutex.RLock() - defer fake.uAAEndpointMutex.RUnlock() - fake.isLoggedInMutex.RLock() - defer fake.isLoggedInMutex.RUnlock() - fake.usernameMutex.RLock() - defer fake.usernameMutex.RUnlock() - fake.userEmailMutex.RLock() - defer fake.userEmailMutex.RUnlock() - fake.userGUIDMutex.RLock() - defer fake.userGUIDMutex.RUnlock() - fake.uAATokenMutex.RLock() - defer fake.uAATokenMutex.RUnlock() - fake.uAARefreshTokenMutex.RLock() - defer fake.uAARefreshTokenMutex.RUnlock() - fake.refreshUAATokenMutex.RLock() - defer fake.refreshUAATokenMutex.RUnlock() - fake.currentOrganizationMutex.RLock() - defer fake.currentOrganizationMutex.RUnlock() - fake.hasTargetedOrganizationMutex.RLock() - defer fake.hasTargetedOrganizationMutex.RUnlock() - fake.currentSpaceMutex.RLock() - defer fake.currentSpaceMutex.RUnlock() - fake.hasTargetedSpaceMutex.RLock() - defer fake.hasTargetedSpaceMutex.RUnlock() - return fake.invocations -} - -func (fake *FakeCFContext) recordInvocation(key string, args []interface{}) { - fake.invocationsMutex.Lock() - defer fake.invocationsMutex.Unlock() - if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} - } - if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} - } - fake.invocations[key] = append(fake.invocations[key], args) -} - -var _ plugin.CFContext = new(FakeCFContext) diff --git a/plugin/pluginfakes/fake_plugin.go b/plugin/pluginfakes/fake_plugin.go deleted file mode 100644 index 840185f..0000000 --- a/plugin/pluginfakes/fake_plugin.go +++ /dev/null @@ -1,146 +0,0 @@ -// Code generated by counterfeiter. DO NOT EDIT. -package pluginfakes - -import ( - "sync" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin" -) - -type FakePlugin struct { - GetMetadataStub func() plugin.PluginMetadata - getMetadataMutex sync.RWMutex - getMetadataArgsForCall []struct { - } - getMetadataReturns struct { - result1 plugin.PluginMetadata - } - getMetadataReturnsOnCall map[int]struct { - result1 plugin.PluginMetadata - } - RunStub func(plugin.PluginContext, []string) - runMutex sync.RWMutex - runArgsForCall []struct { - arg1 plugin.PluginContext - arg2 []string - } - invocations map[string][][]interface{} - invocationsMutex sync.RWMutex -} - -func (fake *FakePlugin) GetMetadata() plugin.PluginMetadata { - fake.getMetadataMutex.Lock() - ret, specificReturn := fake.getMetadataReturnsOnCall[len(fake.getMetadataArgsForCall)] - fake.getMetadataArgsForCall = append(fake.getMetadataArgsForCall, struct { - }{}) - fake.recordInvocation("GetMetadata", []interface{}{}) - fake.getMetadataMutex.Unlock() - if fake.GetMetadataStub != nil { - return fake.GetMetadataStub() - } - if specificReturn { - return ret.result1 - } - fakeReturns := fake.getMetadataReturns - return fakeReturns.result1 -} - -func (fake *FakePlugin) GetMetadataCallCount() int { - fake.getMetadataMutex.RLock() - defer fake.getMetadataMutex.RUnlock() - return len(fake.getMetadataArgsForCall) -} - -func (fake *FakePlugin) GetMetadataCalls(stub func() plugin.PluginMetadata) { - fake.getMetadataMutex.Lock() - defer fake.getMetadataMutex.Unlock() - fake.GetMetadataStub = stub -} - -func (fake *FakePlugin) GetMetadataReturns(result1 plugin.PluginMetadata) { - fake.getMetadataMutex.Lock() - defer fake.getMetadataMutex.Unlock() - fake.GetMetadataStub = nil - fake.getMetadataReturns = struct { - result1 plugin.PluginMetadata - }{result1} -} - -func (fake *FakePlugin) GetMetadataReturnsOnCall(i int, result1 plugin.PluginMetadata) { - fake.getMetadataMutex.Lock() - defer fake.getMetadataMutex.Unlock() - fake.GetMetadataStub = nil - if fake.getMetadataReturnsOnCall == nil { - fake.getMetadataReturnsOnCall = make(map[int]struct { - result1 plugin.PluginMetadata - }) - } - fake.getMetadataReturnsOnCall[i] = struct { - result1 plugin.PluginMetadata - }{result1} -} - -func (fake *FakePlugin) Run(arg1 plugin.PluginContext, arg2 []string) { - var arg2Copy []string - if arg2 != nil { - arg2Copy = make([]string, len(arg2)) - copy(arg2Copy, arg2) - } - fake.runMutex.Lock() - fake.runArgsForCall = append(fake.runArgsForCall, struct { - arg1 plugin.PluginContext - arg2 []string - }{arg1, arg2Copy}) - fake.recordInvocation("Run", []interface{}{arg1, arg2Copy}) - fake.runMutex.Unlock() - if fake.RunStub != nil { - fake.RunStub(arg1, arg2) - } -} - -func (fake *FakePlugin) RunCallCount() int { - fake.runMutex.RLock() - defer fake.runMutex.RUnlock() - return len(fake.runArgsForCall) -} - -func (fake *FakePlugin) RunCalls(stub func(plugin.PluginContext, []string)) { - fake.runMutex.Lock() - defer fake.runMutex.Unlock() - fake.RunStub = stub -} - -func (fake *FakePlugin) RunArgsForCall(i int) (plugin.PluginContext, []string) { - fake.runMutex.RLock() - defer fake.runMutex.RUnlock() - argsForCall := fake.runArgsForCall[i] - return argsForCall.arg1, argsForCall.arg2 -} - -func (fake *FakePlugin) Invocations() map[string][][]interface{} { - fake.invocationsMutex.RLock() - defer fake.invocationsMutex.RUnlock() - fake.getMetadataMutex.RLock() - defer fake.getMetadataMutex.RUnlock() - fake.runMutex.RLock() - defer fake.runMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} - for key, value := range fake.invocations { - copiedInvocations[key] = value - } - return copiedInvocations -} - -func (fake *FakePlugin) recordInvocation(key string, args []interface{}) { - fake.invocationsMutex.Lock() - defer fake.invocationsMutex.Unlock() - if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} - } - if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} - } - fake.invocations[key] = append(fake.invocations[key], args) -} - -var _ plugin.Plugin = new(FakePlugin) diff --git a/plugin/pluginfakes/fake_plugin_config.go b/plugin/pluginfakes/fake_plugin_config.go deleted file mode 100644 index dcc2863..0000000 --- a/plugin/pluginfakes/fake_plugin_config.go +++ /dev/null @@ -1,1428 +0,0 @@ -// Code generated by counterfeiter. DO NOT EDIT. -package pluginfakes - -import ( - "sync" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin" -) - -type FakePluginConfig struct { - EraseStub func(string) error - eraseMutex sync.RWMutex - eraseArgsForCall []struct { - arg1 string - } - eraseReturns struct { - result1 error - } - eraseReturnsOnCall map[int]struct { - result1 error - } - ExistsStub func(string) bool - existsMutex sync.RWMutex - existsArgsForCall []struct { - arg1 string - } - existsReturns struct { - result1 bool - } - existsReturnsOnCall map[int]struct { - result1 bool - } - GetStub func(string) interface{} - getMutex sync.RWMutex - getArgsForCall []struct { - arg1 string - } - getReturns struct { - result1 interface{} - } - getReturnsOnCall map[int]struct { - result1 interface{} - } - GetBoolStub func(string) (bool, error) - getBoolMutex sync.RWMutex - getBoolArgsForCall []struct { - arg1 string - } - getBoolReturns struct { - result1 bool - result2 error - } - getBoolReturnsOnCall map[int]struct { - result1 bool - result2 error - } - GetBoolWithDefaultStub func(string, bool) (bool, error) - getBoolWithDefaultMutex sync.RWMutex - getBoolWithDefaultArgsForCall []struct { - arg1 string - arg2 bool - } - getBoolWithDefaultReturns struct { - result1 bool - result2 error - } - getBoolWithDefaultReturnsOnCall map[int]struct { - result1 bool - result2 error - } - GetFloatStub func(string) (float64, error) - getFloatMutex sync.RWMutex - getFloatArgsForCall []struct { - arg1 string - } - getFloatReturns struct { - result1 float64 - result2 error - } - getFloatReturnsOnCall map[int]struct { - result1 float64 - result2 error - } - GetFloatSliceStub func(string) ([]float64, error) - getFloatSliceMutex sync.RWMutex - getFloatSliceArgsForCall []struct { - arg1 string - } - getFloatSliceReturns struct { - result1 []float64 - result2 error - } - getFloatSliceReturnsOnCall map[int]struct { - result1 []float64 - result2 error - } - GetFloatWithDefaultStub func(string, float64) (float64, error) - getFloatWithDefaultMutex sync.RWMutex - getFloatWithDefaultArgsForCall []struct { - arg1 string - arg2 float64 - } - getFloatWithDefaultReturns struct { - result1 float64 - result2 error - } - getFloatWithDefaultReturnsOnCall map[int]struct { - result1 float64 - result2 error - } - GetIntStub func(string) (int, error) - getIntMutex sync.RWMutex - getIntArgsForCall []struct { - arg1 string - } - getIntReturns struct { - result1 int - result2 error - } - getIntReturnsOnCall map[int]struct { - result1 int - result2 error - } - GetIntSliceStub func(string) ([]int, error) - getIntSliceMutex sync.RWMutex - getIntSliceArgsForCall []struct { - arg1 string - } - getIntSliceReturns struct { - result1 []int - result2 error - } - getIntSliceReturnsOnCall map[int]struct { - result1 []int - result2 error - } - GetIntWithDefaultStub func(string, int) (int, error) - getIntWithDefaultMutex sync.RWMutex - getIntWithDefaultArgsForCall []struct { - arg1 string - arg2 int - } - getIntWithDefaultReturns struct { - result1 int - result2 error - } - getIntWithDefaultReturnsOnCall map[int]struct { - result1 int - result2 error - } - GetStringStub func(string) (string, error) - getStringMutex sync.RWMutex - getStringArgsForCall []struct { - arg1 string - } - getStringReturns struct { - result1 string - result2 error - } - getStringReturnsOnCall map[int]struct { - result1 string - result2 error - } - GetStringMapStub func(string) (map[string]interface{}, error) - getStringMapMutex sync.RWMutex - getStringMapArgsForCall []struct { - arg1 string - } - getStringMapReturns struct { - result1 map[string]interface{} - result2 error - } - getStringMapReturnsOnCall map[int]struct { - result1 map[string]interface{} - result2 error - } - GetStringMapStringStub func(string) (map[string]string, error) - getStringMapStringMutex sync.RWMutex - getStringMapStringArgsForCall []struct { - arg1 string - } - getStringMapStringReturns struct { - result1 map[string]string - result2 error - } - getStringMapStringReturnsOnCall map[int]struct { - result1 map[string]string - result2 error - } - GetStringSliceStub func(string) ([]string, error) - getStringSliceMutex sync.RWMutex - getStringSliceArgsForCall []struct { - arg1 string - } - getStringSliceReturns struct { - result1 []string - result2 error - } - getStringSliceReturnsOnCall map[int]struct { - result1 []string - result2 error - } - GetStringWithDefaultStub func(string, string) (string, error) - getStringWithDefaultMutex sync.RWMutex - getStringWithDefaultArgsForCall []struct { - arg1 string - arg2 string - } - getStringWithDefaultReturns struct { - result1 string - result2 error - } - getStringWithDefaultReturnsOnCall map[int]struct { - result1 string - result2 error - } - GetWithDefaultStub func(string, interface{}) interface{} - getWithDefaultMutex sync.RWMutex - getWithDefaultArgsForCall []struct { - arg1 string - arg2 interface{} - } - getWithDefaultReturns struct { - result1 interface{} - } - getWithDefaultReturnsOnCall map[int]struct { - result1 interface{} - } - SetStub func(string, interface{}) error - setMutex sync.RWMutex - setArgsForCall []struct { - arg1 string - arg2 interface{} - } - setReturns struct { - result1 error - } - setReturnsOnCall map[int]struct { - result1 error - } - invocations map[string][][]interface{} - invocationsMutex sync.RWMutex -} - -func (fake *FakePluginConfig) Erase(arg1 string) error { - fake.eraseMutex.Lock() - ret, specificReturn := fake.eraseReturnsOnCall[len(fake.eraseArgsForCall)] - fake.eraseArgsForCall = append(fake.eraseArgsForCall, struct { - arg1 string - }{arg1}) - fake.recordInvocation("Erase", []interface{}{arg1}) - fake.eraseMutex.Unlock() - if fake.EraseStub != nil { - return fake.EraseStub(arg1) - } - if specificReturn { - return ret.result1 - } - fakeReturns := fake.eraseReturns - return fakeReturns.result1 -} - -func (fake *FakePluginConfig) EraseCallCount() int { - fake.eraseMutex.RLock() - defer fake.eraseMutex.RUnlock() - return len(fake.eraseArgsForCall) -} - -func (fake *FakePluginConfig) EraseCalls(stub func(string) error) { - fake.eraseMutex.Lock() - defer fake.eraseMutex.Unlock() - fake.EraseStub = stub -} - -func (fake *FakePluginConfig) EraseArgsForCall(i int) string { - fake.eraseMutex.RLock() - defer fake.eraseMutex.RUnlock() - argsForCall := fake.eraseArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakePluginConfig) EraseReturns(result1 error) { - fake.eraseMutex.Lock() - defer fake.eraseMutex.Unlock() - fake.EraseStub = nil - fake.eraseReturns = struct { - result1 error - }{result1} -} - -func (fake *FakePluginConfig) EraseReturnsOnCall(i int, result1 error) { - fake.eraseMutex.Lock() - defer fake.eraseMutex.Unlock() - fake.EraseStub = nil - if fake.eraseReturnsOnCall == nil { - fake.eraseReturnsOnCall = make(map[int]struct { - result1 error - }) - } - fake.eraseReturnsOnCall[i] = struct { - result1 error - }{result1} -} - -func (fake *FakePluginConfig) Exists(arg1 string) bool { - fake.existsMutex.Lock() - ret, specificReturn := fake.existsReturnsOnCall[len(fake.existsArgsForCall)] - fake.existsArgsForCall = append(fake.existsArgsForCall, struct { - arg1 string - }{arg1}) - fake.recordInvocation("Exists", []interface{}{arg1}) - fake.existsMutex.Unlock() - if fake.ExistsStub != nil { - return fake.ExistsStub(arg1) - } - if specificReturn { - return ret.result1 - } - fakeReturns := fake.existsReturns - return fakeReturns.result1 -} - -func (fake *FakePluginConfig) ExistsCallCount() int { - fake.existsMutex.RLock() - defer fake.existsMutex.RUnlock() - return len(fake.existsArgsForCall) -} - -func (fake *FakePluginConfig) ExistsCalls(stub func(string) bool) { - fake.existsMutex.Lock() - defer fake.existsMutex.Unlock() - fake.ExistsStub = stub -} - -func (fake *FakePluginConfig) ExistsArgsForCall(i int) string { - fake.existsMutex.RLock() - defer fake.existsMutex.RUnlock() - argsForCall := fake.existsArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakePluginConfig) ExistsReturns(result1 bool) { - fake.existsMutex.Lock() - defer fake.existsMutex.Unlock() - fake.ExistsStub = nil - fake.existsReturns = struct { - result1 bool - }{result1} -} - -func (fake *FakePluginConfig) ExistsReturnsOnCall(i int, result1 bool) { - fake.existsMutex.Lock() - defer fake.existsMutex.Unlock() - fake.ExistsStub = nil - if fake.existsReturnsOnCall == nil { - fake.existsReturnsOnCall = make(map[int]struct { - result1 bool - }) - } - fake.existsReturnsOnCall[i] = struct { - result1 bool - }{result1} -} - -func (fake *FakePluginConfig) Get(arg1 string) interface{} { - fake.getMutex.Lock() - ret, specificReturn := fake.getReturnsOnCall[len(fake.getArgsForCall)] - fake.getArgsForCall = append(fake.getArgsForCall, struct { - arg1 string - }{arg1}) - fake.recordInvocation("Get", []interface{}{arg1}) - fake.getMutex.Unlock() - if fake.GetStub != nil { - return fake.GetStub(arg1) - } - if specificReturn { - return ret.result1 - } - fakeReturns := fake.getReturns - return fakeReturns.result1 -} - -func (fake *FakePluginConfig) GetCallCount() int { - fake.getMutex.RLock() - defer fake.getMutex.RUnlock() - return len(fake.getArgsForCall) -} - -func (fake *FakePluginConfig) GetCalls(stub func(string) interface{}) { - fake.getMutex.Lock() - defer fake.getMutex.Unlock() - fake.GetStub = stub -} - -func (fake *FakePluginConfig) GetArgsForCall(i int) string { - fake.getMutex.RLock() - defer fake.getMutex.RUnlock() - argsForCall := fake.getArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakePluginConfig) GetReturns(result1 interface{}) { - fake.getMutex.Lock() - defer fake.getMutex.Unlock() - fake.GetStub = nil - fake.getReturns = struct { - result1 interface{} - }{result1} -} - -func (fake *FakePluginConfig) GetReturnsOnCall(i int, result1 interface{}) { - fake.getMutex.Lock() - defer fake.getMutex.Unlock() - fake.GetStub = nil - if fake.getReturnsOnCall == nil { - fake.getReturnsOnCall = make(map[int]struct { - result1 interface{} - }) - } - fake.getReturnsOnCall[i] = struct { - result1 interface{} - }{result1} -} - -func (fake *FakePluginConfig) GetBool(arg1 string) (bool, error) { - fake.getBoolMutex.Lock() - ret, specificReturn := fake.getBoolReturnsOnCall[len(fake.getBoolArgsForCall)] - fake.getBoolArgsForCall = append(fake.getBoolArgsForCall, struct { - arg1 string - }{arg1}) - fake.recordInvocation("GetBool", []interface{}{arg1}) - fake.getBoolMutex.Unlock() - if fake.GetBoolStub != nil { - return fake.GetBoolStub(arg1) - } - if specificReturn { - return ret.result1, ret.result2 - } - fakeReturns := fake.getBoolReturns - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakePluginConfig) GetBoolCallCount() int { - fake.getBoolMutex.RLock() - defer fake.getBoolMutex.RUnlock() - return len(fake.getBoolArgsForCall) -} - -func (fake *FakePluginConfig) GetBoolCalls(stub func(string) (bool, error)) { - fake.getBoolMutex.Lock() - defer fake.getBoolMutex.Unlock() - fake.GetBoolStub = stub -} - -func (fake *FakePluginConfig) GetBoolArgsForCall(i int) string { - fake.getBoolMutex.RLock() - defer fake.getBoolMutex.RUnlock() - argsForCall := fake.getBoolArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakePluginConfig) GetBoolReturns(result1 bool, result2 error) { - fake.getBoolMutex.Lock() - defer fake.getBoolMutex.Unlock() - fake.GetBoolStub = nil - fake.getBoolReturns = struct { - result1 bool - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetBoolReturnsOnCall(i int, result1 bool, result2 error) { - fake.getBoolMutex.Lock() - defer fake.getBoolMutex.Unlock() - fake.GetBoolStub = nil - if fake.getBoolReturnsOnCall == nil { - fake.getBoolReturnsOnCall = make(map[int]struct { - result1 bool - result2 error - }) - } - fake.getBoolReturnsOnCall[i] = struct { - result1 bool - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetBoolWithDefault(arg1 string, arg2 bool) (bool, error) { - fake.getBoolWithDefaultMutex.Lock() - ret, specificReturn := fake.getBoolWithDefaultReturnsOnCall[len(fake.getBoolWithDefaultArgsForCall)] - fake.getBoolWithDefaultArgsForCall = append(fake.getBoolWithDefaultArgsForCall, struct { - arg1 string - arg2 bool - }{arg1, arg2}) - fake.recordInvocation("GetBoolWithDefault", []interface{}{arg1, arg2}) - fake.getBoolWithDefaultMutex.Unlock() - if fake.GetBoolWithDefaultStub != nil { - return fake.GetBoolWithDefaultStub(arg1, arg2) - } - if specificReturn { - return ret.result1, ret.result2 - } - fakeReturns := fake.getBoolWithDefaultReturns - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakePluginConfig) GetBoolWithDefaultCallCount() int { - fake.getBoolWithDefaultMutex.RLock() - defer fake.getBoolWithDefaultMutex.RUnlock() - return len(fake.getBoolWithDefaultArgsForCall) -} - -func (fake *FakePluginConfig) GetBoolWithDefaultCalls(stub func(string, bool) (bool, error)) { - fake.getBoolWithDefaultMutex.Lock() - defer fake.getBoolWithDefaultMutex.Unlock() - fake.GetBoolWithDefaultStub = stub -} - -func (fake *FakePluginConfig) GetBoolWithDefaultArgsForCall(i int) (string, bool) { - fake.getBoolWithDefaultMutex.RLock() - defer fake.getBoolWithDefaultMutex.RUnlock() - argsForCall := fake.getBoolWithDefaultArgsForCall[i] - return argsForCall.arg1, argsForCall.arg2 -} - -func (fake *FakePluginConfig) GetBoolWithDefaultReturns(result1 bool, result2 error) { - fake.getBoolWithDefaultMutex.Lock() - defer fake.getBoolWithDefaultMutex.Unlock() - fake.GetBoolWithDefaultStub = nil - fake.getBoolWithDefaultReturns = struct { - result1 bool - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetBoolWithDefaultReturnsOnCall(i int, result1 bool, result2 error) { - fake.getBoolWithDefaultMutex.Lock() - defer fake.getBoolWithDefaultMutex.Unlock() - fake.GetBoolWithDefaultStub = nil - if fake.getBoolWithDefaultReturnsOnCall == nil { - fake.getBoolWithDefaultReturnsOnCall = make(map[int]struct { - result1 bool - result2 error - }) - } - fake.getBoolWithDefaultReturnsOnCall[i] = struct { - result1 bool - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetFloat(arg1 string) (float64, error) { - fake.getFloatMutex.Lock() - ret, specificReturn := fake.getFloatReturnsOnCall[len(fake.getFloatArgsForCall)] - fake.getFloatArgsForCall = append(fake.getFloatArgsForCall, struct { - arg1 string - }{arg1}) - fake.recordInvocation("GetFloat", []interface{}{arg1}) - fake.getFloatMutex.Unlock() - if fake.GetFloatStub != nil { - return fake.GetFloatStub(arg1) - } - if specificReturn { - return ret.result1, ret.result2 - } - fakeReturns := fake.getFloatReturns - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakePluginConfig) GetFloatCallCount() int { - fake.getFloatMutex.RLock() - defer fake.getFloatMutex.RUnlock() - return len(fake.getFloatArgsForCall) -} - -func (fake *FakePluginConfig) GetFloatCalls(stub func(string) (float64, error)) { - fake.getFloatMutex.Lock() - defer fake.getFloatMutex.Unlock() - fake.GetFloatStub = stub -} - -func (fake *FakePluginConfig) GetFloatArgsForCall(i int) string { - fake.getFloatMutex.RLock() - defer fake.getFloatMutex.RUnlock() - argsForCall := fake.getFloatArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakePluginConfig) GetFloatReturns(result1 float64, result2 error) { - fake.getFloatMutex.Lock() - defer fake.getFloatMutex.Unlock() - fake.GetFloatStub = nil - fake.getFloatReturns = struct { - result1 float64 - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetFloatReturnsOnCall(i int, result1 float64, result2 error) { - fake.getFloatMutex.Lock() - defer fake.getFloatMutex.Unlock() - fake.GetFloatStub = nil - if fake.getFloatReturnsOnCall == nil { - fake.getFloatReturnsOnCall = make(map[int]struct { - result1 float64 - result2 error - }) - } - fake.getFloatReturnsOnCall[i] = struct { - result1 float64 - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetFloatSlice(arg1 string) ([]float64, error) { - fake.getFloatSliceMutex.Lock() - ret, specificReturn := fake.getFloatSliceReturnsOnCall[len(fake.getFloatSliceArgsForCall)] - fake.getFloatSliceArgsForCall = append(fake.getFloatSliceArgsForCall, struct { - arg1 string - }{arg1}) - fake.recordInvocation("GetFloatSlice", []interface{}{arg1}) - fake.getFloatSliceMutex.Unlock() - if fake.GetFloatSliceStub != nil { - return fake.GetFloatSliceStub(arg1) - } - if specificReturn { - return ret.result1, ret.result2 - } - fakeReturns := fake.getFloatSliceReturns - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakePluginConfig) GetFloatSliceCallCount() int { - fake.getFloatSliceMutex.RLock() - defer fake.getFloatSliceMutex.RUnlock() - return len(fake.getFloatSliceArgsForCall) -} - -func (fake *FakePluginConfig) GetFloatSliceCalls(stub func(string) ([]float64, error)) { - fake.getFloatSliceMutex.Lock() - defer fake.getFloatSliceMutex.Unlock() - fake.GetFloatSliceStub = stub -} - -func (fake *FakePluginConfig) GetFloatSliceArgsForCall(i int) string { - fake.getFloatSliceMutex.RLock() - defer fake.getFloatSliceMutex.RUnlock() - argsForCall := fake.getFloatSliceArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakePluginConfig) GetFloatSliceReturns(result1 []float64, result2 error) { - fake.getFloatSliceMutex.Lock() - defer fake.getFloatSliceMutex.Unlock() - fake.GetFloatSliceStub = nil - fake.getFloatSliceReturns = struct { - result1 []float64 - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetFloatSliceReturnsOnCall(i int, result1 []float64, result2 error) { - fake.getFloatSliceMutex.Lock() - defer fake.getFloatSliceMutex.Unlock() - fake.GetFloatSliceStub = nil - if fake.getFloatSliceReturnsOnCall == nil { - fake.getFloatSliceReturnsOnCall = make(map[int]struct { - result1 []float64 - result2 error - }) - } - fake.getFloatSliceReturnsOnCall[i] = struct { - result1 []float64 - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetFloatWithDefault(arg1 string, arg2 float64) (float64, error) { - fake.getFloatWithDefaultMutex.Lock() - ret, specificReturn := fake.getFloatWithDefaultReturnsOnCall[len(fake.getFloatWithDefaultArgsForCall)] - fake.getFloatWithDefaultArgsForCall = append(fake.getFloatWithDefaultArgsForCall, struct { - arg1 string - arg2 float64 - }{arg1, arg2}) - fake.recordInvocation("GetFloatWithDefault", []interface{}{arg1, arg2}) - fake.getFloatWithDefaultMutex.Unlock() - if fake.GetFloatWithDefaultStub != nil { - return fake.GetFloatWithDefaultStub(arg1, arg2) - } - if specificReturn { - return ret.result1, ret.result2 - } - fakeReturns := fake.getFloatWithDefaultReturns - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakePluginConfig) GetFloatWithDefaultCallCount() int { - fake.getFloatWithDefaultMutex.RLock() - defer fake.getFloatWithDefaultMutex.RUnlock() - return len(fake.getFloatWithDefaultArgsForCall) -} - -func (fake *FakePluginConfig) GetFloatWithDefaultCalls(stub func(string, float64) (float64, error)) { - fake.getFloatWithDefaultMutex.Lock() - defer fake.getFloatWithDefaultMutex.Unlock() - fake.GetFloatWithDefaultStub = stub -} - -func (fake *FakePluginConfig) GetFloatWithDefaultArgsForCall(i int) (string, float64) { - fake.getFloatWithDefaultMutex.RLock() - defer fake.getFloatWithDefaultMutex.RUnlock() - argsForCall := fake.getFloatWithDefaultArgsForCall[i] - return argsForCall.arg1, argsForCall.arg2 -} - -func (fake *FakePluginConfig) GetFloatWithDefaultReturns(result1 float64, result2 error) { - fake.getFloatWithDefaultMutex.Lock() - defer fake.getFloatWithDefaultMutex.Unlock() - fake.GetFloatWithDefaultStub = nil - fake.getFloatWithDefaultReturns = struct { - result1 float64 - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetFloatWithDefaultReturnsOnCall(i int, result1 float64, result2 error) { - fake.getFloatWithDefaultMutex.Lock() - defer fake.getFloatWithDefaultMutex.Unlock() - fake.GetFloatWithDefaultStub = nil - if fake.getFloatWithDefaultReturnsOnCall == nil { - fake.getFloatWithDefaultReturnsOnCall = make(map[int]struct { - result1 float64 - result2 error - }) - } - fake.getFloatWithDefaultReturnsOnCall[i] = struct { - result1 float64 - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetInt(arg1 string) (int, error) { - fake.getIntMutex.Lock() - ret, specificReturn := fake.getIntReturnsOnCall[len(fake.getIntArgsForCall)] - fake.getIntArgsForCall = append(fake.getIntArgsForCall, struct { - arg1 string - }{arg1}) - fake.recordInvocation("GetInt", []interface{}{arg1}) - fake.getIntMutex.Unlock() - if fake.GetIntStub != nil { - return fake.GetIntStub(arg1) - } - if specificReturn { - return ret.result1, ret.result2 - } - fakeReturns := fake.getIntReturns - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakePluginConfig) GetIntCallCount() int { - fake.getIntMutex.RLock() - defer fake.getIntMutex.RUnlock() - return len(fake.getIntArgsForCall) -} - -func (fake *FakePluginConfig) GetIntCalls(stub func(string) (int, error)) { - fake.getIntMutex.Lock() - defer fake.getIntMutex.Unlock() - fake.GetIntStub = stub -} - -func (fake *FakePluginConfig) GetIntArgsForCall(i int) string { - fake.getIntMutex.RLock() - defer fake.getIntMutex.RUnlock() - argsForCall := fake.getIntArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakePluginConfig) GetIntReturns(result1 int, result2 error) { - fake.getIntMutex.Lock() - defer fake.getIntMutex.Unlock() - fake.GetIntStub = nil - fake.getIntReturns = struct { - result1 int - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetIntReturnsOnCall(i int, result1 int, result2 error) { - fake.getIntMutex.Lock() - defer fake.getIntMutex.Unlock() - fake.GetIntStub = nil - if fake.getIntReturnsOnCall == nil { - fake.getIntReturnsOnCall = make(map[int]struct { - result1 int - result2 error - }) - } - fake.getIntReturnsOnCall[i] = struct { - result1 int - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetIntSlice(arg1 string) ([]int, error) { - fake.getIntSliceMutex.Lock() - ret, specificReturn := fake.getIntSliceReturnsOnCall[len(fake.getIntSliceArgsForCall)] - fake.getIntSliceArgsForCall = append(fake.getIntSliceArgsForCall, struct { - arg1 string - }{arg1}) - fake.recordInvocation("GetIntSlice", []interface{}{arg1}) - fake.getIntSliceMutex.Unlock() - if fake.GetIntSliceStub != nil { - return fake.GetIntSliceStub(arg1) - } - if specificReturn { - return ret.result1, ret.result2 - } - fakeReturns := fake.getIntSliceReturns - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakePluginConfig) GetIntSliceCallCount() int { - fake.getIntSliceMutex.RLock() - defer fake.getIntSliceMutex.RUnlock() - return len(fake.getIntSliceArgsForCall) -} - -func (fake *FakePluginConfig) GetIntSliceCalls(stub func(string) ([]int, error)) { - fake.getIntSliceMutex.Lock() - defer fake.getIntSliceMutex.Unlock() - fake.GetIntSliceStub = stub -} - -func (fake *FakePluginConfig) GetIntSliceArgsForCall(i int) string { - fake.getIntSliceMutex.RLock() - defer fake.getIntSliceMutex.RUnlock() - argsForCall := fake.getIntSliceArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakePluginConfig) GetIntSliceReturns(result1 []int, result2 error) { - fake.getIntSliceMutex.Lock() - defer fake.getIntSliceMutex.Unlock() - fake.GetIntSliceStub = nil - fake.getIntSliceReturns = struct { - result1 []int - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetIntSliceReturnsOnCall(i int, result1 []int, result2 error) { - fake.getIntSliceMutex.Lock() - defer fake.getIntSliceMutex.Unlock() - fake.GetIntSliceStub = nil - if fake.getIntSliceReturnsOnCall == nil { - fake.getIntSliceReturnsOnCall = make(map[int]struct { - result1 []int - result2 error - }) - } - fake.getIntSliceReturnsOnCall[i] = struct { - result1 []int - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetIntWithDefault(arg1 string, arg2 int) (int, error) { - fake.getIntWithDefaultMutex.Lock() - ret, specificReturn := fake.getIntWithDefaultReturnsOnCall[len(fake.getIntWithDefaultArgsForCall)] - fake.getIntWithDefaultArgsForCall = append(fake.getIntWithDefaultArgsForCall, struct { - arg1 string - arg2 int - }{arg1, arg2}) - fake.recordInvocation("GetIntWithDefault", []interface{}{arg1, arg2}) - fake.getIntWithDefaultMutex.Unlock() - if fake.GetIntWithDefaultStub != nil { - return fake.GetIntWithDefaultStub(arg1, arg2) - } - if specificReturn { - return ret.result1, ret.result2 - } - fakeReturns := fake.getIntWithDefaultReturns - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakePluginConfig) GetIntWithDefaultCallCount() int { - fake.getIntWithDefaultMutex.RLock() - defer fake.getIntWithDefaultMutex.RUnlock() - return len(fake.getIntWithDefaultArgsForCall) -} - -func (fake *FakePluginConfig) GetIntWithDefaultCalls(stub func(string, int) (int, error)) { - fake.getIntWithDefaultMutex.Lock() - defer fake.getIntWithDefaultMutex.Unlock() - fake.GetIntWithDefaultStub = stub -} - -func (fake *FakePluginConfig) GetIntWithDefaultArgsForCall(i int) (string, int) { - fake.getIntWithDefaultMutex.RLock() - defer fake.getIntWithDefaultMutex.RUnlock() - argsForCall := fake.getIntWithDefaultArgsForCall[i] - return argsForCall.arg1, argsForCall.arg2 -} - -func (fake *FakePluginConfig) GetIntWithDefaultReturns(result1 int, result2 error) { - fake.getIntWithDefaultMutex.Lock() - defer fake.getIntWithDefaultMutex.Unlock() - fake.GetIntWithDefaultStub = nil - fake.getIntWithDefaultReturns = struct { - result1 int - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetIntWithDefaultReturnsOnCall(i int, result1 int, result2 error) { - fake.getIntWithDefaultMutex.Lock() - defer fake.getIntWithDefaultMutex.Unlock() - fake.GetIntWithDefaultStub = nil - if fake.getIntWithDefaultReturnsOnCall == nil { - fake.getIntWithDefaultReturnsOnCall = make(map[int]struct { - result1 int - result2 error - }) - } - fake.getIntWithDefaultReturnsOnCall[i] = struct { - result1 int - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetString(arg1 string) (string, error) { - fake.getStringMutex.Lock() - ret, specificReturn := fake.getStringReturnsOnCall[len(fake.getStringArgsForCall)] - fake.getStringArgsForCall = append(fake.getStringArgsForCall, struct { - arg1 string - }{arg1}) - fake.recordInvocation("GetString", []interface{}{arg1}) - fake.getStringMutex.Unlock() - if fake.GetStringStub != nil { - return fake.GetStringStub(arg1) - } - if specificReturn { - return ret.result1, ret.result2 - } - fakeReturns := fake.getStringReturns - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakePluginConfig) GetStringCallCount() int { - fake.getStringMutex.RLock() - defer fake.getStringMutex.RUnlock() - return len(fake.getStringArgsForCall) -} - -func (fake *FakePluginConfig) GetStringCalls(stub func(string) (string, error)) { - fake.getStringMutex.Lock() - defer fake.getStringMutex.Unlock() - fake.GetStringStub = stub -} - -func (fake *FakePluginConfig) GetStringArgsForCall(i int) string { - fake.getStringMutex.RLock() - defer fake.getStringMutex.RUnlock() - argsForCall := fake.getStringArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakePluginConfig) GetStringReturns(result1 string, result2 error) { - fake.getStringMutex.Lock() - defer fake.getStringMutex.Unlock() - fake.GetStringStub = nil - fake.getStringReturns = struct { - result1 string - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetStringReturnsOnCall(i int, result1 string, result2 error) { - fake.getStringMutex.Lock() - defer fake.getStringMutex.Unlock() - fake.GetStringStub = nil - if fake.getStringReturnsOnCall == nil { - fake.getStringReturnsOnCall = make(map[int]struct { - result1 string - result2 error - }) - } - fake.getStringReturnsOnCall[i] = struct { - result1 string - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetStringMap(arg1 string) (map[string]interface{}, error) { - fake.getStringMapMutex.Lock() - ret, specificReturn := fake.getStringMapReturnsOnCall[len(fake.getStringMapArgsForCall)] - fake.getStringMapArgsForCall = append(fake.getStringMapArgsForCall, struct { - arg1 string - }{arg1}) - fake.recordInvocation("GetStringMap", []interface{}{arg1}) - fake.getStringMapMutex.Unlock() - if fake.GetStringMapStub != nil { - return fake.GetStringMapStub(arg1) - } - if specificReturn { - return ret.result1, ret.result2 - } - fakeReturns := fake.getStringMapReturns - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakePluginConfig) GetStringMapCallCount() int { - fake.getStringMapMutex.RLock() - defer fake.getStringMapMutex.RUnlock() - return len(fake.getStringMapArgsForCall) -} - -func (fake *FakePluginConfig) GetStringMapCalls(stub func(string) (map[string]interface{}, error)) { - fake.getStringMapMutex.Lock() - defer fake.getStringMapMutex.Unlock() - fake.GetStringMapStub = stub -} - -func (fake *FakePluginConfig) GetStringMapArgsForCall(i int) string { - fake.getStringMapMutex.RLock() - defer fake.getStringMapMutex.RUnlock() - argsForCall := fake.getStringMapArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakePluginConfig) GetStringMapReturns(result1 map[string]interface{}, result2 error) { - fake.getStringMapMutex.Lock() - defer fake.getStringMapMutex.Unlock() - fake.GetStringMapStub = nil - fake.getStringMapReturns = struct { - result1 map[string]interface{} - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetStringMapReturnsOnCall(i int, result1 map[string]interface{}, result2 error) { - fake.getStringMapMutex.Lock() - defer fake.getStringMapMutex.Unlock() - fake.GetStringMapStub = nil - if fake.getStringMapReturnsOnCall == nil { - fake.getStringMapReturnsOnCall = make(map[int]struct { - result1 map[string]interface{} - result2 error - }) - } - fake.getStringMapReturnsOnCall[i] = struct { - result1 map[string]interface{} - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetStringMapString(arg1 string) (map[string]string, error) { - fake.getStringMapStringMutex.Lock() - ret, specificReturn := fake.getStringMapStringReturnsOnCall[len(fake.getStringMapStringArgsForCall)] - fake.getStringMapStringArgsForCall = append(fake.getStringMapStringArgsForCall, struct { - arg1 string - }{arg1}) - fake.recordInvocation("GetStringMapString", []interface{}{arg1}) - fake.getStringMapStringMutex.Unlock() - if fake.GetStringMapStringStub != nil { - return fake.GetStringMapStringStub(arg1) - } - if specificReturn { - return ret.result1, ret.result2 - } - fakeReturns := fake.getStringMapStringReturns - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakePluginConfig) GetStringMapStringCallCount() int { - fake.getStringMapStringMutex.RLock() - defer fake.getStringMapStringMutex.RUnlock() - return len(fake.getStringMapStringArgsForCall) -} - -func (fake *FakePluginConfig) GetStringMapStringCalls(stub func(string) (map[string]string, error)) { - fake.getStringMapStringMutex.Lock() - defer fake.getStringMapStringMutex.Unlock() - fake.GetStringMapStringStub = stub -} - -func (fake *FakePluginConfig) GetStringMapStringArgsForCall(i int) string { - fake.getStringMapStringMutex.RLock() - defer fake.getStringMapStringMutex.RUnlock() - argsForCall := fake.getStringMapStringArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakePluginConfig) GetStringMapStringReturns(result1 map[string]string, result2 error) { - fake.getStringMapStringMutex.Lock() - defer fake.getStringMapStringMutex.Unlock() - fake.GetStringMapStringStub = nil - fake.getStringMapStringReturns = struct { - result1 map[string]string - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetStringMapStringReturnsOnCall(i int, result1 map[string]string, result2 error) { - fake.getStringMapStringMutex.Lock() - defer fake.getStringMapStringMutex.Unlock() - fake.GetStringMapStringStub = nil - if fake.getStringMapStringReturnsOnCall == nil { - fake.getStringMapStringReturnsOnCall = make(map[int]struct { - result1 map[string]string - result2 error - }) - } - fake.getStringMapStringReturnsOnCall[i] = struct { - result1 map[string]string - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetStringSlice(arg1 string) ([]string, error) { - fake.getStringSliceMutex.Lock() - ret, specificReturn := fake.getStringSliceReturnsOnCall[len(fake.getStringSliceArgsForCall)] - fake.getStringSliceArgsForCall = append(fake.getStringSliceArgsForCall, struct { - arg1 string - }{arg1}) - fake.recordInvocation("GetStringSlice", []interface{}{arg1}) - fake.getStringSliceMutex.Unlock() - if fake.GetStringSliceStub != nil { - return fake.GetStringSliceStub(arg1) - } - if specificReturn { - return ret.result1, ret.result2 - } - fakeReturns := fake.getStringSliceReturns - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakePluginConfig) GetStringSliceCallCount() int { - fake.getStringSliceMutex.RLock() - defer fake.getStringSliceMutex.RUnlock() - return len(fake.getStringSliceArgsForCall) -} - -func (fake *FakePluginConfig) GetStringSliceCalls(stub func(string) ([]string, error)) { - fake.getStringSliceMutex.Lock() - defer fake.getStringSliceMutex.Unlock() - fake.GetStringSliceStub = stub -} - -func (fake *FakePluginConfig) GetStringSliceArgsForCall(i int) string { - fake.getStringSliceMutex.RLock() - defer fake.getStringSliceMutex.RUnlock() - argsForCall := fake.getStringSliceArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakePluginConfig) GetStringSliceReturns(result1 []string, result2 error) { - fake.getStringSliceMutex.Lock() - defer fake.getStringSliceMutex.Unlock() - fake.GetStringSliceStub = nil - fake.getStringSliceReturns = struct { - result1 []string - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetStringSliceReturnsOnCall(i int, result1 []string, result2 error) { - fake.getStringSliceMutex.Lock() - defer fake.getStringSliceMutex.Unlock() - fake.GetStringSliceStub = nil - if fake.getStringSliceReturnsOnCall == nil { - fake.getStringSliceReturnsOnCall = make(map[int]struct { - result1 []string - result2 error - }) - } - fake.getStringSliceReturnsOnCall[i] = struct { - result1 []string - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetStringWithDefault(arg1 string, arg2 string) (string, error) { - fake.getStringWithDefaultMutex.Lock() - ret, specificReturn := fake.getStringWithDefaultReturnsOnCall[len(fake.getStringWithDefaultArgsForCall)] - fake.getStringWithDefaultArgsForCall = append(fake.getStringWithDefaultArgsForCall, struct { - arg1 string - arg2 string - }{arg1, arg2}) - fake.recordInvocation("GetStringWithDefault", []interface{}{arg1, arg2}) - fake.getStringWithDefaultMutex.Unlock() - if fake.GetStringWithDefaultStub != nil { - return fake.GetStringWithDefaultStub(arg1, arg2) - } - if specificReturn { - return ret.result1, ret.result2 - } - fakeReturns := fake.getStringWithDefaultReturns - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakePluginConfig) GetStringWithDefaultCallCount() int { - fake.getStringWithDefaultMutex.RLock() - defer fake.getStringWithDefaultMutex.RUnlock() - return len(fake.getStringWithDefaultArgsForCall) -} - -func (fake *FakePluginConfig) GetStringWithDefaultCalls(stub func(string, string) (string, error)) { - fake.getStringWithDefaultMutex.Lock() - defer fake.getStringWithDefaultMutex.Unlock() - fake.GetStringWithDefaultStub = stub -} - -func (fake *FakePluginConfig) GetStringWithDefaultArgsForCall(i int) (string, string) { - fake.getStringWithDefaultMutex.RLock() - defer fake.getStringWithDefaultMutex.RUnlock() - argsForCall := fake.getStringWithDefaultArgsForCall[i] - return argsForCall.arg1, argsForCall.arg2 -} - -func (fake *FakePluginConfig) GetStringWithDefaultReturns(result1 string, result2 error) { - fake.getStringWithDefaultMutex.Lock() - defer fake.getStringWithDefaultMutex.Unlock() - fake.GetStringWithDefaultStub = nil - fake.getStringWithDefaultReturns = struct { - result1 string - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetStringWithDefaultReturnsOnCall(i int, result1 string, result2 error) { - fake.getStringWithDefaultMutex.Lock() - defer fake.getStringWithDefaultMutex.Unlock() - fake.GetStringWithDefaultStub = nil - if fake.getStringWithDefaultReturnsOnCall == nil { - fake.getStringWithDefaultReturnsOnCall = make(map[int]struct { - result1 string - result2 error - }) - } - fake.getStringWithDefaultReturnsOnCall[i] = struct { - result1 string - result2 error - }{result1, result2} -} - -func (fake *FakePluginConfig) GetWithDefault(arg1 string, arg2 interface{}) interface{} { - fake.getWithDefaultMutex.Lock() - ret, specificReturn := fake.getWithDefaultReturnsOnCall[len(fake.getWithDefaultArgsForCall)] - fake.getWithDefaultArgsForCall = append(fake.getWithDefaultArgsForCall, struct { - arg1 string - arg2 interface{} - }{arg1, arg2}) - fake.recordInvocation("GetWithDefault", []interface{}{arg1, arg2}) - fake.getWithDefaultMutex.Unlock() - if fake.GetWithDefaultStub != nil { - return fake.GetWithDefaultStub(arg1, arg2) - } - if specificReturn { - return ret.result1 - } - fakeReturns := fake.getWithDefaultReturns - return fakeReturns.result1 -} - -func (fake *FakePluginConfig) GetWithDefaultCallCount() int { - fake.getWithDefaultMutex.RLock() - defer fake.getWithDefaultMutex.RUnlock() - return len(fake.getWithDefaultArgsForCall) -} - -func (fake *FakePluginConfig) GetWithDefaultCalls(stub func(string, interface{}) interface{}) { - fake.getWithDefaultMutex.Lock() - defer fake.getWithDefaultMutex.Unlock() - fake.GetWithDefaultStub = stub -} - -func (fake *FakePluginConfig) GetWithDefaultArgsForCall(i int) (string, interface{}) { - fake.getWithDefaultMutex.RLock() - defer fake.getWithDefaultMutex.RUnlock() - argsForCall := fake.getWithDefaultArgsForCall[i] - return argsForCall.arg1, argsForCall.arg2 -} - -func (fake *FakePluginConfig) GetWithDefaultReturns(result1 interface{}) { - fake.getWithDefaultMutex.Lock() - defer fake.getWithDefaultMutex.Unlock() - fake.GetWithDefaultStub = nil - fake.getWithDefaultReturns = struct { - result1 interface{} - }{result1} -} - -func (fake *FakePluginConfig) GetWithDefaultReturnsOnCall(i int, result1 interface{}) { - fake.getWithDefaultMutex.Lock() - defer fake.getWithDefaultMutex.Unlock() - fake.GetWithDefaultStub = nil - if fake.getWithDefaultReturnsOnCall == nil { - fake.getWithDefaultReturnsOnCall = make(map[int]struct { - result1 interface{} - }) - } - fake.getWithDefaultReturnsOnCall[i] = struct { - result1 interface{} - }{result1} -} - -func (fake *FakePluginConfig) Set(arg1 string, arg2 interface{}) error { - fake.setMutex.Lock() - ret, specificReturn := fake.setReturnsOnCall[len(fake.setArgsForCall)] - fake.setArgsForCall = append(fake.setArgsForCall, struct { - arg1 string - arg2 interface{} - }{arg1, arg2}) - fake.recordInvocation("Set", []interface{}{arg1, arg2}) - fake.setMutex.Unlock() - if fake.SetStub != nil { - return fake.SetStub(arg1, arg2) - } - if specificReturn { - return ret.result1 - } - fakeReturns := fake.setReturns - return fakeReturns.result1 -} - -func (fake *FakePluginConfig) SetCallCount() int { - fake.setMutex.RLock() - defer fake.setMutex.RUnlock() - return len(fake.setArgsForCall) -} - -func (fake *FakePluginConfig) SetCalls(stub func(string, interface{}) error) { - fake.setMutex.Lock() - defer fake.setMutex.Unlock() - fake.SetStub = stub -} - -func (fake *FakePluginConfig) SetArgsForCall(i int) (string, interface{}) { - fake.setMutex.RLock() - defer fake.setMutex.RUnlock() - argsForCall := fake.setArgsForCall[i] - return argsForCall.arg1, argsForCall.arg2 -} - -func (fake *FakePluginConfig) SetReturns(result1 error) { - fake.setMutex.Lock() - defer fake.setMutex.Unlock() - fake.SetStub = nil - fake.setReturns = struct { - result1 error - }{result1} -} - -func (fake *FakePluginConfig) SetReturnsOnCall(i int, result1 error) { - fake.setMutex.Lock() - defer fake.setMutex.Unlock() - fake.SetStub = nil - if fake.setReturnsOnCall == nil { - fake.setReturnsOnCall = make(map[int]struct { - result1 error - }) - } - fake.setReturnsOnCall[i] = struct { - result1 error - }{result1} -} - -func (fake *FakePluginConfig) Invocations() map[string][][]interface{} { - fake.invocationsMutex.RLock() - defer fake.invocationsMutex.RUnlock() - fake.eraseMutex.RLock() - defer fake.eraseMutex.RUnlock() - fake.existsMutex.RLock() - defer fake.existsMutex.RUnlock() - fake.getMutex.RLock() - defer fake.getMutex.RUnlock() - fake.getBoolMutex.RLock() - defer fake.getBoolMutex.RUnlock() - fake.getBoolWithDefaultMutex.RLock() - defer fake.getBoolWithDefaultMutex.RUnlock() - fake.getFloatMutex.RLock() - defer fake.getFloatMutex.RUnlock() - fake.getFloatSliceMutex.RLock() - defer fake.getFloatSliceMutex.RUnlock() - fake.getFloatWithDefaultMutex.RLock() - defer fake.getFloatWithDefaultMutex.RUnlock() - fake.getIntMutex.RLock() - defer fake.getIntMutex.RUnlock() - fake.getIntSliceMutex.RLock() - defer fake.getIntSliceMutex.RUnlock() - fake.getIntWithDefaultMutex.RLock() - defer fake.getIntWithDefaultMutex.RUnlock() - fake.getStringMutex.RLock() - defer fake.getStringMutex.RUnlock() - fake.getStringMapMutex.RLock() - defer fake.getStringMapMutex.RUnlock() - fake.getStringMapStringMutex.RLock() - defer fake.getStringMapStringMutex.RUnlock() - fake.getStringSliceMutex.RLock() - defer fake.getStringSliceMutex.RUnlock() - fake.getStringWithDefaultMutex.RLock() - defer fake.getStringWithDefaultMutex.RUnlock() - fake.getWithDefaultMutex.RLock() - defer fake.getWithDefaultMutex.RUnlock() - fake.setMutex.RLock() - defer fake.setMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} - for key, value := range fake.invocations { - copiedInvocations[key] = value - } - return copiedInvocations -} - -func (fake *FakePluginConfig) recordInvocation(key string, args []interface{}) { - fake.invocationsMutex.Lock() - defer fake.invocationsMutex.Unlock() - if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} - } - if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} - } - fake.invocations[key] = append(fake.invocations[key], args) -} - -var _ plugin.PluginConfig = new(FakePluginConfig) diff --git a/plugin/pluginfakes/fake_plugin_context.go b/plugin/pluginfakes/fake_plugin_context.go index c0e8933..96bb171 100644 --- a/plugin/pluginfakes/fake_plugin_context.go +++ b/plugin/pluginfakes/fake_plugin_context.go @@ -20,26 +20,6 @@ type FakePluginContext struct { aPIEndpointReturnsOnCall map[int]struct { result1 string } - CFStub func() plugin.CFContext - cFMutex sync.RWMutex - cFArgsForCall []struct { - } - cFReturns struct { - result1 plugin.CFContext - } - cFReturnsOnCall map[int]struct { - result1 plugin.CFContext - } - CFEEEnvIDStub func() string - cFEEEnvIDMutex sync.RWMutex - cFEEEnvIDArgsForCall []struct { - } - cFEEEnvIDReturns struct { - result1 string - } - cFEEEnvIDReturnsOnCall map[int]struct { - result1 string - } CLINameStub func() string cLINameMutex sync.RWMutex cLINameArgsForCall []struct { @@ -203,26 +183,6 @@ type FakePluginContext struct { hasTargetedAccountReturnsOnCall map[int]struct { result1 bool } - HasTargetedCFStub func() bool - hasTargetedCFMutex sync.RWMutex - hasTargetedCFArgsForCall []struct { - } - hasTargetedCFReturns struct { - result1 bool - } - hasTargetedCFReturnsOnCall map[int]struct { - result1 bool - } - HasTargetedCFEEStub func() bool - hasTargetedCFEEMutex sync.RWMutex - hasTargetedCFEEArgsForCall []struct { - } - hasTargetedCFEEReturns struct { - result1 bool - } - hasTargetedCFEEReturnsOnCall map[int]struct { - result1 bool - } HasTargetedComputeResourceStub func() bool hasTargetedComputeResourceMutex sync.RWMutex hasTargetedComputeResourceArgsForCall []struct { @@ -243,16 +203,6 @@ type FakePluginContext struct { hasTargetedProfileReturnsOnCall map[int]struct { result1 bool } - HasTargetedPublicCFStub func() bool - hasTargetedPublicCFMutex sync.RWMutex - hasTargetedPublicCFArgsForCall []struct { - } - hasTargetedPublicCFReturns struct { - result1 bool - } - hasTargetedPublicCFReturnsOnCall map[int]struct { - result1 bool - } HasTargetedRegionStub func() bool hasTargetedRegionMutex sync.RWMutex hasTargetedRegionArgsForCall []struct { @@ -484,15 +434,16 @@ func (fake *FakePluginContext) APIEndpoint() string { ret, specificReturn := fake.aPIEndpointReturnsOnCall[len(fake.aPIEndpointArgsForCall)] fake.aPIEndpointArgsForCall = append(fake.aPIEndpointArgsForCall, struct { }{}) + stub := fake.APIEndpointStub + fakeReturns := fake.aPIEndpointReturns fake.recordInvocation("APIEndpoint", []interface{}{}) fake.aPIEndpointMutex.Unlock() - if fake.APIEndpointStub != nil { - return fake.APIEndpointStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.aPIEndpointReturns return fakeReturns.result1 } @@ -531,124 +482,21 @@ func (fake *FakePluginContext) APIEndpointReturnsOnCall(i int, result1 string) { }{result1} } -func (fake *FakePluginContext) CF() plugin.CFContext { - fake.cFMutex.Lock() - ret, specificReturn := fake.cFReturnsOnCall[len(fake.cFArgsForCall)] - fake.cFArgsForCall = append(fake.cFArgsForCall, struct { - }{}) - fake.recordInvocation("CF", []interface{}{}) - fake.cFMutex.Unlock() - if fake.CFStub != nil { - return fake.CFStub() - } - if specificReturn { - return ret.result1 - } - fakeReturns := fake.cFReturns - return fakeReturns.result1 -} - -func (fake *FakePluginContext) CFCallCount() int { - fake.cFMutex.RLock() - defer fake.cFMutex.RUnlock() - return len(fake.cFArgsForCall) -} - -func (fake *FakePluginContext) CFCalls(stub func() plugin.CFContext) { - fake.cFMutex.Lock() - defer fake.cFMutex.Unlock() - fake.CFStub = stub -} - -func (fake *FakePluginContext) CFReturns(result1 plugin.CFContext) { - fake.cFMutex.Lock() - defer fake.cFMutex.Unlock() - fake.CFStub = nil - fake.cFReturns = struct { - result1 plugin.CFContext - }{result1} -} - -func (fake *FakePluginContext) CFReturnsOnCall(i int, result1 plugin.CFContext) { - fake.cFMutex.Lock() - defer fake.cFMutex.Unlock() - fake.CFStub = nil - if fake.cFReturnsOnCall == nil { - fake.cFReturnsOnCall = make(map[int]struct { - result1 plugin.CFContext - }) - } - fake.cFReturnsOnCall[i] = struct { - result1 plugin.CFContext - }{result1} -} - -func (fake *FakePluginContext) CFEEEnvID() string { - fake.cFEEEnvIDMutex.Lock() - ret, specificReturn := fake.cFEEEnvIDReturnsOnCall[len(fake.cFEEEnvIDArgsForCall)] - fake.cFEEEnvIDArgsForCall = append(fake.cFEEEnvIDArgsForCall, struct { - }{}) - fake.recordInvocation("CFEEEnvID", []interface{}{}) - fake.cFEEEnvIDMutex.Unlock() - if fake.CFEEEnvIDStub != nil { - return fake.CFEEEnvIDStub() - } - if specificReturn { - return ret.result1 - } - fakeReturns := fake.cFEEEnvIDReturns - return fakeReturns.result1 -} - -func (fake *FakePluginContext) CFEEEnvIDCallCount() int { - fake.cFEEEnvIDMutex.RLock() - defer fake.cFEEEnvIDMutex.RUnlock() - return len(fake.cFEEEnvIDArgsForCall) -} - -func (fake *FakePluginContext) CFEEEnvIDCalls(stub func() string) { - fake.cFEEEnvIDMutex.Lock() - defer fake.cFEEEnvIDMutex.Unlock() - fake.CFEEEnvIDStub = stub -} - -func (fake *FakePluginContext) CFEEEnvIDReturns(result1 string) { - fake.cFEEEnvIDMutex.Lock() - defer fake.cFEEEnvIDMutex.Unlock() - fake.CFEEEnvIDStub = nil - fake.cFEEEnvIDReturns = struct { - result1 string - }{result1} -} - -func (fake *FakePluginContext) CFEEEnvIDReturnsOnCall(i int, result1 string) { - fake.cFEEEnvIDMutex.Lock() - defer fake.cFEEEnvIDMutex.Unlock() - fake.CFEEEnvIDStub = nil - if fake.cFEEEnvIDReturnsOnCall == nil { - fake.cFEEEnvIDReturnsOnCall = make(map[int]struct { - result1 string - }) - } - fake.cFEEEnvIDReturnsOnCall[i] = struct { - result1 string - }{result1} -} - func (fake *FakePluginContext) CLIName() string { fake.cLINameMutex.Lock() ret, specificReturn := fake.cLINameReturnsOnCall[len(fake.cLINameArgsForCall)] fake.cLINameArgsForCall = append(fake.cLINameArgsForCall, struct { }{}) + stub := fake.CLINameStub + fakeReturns := fake.cLINameReturns fake.recordInvocation("CLIName", []interface{}{}) fake.cLINameMutex.Unlock() - if fake.CLINameStub != nil { - return fake.CLINameStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.cLINameReturns return fakeReturns.result1 } @@ -745,15 +593,16 @@ func (fake *FakePluginContext) CloudName() string { ret, specificReturn := fake.cloudNameReturnsOnCall[len(fake.cloudNameArgsForCall)] fake.cloudNameArgsForCall = append(fake.cloudNameArgsForCall, struct { }{}) + stub := fake.CloudNameStub + fakeReturns := fake.cloudNameReturns fake.recordInvocation("CloudName", []interface{}{}) fake.cloudNameMutex.Unlock() - if fake.CloudNameStub != nil { - return fake.CloudNameStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.cloudNameReturns return fakeReturns.result1 } @@ -797,15 +646,16 @@ func (fake *FakePluginContext) CloudType() string { ret, specificReturn := fake.cloudTypeReturnsOnCall[len(fake.cloudTypeArgsForCall)] fake.cloudTypeArgsForCall = append(fake.cloudTypeArgsForCall, struct { }{}) + stub := fake.CloudTypeStub + fakeReturns := fake.cloudTypeReturns fake.recordInvocation("CloudType", []interface{}{}) fake.cloudTypeMutex.Unlock() - if fake.CloudTypeStub != nil { - return fake.CloudTypeStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.cloudTypeReturns return fakeReturns.result1 } @@ -849,15 +699,16 @@ func (fake *FakePluginContext) ColorEnabled() string { ret, specificReturn := fake.colorEnabledReturnsOnCall[len(fake.colorEnabledArgsForCall)] fake.colorEnabledArgsForCall = append(fake.colorEnabledArgsForCall, struct { }{}) + stub := fake.ColorEnabledStub + fakeReturns := fake.colorEnabledReturns fake.recordInvocation("ColorEnabled", []interface{}{}) fake.colorEnabledMutex.Unlock() - if fake.ColorEnabledStub != nil { - return fake.ColorEnabledStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.colorEnabledReturns return fakeReturns.result1 } @@ -901,15 +752,16 @@ func (fake *FakePluginContext) CommandNamespace() string { ret, specificReturn := fake.commandNamespaceReturnsOnCall[len(fake.commandNamespaceArgsForCall)] fake.commandNamespaceArgsForCall = append(fake.commandNamespaceArgsForCall, struct { }{}) + stub := fake.CommandNamespaceStub + fakeReturns := fake.commandNamespaceReturns fake.recordInvocation("CommandNamespace", []interface{}{}) fake.commandNamespaceMutex.Unlock() - if fake.CommandNamespaceStub != nil { - return fake.CommandNamespaceStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.commandNamespaceReturns return fakeReturns.result1 } @@ -953,15 +805,16 @@ func (fake *FakePluginContext) ConsoleEndpoint() string { ret, specificReturn := fake.consoleEndpointReturnsOnCall[len(fake.consoleEndpointArgsForCall)] fake.consoleEndpointArgsForCall = append(fake.consoleEndpointArgsForCall, struct { }{}) + stub := fake.ConsoleEndpointStub + fakeReturns := fake.consoleEndpointReturns fake.recordInvocation("ConsoleEndpoint", []interface{}{}) fake.consoleEndpointMutex.Unlock() - if fake.ConsoleEndpointStub != nil { - return fake.ConsoleEndpointStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.consoleEndpointReturns return fakeReturns.result1 } @@ -1005,15 +858,16 @@ func (fake *FakePluginContext) ConsoleEndpoints() models.Endpoints { ret, specificReturn := fake.consoleEndpointsReturnsOnCall[len(fake.consoleEndpointsArgsForCall)] fake.consoleEndpointsArgsForCall = append(fake.consoleEndpointsArgsForCall, struct { }{}) + stub := fake.ConsoleEndpointsStub + fakeReturns := fake.consoleEndpointsReturns fake.recordInvocation("ConsoleEndpoints", []interface{}{}) fake.consoleEndpointsMutex.Unlock() - if fake.ConsoleEndpointsStub != nil { - return fake.ConsoleEndpointsStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.consoleEndpointsReturns return fakeReturns.result1 } @@ -1057,15 +911,16 @@ func (fake *FakePluginContext) CurrentAccount() models.Account { ret, specificReturn := fake.currentAccountReturnsOnCall[len(fake.currentAccountArgsForCall)] fake.currentAccountArgsForCall = append(fake.currentAccountArgsForCall, struct { }{}) + stub := fake.CurrentAccountStub + fakeReturns := fake.currentAccountReturns fake.recordInvocation("CurrentAccount", []interface{}{}) fake.currentAccountMutex.Unlock() - if fake.CurrentAccountStub != nil { - return fake.CurrentAccountStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.currentAccountReturns return fakeReturns.result1 } @@ -1109,15 +964,16 @@ func (fake *FakePluginContext) CurrentProfile() models.Profile { ret, specificReturn := fake.currentProfileReturnsOnCall[len(fake.currentProfileArgsForCall)] fake.currentProfileArgsForCall = append(fake.currentProfileArgsForCall, struct { }{}) + stub := fake.CurrentProfileStub + fakeReturns := fake.currentProfileReturns fake.recordInvocation("CurrentProfile", []interface{}{}) fake.currentProfileMutex.Unlock() - if fake.CurrentProfileStub != nil { - return fake.CurrentProfileStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.currentProfileReturns return fakeReturns.result1 } @@ -1161,15 +1017,16 @@ func (fake *FakePluginContext) CurrentRegion() models.Region { ret, specificReturn := fake.currentRegionReturnsOnCall[len(fake.currentRegionArgsForCall)] fake.currentRegionArgsForCall = append(fake.currentRegionArgsForCall, struct { }{}) + stub := fake.CurrentRegionStub + fakeReturns := fake.currentRegionReturns fake.recordInvocation("CurrentRegion", []interface{}{}) fake.currentRegionMutex.Unlock() - if fake.CurrentRegionStub != nil { - return fake.CurrentRegionStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.currentRegionReturns return fakeReturns.result1 } @@ -1213,15 +1070,16 @@ func (fake *FakePluginContext) CurrentResourceGroup() models.ResourceGroup { ret, specificReturn := fake.currentResourceGroupReturnsOnCall[len(fake.currentResourceGroupArgsForCall)] fake.currentResourceGroupArgsForCall = append(fake.currentResourceGroupArgsForCall, struct { }{}) + stub := fake.CurrentResourceGroupStub + fakeReturns := fake.currentResourceGroupReturns fake.recordInvocation("CurrentResourceGroup", []interface{}{}) fake.currentResourceGroupMutex.Unlock() - if fake.CurrentResourceGroupStub != nil { - return fake.CurrentResourceGroupStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.currentResourceGroupReturns return fakeReturns.result1 } @@ -1266,15 +1124,16 @@ func (fake *FakePluginContext) GetEndpoint(arg1 endpoints.Service) (string, erro fake.getEndpointArgsForCall = append(fake.getEndpointArgsForCall, struct { arg1 endpoints.Service }{arg1}) + stub := fake.GetEndpointStub + fakeReturns := fake.getEndpointReturns fake.recordInvocation("GetEndpoint", []interface{}{arg1}) fake.getEndpointMutex.Unlock() - if fake.GetEndpointStub != nil { - return fake.GetEndpointStub(arg1) + if stub != nil { + return stub(arg1) } if specificReturn { return ret.result1, ret.result2 } - fakeReturns := fake.getEndpointReturns return fakeReturns.result1, fakeReturns.result2 } @@ -1328,15 +1187,16 @@ func (fake *FakePluginContext) HTTPTimeout() int { ret, specificReturn := fake.hTTPTimeoutReturnsOnCall[len(fake.hTTPTimeoutArgsForCall)] fake.hTTPTimeoutArgsForCall = append(fake.hTTPTimeoutArgsForCall, struct { }{}) + stub := fake.HTTPTimeoutStub + fakeReturns := fake.hTTPTimeoutReturns fake.recordInvocation("HTTPTimeout", []interface{}{}) fake.hTTPTimeoutMutex.Unlock() - if fake.HTTPTimeoutStub != nil { - return fake.HTTPTimeoutStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.hTTPTimeoutReturns return fakeReturns.result1 } @@ -1380,15 +1240,16 @@ func (fake *FakePluginContext) HasAPIEndpoint() bool { ret, specificReturn := fake.hasAPIEndpointReturnsOnCall[len(fake.hasAPIEndpointArgsForCall)] fake.hasAPIEndpointArgsForCall = append(fake.hasAPIEndpointArgsForCall, struct { }{}) + stub := fake.HasAPIEndpointStub + fakeReturns := fake.hasAPIEndpointReturns fake.recordInvocation("HasAPIEndpoint", []interface{}{}) fake.hasAPIEndpointMutex.Unlock() - if fake.HasAPIEndpointStub != nil { - return fake.HasAPIEndpointStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.hasAPIEndpointReturns return fakeReturns.result1 } @@ -1432,15 +1293,16 @@ func (fake *FakePluginContext) HasTargetedAccount() bool { ret, specificReturn := fake.hasTargetedAccountReturnsOnCall[len(fake.hasTargetedAccountArgsForCall)] fake.hasTargetedAccountArgsForCall = append(fake.hasTargetedAccountArgsForCall, struct { }{}) + stub := fake.HasTargetedAccountStub + fakeReturns := fake.hasTargetedAccountReturns fake.recordInvocation("HasTargetedAccount", []interface{}{}) fake.hasTargetedAccountMutex.Unlock() - if fake.HasTargetedAccountStub != nil { - return fake.HasTargetedAccountStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.hasTargetedAccountReturns return fakeReturns.result1 } @@ -1479,124 +1341,21 @@ func (fake *FakePluginContext) HasTargetedAccountReturnsOnCall(i int, result1 bo }{result1} } -func (fake *FakePluginContext) HasTargetedCF() bool { - fake.hasTargetedCFMutex.Lock() - ret, specificReturn := fake.hasTargetedCFReturnsOnCall[len(fake.hasTargetedCFArgsForCall)] - fake.hasTargetedCFArgsForCall = append(fake.hasTargetedCFArgsForCall, struct { - }{}) - fake.recordInvocation("HasTargetedCF", []interface{}{}) - fake.hasTargetedCFMutex.Unlock() - if fake.HasTargetedCFStub != nil { - return fake.HasTargetedCFStub() - } - if specificReturn { - return ret.result1 - } - fakeReturns := fake.hasTargetedCFReturns - return fakeReturns.result1 -} - -func (fake *FakePluginContext) HasTargetedCFCallCount() int { - fake.hasTargetedCFMutex.RLock() - defer fake.hasTargetedCFMutex.RUnlock() - return len(fake.hasTargetedCFArgsForCall) -} - -func (fake *FakePluginContext) HasTargetedCFCalls(stub func() bool) { - fake.hasTargetedCFMutex.Lock() - defer fake.hasTargetedCFMutex.Unlock() - fake.HasTargetedCFStub = stub -} - -func (fake *FakePluginContext) HasTargetedCFReturns(result1 bool) { - fake.hasTargetedCFMutex.Lock() - defer fake.hasTargetedCFMutex.Unlock() - fake.HasTargetedCFStub = nil - fake.hasTargetedCFReturns = struct { - result1 bool - }{result1} -} - -func (fake *FakePluginContext) HasTargetedCFReturnsOnCall(i int, result1 bool) { - fake.hasTargetedCFMutex.Lock() - defer fake.hasTargetedCFMutex.Unlock() - fake.HasTargetedCFStub = nil - if fake.hasTargetedCFReturnsOnCall == nil { - fake.hasTargetedCFReturnsOnCall = make(map[int]struct { - result1 bool - }) - } - fake.hasTargetedCFReturnsOnCall[i] = struct { - result1 bool - }{result1} -} - -func (fake *FakePluginContext) HasTargetedCFEE() bool { - fake.hasTargetedCFEEMutex.Lock() - ret, specificReturn := fake.hasTargetedCFEEReturnsOnCall[len(fake.hasTargetedCFEEArgsForCall)] - fake.hasTargetedCFEEArgsForCall = append(fake.hasTargetedCFEEArgsForCall, struct { - }{}) - fake.recordInvocation("HasTargetedCFEE", []interface{}{}) - fake.hasTargetedCFEEMutex.Unlock() - if fake.HasTargetedCFEEStub != nil { - return fake.HasTargetedCFEEStub() - } - if specificReturn { - return ret.result1 - } - fakeReturns := fake.hasTargetedCFEEReturns - return fakeReturns.result1 -} - -func (fake *FakePluginContext) HasTargetedCFEECallCount() int { - fake.hasTargetedCFEEMutex.RLock() - defer fake.hasTargetedCFEEMutex.RUnlock() - return len(fake.hasTargetedCFEEArgsForCall) -} - -func (fake *FakePluginContext) HasTargetedCFEECalls(stub func() bool) { - fake.hasTargetedCFEEMutex.Lock() - defer fake.hasTargetedCFEEMutex.Unlock() - fake.HasTargetedCFEEStub = stub -} - -func (fake *FakePluginContext) HasTargetedCFEEReturns(result1 bool) { - fake.hasTargetedCFEEMutex.Lock() - defer fake.hasTargetedCFEEMutex.Unlock() - fake.HasTargetedCFEEStub = nil - fake.hasTargetedCFEEReturns = struct { - result1 bool - }{result1} -} - -func (fake *FakePluginContext) HasTargetedCFEEReturnsOnCall(i int, result1 bool) { - fake.hasTargetedCFEEMutex.Lock() - defer fake.hasTargetedCFEEMutex.Unlock() - fake.HasTargetedCFEEStub = nil - if fake.hasTargetedCFEEReturnsOnCall == nil { - fake.hasTargetedCFEEReturnsOnCall = make(map[int]struct { - result1 bool - }) - } - fake.hasTargetedCFEEReturnsOnCall[i] = struct { - result1 bool - }{result1} -} - func (fake *FakePluginContext) HasTargetedComputeResource() bool { fake.hasTargetedComputeResourceMutex.Lock() ret, specificReturn := fake.hasTargetedComputeResourceReturnsOnCall[len(fake.hasTargetedComputeResourceArgsForCall)] fake.hasTargetedComputeResourceArgsForCall = append(fake.hasTargetedComputeResourceArgsForCall, struct { }{}) + stub := fake.HasTargetedComputeResourceStub + fakeReturns := fake.hasTargetedComputeResourceReturns fake.recordInvocation("HasTargetedComputeResource", []interface{}{}) fake.hasTargetedComputeResourceMutex.Unlock() - if fake.HasTargetedComputeResourceStub != nil { - return fake.HasTargetedComputeResourceStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.hasTargetedComputeResourceReturns return fakeReturns.result1 } @@ -1640,15 +1399,16 @@ func (fake *FakePluginContext) HasTargetedProfile() bool { ret, specificReturn := fake.hasTargetedProfileReturnsOnCall[len(fake.hasTargetedProfileArgsForCall)] fake.hasTargetedProfileArgsForCall = append(fake.hasTargetedProfileArgsForCall, struct { }{}) + stub := fake.HasTargetedProfileStub + fakeReturns := fake.hasTargetedProfileReturns fake.recordInvocation("HasTargetedProfile", []interface{}{}) fake.hasTargetedProfileMutex.Unlock() - if fake.HasTargetedProfileStub != nil { - return fake.HasTargetedProfileStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.hasTargetedProfileReturns return fakeReturns.result1 } @@ -1687,72 +1447,21 @@ func (fake *FakePluginContext) HasTargetedProfileReturnsOnCall(i int, result1 bo }{result1} } -func (fake *FakePluginContext) HasTargetedPublicCF() bool { - fake.hasTargetedPublicCFMutex.Lock() - ret, specificReturn := fake.hasTargetedPublicCFReturnsOnCall[len(fake.hasTargetedPublicCFArgsForCall)] - fake.hasTargetedPublicCFArgsForCall = append(fake.hasTargetedPublicCFArgsForCall, struct { - }{}) - fake.recordInvocation("HasTargetedPublicCF", []interface{}{}) - fake.hasTargetedPublicCFMutex.Unlock() - if fake.HasTargetedPublicCFStub != nil { - return fake.HasTargetedPublicCFStub() - } - if specificReturn { - return ret.result1 - } - fakeReturns := fake.hasTargetedPublicCFReturns - return fakeReturns.result1 -} - -func (fake *FakePluginContext) HasTargetedPublicCFCallCount() int { - fake.hasTargetedPublicCFMutex.RLock() - defer fake.hasTargetedPublicCFMutex.RUnlock() - return len(fake.hasTargetedPublicCFArgsForCall) -} - -func (fake *FakePluginContext) HasTargetedPublicCFCalls(stub func() bool) { - fake.hasTargetedPublicCFMutex.Lock() - defer fake.hasTargetedPublicCFMutex.Unlock() - fake.HasTargetedPublicCFStub = stub -} - -func (fake *FakePluginContext) HasTargetedPublicCFReturns(result1 bool) { - fake.hasTargetedPublicCFMutex.Lock() - defer fake.hasTargetedPublicCFMutex.Unlock() - fake.HasTargetedPublicCFStub = nil - fake.hasTargetedPublicCFReturns = struct { - result1 bool - }{result1} -} - -func (fake *FakePluginContext) HasTargetedPublicCFReturnsOnCall(i int, result1 bool) { - fake.hasTargetedPublicCFMutex.Lock() - defer fake.hasTargetedPublicCFMutex.Unlock() - fake.HasTargetedPublicCFStub = nil - if fake.hasTargetedPublicCFReturnsOnCall == nil { - fake.hasTargetedPublicCFReturnsOnCall = make(map[int]struct { - result1 bool - }) - } - fake.hasTargetedPublicCFReturnsOnCall[i] = struct { - result1 bool - }{result1} -} - func (fake *FakePluginContext) HasTargetedRegion() bool { fake.hasTargetedRegionMutex.Lock() ret, specificReturn := fake.hasTargetedRegionReturnsOnCall[len(fake.hasTargetedRegionArgsForCall)] fake.hasTargetedRegionArgsForCall = append(fake.hasTargetedRegionArgsForCall, struct { }{}) + stub := fake.HasTargetedRegionStub + fakeReturns := fake.hasTargetedRegionReturns fake.recordInvocation("HasTargetedRegion", []interface{}{}) fake.hasTargetedRegionMutex.Unlock() - if fake.HasTargetedRegionStub != nil { - return fake.HasTargetedRegionStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.hasTargetedRegionReturns return fakeReturns.result1 } @@ -1796,15 +1505,16 @@ func (fake *FakePluginContext) HasTargetedResourceGroup() bool { ret, specificReturn := fake.hasTargetedResourceGroupReturnsOnCall[len(fake.hasTargetedResourceGroupArgsForCall)] fake.hasTargetedResourceGroupArgsForCall = append(fake.hasTargetedResourceGroupArgsForCall, struct { }{}) + stub := fake.HasTargetedResourceGroupStub + fakeReturns := fake.hasTargetedResourceGroupReturns fake.recordInvocation("HasTargetedResourceGroup", []interface{}{}) fake.hasTargetedResourceGroupMutex.Unlock() - if fake.HasTargetedResourceGroupStub != nil { - return fake.HasTargetedResourceGroupStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.hasTargetedResourceGroupReturns return fakeReturns.result1 } @@ -1848,15 +1558,16 @@ func (fake *FakePluginContext) IAMEndpoint() string { ret, specificReturn := fake.iAMEndpointReturnsOnCall[len(fake.iAMEndpointArgsForCall)] fake.iAMEndpointArgsForCall = append(fake.iAMEndpointArgsForCall, struct { }{}) + stub := fake.IAMEndpointStub + fakeReturns := fake.iAMEndpointReturns fake.recordInvocation("IAMEndpoint", []interface{}{}) fake.iAMEndpointMutex.Unlock() - if fake.IAMEndpointStub != nil { - return fake.IAMEndpointStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.iAMEndpointReturns return fakeReturns.result1 } @@ -1900,15 +1611,16 @@ func (fake *FakePluginContext) IAMEndpoints() models.Endpoints { ret, specificReturn := fake.iAMEndpointsReturnsOnCall[len(fake.iAMEndpointsArgsForCall)] fake.iAMEndpointsArgsForCall = append(fake.iAMEndpointsArgsForCall, struct { }{}) + stub := fake.IAMEndpointsStub + fakeReturns := fake.iAMEndpointsReturns fake.recordInvocation("IAMEndpoints", []interface{}{}) fake.iAMEndpointsMutex.Unlock() - if fake.IAMEndpointsStub != nil { - return fake.IAMEndpointsStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.iAMEndpointsReturns return fakeReturns.result1 } @@ -1952,15 +1664,16 @@ func (fake *FakePluginContext) IAMRefreshToken() string { ret, specificReturn := fake.iAMRefreshTokenReturnsOnCall[len(fake.iAMRefreshTokenArgsForCall)] fake.iAMRefreshTokenArgsForCall = append(fake.iAMRefreshTokenArgsForCall, struct { }{}) + stub := fake.IAMRefreshTokenStub + fakeReturns := fake.iAMRefreshTokenReturns fake.recordInvocation("IAMRefreshToken", []interface{}{}) fake.iAMRefreshTokenMutex.Unlock() - if fake.IAMRefreshTokenStub != nil { - return fake.IAMRefreshTokenStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.iAMRefreshTokenReturns return fakeReturns.result1 } @@ -2004,15 +1717,16 @@ func (fake *FakePluginContext) IAMToken() string { ret, specificReturn := fake.iAMTokenReturnsOnCall[len(fake.iAMTokenArgsForCall)] fake.iAMTokenArgsForCall = append(fake.iAMTokenArgsForCall, struct { }{}) + stub := fake.IAMTokenStub + fakeReturns := fake.iAMTokenReturns fake.recordInvocation("IAMToken", []interface{}{}) fake.iAMTokenMutex.Unlock() - if fake.IAMTokenStub != nil { - return fake.IAMTokenStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.iAMTokenReturns return fakeReturns.result1 } @@ -2056,15 +1770,16 @@ func (fake *FakePluginContext) IMSAccountID() string { ret, specificReturn := fake.iMSAccountIDReturnsOnCall[len(fake.iMSAccountIDArgsForCall)] fake.iMSAccountIDArgsForCall = append(fake.iMSAccountIDArgsForCall, struct { }{}) + stub := fake.IMSAccountIDStub + fakeReturns := fake.iMSAccountIDReturns fake.recordInvocation("IMSAccountID", []interface{}{}) fake.iMSAccountIDMutex.Unlock() - if fake.IMSAccountIDStub != nil { - return fake.IMSAccountIDStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.iMSAccountIDReturns return fakeReturns.result1 } @@ -2108,15 +1823,16 @@ func (fake *FakePluginContext) IsAccessFromVPC() bool { ret, specificReturn := fake.isAccessFromVPCReturnsOnCall[len(fake.isAccessFromVPCArgsForCall)] fake.isAccessFromVPCArgsForCall = append(fake.isAccessFromVPCArgsForCall, struct { }{}) + stub := fake.IsAccessFromVPCStub + fakeReturns := fake.isAccessFromVPCReturns fake.recordInvocation("IsAccessFromVPC", []interface{}{}) fake.isAccessFromVPCMutex.Unlock() - if fake.IsAccessFromVPCStub != nil { - return fake.IsAccessFromVPCStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.isAccessFromVPCReturns return fakeReturns.result1 } @@ -2160,15 +1876,16 @@ func (fake *FakePluginContext) IsLoggedIn() bool { ret, specificReturn := fake.isLoggedInReturnsOnCall[len(fake.isLoggedInArgsForCall)] fake.isLoggedInArgsForCall = append(fake.isLoggedInArgsForCall, struct { }{}) + stub := fake.IsLoggedInStub + fakeReturns := fake.isLoggedInReturns fake.recordInvocation("IsLoggedIn", []interface{}{}) fake.isLoggedInMutex.Unlock() - if fake.IsLoggedInStub != nil { - return fake.IsLoggedInStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.isLoggedInReturns return fakeReturns.result1 } @@ -2265,15 +1982,16 @@ func (fake *FakePluginContext) IsLoggedInAsProfile() bool { ret, specificReturn := fake.isLoggedInAsProfileReturnsOnCall[len(fake.isLoggedInAsProfileArgsForCall)] fake.isLoggedInAsProfileArgsForCall = append(fake.isLoggedInAsProfileArgsForCall, struct { }{}) + stub := fake.IsLoggedInAsProfileStub + fakeReturns := fake.isLoggedInAsProfileReturns fake.recordInvocation("IsLoggedInAsProfile", []interface{}{}) fake.isLoggedInAsProfileMutex.Unlock() - if fake.IsLoggedInAsProfileStub != nil { - return fake.IsLoggedInAsProfileStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.isLoggedInAsProfileReturns return fakeReturns.result1 } @@ -2317,15 +2035,16 @@ func (fake *FakePluginContext) IsLoggedInWithServiceID() bool { ret, specificReturn := fake.isLoggedInWithServiceIDReturnsOnCall[len(fake.isLoggedInWithServiceIDArgsForCall)] fake.isLoggedInWithServiceIDArgsForCall = append(fake.isLoggedInWithServiceIDArgsForCall, struct { }{}) + stub := fake.IsLoggedInWithServiceIDStub + fakeReturns := fake.isLoggedInWithServiceIDReturns fake.recordInvocation("IsLoggedInWithServiceID", []interface{}{}) fake.isLoggedInWithServiceIDMutex.Unlock() - if fake.IsLoggedInWithServiceIDStub != nil { - return fake.IsLoggedInWithServiceIDStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.isLoggedInWithServiceIDReturns return fakeReturns.result1 } @@ -2369,15 +2088,16 @@ func (fake *FakePluginContext) IsPrivateEndpointEnabled() bool { ret, specificReturn := fake.isPrivateEndpointEnabledReturnsOnCall[len(fake.isPrivateEndpointEnabledArgsForCall)] fake.isPrivateEndpointEnabledArgsForCall = append(fake.isPrivateEndpointEnabledArgsForCall, struct { }{}) + stub := fake.IsPrivateEndpointEnabledStub + fakeReturns := fake.isPrivateEndpointEnabledReturns fake.recordInvocation("IsPrivateEndpointEnabled", []interface{}{}) fake.isPrivateEndpointEnabledMutex.Unlock() - if fake.IsPrivateEndpointEnabledStub != nil { - return fake.IsPrivateEndpointEnabledStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.isPrivateEndpointEnabledReturns return fakeReturns.result1 } @@ -2421,15 +2141,16 @@ func (fake *FakePluginContext) IsSSLDisabled() bool { ret, specificReturn := fake.isSSLDisabledReturnsOnCall[len(fake.isSSLDisabledArgsForCall)] fake.isSSLDisabledArgsForCall = append(fake.isSSLDisabledArgsForCall, struct { }{}) + stub := fake.IsSSLDisabledStub + fakeReturns := fake.isSSLDisabledReturns fake.recordInvocation("IsSSLDisabled", []interface{}{}) fake.isSSLDisabledMutex.Unlock() - if fake.IsSSLDisabledStub != nil { - return fake.IsSSLDisabledStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.isSSLDisabledReturns return fakeReturns.result1 } @@ -2473,15 +2194,16 @@ func (fake *FakePluginContext) Locale() string { ret, specificReturn := fake.localeReturnsOnCall[len(fake.localeArgsForCall)] fake.localeArgsForCall = append(fake.localeArgsForCall, struct { }{}) + stub := fake.LocaleStub + fakeReturns := fake.localeReturns fake.recordInvocation("Locale", []interface{}{}) fake.localeMutex.Unlock() - if fake.LocaleStub != nil { - return fake.LocaleStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.localeReturns return fakeReturns.result1 } @@ -2525,15 +2247,16 @@ func (fake *FakePluginContext) PluginConfig() plugin.PluginConfig { ret, specificReturn := fake.pluginConfigReturnsOnCall[len(fake.pluginConfigArgsForCall)] fake.pluginConfigArgsForCall = append(fake.pluginConfigArgsForCall, struct { }{}) + stub := fake.PluginConfigStub + fakeReturns := fake.pluginConfigReturns fake.recordInvocation("PluginConfig", []interface{}{}) fake.pluginConfigMutex.Unlock() - if fake.PluginConfigStub != nil { - return fake.PluginConfigStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.pluginConfigReturns return fakeReturns.result1 } @@ -2577,15 +2300,16 @@ func (fake *FakePluginContext) PluginDirectory() string { ret, specificReturn := fake.pluginDirectoryReturnsOnCall[len(fake.pluginDirectoryArgsForCall)] fake.pluginDirectoryArgsForCall = append(fake.pluginDirectoryArgsForCall, struct { }{}) + stub := fake.PluginDirectoryStub + fakeReturns := fake.pluginDirectoryReturns fake.recordInvocation("PluginDirectory", []interface{}{}) fake.pluginDirectoryMutex.Unlock() - if fake.PluginDirectoryStub != nil { - return fake.PluginDirectoryStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.pluginDirectoryReturns return fakeReturns.result1 } @@ -2629,15 +2353,16 @@ func (fake *FakePluginContext) RefreshIAMToken() (string, error) { ret, specificReturn := fake.refreshIAMTokenReturnsOnCall[len(fake.refreshIAMTokenArgsForCall)] fake.refreshIAMTokenArgsForCall = append(fake.refreshIAMTokenArgsForCall, struct { }{}) + stub := fake.RefreshIAMTokenStub + fakeReturns := fake.refreshIAMTokenReturns fake.recordInvocation("RefreshIAMToken", []interface{}{}) fake.refreshIAMTokenMutex.Unlock() - if fake.RefreshIAMTokenStub != nil { - return fake.RefreshIAMTokenStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1, ret.result2 } - fakeReturns := fake.refreshIAMTokenReturns return fakeReturns.result1, fakeReturns.result2 } @@ -2684,15 +2409,16 @@ func (fake *FakePluginContext) Trace() string { ret, specificReturn := fake.traceReturnsOnCall[len(fake.traceArgsForCall)] fake.traceArgsForCall = append(fake.traceArgsForCall, struct { }{}) + stub := fake.TraceStub + fakeReturns := fake.traceReturns fake.recordInvocation("Trace", []interface{}{}) fake.traceMutex.Unlock() - if fake.TraceStub != nil { - return fake.TraceStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.traceReturns return fakeReturns.result1 } @@ -2736,15 +2462,16 @@ func (fake *FakePluginContext) UserEmail() string { ret, specificReturn := fake.userEmailReturnsOnCall[len(fake.userEmailArgsForCall)] fake.userEmailArgsForCall = append(fake.userEmailArgsForCall, struct { }{}) + stub := fake.UserEmailStub + fakeReturns := fake.userEmailReturns fake.recordInvocation("UserEmail", []interface{}{}) fake.userEmailMutex.Unlock() - if fake.UserEmailStub != nil { - return fake.UserEmailStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.userEmailReturns return fakeReturns.result1 } @@ -2841,15 +2568,16 @@ func (fake *FakePluginContext) VersionCheckEnabled() bool { ret, specificReturn := fake.versionCheckEnabledReturnsOnCall[len(fake.versionCheckEnabledArgsForCall)] fake.versionCheckEnabledArgsForCall = append(fake.versionCheckEnabledArgsForCall, struct { }{}) + stub := fake.VersionCheckEnabledStub + fakeReturns := fake.versionCheckEnabledReturns fake.recordInvocation("VersionCheckEnabled", []interface{}{}) fake.versionCheckEnabledMutex.Unlock() - if fake.VersionCheckEnabledStub != nil { - return fake.VersionCheckEnabledStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - fakeReturns := fake.versionCheckEnabledReturns return fakeReturns.result1 } @@ -2893,10 +2621,6 @@ func (fake *FakePluginContext) Invocations() map[string][][]interface{} { defer fake.invocationsMutex.RUnlock() fake.aPIEndpointMutex.RLock() defer fake.aPIEndpointMutex.RUnlock() - fake.cFMutex.RLock() - defer fake.cFMutex.RUnlock() - fake.cFEEEnvIDMutex.RLock() - defer fake.cFEEEnvIDMutex.RUnlock() fake.cLINameMutex.RLock() defer fake.cLINameMutex.RUnlock() fake.cRITypeMutex.RLock() @@ -2929,16 +2653,10 @@ func (fake *FakePluginContext) Invocations() map[string][][]interface{} { defer fake.hasAPIEndpointMutex.RUnlock() fake.hasTargetedAccountMutex.RLock() defer fake.hasTargetedAccountMutex.RUnlock() - fake.hasTargetedCFMutex.RLock() - defer fake.hasTargetedCFMutex.RUnlock() - fake.hasTargetedCFEEMutex.RLock() - defer fake.hasTargetedCFEEMutex.RUnlock() fake.hasTargetedComputeResourceMutex.RLock() defer fake.hasTargetedComputeResourceMutex.RUnlock() fake.hasTargetedProfileMutex.RLock() defer fake.hasTargetedProfileMutex.RUnlock() - fake.hasTargetedPublicCFMutex.RLock() - defer fake.hasTargetedPublicCFMutex.RUnlock() fake.hasTargetedRegionMutex.RLock() defer fake.hasTargetedRegionMutex.RUnlock() fake.hasTargetedResourceGroupMutex.RLock() diff --git a/plugin_examples/auto_complete_delegation.go b/plugin_examples/auto_complete_delegation.go deleted file mode 100644 index c2dc175..0000000 --- a/plugin_examples/auto_complete_delegation.go +++ /dev/null @@ -1,84 +0,0 @@ -package main - -import ( - "fmt" - "strings" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin" -) - -type AutoCompleteDelegationSample struct{} - -func main() { - plugin.Start(new(AutoCompleteDelegationSample)) -} - -func (pluginDemo *AutoCompleteDelegationSample) Run(context plugin.PluginContext, args []string) { - switch args[0] { - case "SendCompletion": - // CLI invokes 'PATH_TO_PLUGIN_BINARY SendCompletion [NAMESPACE] ... [COMMAND] [ARGS]...' - // for example: 'AutoCompleteDelegationSample SendCompletion autocomplete-sample set-role' - - subCommands := []string{"get-role", "set-role", "help"} - var cmd string - if len(args) > 2 { - for _, c := range subCommands { - if c == args[2] { - cmd = c - break - } - } - } - - if cmd == "" { - // completion for sub-commands - fmt.Println(strings.Join(subCommands, "\n")) - return - } - - if cmd == "set-role" { - // completion for command args - fmt.Println("Viewer\nEditor\nOperator\nAdministrator") - } - default: - fmt.Printf("Running command %q\n", args[0]) - } -} - -func (pluginDemo *AutoCompleteDelegationSample) GetMetadata() plugin.PluginMetadata { - return plugin.PluginMetadata{ - Name: "auto-complete-delegation-sample", - Version: plugin.VersionType{ - Major: 0, - Minor: 0, - Build: 1, - }, - DelegateBashCompletion: true, // enable command completion delegation - Namespaces: []plugin.Namespace{ - { - Name: "autocomplete-sample", - Description: "Demonstrate delegate command completion to plugin.", - }, - }, - Commands: []plugin.Command{ - { - Namespace: "autocomplete-sample", - Name: "get-role", - Description: "get user's role", - Usage: "ibmcloud autocomplete-sample get-role", - }, - { - Namespace: "autocomplete-sample", - Name: "set-role", - Description: "set a user role (Viewer, Editor, Operator or Administrator)", - Usage: "ibmcloud autocomplete-sample set-role", - }, - { - Namespace: "autocomplete-sample", - Name: "help", - Description: "show help", - Usage: "ibmcloud autocomplete-sample help", - }, - }, - } -} diff --git a/plugin_examples/context.go b/plugin_examples/context.go deleted file mode 100644 index fefdbc3..0000000 --- a/plugin_examples/context.go +++ /dev/null @@ -1,66 +0,0 @@ -package main - -import ( - "strconv" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/terminal" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin" -) - -type PrintContext struct { - ui terminal.UI -} - -func main() { - plugin.Start(NewPrintContext()) -} - -func NewPrintContext() *PrintContext { - return &PrintContext{ - ui: terminal.NewStdUI(), - } -} - -func (p *PrintContext) Run(context plugin.PluginContext, args []string) { - table := p.ui.Table([]string{"Name", "Value"}) - table.Add("API endpoint", context.APIEndpoint()) - table.Add("IAM endpoint", context.IAMEndpoint()) - table.Add("Username", context.UserEmail()) - - cf := context.CF() - table.Add("CC endpoint", cf.APIEndpoint()) - table.Add("UAA endpoint", cf.UAAEndpoint()) - table.Add("Doppler logging endpoint", cf.DopplerEndpoint()) - table.Add("Org", cf.CurrentOrganization().Name) - table.Add("Space", cf.CurrentSpace().Name) - - table.Add("Color enabled", context.ColorEnabled()) - table.Add("HTTP timeout (second)", strconv.Itoa(context.HTTPTimeout())) - table.Add("Trace", context.Trace()) - table.Add("Locale", context.Locale()) - - table.Print() -} - -func (p *PrintContext) GetMetadata() plugin.PluginMetadata { - return plugin.PluginMetadata{ - Name: "context-sample", - Version: plugin.VersionType{ - Major: 0, - Minor: 1, - Build: 0, - }, - MinCliVersion: plugin.VersionType{ - Major: 0, - Minor: 0, - Build: 1, - }, - Commands: []plugin.Command{ - { - Name: "context", - Description: "Print IBM Cloud plugin context", - Usage: "ibmcloud context", - }, - }, - } -} diff --git a/plugin_examples/hello.go b/plugin_examples/hello.go deleted file mode 100644 index 512b2ae..0000000 --- a/plugin_examples/hello.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin" -) - -type HelloWorldPlugin struct{} - -func main() { - plugin.Start(new(HelloWorldPlugin)) -} - -func (pluginDemo *HelloWorldPlugin) Run(context plugin.PluginContext, args []string) { - fmt.Println("Hi, this is my first plugin for IBM Cloud CLI.") -} - -func (pluginDemo *HelloWorldPlugin) GetMetadata() plugin.PluginMetadata { - return plugin.PluginMetadata{ - Name: "hello-sample", - Version: plugin.VersionType{ - Major: 0, - Minor: 0, - Build: 1, - }, - Commands: []plugin.Command{ - { - Name: "hello", - Alias: "hi", - Description: "Say hello to IBM Cloud.", - Usage: "ibmcloud hello", - }, - }, - } -} diff --git a/plugin_examples/list_plugin/api/api_suite_test.go b/plugin_examples/list_plugin/api/api_suite_test.go deleted file mode 100644 index 6ffd078..0000000 --- a/plugin_examples/list_plugin/api/api_suite_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package api_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "testing" -) - -func TestApi(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Api Suite") -} diff --git a/plugin_examples/list_plugin/api/cc_client.go b/plugin_examples/list_plugin/api/cc_client.go deleted file mode 100644 index 2ce254e..0000000 --- a/plugin_examples/list_plugin/api/cc_client.go +++ /dev/null @@ -1,62 +0,0 @@ -package api - -import ( - "fmt" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/common/rest" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/models" -) - -type CCError struct { - Code int `json:"code"` - Description string `json:"description"` -} - -func (c CCError) Error() string { - return fmt.Sprintf("Error response from server. Status code: %d; description: %s.", c.Code, c.Description) -} - -type CCClient interface { - AppsAndServices(spaceId string) (models.AppsAndServices, error) - OrgUsage(orgId string) (models.OrgUsage, error) -} - -type ccClient struct { - endpoint string - client *rest.Client -} - -func NewCCClient(endpoint string, client *rest.Client) CCClient { - return &ccClient{ - endpoint: endpoint, - client: client, - } -} - -func (c *ccClient) AppsAndServices(spaceId string) (models.AppsAndServices, error) { - var summary models.AppsAndServices - var apiErr CCError - - req := rest.GetRequest(c.endpoint + fmt.Sprintf("/v2/spaces/%s/summary", spaceId)) - _, err := c.client.Do(req, &summary, &apiErr) - return summary, c.handleError(err, apiErr) -} - -func (c *ccClient) OrgUsage(orgId string) (models.OrgUsage, error) { - var summary models.OrgUsage - var apiErr CCError - - req := rest.GetRequest(c.endpoint + fmt.Sprintf("/v2/organizations/%s/summary", orgId)) - _, err := c.client.Do(req, &summary, &apiErr) - return summary, c.handleError(err, apiErr) -} - -func (c *ccClient) handleError(httpErr error, apiErr CCError) error { - if httpErr != nil { - return httpErr - } - if apiErr != (CCError{}) { - return apiErr - } - return nil -} diff --git a/plugin_examples/list_plugin/api/cc_client_test.go b/plugin_examples/list_plugin/api/cc_client_test.go deleted file mode 100644 index a8a587d..0000000 --- a/plugin_examples/list_plugin/api/cc_client_test.go +++ /dev/null @@ -1,215 +0,0 @@ -package api_test - -import ( - "net/http" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/common/rest" - . "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/api" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/models" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - . "github.com/onsi/gomega/ghttp" -) - -var _ = Describe("CCClient", func() { - var server *Server - var client CCClient - - AfterEach(func() { - server.Close() - }) - - BeforeEach(func() { - server = NewServer() - client = NewCCClient(server.URL(), rest.NewClient()) - }) - - Describe("AppsAndServices()", func() { - Context("When server returns successfully", func() { - BeforeEach(func() { - response := ` - { - "guid":"space-guid", - "name":"space-name", - "apps":[ - { - "guid":"app1-guid", - "urls":[ - "app1.mybluemix.net" - ], - "routes":[ - { - "guid":"route-id", - "host":"app1", - "domain":{ - "guid":"domain-id", - "name":"mybluemix.net" - } - } - ], - "service_count":1, - "service_names":[ - "serviceB-instance1" - ], - "running_instances":0, - "name":"app1", - "memory":256, - "instances":2, - "disk_quota":1024, - "state":"STOPPED" - } - ], - "services":[ - { - "guid":"serviceA-instance1-id", - "name":"serviceA-instance1", - "bound_app_count":0, - "last_operation":{ - "type":"create", - "state":"succeeded", - "description":"" - }, - "dashboard_url":null, - "service_plan":{ - "guid":"serviceA-plan-guid", - "name":"serviceA-plan", - "service":{ - "guid":"serviceA-guid", - "label":"serviceA", - "provider":"serviceA-provider", - "version":"serviceA-version" - } - } - }, - { - "guid":"serviceB-instance1-id", - "name":"serviceB-instance1", - "bound_app_count":1, - "last_operation":{ - "type":"create", - "state":"succeeded", - "description":"" - }, - "dashboard_url":null, - "service_plan":{ - "guid":"serviceB-plan-guid", - "name":"serviceB-plan", - "service":{ - "guid":"serviceB-guid", - "label":"serviceB", - "provider":"serviceB-provider", - "version":"serviceB-version" - } - } - } - ] - }` - - server.AppendHandlers( - CombineHandlers( - VerifyRequest(http.MethodGet, "/v2/spaces/space-id/summary"), - RespondWith(http.StatusOK, response), - ), - ) - }) - - It("should return apps and services summary", func() { - summary, err := client.AppsAndServices("space-id") - - Expect(err).NotTo(HaveOccurred()) - Expect(len(summary.Apps)).To(Equal(1)) - Expect(summary.Apps[0].Name).To(Equal("app1")) - Expect(summary.Apps[0].URLs).To(Equal([]string{"app1.mybluemix.net"})) - Expect(summary.Apps[0].Memory).To(Equal(int64(256))) - Expect(summary.Apps[0].TotalInstances).To(Equal(2)) - Expect(summary.Apps[0].RunningInstances).To(Equal(0)) - Expect(summary.Apps[0].State).To(Equal("STOPPED")) - - Expect(len(summary.Services)).To(Equal(2)) - Expect(summary.Services[0].Name).To(Equal("serviceA-instance1")) - Expect(summary.Services[0].ServicePlan.Name).To(Equal("serviceA-plan")) - Expect(summary.Services[0].ServicePlan.ServiceOffering.Label).To(Equal("serviceA")) - Expect(summary.Services[1].Name).To(Equal("serviceB-instance1")) - Expect(summary.Services[1].ServicePlan.Name).To(Equal("serviceB-plan")) - Expect(summary.Services[1].ServicePlan.ServiceOffering.Label).To(Equal("serviceB")) - }) - }) - - Context("When server return recognized error", func() { - BeforeEach(func() { - server.AppendHandlers( - CombineHandlers( - VerifyRequest(http.MethodGet, "/v2/spaces/space-id/summary"), - RespondWith(http.StatusInternalServerError, ` - { - "code":500, - "description":"the-error-message" - }`, - ), - ), - ) - }) - - It("should return cc api error", func() { - summary, err := client.AppsAndServices("space-id") - - Expect(summary).To(Equal(models.AppsAndServices{})) - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(CCError{Code: 500, Description: "the-error-message"})) - }) - }) - }) - - Describe("OrgUsage()", func() { - Context("When server returns the org summary", func() { - BeforeEach(func() { - response := ` - { - "guid": "org1-id", - "name": "org1", - "status": "active", - "spaces": [ - { - "guid": "space1-id", - "name": "space1", - "service_count": 1, - "app_count": 6, - "mem_dev_total": 1152, - "mem_prod_total": 0 - }, - { - "guid": "space2-id", - "name": "space2", - "service_count": 1, - "app_count": 1, - "mem_dev_total": 128, - "mem_prod_total": 0 - } - ] - } - ` - - server.AppendHandlers( - CombineHandlers( - VerifyRequest(http.MethodGet, "/v2/organizations/org1-id/summary"), - RespondWith(http.StatusOK, response), - ), - ) - }) - - It("Should returns the usage", func() { - usage, err := client.OrgUsage("org1-id") - - Expect(err).NotTo(HaveOccurred()) - Expect(usage.Org).To(Equal("org1")) - Expect(len(usage.Spaces)).To(Equal(2)) - Expect(usage.Spaces[0].Space).To(Equal("space1")) - Expect(usage.Spaces[0].Apps).To(Equal(6)) - Expect(usage.Spaces[0].Services).To(Equal(1)) - Expect(usage.Spaces[0].MemoryInDev).To(Equal(int64(1152))) - Expect(usage.Spaces[0].MemoryInProd).To(Equal(int64(0))) - }) - }) - }) -}) diff --git a/plugin_examples/list_plugin/api/container_client.go b/plugin_examples/list_plugin/api/container_client.go deleted file mode 100644 index aece972..0000000 --- a/plugin_examples/list_plugin/api/container_client.go +++ /dev/null @@ -1,65 +0,0 @@ -package api - -import ( - "fmt" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/common/rest" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/models" -) - -type ContainerError struct { - Code string `json:"code"` - StatusCode string `json:"rc"` - Description string `json:"description"` - IncidentId string `json:"incident_id"` -} - -func (e ContainerError) Error() string { - return fmt.Sprintf("Server error, status code: %s, error code: %s, incident id: %s, message: %s", - e.StatusCode, e.Code, e.IncidentId, e.Description) -} - -type ContainerClient interface { - Containers(spaceId string) ([]models.Container, error) - ContainersQuotaAndUsage(spaceId string) (models.ContainersQuotaAndUsage, error) -} - -type containerClient struct { - endpoint string - client *rest.Client -} - -func NewContainerClient(endpoint string, client *rest.Client) ContainerClient { - return &containerClient{ - endpoint: endpoint, - client: client, - } -} - -func (c *containerClient) Containers(spaceId string) ([]models.Container, error) { - var containers []models.Container - var apiErr ContainerError - - req := rest.GetRequest(c.endpoint+"/v3/containers/json").Add("X-Auth-Project-Id", spaceId).Query("all", "true") - _, err := c.client.Do(req, &containers, &apiErr) - return containers, c.handleError(err, apiErr) -} - -func (c *containerClient) ContainersQuotaAndUsage(spaceId string) (models.ContainersQuotaAndUsage, error) { - var quotaAndUsage models.ContainersQuotaAndUsage - var apiErr ContainerError - - req := rest.GetRequest(c.endpoint+"/v3/containers/usage").Add("X-Auth-Project-Id", spaceId) - _, err := c.client.Do(req, "aAndUsage, &apiErr) - return quotaAndUsage, c.handleError(err, apiErr) -} - -func (c *containerClient) handleError(httpErr error, apiErr ContainerError) error { - if httpErr != nil { - return httpErr - } - if apiErr != (ContainerError{}) { - return apiErr - } - return nil -} diff --git a/plugin_examples/list_plugin/api/container_client_test.go b/plugin_examples/list_plugin/api/container_client_test.go deleted file mode 100644 index 528dab5..0000000 --- a/plugin_examples/list_plugin/api/container_client_test.go +++ /dev/null @@ -1,209 +0,0 @@ -package api_test - -import ( - "net/http" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/common/rest" - . "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/api" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - . "github.com/onsi/gomega/ghttp" -) - -var _ = Describe("ContainerClient", func() { - var server *Server - var client ContainerClient - - AfterEach(func() { - server.Close() - }) - - BeforeEach(func() { - server = NewServer() - client = NewContainerClient(server.URL(), rest.NewClient()) - }) - - Describe("Containers()", func() { - Context("When server returns successfully", func() { - BeforeEach(func() { - response := ` - [ - { - "ContainerState": "Running", - "Created": 1484718255, - "Group": { - "Id": "group1-id", - "Name": "group1" - }, - "Id": "container1-id", - "Name": "container1", - "Image": "registry/image1", - "Memory": 256, - "Started": 1484718271 - }, - { - "ContainerState": "Running", - "Created": 1484718254, - "Group": { - "Id": "group1-id", - "Name": "group1" - }, - "Id": "container2-id", - "Image": "registry/image1", - "Memory": 256, - "Name": "container2", - "Started": 1484718273 - }, - { - "ContainerState": "Shutdown", - "Created": 1484718254, - "Group": {}, - "Id": "container3-id", - "Image": "registry/image2", - "Memory": 512, - "Name": "container3", - "Started": 1484718273 - } - ] - ` - - server.AppendHandlers( - CombineHandlers( - VerifyRequest(http.MethodGet, "/v3/containers/json", "all=true"), - VerifyHeaderKV("X-Auth-Project-Id", "space-id"), - RespondWith(http.StatusOK, response), - ), - ) - }) - - It("should return apps and services summary", func() { - containers, err := client.Containers("space-id") - - Expect(err).NotTo(HaveOccurred()) - Expect(len(containers)).To(Equal(3)) - - Expect(containers[0].Name).To(Equal("container1")) - Expect(containers[0].Group.Name).To(Equal("group1")) - Expect(containers[0].Memory).To(Equal(int64(256))) - Expect(containers[0].Created).To(Equal(int64(1484718255))) - Expect(containers[0].Image).To(Equal("registry/image1")) - Expect(containers[0].State).To(Equal("Running")) - - Expect(containers[1].Name).To(Equal("container2")) - Expect(containers[1].Group.Name).To(Equal("group1")) - Expect(containers[1].Memory).To(Equal(int64(256))) - Expect(containers[1].Created).To(Equal(int64(1484718254))) - Expect(containers[1].Image).To(Equal("registry/image1")) - Expect(containers[1].State).To(Equal("Running")) - - Expect(containers[2].Name).To(Equal("container3")) - Expect(containers[2].Group.Name).To(Equal("")) - Expect(containers[2].Memory).To(Equal(int64(512))) - Expect(containers[2].Created).To(Equal(int64(1484718254))) - Expect(containers[2].Image).To(Equal("registry/image2")) - Expect(containers[2].State).To(Equal("Shutdown")) - }) - }) - - Context("When server return empty json array", func() { - BeforeEach(func() { - server.AppendHandlers(RespondWith(http.StatusOK, "[]")) - }) - - It("should return empty containers and no error", func() { - containers, err := client.Containers("space-id") - - Expect(err).NotTo(HaveOccurred()) - Expect(containers).To(BeEmpty()) - }) - }) - - Context("When server return errors", func() { - BeforeEach(func() { - server.AppendHandlers( - RespondWith(http.StatusBadRequest, ` - { - "code": "the-error-code", - "description": "the-error-message", - "incident_id": "the-incident-id", - "rc": "400" - }`, - ), - ) - }) - - It("should return error", func() { - containers, err := client.Containers("space-id") - - Expect(err).To(HaveOccurred()) - Expect(err).To(MatchError(ContainerError{ - Code: "the-error-code", - StatusCode: "400", - Description: "the-error-message", - IncidentId: "the-incident-id", - })) - Expect(containers).To(BeEmpty()) - }) - }) - }) - - Describe("ContainersQuotaAndUsage()", func() { - Context("When server returns containers usage and quota in the given space", func() { - BeforeEach(func() { - response := ` - { - "Limits": { - "containers": -1, - "floating_ips": 2, - "memory_MB": 2048, - "networks": 5, - "subnets": 5, - "vcpu": -1 - }, - "Usage": { - "containers": 5, - "custom_networks": 0, - "file_share_count": 0, - "floating_ips": 1, - "floating_ips_bound": 1, - "images": 0, - "memory_MB": 1280, - "networks": 1, - "running": 2, - "subnets": 1, - "vcpu": 5 - } - } - ` - - server.AppendHandlers( - CombineHandlers( - VerifyRequest(http.MethodGet, "/v3/containers/usage"), - VerifyHeaderKV("X-Auth-Project-Id", "space-id"), - RespondWith(http.StatusOK, response), - ), - ) - }) - - It("Should return the quota and usage", func() { - quotaAndUsage, err := client.ContainersQuotaAndUsage("space-id") - - Expect(err).NotTo(HaveOccurred()) - - Expect(quotaAndUsage.Usage.TotalInstances).To(Equal(5)) - Expect(quotaAndUsage.Usage.RunningInstances).To(Equal(2)) - Expect(quotaAndUsage.Usage.FloatingIpsCount).To(Equal(1)) - Expect(quotaAndUsage.Usage.BoundFloatingIpsCount).To(Equal(1)) - Expect(quotaAndUsage.Usage.MemoryInMB).To(Equal(int64(1280))) - Expect(quotaAndUsage.Usage.CPUCount).To(Equal(5)) - - Expect(quotaAndUsage.Limits.CPUCountLimit).To(Equal(-1)) - Expect(quotaAndUsage.Limits.MemoryLimitInMB).To(Equal(int64(2048))) - Expect(quotaAndUsage.Limits.InstancesCountLimit).To(Equal(-1)) - Expect(quotaAndUsage.Limits.FloatingIpCountLimit).To(Equal(2)) - - }) - }) - }) -}) diff --git a/plugin_examples/list_plugin/api/fakes/fake_ccclient.go b/plugin_examples/list_plugin/api/fakes/fake_ccclient.go deleted file mode 100644 index bd55389..0000000 --- a/plugin_examples/list_plugin/api/fakes/fake_ccclient.go +++ /dev/null @@ -1,98 +0,0 @@ -// This file was generated by counterfeiter -package fakes - -import ( - "sync" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/api" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/models" -) - -type FakeCCClient struct { - AppsAndServicesStub func(spaceId string) (models.AppsAndServices, error) - appsAndServicesMutex sync.RWMutex - appsAndServicesArgsForCall []struct { - spaceId string - } - appsAndServicesReturns struct { - result1 models.AppsAndServices - result2 error - } - OrgUsageStub func(orgId string) (models.OrgUsage, error) - orgUsageMutex sync.RWMutex - orgUsageArgsForCall []struct { - orgId string - } - orgUsageReturns struct { - result1 models.OrgUsage - result2 error - } -} - -func (fake *FakeCCClient) AppsAndServices(spaceId string) (models.AppsAndServices, error) { - fake.appsAndServicesMutex.Lock() - fake.appsAndServicesArgsForCall = append(fake.appsAndServicesArgsForCall, struct { - spaceId string - }{spaceId}) - fake.appsAndServicesMutex.Unlock() - if fake.AppsAndServicesStub != nil { - return fake.AppsAndServicesStub(spaceId) - } else { - return fake.appsAndServicesReturns.result1, fake.appsAndServicesReturns.result2 - } -} - -func (fake *FakeCCClient) AppsAndServicesCallCount() int { - fake.appsAndServicesMutex.RLock() - defer fake.appsAndServicesMutex.RUnlock() - return len(fake.appsAndServicesArgsForCall) -} - -func (fake *FakeCCClient) AppsAndServicesArgsForCall(i int) string { - fake.appsAndServicesMutex.RLock() - defer fake.appsAndServicesMutex.RUnlock() - return fake.appsAndServicesArgsForCall[i].spaceId -} - -func (fake *FakeCCClient) AppsAndServicesReturns(result1 models.AppsAndServices, result2 error) { - fake.AppsAndServicesStub = nil - fake.appsAndServicesReturns = struct { - result1 models.AppsAndServices - result2 error - }{result1, result2} -} - -func (fake *FakeCCClient) OrgUsage(orgId string) (models.OrgUsage, error) { - fake.orgUsageMutex.Lock() - fake.orgUsageArgsForCall = append(fake.orgUsageArgsForCall, struct { - orgId string - }{orgId}) - fake.orgUsageMutex.Unlock() - if fake.OrgUsageStub != nil { - return fake.OrgUsageStub(orgId) - } else { - return fake.orgUsageReturns.result1, fake.orgUsageReturns.result2 - } -} - -func (fake *FakeCCClient) OrgUsageCallCount() int { - fake.orgUsageMutex.RLock() - defer fake.orgUsageMutex.RUnlock() - return len(fake.orgUsageArgsForCall) -} - -func (fake *FakeCCClient) OrgUsageArgsForCall(i int) string { - fake.orgUsageMutex.RLock() - defer fake.orgUsageMutex.RUnlock() - return fake.orgUsageArgsForCall[i].orgId -} - -func (fake *FakeCCClient) OrgUsageReturns(result1 models.OrgUsage, result2 error) { - fake.OrgUsageStub = nil - fake.orgUsageReturns = struct { - result1 models.OrgUsage - result2 error - }{result1, result2} -} - -var _ api.CCClient = new(FakeCCClient) diff --git a/plugin_examples/list_plugin/api/fakes/fake_container_client.go b/plugin_examples/list_plugin/api/fakes/fake_container_client.go deleted file mode 100644 index 1029511..0000000 --- a/plugin_examples/list_plugin/api/fakes/fake_container_client.go +++ /dev/null @@ -1,98 +0,0 @@ -// This file was generated by counterfeiter -package fakes - -import ( - "sync" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/api" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/models" -) - -type FakeContainerClient struct { - ContainersStub func(spaceId string) ([]models.Container, error) - containersMutex sync.RWMutex - containersArgsForCall []struct { - spaceId string - } - containersReturns struct { - result1 []models.Container - result2 error - } - ContainersQuotaAndUsageStub func(spaceId string) (models.ContainersQuotaAndUsage, error) - containersQuotaAndUsageMutex sync.RWMutex - containersQuotaAndUsageArgsForCall []struct { - spaceId string - } - containersQuotaAndUsageReturns struct { - result1 models.ContainersQuotaAndUsage - result2 error - } -} - -func (fake *FakeContainerClient) Containers(spaceId string) ([]models.Container, error) { - fake.containersMutex.Lock() - fake.containersArgsForCall = append(fake.containersArgsForCall, struct { - spaceId string - }{spaceId}) - fake.containersMutex.Unlock() - if fake.ContainersStub != nil { - return fake.ContainersStub(spaceId) - } else { - return fake.containersReturns.result1, fake.containersReturns.result2 - } -} - -func (fake *FakeContainerClient) ContainersCallCount() int { - fake.containersMutex.RLock() - defer fake.containersMutex.RUnlock() - return len(fake.containersArgsForCall) -} - -func (fake *FakeContainerClient) ContainersArgsForCall(i int) string { - fake.containersMutex.RLock() - defer fake.containersMutex.RUnlock() - return fake.containersArgsForCall[i].spaceId -} - -func (fake *FakeContainerClient) ContainersReturns(result1 []models.Container, result2 error) { - fake.ContainersStub = nil - fake.containersReturns = struct { - result1 []models.Container - result2 error - }{result1, result2} -} - -func (fake *FakeContainerClient) ContainersQuotaAndUsage(spaceId string) (models.ContainersQuotaAndUsage, error) { - fake.containersQuotaAndUsageMutex.Lock() - fake.containersQuotaAndUsageArgsForCall = append(fake.containersQuotaAndUsageArgsForCall, struct { - spaceId string - }{spaceId}) - fake.containersQuotaAndUsageMutex.Unlock() - if fake.ContainersQuotaAndUsageStub != nil { - return fake.ContainersQuotaAndUsageStub(spaceId) - } else { - return fake.containersQuotaAndUsageReturns.result1, fake.containersQuotaAndUsageReturns.result2 - } -} - -func (fake *FakeContainerClient) ContainersQuotaAndUsageCallCount() int { - fake.containersQuotaAndUsageMutex.RLock() - defer fake.containersQuotaAndUsageMutex.RUnlock() - return len(fake.containersQuotaAndUsageArgsForCall) -} - -func (fake *FakeContainerClient) ContainersQuotaAndUsageArgsForCall(i int) string { - fake.containersQuotaAndUsageMutex.RLock() - defer fake.containersQuotaAndUsageMutex.RUnlock() - return fake.containersQuotaAndUsageArgsForCall[i].spaceId -} - -func (fake *FakeContainerClient) ContainersQuotaAndUsageReturns(result1 models.ContainersQuotaAndUsage, result2 error) { - fake.ContainersQuotaAndUsageStub = nil - fake.containersQuotaAndUsageReturns = struct { - result1 models.ContainersQuotaAndUsage - result2 error - }{result1, result2} -} - -var _ api.ContainerClient = new(FakeContainerClient) diff --git a/plugin_examples/list_plugin/bin/generate-i18n-resources b/plugin_examples/list_plugin/bin/generate-i18n-resources deleted file mode 100755 index 5b15856..0000000 --- a/plugin_examples/list_plugin/bin/generate-i18n-resources +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -set -e - -go get github.com/jteeuwen/go-bindata/... - -echo "Generating i18n resource file ..." -go-bindata -pkg resources -o resources/i18n_resources.go i18n/resources/*.json -echo "Done." diff --git a/plugin_examples/list_plugin/commands/commands_suite_test.go b/plugin_examples/list_plugin/commands/commands_suite_test.go deleted file mode 100644 index e95f21e..0000000 --- a/plugin_examples/list_plugin/commands/commands_suite_test.go +++ /dev/null @@ -1,18 +0,0 @@ -package commands_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "testing" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin/pluginfakes" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/i18n" -) - -func TestCommands(t *testing.T) { - i18n.T = i18n.Init(new(pluginfakes.FakePluginContext)) - - RegisterFailHandler(Fail) - RunSpecs(t, "Commands Suite") -} diff --git a/plugin_examples/list_plugin/commands/list.go b/plugin_examples/list_plugin/commands/list.go deleted file mode 100644 index 407bd7f..0000000 --- a/plugin_examples/list_plugin/commands/list.go +++ /dev/null @@ -1,190 +0,0 @@ -package commands - -import ( - "fmt" - "strconv" - "strings" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/terminal" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/api" - . "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/i18n" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/models" - "github.com/fatih/color" -) - -type List struct { - ui terminal.UI - cf plugin.CFContext - ccClient api.CCClient - containerClient api.ContainerClient -} - -func NewList( - ui terminal.UI, - context plugin.PluginContext, - ccClient api.CCClient, - containerClient api.ContainerClient) *List { - - return &List{ - ui: ui, - cf: context.CF(), - ccClient: ccClient, - containerClient: containerClient, - } -} - -func (cmd *List) Run(args []string) error { - err := checkTarget(cmd.cf) - if err != nil { - return err - } - - orgId := cmd.cf.CurrentOrganization().GUID - spaceId := cmd.cf.CurrentSpace().GUID - - summary, err := cmd.ccClient.AppsAndServices(spaceId) - if err != nil { - return fmt.Errorf(T("Unable to query apps and services of the target space:\n") + err.Error()) - } - - orgUsage, err := cmd.ccClient.OrgUsage(orgId) - if err != nil { - return fmt.Errorf(T("Unable to retrieve usage of the target org:\n") + err.Error()) - } - - cmd.printApps(summary.Apps, orgUsage) - cmd.printServices(summary.Services, orgUsage) - - containers, err := cmd.containerClient.Containers(spaceId) - if err != nil { - return fmt.Errorf(T("Unable to query containers of the target space:\n") + err.Error()) - } - - containersQuotaAndUsage, err := cmd.containerClient.ContainersQuotaAndUsage(spaceId) - if err != nil { - return fmt.Errorf(T("Unable to retrieve containers' usage and quota of the target space:\n") + err.Error()) - } - - cmd.printContainers(containers, containersQuotaAndUsage) - - return nil -} - -func (cmd *List) printApps(apps []models.App, orgUsage models.OrgUsage) { - cmd.ui.Say(terminal.Colorize( - T("CloudFoundy Applications {{.Used}}/{{.Limit}} used", - map[string]interface{}{ - "Used": formattedGB(orgUsage.TotalMemoryUsed()), - "Limit": formattedGB(cmd.cf.CurrentOrganization().QuotaDefinition.InstanceMemoryLimitInMB)}), color.New(color.FgYellow, color.Bold))) - - table := cmd.ui.Table([]string{T("Name"), T("Routes"), T("Memory (MB)"), T("Instances"), T("State")}) - for _, a := range apps { - table.Add( - a.Name, - strings.Join(a.URLs, "\n"), - strconv.FormatInt(a.Memory, 10), - fmt.Sprintf("%d/%d", a.RunningInstances, a.TotalInstances), - a.State) - } - table.Print() - - cmd.ui.Say("") -} - -func (cmd *List) printServices(services []models.ServiceInstance, orgUsage models.OrgUsage) { - cmd.ui.Say(terminal.Colorize( - T("Services {{.Count}}/{{.Limit}} used", map[string]interface{}{ - "Count": orgUsage.ServicesCount(), - "Limit": cmd.cf.CurrentOrganization().QuotaDefinition.ServicesLimit}), color.New(color.FgYellow, color.Bold))) - - table := cmd.ui.Table([]string{T("Name"), T("Service Offering"), T("Plan")}) - for _, s := range services { - table.Add( - s.Name, - s.ServicePlan.ServiceOffering.Label, - s.ServicePlan.Name) - } - table.Print() - - cmd.ui.Say("") -} - -func (cmd *List) printContainers(containers []models.Container, quotaAndUsage models.ContainersQuotaAndUsage) { - cmd.ui.Say(terminal.Colorize( - T("Containers {{.MemoryUsed}}/{{.MemoryLimit}} {{.IPCount}}/{{.IPLimit}} Public IPs Requested|{{.BoundIPCount}} Used", - map[string]interface{}{ - "MemoryUsed": formattedGB(quotaAndUsage.Usage.MemoryInMB), - "MemoryLimit": formattedGB(quotaAndUsage.Limits.MemoryLimitInMB), - "IPCount": quotaAndUsage.Usage.FloatingIpsCount, - "IPLimit": quotaAndUsage.Limits.FloatingIpCountLimit, - "BoundIPCount": quotaAndUsage.Usage.BoundFloatingIpsCount}), color.New(color.FgYellow, color.Bold))) - - byName := make(map[string][]models.Container) - for _, c := range containers { - name := c.Group.Name - if name == "" { - name = c.Name - } - byName[name] = append(byName[name], c) - } - - table := cmd.ui.Table([]string{T("Name"), T("Instances"), T("Image"), T("Created"), T("Status")}) - for name, containers := range byName { - var image string - parts := strings.Split(containers[0].Image, "/") - if len(parts) > 0 { - image = parts[len(parts)-1] - } - - var createdStr string - if len(containers) > 1 { - createdStr = "--" - } else { - createdStr = fmt.Sprintf("%d", containers[0].Created) - } - - status := containers[0].State - if len(containers) > 1 { - for i := 1; i < len(containers); i++ { - if status != containers[i].State { - status = "??" //TODO - break - } - } - } - - table.Add( - name, - strconv.Itoa(len(containers)), - image, - createdStr, - status) - } - table.Print() - - cmd.ui.Say("") -} - -func checkTarget(cf plugin.CFContext) error { - if !cf.HasAPIEndpoint() { - return fmt.Errorf(T("No CF API endpoint set. Use '{{.Command}}' to target a CloudFoundry environment.", - map[string]interface{}{"Command": terminal.CommandColor("bx target --cf")})) - } - - if !cf.IsLoggedIn() { - return fmt.Errorf(T("Not logged in. Use '{{.Command}}' to log in.", - map[string]interface{}{"Command": terminal.CommandColor("bx target --cf")})) - } - - if !cf.HasTargetedSpace() { - return fmt.Errorf(T("No space targeted. Use '{{.Command}}' to target an org and a space.", - map[string]interface{}{"Command": terminal.CommandColor("bx target -o ORG -s SPACE")})) - } - - return nil -} - -func formattedGB(sizeInMB int64) string { - return strings.TrimRight(strings.TrimRight(fmt.Sprintf("%0.2f", float64(sizeInMB)/1024), "0"), ".") + " GB" -} diff --git a/plugin_examples/list_plugin/commands/list_test.go b/plugin_examples/list_plugin/commands/list_test.go deleted file mode 100644 index 90bbf26..0000000 --- a/plugin_examples/list_plugin/commands/list_test.go +++ /dev/null @@ -1,216 +0,0 @@ -package commands_test - -import ( - sdkmodels "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/models" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin/pluginfakes" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/api/fakes" - . "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/commands" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/models" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -var _ = Describe("ListCommand", func() { - var ui *terminal.FakeUI - var cf *pluginfakes.FakeCFContext - var ccClient *fakes.FakeCCClient - var containerClient *fakes.FakeContainerClient - var cmd *List - var err error - - BeforeEach(func() { - ui = terminal.NewFakeUI() - cf = new(pluginfakes.FakeCFContext) - cf.HasAPIEndpointReturns(true) - cf.IsLoggedInReturns(true) - cf.HasTargetedSpaceReturns(true) - - context := new(pluginfakes.FakePluginContext) - context.CFReturns(cf) - - ccClient = new(fakes.FakeCCClient) - containerClient = new(fakes.FakeContainerClient) - cmd = NewList(ui, context, ccClient, containerClient) - - }) - - Context("When API endpoint not set", func() { - Context("when no fallback localized error message can be found", func() { - BeforeEach(func() { - cf.HasAPIEndpointReturns(false) - }) - - It("Should fail", func() { - err = cmd.Run([]string{}) - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal("No CF API endpoint set. Use '{{.Command}}' to target a CloudFoundry environment.")) - }) - }) - }) - - Context("When user not logged in", func() { - BeforeEach(func() { - cf.IsLoggedInReturns(false) - }) - - It("Should fail", func() { - err = cmd.Run([]string{}) - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("Not logged in")) - }) - }) - - Context("When user not target a space", func() { - BeforeEach(func() { - cf.HasTargetedSpaceReturns(false) - }) - - It("Should fail", func() { - err = cmd.Run([]string{}) - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("No space targeted")) - }) - }) - - Context("When user is logged in and a space is target", func() { - JustBeforeEach(func() { - err = cmd.Run([]string{}) - }) - - BeforeEach(func() { - cf.CurrentOrganizationReturns(sdkmodels.OrganizationFields{ - QuotaDefinition: sdkmodels.QuotaFields{ - InstanceMemoryLimitInMB: 2048, - ServicesLimit: 10, - }, - }) - - ccClient.AppsAndServicesReturns(models.AppsAndServices{ - Apps: []models.App{ - { - Name: "app1", - URLs: []string{"https://app1.example.com"}, - Memory: int64(512), - TotalInstances: 2, - RunningInstances: 1, - IsDiego: true, - State: "STARTED", - }, - { - Name: "app2", - URLs: []string{"https://app2.example.com", "https://app2.another.com"}, - Memory: int64(256), - TotalInstances: 1, - RunningInstances: 0, - IsDiego: false, - State: "STOPPED", - }, - }, - Services: []models.ServiceInstance{ - { - Name: "service1-instance1", - ServicePlan: models.ServicePlan{ - Name: "plan1", - ServiceOffering: models.ServiceOffering{ - Label: "service1", - }, - }, - }, - }, - }, nil) - - ccClient.OrgUsageReturns(models.OrgUsage{ - Org: "org1", - Spaces: []models.SpaceUsage{ - { - Space: "space1", - Apps: 2, - Services: 1, - MemoryInDev: int64(1028), - MemoryInProd: int64(512), - }, - { - Space: "space2", - Apps: 1, - Services: 1, - MemoryInDev: int64(256), - MemoryInProd: int64(0), - }, - }, - }, nil) - - containerClient.ContainersReturns([]models.Container{ - { - Name: "container1", - Group: models.ContainerGroup{ - Name: "group1", - }, - Memory: int64(256), - Created: 1484718271, - Image: "registry/image1", - State: "Running", - }, - { - Name: "container2", - Group: models.ContainerGroup{ - Name: "group1", - }, - Memory: int64(256), - Created: 1484718271, - Image: "registry/image1", - State: "Running", - }, - { - Name: "container3", - Memory: int64(512), - Created: 1484718271, - Image: "registry/image2", - State: "Shutdown", - }, - }, nil) - - containerClient.ContainersQuotaAndUsageReturns(models.ContainersQuotaAndUsage{ - Limits: models.ContainersQuota{ - InstancesCountLimit: 10, - CPUCountLimit: -1, - MemoryLimitInMB: 20480, - FloatingIpCountLimit: 2, - }, - Usage: models.ContainersUsage{ - TotalInstances: 3, - RunningInstances: 1, - CPUCount: 6, - MemoryInMB: 1024, - FloatingIpsCount: 2, - BoundFloatingIpsCount: 1, - }, - }, nil) - }) - - It("List apps", func() { - Expect(err).NotTo(HaveOccurred()) - Expect(ui.Outputs()).To(ContainSubstring("CloudFoundy Applications 1.75 GB/2 GB used")) - Expect(ui.Outputs()).To(ContainSubstring("Name Routes Memory (MB) Instances State")) - Expect(ui.Outputs()).To(ContainSubstring("app1 https://app1.example.com 512 1/2 STARTED")) - Expect(ui.Outputs()).To(ContainSubstring("app2 https://app2.example.com 256 0/1 STOPPED")) - Expect(ui.Outputs()).To(ContainSubstring(" https://app2.another.com")) - }) - - It("List services", func() { - Expect(err).NotTo(HaveOccurred()) - Expect(ui.Outputs()).To(ContainSubstring("Services 2/10 used")) - Expect(ui.Outputs()).To(ContainSubstring("Name Service Offering Plan")) - Expect(ui.Outputs()).To(ContainSubstring("service1-instance1 service1 plan1")) - }) - - It("List containers", func() { - Expect(err).NotTo(HaveOccurred()) - Expect(ui.Outputs()).To(ContainSubstring("Containers 1 GB/20 GB 2/2 Public IPs Requested|1 Used")) - Expect(ui.Outputs()).To(ContainSubstring("Name Instances Image Created Status")) - Expect(ui.Outputs()).To(ContainSubstring("group1 2 image1 -- Running")) - Expect(ui.Outputs()).To(ContainSubstring("container3 1 image2 1484718271 Shutdown")) - }) - }) -}) diff --git a/plugin_examples/list_plugin/i18n/i18n.go b/plugin_examples/list_plugin/i18n/i18n.go deleted file mode 100644 index 3a3ddde..0000000 --- a/plugin_examples/list_plugin/i18n/i18n.go +++ /dev/null @@ -1,110 +0,0 @@ -package i18n - -import ( - "os" - "path" - "path/filepath" - "strings" - - goi18n "github.com/nicksnyder/go-i18n/v2/i18n" - "golang.org/x/text/language" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/i18n" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/resources" -) - -const ( - defaultLocale = "en_US" - resourcePrefix = "all." - resourcesSuffix = ".json" -) - -var ( - bundle *goi18n.Bundle - T i18n.TranslateFunc - RESOURCE_PATH = filepath.Join("i18n", "resources") -) - -func Init(context plugin.PluginContext) i18n.TranslateFunc { - bundle = i18n.Bundle() - resource := resourcePrefix + defaultLocale + resourcesSuffix - loadAsset(filepath.Join(RESOURCE_PATH, resource)) - defaultLocalizer := goi18n.NewLocalizer(bundle, defaultLocale) - defaultTfunc := i18n.Translate(defaultLocalizer) - - supportedLocales, supportedLocalToAsssetMap := supportedLocales() - - sources := []string{ - context.Locale(), - os.Getenv("LC_ALL"), // can also use jibber_jabber.DetectIETF() - os.Getenv("LANG"), // can also use jibber_jabber.DetectLanguage() - } - - for _, source := range sources { - if source == "" { - continue - } - - // Handle chinese language variants - // (eg. Chinese (Simplified, Singapore), Chinese (Traditional, Hong Kong S.A.R.) - switch source { - case "zh-cn", "zh-sg": - source = "zh-hans" - case "zh-hk", "zh-tw": - source = "zh-hant" - } - - lang, _ := language.Parse(source) - matcher := language.NewMatcher(supportedLocales) - tag, _ := language.MatchStrings(matcher, lang.String()) - assetName, found := supportedLocalToAsssetMap[tag.String()] - - if found { - loadAsset(assetName) - localizer := goi18n.NewLocalizer(bundle, source) - - t := i18n.Translate(localizer) - return func(translationID string, args ...interface{}) string { - if translated := t(translationID, args...); translated != translationID { - return translated - } - - return defaultTfunc(translationID, args...) - } - } - } - - return defaultTfunc -} - -func supportedLocales() ([]language.Tag, map[string]string) { - l := []language.Tag{language.English} - m := make(map[string]string) - for _, assetName := range resources.AssetNames() { - // Remove the "all." prefix and ".json" suffix to get language/locale - locale := normalizeLocale(strings.TrimSuffix(path.Base(assetName), ".json")) - locale = strings.TrimPrefix(locale, "all.") - - if !strings.Contains(locale, normalizeLocale(defaultLocale)) { - lang, _ := language.Parse(locale) - l = append(l, lang) - m[lang.String()] = assetName - } - } - return l, m -} - -func normalizeLocale(locale string) string { - return strings.ToLower(strings.Replace(locale, "_", "-", -1)) -} - -func loadAsset(assetName string) { - bytes, err := resources.Asset(assetName) - if err == nil { - _, err = bundle.ParseMessageFileBytes(bytes, assetName) - } - if err != nil { - panic(err) - } -} diff --git a/plugin_examples/list_plugin/i18n/i18n_suite_test.go b/plugin_examples/list_plugin/i18n/i18n_suite_test.go deleted file mode 100644 index fe98cc7..0000000 --- a/plugin_examples/list_plugin/i18n/i18n_suite_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package i18n_test - -import ( - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -func TestI18n(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "I18n Suite") -} diff --git a/plugin_examples/list_plugin/i18n/i18n_test.go b/plugin_examples/list_plugin/i18n/i18n_test.go deleted file mode 100644 index db45520..0000000 --- a/plugin_examples/list_plugin/i18n/i18n_test.go +++ /dev/null @@ -1,187 +0,0 @@ -package i18n_test - -import ( - "fmt" - "os" - - bxi18n "github.com/IBM-Cloud/ibm-cloud-cli-sdk/i18n" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin/pluginfakes" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/i18n" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -var _ = Describe("i18n", func() { - var ( - pluginContext *pluginfakes.FakePluginContext - t bxi18n.TranslateFunc - locale string - translationID string - translatedMsg string - ) - - BeforeEach(func() { - pluginContext = new(pluginfakes.FakePluginContext) - }) - - Context("Default Config (English)", func() { - BeforeEach(func() { - pluginContext.LocaleReturns("") - }) - It("should translate message ID \"Created\" successfully in English", func() { - t = i18n.Init(pluginContext) - Expect(t("Created")).To(Equal("Created")) - }) - }) - - Context("User Config", func() { - - Context("When config is set to zh_Hans", func() { - BeforeEach(func() { - locale = "zh_Hans" - pluginContext.LocaleReturns(locale) - }) - - It("should translate message ID \"Created\" successfully", func() { - t = i18n.Init(pluginContext) - Expect(t("Created")).To(Equal("创建")) - }) - }) - }) - - Context("Environment variables", func() { - var origEnv string - Context("LC_ALL is set", func() { - BeforeEach(func() { - pluginContext.LocaleReturns("") - origEnv = os.Getenv("LC_ALL") - }) - - AfterEach(func() { - os.Setenv("LC_ALL", origEnv) - }) - - Context("When config is set to zh_Hans", func() { - BeforeEach(func() { - locale = "zh_Hans" - pluginContext.LocaleReturns("") - os.Setenv("LC_ALL", locale) - }) - - It("should translate message ID \"Created\" successfully", func() { - t = i18n.Init(pluginContext) - Expect(t("Created")).To(Equal("创建")) - }) - }) - }) - - Context("LANG is set", func() { - BeforeEach(func() { - pluginContext.LocaleReturns("") - origEnv = os.Getenv("LANG") - }) - - AfterEach(func() { - os.Setenv("LANG", origEnv) - }) - - Context("When config is set to zh_Hans", func() { - BeforeEach(func() { - locale = "zh_Hans" - pluginContext.LocaleReturns("") - os.Setenv("LANG", locale) - }) - - It("should translate message ID \"Created\" successfully", func() { - t = i18n.Init(pluginContext) - Expect(t("Created")).To(Equal("创建")) - }) - }) - }) - }) - - Context("Chinese variations", func() { - Context("When config is set to zh-cn", func() { - BeforeEach(func() { - locale = "zh-cn" - pluginContext.LocaleReturns(locale) - }) - - It("should translate message ID \"Created\" successfully using zh_Hans", func() { - t = i18n.Init(pluginContext) - Expect(t("Created")).To(Equal("创建")) - }) - }) - - Context("When config is set to zh-sg", func() { - BeforeEach(func() { - locale = "zh-sg" - pluginContext.LocaleReturns(locale) - }) - - It("should translate message ID \"Created\" successfully using zh_Hans", func() { - t = i18n.Init(pluginContext) - Expect(t("Created")).To(Equal("创建")) - }) - }) - }) - - Context("Missing translation ID in Chinese language", func() { - BeforeEach(func() { - locale = "zh_Hans" - pluginContext.LocaleReturns(locale) - }) - - Context("Translation exist in default language (English)", func() { - BeforeEach(func() { - translationID = "Test translation only in English" - translatedMsg = translationID - }) - - It("should translate message in english", func() { - t = i18n.Init(pluginContext) - Expect(t(translationID)).To(Equal(translatedMsg)) - }) - }) - }) - - Context("Translation with template", func() { - var templateData map[string]interface{} - - BeforeEach(func() { - templateData = map[string]interface{}{ - "Used": "10G", - "Limit": "500G", - } - translationID = "CloudFoundy Applications {{.Used}}/{{.Limit}} used" - }) - - Context("When locale is zh_Hans", func() { - - BeforeEach(func() { - locale = "zh_Hans" - pluginContext.LocaleReturns(locale) - }) - - It("should translate with template successfully in zh_Hans", func() { - t = i18n.Init(pluginContext) - translatedMsg = fmt.Sprintf("CloudFoundy 应用程序 %s/%s 已使用", templateData["Used"], templateData["Limit"]) - Expect(t(translationID, templateData)).To(Equal(translatedMsg)) - }) - }) - - Context("When locale is en_US", func() { - - BeforeEach(func() { - locale = "en_US" - pluginContext.LocaleReturns(locale) - }) - - It("should translate with template successfully in en_US", func() { - t = i18n.Init(pluginContext) - translatedMsg = fmt.Sprintf("CloudFoundy Applications %s/%s used", templateData["Used"], templateData["Limit"]) - Expect(t(translationID, templateData)).To(Equal(translatedMsg)) - }) - }) - }) -}) diff --git a/plugin_examples/list_plugin/i18n/resources/all.en_US.json b/plugin_examples/list_plugin/i18n/resources/all.en_US.json deleted file mode 100644 index 1aa8e8f..0000000 --- a/plugin_examples/list_plugin/i18n/resources/all.en_US.json +++ /dev/null @@ -1,86 +0,0 @@ -[ - { - "id": "CloudFoundy Applications {{.Used}}/{{.Limit}} used", - "translation": "CloudFoundy Applications {{.Used}}/{{.Limit}} used" - }, - { - "id": "Containers {{.MemoryUsed}}/{{.MemoryLimit}} {{.IPCount}}/{{.IPLimit}} Public IPs Requested|{{.BoundIPCount}} Used", - "translation": "Containers {{.MemoryUsed}}/{{.MemoryLimit}} {{.IPCount}}/{{.IPLimit}} Public IPs Requested|{{.BoundIPCount}} Used" - }, - { - "id": "Created", - "translation": "Created" - }, - { - "id": "Image", - "translation": "Image" - }, - { - "id": "Instances", - "translation": "Instances" - }, - { - "id": "Memory (MB)", - "translation": "Memory (MB)" - }, - { - "id": "Name", - "translation": "Name" - }, - { - "id": "No API endpoint set. Use '{{.Command}}' to set an endpoint.", - "translation": "No API endpoint set. Use '{{.Command}}' to set an endpoint." - }, - { - "id": "No space targeted. Use '{{.Command}}' to target an org and a space.", - "translation": "No space targeted. Use '{{.Command}}' to target an org and a space." - }, - { - "id": "Not logged in. Use '{{.Command}}' to log in.", - "translation": "Not logged in. Use '{{.Command}}' to log in." - }, - { - "id": "Plan", - "translation": "Plan" - }, - { - "id": "Routes", - "translation": "Routes" - }, - { - "id": "Service Offering", - "translation": "Service Offering" - }, - { - "id": "Services {{.Count}}/{{.Limit}} used", - "translation": "Services {{.Count}}/{{.Limit}} used" - }, - { - "id": "State", - "translation": "State" - }, - { - "id": "Status", - "translation": "Status" - }, - { - "id": "Unable to query apps and services of the target space:\n", - "translation": "Unable to query apps and services of the target space:\n" - }, - { - "id": "Unable to query containers of the target space:\n", - "translation": "Unable to query containers of the target space:\n" - }, - { - "id": "Unable to retrieve containers' usage and quota of the target space:\n", - "translation": "Unable to retrieve containers' usage and quota of the target space:\n" - }, - { - "id": "Unable to retrieve usage of the target org:\n", - "translation": "Unable to retrieve usage of the target org:\n" - }, - { - "id": "Test translation only in English", - "translation": "Test translation only in English" - } -] diff --git a/plugin_examples/list_plugin/i18n/resources/all.zh_Hans.json b/plugin_examples/list_plugin/i18n/resources/all.zh_Hans.json deleted file mode 100644 index 371513c..0000000 --- a/plugin_examples/list_plugin/i18n/resources/all.zh_Hans.json +++ /dev/null @@ -1,82 +0,0 @@ -[ - { - "id": "CloudFoundy Applications {{.Used}}/{{.Limit}} used", - "translation": "CloudFoundy 应用程序 {{.Used}}/{{.Limit}} 已使用" - }, - { - "id": "Containers {{.MemoryUsed}}/{{.MemoryLimit}} {{.IPCount}}/{{.IPLimit}} Public IPs Requested|{{.BoundIPCount}} Used", - "translation": "容器 {{.MemoryUsed}}/{{.MemoryLimit}} {{.IPCount}}/{{.IPLimit}} 公共IP地址 已请求|{{.BoundIPCount}} 已使用" - }, - { - "id": "Created", - "translation": "创建" - }, - { - "id": "Image", - "translation": "镜像" - }, - { - "id": "Instances", - "translation": "实例" - }, - { - "id": "Memory (MB)", - "translation": "内存 (MB)" - }, - { - "id": "Name", - "translation": "名称" - }, - { - "id": "No API endpoint set. Use '{{.Command}}' to set an endpoint.", - "translation": "未设置任何 API 端点。请使用“{{.Command}}”来设置端点。" - }, - { - "id": "No space targeted. Use '{{.Command}}' to target an org and a space.", - "translation": "未选择目标空间。请使用“{{.Command}}”来选择目标空间。" - }, - { - "id": "Not logged in. Use '{{.Command}}' to log in.", - "translation": "未登录。请使用 '{{.Command}}' 登录。" - }, - { - "id": "Plan", - "translation": "套餐" - }, - { - "id": "Routes", - "translation": "路由" - }, - { - "id": "Service Offering", - "translation": "服务产品" - }, - { - "id": "Services {{.Count}}/{{.Limit}} used", - "translation": "服务 {{.Count}}/{{.Limit}} 已使用" - }, - { - "id": "State", - "translation": "状态" - }, - { - "id": "Status", - "translation": "状态" - }, - { - "id": "Unable to query apps and services of the target space:\n", - "translation": "无法获取目标空间中的应用程序和服务:\n" - }, - { - "id": "Unable to query containers of the target space:\n", - "translation": "无法获取目标空间中的容器\n" - }, - { - "id": "Unable to retrieve containers' usage and quota of the target space:\n", - "translation": "无法获取目标空间中容器的使用情况和配额\n" - }, - { - "id": "Unable to retrieve usage of the target org:\n", - "translation": "无法获取目标组织中的使用情况信息\n" - } -] diff --git a/plugin_examples/list_plugin/models/models.go b/plugin_examples/list_plugin/models/models.go deleted file mode 100644 index 85917a0..0000000 --- a/plugin_examples/list_plugin/models/models.go +++ /dev/null @@ -1,101 +0,0 @@ -package models - -type AppsAndServices struct { - Apps []App - Services []ServiceInstance -} - -type App struct { - Name string - URLs []string `json:"urls"` - Memory int64 `json:"memory"` - TotalInstances int `json:"instances"` - RunningInstances int `json:"running_instances"` - IsDiego bool `json:"diego"` - State string -} - -type ServiceInstance struct { - Name string - ServicePlan ServicePlan `json:"service_plan"` -} - -type ServicePlan struct { - Name string - ServiceOffering ServiceOffering `json:"service"` -} - -type ServiceOffering struct { - Label string -} - -type OrgUsage struct { - Org string `json:"name"` - Spaces []SpaceUsage -} - -func (o OrgUsage) TotalMemoryUsed() int64 { - var sum int64 - for _, s := range o.Spaces { - sum += s.MemoryInDev + s.MemoryInProd - } - return sum -} - -func (o OrgUsage) AppsCount() int { - var sum int - for _, s := range o.Spaces { - sum += s.Apps - } - return sum -} - -func (o OrgUsage) ServicesCount() int { - var sum int - for _, s := range o.Spaces { - sum += s.Services - } - return sum -} - -type SpaceUsage struct { - Space string `json:"name"` - Apps int `json:"app_count"` - Services int `json:"service_count"` - MemoryInDev int64 `json:"mem_dev_total"` - MemoryInProd int64 `json:"mem_prod_total"` -} - -type Container struct { - Name string - Group ContainerGroup - Memory int64 - Created int64 - Image string - State string `json:"ContainerState"` -} - -type ContainerGroup struct { - Name string -} - -type ContainersQuotaAndUsage struct { - Limits ContainersQuota `json:"Limits"` - Usage ContainersUsage `json:"Usage"` -} - -type ContainersQuota struct { - InstancesCountLimit int `json:"containers"` - CPUCountLimit int `json:"vcpu"` - MemoryLimitInMB int64 `json:"memory_MB"` - FloatingIpCountLimit int `json:"floating_ips"` -} - -type ContainersUsage struct { - TotalInstances int `json:"containers"` - RunningInstances int `json:"running"` - CPUCount int `json:"vcpu"` - MemoryInMB int64 `json:"memory_MB"` - FloatingIpsCount int `json:"floating_ips"` - BoundFloatingIpsCount int `json:"floating_ips_bound"` -} diff --git a/plugin_examples/list_plugin/plugin.go b/plugin_examples/list_plugin/plugin.go deleted file mode 100644 index 014e3e1..0000000 --- a/plugin_examples/list_plugin/plugin.go +++ /dev/null @@ -1,110 +0,0 @@ -package main - -import ( - "crypto/tls" - "fmt" - "net/http" - "os" - "regexp" - "time" - - bhttp "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/http" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/terminal" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/trace" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/common/rest" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/api" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/commands" - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin_examples/list_plugin/i18n" -) - -type ListPlugin struct{} - -func (p *ListPlugin) GetMetadata() plugin.PluginMetadata { - return plugin.PluginMetadata{ - Name: "ibmcloud-list", - Version: plugin.VersionType{ - Major: 0, - Minor: 0, - Build: 1, - }, - Commands: []plugin.Command{ - { - Name: "list", - Description: "List your apps, containers and services in the target space.", - Usage: "ibmcloud list", - }, - }, - } -} - -func (p *ListPlugin) Run(context plugin.PluginContext, args []string) { - p.init(context) - - cf := context.CF() - - ui := terminal.NewStdUI() - client := &rest.Client{ - HTTPClient: NewHTTPClient(context), - DefaultHeader: DefaultHeader(cf), - } - - var err error - switch args[0] { - case "list": - err = commands.NewList(ui, - context, - api.NewCCClient(cf.APIEndpoint(), client), - api.NewContainerClient(containerEndpoint(cf.APIEndpoint()), client), - ).Run(args[1:]) - } - - if err != nil { - ui.Failed("%v\n", err) - os.Exit(1) - } -} - -func (p *ListPlugin) init(context plugin.PluginContext) { - i18n.T = i18n.Init(context) - - trace.Logger = trace.NewLogger(context.Trace()) - - terminal.UserAskedForColors = context.ColorEnabled() - terminal.InitColorSupport() -} - -func NewHTTPClient(context plugin.PluginContext) *http.Client { - transport := bhttp.NewTraceLoggingTransport( - &http.Transport{ - Proxy: http.ProxyFromEnvironment, - // #nosec G402: used for example and for some customer cases, we need to allow insecure SSL - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: context.IsSSLDisabled(), - }, - }) - - return &http.Client{ - Transport: transport, - Timeout: time.Duration(context.HTTPTimeout()) * time.Second, - } -} - -func DefaultHeader(cf plugin.CFContext) http.Header { - _, err := cf.RefreshUAAToken() - if err != nil { - fmt.Println(err.Error()) - } - - h := http.Header{} - h.Add("Authorization", cf.UAAToken()) - return h -} - -func containerEndpoint(cfAPIEndpoint string) string { - return regexp.MustCompile(`(^https?://)?[^\.]+(\..+)+`).ReplaceAllString(cfAPIEndpoint, "${1}containers-api${2}") -} - -func main() { - plugin.Start(new(ListPlugin)) -} diff --git a/plugin_examples/list_plugin/resources/i18n_resources.go b/plugin_examples/list_plugin/resources/i18n_resources.go deleted file mode 100644 index 3d8165b..0000000 --- a/plugin_examples/list_plugin/resources/i18n_resources.go +++ /dev/null @@ -1,273 +0,0 @@ -// Code generated by go-bindata. (@generated) DO NOT EDIT. - -// Package resources generated by go-bindata. -// sources: -// i18n/resources/all.en_US.json -// i18n/resources/all.zh_Hans.json -package resources - -import ( - "bytes" - "compress/gzip" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "strings" - "time" -) - -func bindataRead(data []byte, name string) ([]byte, error) { - gz, err := gzip.NewReader(bytes.NewBuffer(data)) - if err != nil { - return nil, fmt.Errorf("read %q: %v", name, err) - } - - var buf bytes.Buffer - _, err = io.Copy(&buf, gz) - clErr := gz.Close() - - if err != nil { - return nil, fmt.Errorf("read %q: %v", name, err) - } - if clErr != nil { - return nil, err - } - - return buf.Bytes(), nil -} - -type asset struct { - bytes []byte - info os.FileInfo -} - -type bindataFileInfo struct { - name string - size int64 - mode os.FileMode - modTime time.Time -} - -// Name return file name -func (fi bindataFileInfo) Name() string { - return fi.name -} - -// Size return file size -func (fi bindataFileInfo) Size() int64 { - return fi.size -} - -// Mode return file mode -func (fi bindataFileInfo) Mode() os.FileMode { - return fi.mode -} - -// ModTime return file modify time -func (fi bindataFileInfo) ModTime() time.Time { - return fi.modTime -} - -// IsDir return file whether a directory -func (fi bindataFileInfo) IsDir() bool { - return fi.mode&os.ModeDir != 0 -} - -// Sys return file is sys mode -func (fi bindataFileInfo) Sys() interface{} { - return nil -} - -var _i18nResourcesAllEn_usJson = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xc4\x94\x31\x6f\xdb\x3c\x10\x86\x77\xfd\x8a\x83\x17\x7f\x1f\x10\xa8\x7b\xb6\xc4\x68\x01\x01\x4d\x2b\xa4\xf5\xd4\x76\x60\xc4\x33\x43\x80\x3a\xca\xe4\x31\x80\xa1\xea\xbf\x17\x12\x6d\xc7\x45\x48\xdb\xb1\x87\x8e\xc6\x7b\xef\xc3\x87\x14\xcd\x1f\x05\x40\x5f\x00\x00\xcc\xb4\x9c\xdd\xc2\x6c\x61\x6c\x90\x9f\x6c\x20\xb9\x81\xbb\xae\x33\xba\x11\xac\x2d\x79\x80\xbe\x2f\x97\x1e\xe5\x30\x7c\xe8\xfb\xf2\xb3\x6e\x35\x0f\x03\x04\x8f\x72\x76\x13\x01\xec\x04\x79\x33\x8d\x5f\x4a\x2a\x00\x86\x9b\x37\x4a\x96\x58\x68\x42\x17\xab\x0f\xd8\x5a\xb7\x79\x05\xc4\xdf\x3b\xcc\x38\x51\xd5\x0b\x1b\x88\x63\x5c\xd5\xbb\xa8\x0e\x4f\x46\x37\x50\xd5\x1e\x1e\x71\x1d\xd0\x33\xca\xdf\x7d\x5f\xde\x8f\x8e\xfb\x0e\x2c\x8f\x6c\xe9\x1f\x98\xa4\x8f\xc4\xa1\xe0\xbc\xe6\x36\x4d\x56\xab\x56\x28\xcc\x14\x63\x96\xae\x91\x67\x41\x0d\xfa\x5c\x75\x9f\x27\xeb\xf1\x68\xe0\xbf\x87\xfb\xff\x33\x80\xc3\x89\x24\xe2\x8b\x68\x73\xde\x53\x94\x2e\x59\xb8\xab\x2b\x40\x92\x9d\xd5\xc4\xe0\x91\xcb\xf1\x5c\x61\xde\xf7\xe5\xc2\xb6\xad\x20\x39\x0c\x73\x60\x3b\x46\x20\x68\x3f\x5a\xe6\xd6\xba\x82\x98\x53\xf4\x9d\x68\x10\x58\x38\x85\x8c\x32\x87\x8b\xf9\x48\xb4\x4e\x81\x20\x09\x22\x36\x8f\xa8\x5e\x4d\xce\x28\x33\x18\xab\x14\x4a\xd0\x94\x83\x1a\xab\xc6\x34\xeb\xf6\x0e\x44\x52\xa2\x36\x82\x32\xf0\x29\x4a\x96\x1e\x6d\xe0\xec\x1d\xde\x86\xc9\xe2\x37\x74\x2f\xba\x41\xf8\xba\x5a\xa1\xd3\xa4\x32\x88\x37\x63\xc7\x60\x1e\xa6\x1d\xef\x1f\x88\x33\x1e\xd5\x73\x9a\xe9\x25\x59\x70\xee\xef\x13\xb3\x6c\x2d\xe4\xce\x6b\x1b\x26\x8b\x4b\x12\x4f\x06\xc7\x8f\xb8\x0e\xe8\x36\x20\xba\xce\x4f\x37\xcb\xef\x76\x60\x57\xc0\xcf\xbb\xbb\x19\xaf\xdb\xed\xcf\xdc\x17\xbd\x18\x77\x96\x5c\xf3\xfa\xae\x5f\x65\x75\x9a\x73\x42\xc7\x21\x3b\x8d\x2f\x78\x40\x9a\x43\xf0\x42\xe1\xb4\xd9\x75\xb0\x2c\x2e\x55\xbc\x86\x7d\xae\x76\xc4\xfd\x0d\xb1\x4e\xbd\x4b\xef\x08\x23\xa9\xf1\x1d\x3d\xc3\x01\x16\x2c\x99\x0d\x68\x82\x8f\xa4\x8c\xf6\xcf\x99\x95\x4f\xd6\xc6\xc5\x8a\x5f\xc5\x9f\x00\x00\x00\xff\xff\x8a\x3c\x21\x22\x22\x09\x00\x00") - -func i18nResourcesAllEn_usJsonBytes() ([]byte, error) { - return bindataRead( - _i18nResourcesAllEn_usJson, - "i18n/resources/all.en_US.json", - ) -} - -func i18nResourcesAllEn_usJson() (*asset, error) { - bytes, err := i18nResourcesAllEn_usJsonBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "i18n/resources/all.en_US.json", size: 2338, mode: os.FileMode(420), modTime: time.Unix(1665005508, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -var _i18nResourcesAllZh_hansJson = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x95\xcd\x4e\x1b\x49\x10\xc7\xef\x7e\x8a\x92\x2f\xec\x4a\xc8\x7b\xe7\x06\x48\x2b\x59\x5a\x76\x2d\x10\xa7\xdd\x3d\x34\x9e\x66\x76\xa4\x71\xb7\x99\xe9\x41\x42\xb3\x96\xcc\x87\xf9\x26\x20\x62\x87\x00\x76\x04\x51\x10\x26\x09\x36\xe4\xcb\xc1\xc6\xf0\x2e\xc4\x3d\x63\x9f\x78\x85\x68\xdc\xb1\x71\xc8\x34\x06\x85\xe3\xa8\xea\xff\x9f\x5f\x55\x57\x77\xfd\x1d\x00\xb0\x03\x00\x00\x41\x4d\x09\xf6\x41\x70\x50\xa7\x96\xf2\x3b\xb5\x88\x32\x05\xfd\xf1\xb8\xae\x45\x11\xd3\x28\x31\x01\x6c\x3b\x34\x6a\x62\x25\x91\xf8\xcd\xb6\x43\x7f\x68\x31\x8d\x25\x12\x60\x99\x58\x09\xf6\x0a\x03\x66\x20\x62\xea\xcd\xf4\xdb\x4e\xbc\x9c\x76\xd3\x79\x37\xbf\xc2\xcb\xeb\x12\x27\x5e\x7a\x57\xab\x5e\xba\xe9\x7c\x30\x00\x90\xe8\xfd\x81\x8b\x12\x86\x34\x82\x0d\x41\x32\x84\x63\xd4\x98\xba\x71\x11\xdf\x2d\x2f\x2f\x23\x1c\x19\xa4\x16\x61\x22\x1c\x8e\xb4\x42\x11\x6b\x4c\xd7\xa2\x10\x8e\x98\x30\x8c\x27\x2c\x6c\x32\xac\xfc\x6f\xdb\xa1\x01\x0f\xb4\xad\x81\x51\x79\x5d\xbc\x70\xc6\xb7\xf3\x3f\x47\xc1\x53\x6f\x79\xea\x34\x1c\xe1\xd9\x13\x9e\x4b\x7a\xb5\xd7\x8b\x25\xe7\x74\xc6\x87\xa4\x5b\x5f\x0c\x8c\x98\x9c\x75\x71\x97\x57\xca\xfe\xca\x70\x0c\xa9\x58\xa2\x6b\x64\xb2\x7c\x76\x5d\xa2\x23\x26\x43\x24\x8a\x4d\x69\x7f\x5e\xd4\x2e\x56\xfc\xb5\xa2\x41\xf0\xcb\xd0\xc0\xaf\x32\xf5\x7c\x8a\x1f\x3f\x87\xeb\xf3\xc5\xa1\x81\xeb\xf3\x25\x7f\x9b\x3f\x51\x4c\x46\xce\x37\xd6\xdc\xc3\x13\x89\x8c\x42\x7f\x24\x0c\x98\x28\x71\xaa\x11\x06\x26\x66\x21\xef\xa4\xa1\xc7\xb6\x43\x83\x34\x16\x43\x44\x49\x24\x7a\x80\x51\x2f\x04\x88\xb4\x53\x43\x92\xbf\x39\xd9\xd7\xf5\xc2\x85\x5b\x2d\xd4\x2a\x95\x5a\x35\xd3\xb4\x77\xdf\x14\xdd\x99\xb3\x2f\xc9\x99\x7a\xb1\x24\x4e\xee\x2a\x99\xed\xfc\xc1\x55\x32\xe7\xe4\x0e\x84\xae\x9d\x2c\x25\x36\xe3\x28\x8a\x81\x21\x43\xc5\x0c\x2b\x32\x5e\x11\xf7\x90\xa9\xa1\x02\x22\x0a\x20\xa1\xbc\x83\xbc\x91\x5c\x72\x56\x8e\xdc\xdd\x82\xb3\xb7\xe0\x1e\x95\x1b\x5b\x1f\xba\x42\xfb\x4a\x64\xe8\x0c\x74\xaa\xaa\x58\x01\x8d\xc8\xb0\x75\xaa\x7a\x51\x39\xa3\xbb\x5d\xe1\xd5\x4c\x27\xd7\x6d\x97\x76\x86\x3f\x46\x44\x47\x44\x36\x2a\x07\x5b\x8d\x57\x1b\xfe\xb2\x61\x6a\x31\xe9\x84\xd7\x4b\x45\x37\x7d\xea\x2f\x1c\xc1\xc6\xa4\x16\xc5\xf0\xd7\xf8\x38\x36\x34\xa2\x4a\x4b\x5b\xe3\xcb\xfb\xb5\xf2\x21\x7f\x3a\x7d\xa7\x91\x09\xcd\x72\xdb\x6f\xc8\x3d\x1e\x5e\xe1\x2d\xd1\x75\x79\x4e\x46\x18\x62\xb2\xab\xe5\x2e\x7f\x72\x92\x32\x5a\x86\x98\x25\xeb\xd7\x5d\xc2\x51\x82\xc6\x74\xec\xcd\xc2\x84\x85\x8d\x29\x40\xf1\xb8\xd9\x9c\x5f\xb3\x55\x3f\x1d\x07\xf6\x5f\xeb\x06\x88\xa1\xee\xfb\x47\x76\xa6\xce\xd6\x9e\xf3\x3e\x53\x7f\x52\xe2\xeb\xcf\x3a\xc7\xb4\xf6\xf9\xd8\xdd\x99\xeb\x5c\x43\x7c\x73\x55\x34\xca\x33\xbb\x17\x5a\xf4\x66\x05\x3d\x26\x53\x73\x9d\x74\x67\x30\x30\x33\x34\x3c\x89\x3b\x30\x7a\xc0\x32\x91\x8a\x9b\xed\x9a\xb0\x28\x43\x8f\xc6\x25\xa0\xdc\x9d\x39\x31\x2b\xce\x6c\x8a\xcf\x7f\xe4\x9b\xab\x8d\xd4\x5a\xe3\x65\xee\x01\xb0\x02\xf0\x7b\x2c\x6a\xa8\x0f\x82\xaa\xcc\xb9\x95\x05\xd1\xac\x4e\x9c\xda\xe5\xbe\x33\x5d\xfc\xc6\x12\xf8\x37\xf0\x35\x00\x00\xff\xff\xb1\x15\x45\xfe\xcb\x08\x00\x00") - -func i18nResourcesAllZh_hansJsonBytes() ([]byte, error) { - return bindataRead( - _i18nResourcesAllZh_hansJson, - "i18n/resources/all.zh_Hans.json", - ) -} - -func i18nResourcesAllZh_hansJson() (*asset, error) { - bytes, err := i18nResourcesAllZh_hansJsonBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "i18n/resources/all.zh_Hans.json", size: 2251, mode: os.FileMode(420), modTime: time.Unix(1665005508, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -// Asset loads and returns the asset for the given name. -// It returns an error if the asset could not be found or -// could not be loaded. -func Asset(name string) ([]byte, error) { - canonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[canonicalName]; ok { - a, err := f() - if err != nil { - return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) - } - return a.bytes, nil - } - return nil, fmt.Errorf("Asset %s not found", name) -} - -// MustAsset is like Asset but panics when Asset would return an error. -// It simplifies safe initialization of global variables. -func MustAsset(name string) []byte { - a, err := Asset(name) - if err != nil { - panic("asset: Asset(" + name + "): " + err.Error()) - } - - return a -} - -// AssetInfo loads and returns the asset info for the given name. -// It returns an error if the asset could not be found or -// could not be loaded. -func AssetInfo(name string) (os.FileInfo, error) { - canonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[canonicalName]; ok { - a, err := f() - if err != nil { - return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) - } - return a.info, nil - } - return nil, fmt.Errorf("AssetInfo %s not found", name) -} - -// AssetNames returns the names of the assets. -func AssetNames() []string { - names := make([]string, 0, len(_bindata)) - for name := range _bindata { - names = append(names, name) - } - return names -} - -// _bindata is a table, holding each asset generator, mapped to its name. -var _bindata = map[string]func() (*asset, error){ - "i18n/resources/all.en_US.json": i18nResourcesAllEn_usJson, - "i18n/resources/all.zh_Hans.json": i18nResourcesAllZh_hansJson, -} - -// AssetDir returns the file names below a certain -// directory embedded in the file by go-bindata. -// For example if you run go-bindata on data/... and data contains the -// following hierarchy: -// data/ -// foo.txt -// img/ -// a.png -// b.png -// then AssetDir("data") would return []string{"foo.txt", "img"} -// AssetDir("data/img") would return []string{"a.png", "b.png"} -// AssetDir("foo.txt") and AssetDir("nonexistent") would return an error -// AssetDir("") will return []string{"data"}. -func AssetDir(name string) ([]string, error) { - node := _bintree - if len(name) != 0 { - canonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(canonicalName, "/") - for _, p := range pathList { - node = node.Children[p] - if node == nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - } - } - if node.Func != nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - rv := make([]string, 0, len(node.Children)) - for childName := range node.Children { - rv = append(rv, childName) - } - return rv, nil -} - -type bintree struct { - Func func() (*asset, error) - Children map[string]*bintree -} - -var _bintree = &bintree{nil, map[string]*bintree{ - "i18n": &bintree{nil, map[string]*bintree{ - "resources": &bintree{nil, map[string]*bintree{ - "all.en_US.json": &bintree{i18nResourcesAllEn_usJson, map[string]*bintree{}}, - "all.zh_Hans.json": &bintree{i18nResourcesAllZh_hansJson, map[string]*bintree{}}, - }}, - }}, -}} - -// RestoreAsset restores an asset under the given directory -func RestoreAsset(dir, name string) error { - data, err := Asset(name) - if err != nil { - return err - } - info, err := AssetInfo(name) - if err != nil { - return err - } - err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) - if err != nil { - return err - } - err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) - if err != nil { - return err - } - err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) - if err != nil { - return err - } - return nil -} - -// RestoreAssets restores an asset under the given directory recursively -func RestoreAssets(dir, name string) error { - children, err := AssetDir(name) - // File - if err != nil { - return RestoreAsset(dir, name) - } - // Dir - for _, child := range children { - err = RestoreAssets(dir, filepath.Join(name, child)) - if err != nil { - return err - } - } - return nil -} - -func _filePath(dir, name string) string { - canonicalName := strings.Replace(name, "\\", "/", -1) - return filepath.Join(append([]string{dir}, strings.Split(canonicalName, "/")...)...) -} diff --git a/plugin_examples/namespace.go b/plugin_examples/namespace.go deleted file mode 100644 index cc8b226..0000000 --- a/plugin_examples/namespace.go +++ /dev/null @@ -1,66 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin" -) - -type NamespaceDemo struct{} - -func main() { - plugin.Start(new(NamespaceDemo)) -} - -func (n *NamespaceDemo) Run(context plugin.PluginContext, args []string) { - switch args[0] { - case "list": - fmt.Println("Running command 'list'.") - case "show": - fmt.Println("Running command 'show'.") - case "delete": - fmt.Println("Running command 'delete'.") - } -} - -func (n *NamespaceDemo) GetMetadata() plugin.PluginMetadata { - return plugin.PluginMetadata{ - Name: "namespace-sample", - Version: plugin.VersionType{ - Major: 0, - Minor: 0, - Build: 1, - }, - MinCliVersion: plugin.VersionType{ - Major: 0, - Minor: 0, - Build: 1, - }, - Namespaces: []plugin.Namespace{ - plugin.Namespace{ - Name: "ns", - Description: "Demonstrate namespace.", - }, - }, - Commands: []plugin.Command{ - { - Namespace: "ns", - Name: "list", - Description: "List resources.", - Usage: "ibmcloud ns list", - }, - { - Namespace: "ns", - Name: "show", - Description: "Show details of a resource.", - Usage: "ibmcloud ns show", - }, - { - Namespace: "ns", - Name: "delete", - Description: "Delete a resource.", - Usage: "ibmcloud ns delete", - }, - }, - } -} diff --git a/plugin_examples/stage.go b/plugin_examples/stage.go deleted file mode 100644 index b3bd329..0000000 --- a/plugin_examples/stage.go +++ /dev/null @@ -1,56 +0,0 @@ -package main - -import ( - "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin" - - "fmt" -) - -type StageDemo struct{} - -func main() { - plugin.Start(new(StageDemo)) -} - -func (n *StageDemo) Run(context plugin.PluginContext, args []string) { - switch args[0] { - case "list": - fmt.Println("Running command 'list'.") - case "show": - fmt.Println("Running command 'show'.") - } -} - -func (n *StageDemo) GetMetadata() plugin.PluginMetadata { - return plugin.PluginMetadata{ - Name: "stage-demo", - Version: plugin.VersionType{ - Major: 0, - Minor: 0, - Build: 1, - }, - Namespaces: []plugin.Namespace{ - plugin.Namespace{ - Name: "stage", - Description: "Show example of stage annotation", - Stage: plugin.StageBeta, - }, - }, - Commands: []plugin.Command{ - { - Namespace: "stage", - Name: "list", - Description: "List resources", - Usage: "ibmcloud stage list", - Stage: plugin.StageDeprecated, - }, - { - Namespace: "stage", - Name: "show", - Description: "Show the details of a resource", - Usage: "ibmcloud stage show", - Stage: plugin.StageExperimental, - }, - }, - } -} diff --git a/testhelpers/configuration/test_config.go b/testhelpers/configuration/test_config.go index 0256575..e7e1700 100644 --- a/testhelpers/configuration/test_config.go +++ b/testhelpers/configuration/test_config.go @@ -12,7 +12,6 @@ func (f *FakePersistor) Load(configuration.DataInterface) error { return nil } func (f *FakePersistor) Exists() bool { return true } func NewFakeCoreConfig() core_config.ReadWriter { - config := core_config.NewCoreConfigFromPersistor(new(FakePersistor), new(FakePersistor), func(err error) { panic(err) }) - config.CFConfig().SetAPIVersion("3") + config := core_config.NewCoreConfigFromPersistor(new(FakePersistor), func(err error) { panic(err) }) return config } From 9663f6d489495ff0a16df0f8c86d4767c5aabdc7 Mon Sep 17 00:00:00 2001 From: steveclay Date: Tue, 14 May 2024 10:01:42 -0500 Subject: [PATCH 4/6] chore: bump gomega for CVE (#403) --- go.mod | 19 +++++++----------- go.sum | 61 ++++++++++++++++++++++------------------------------------ 2 files changed, 30 insertions(+), 50 deletions(-) diff --git a/go.mod b/go.mod index f95d2ff..4ffc1b0 100644 --- a/go.mod +++ b/go.mod @@ -9,12 +9,11 @@ require ( github.com/mattn/go-colorable v0.0.0-20160210001857-9fdad7c47650 github.com/mattn/go-runewidth v0.0.0-20151118072159-d96d1bd051f2 github.com/nicksnyder/go-i18n/v2 v2.2.0 - github.com/onsi/ginkgo v1.6.0 - github.com/onsi/gomega v1.10.0 + github.com/onsi/gomega v1.33.0 github.com/spf13/cobra v1.6.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.2.2 - golang.org/x/crypto v0.17.0 + golang.org/x/crypto v0.21.0 golang.org/x/text v0.14.0 gopkg.in/cheggaaa/pb.v1 v1.0.15 gopkg.in/yaml.v2 v2.4.0 @@ -23,16 +22,12 @@ require ( require ( github.com/BurntSushi/toml v1.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/golang/protobuf v1.5.3 // indirect - github.com/hpcloud/tail v1.0.0 // indirect + github.com/google/go-cmp v0.6.0 // indirect github.com/inconshreveable/mousetrap v1.0.1 // indirect github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/sys v0.15.0 // indirect - golang.org/x/term v0.15.0 // indirect - golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect - google.golang.org/protobuf v1.33.0 // indirect - gopkg.in/fsnotify.v1 v1.4.7 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect + golang.org/x/net v0.23.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/term v0.18.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 951fa15..014842c 100644 --- a/go.sum +++ b/go.sum @@ -8,18 +8,16 @@ github.com/fatih/color v1.7.1-0.20180516100307-2d684516a886 h1:NAFoy+QgUpERgK3y1 github.com/fatih/color v1.7.1-0.20180516100307-2d684516a886/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/structs v1.0.1-0.20171020064819-f5faa72e7309 h1:e3z/5nE0uPKuqOc75vXcdV513niF/KDgDddVC8eF9MM= github.com/fatih/structs v1.0.1-0.20171020064819-f5faa72e7309/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/mattn/go-colorable v0.0.0-20160210001857-9fdad7c47650 h1:pwtfAm8Do0gwFJ2J+iUrEVR9qI03BpDSuDQCIqbd6iY= @@ -30,10 +28,10 @@ github.com/mattn/go-runewidth v0.0.0-20151118072159-d96d1bd051f2 h1:K4BQSf+ZGZ8Q github.com/mattn/go-runewidth v0.0.0-20151118072159-d96d1bd051f2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/nicksnyder/go-i18n/v2 v2.2.0 h1:MNXbyPvd141JJqlU6gJKrczThxJy+kdCNivxZpBQFkw= github.com/nicksnyder/go-i18n/v2 v2.2.0/go.mod h1:4OtLfzqyAxsscyCb//3gfqSvBc81gImX91LrZzczN1o= -github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.10.0 h1:Gwkk+PTu/nfOwNMtUB/mRUv0X7ewW5dO4AERT1ThVKo= -github.com/onsi/gomega v1.10.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= +github.com/onsi/ginkgo/v2 v2.17.1 h1:V++EzdbhI4ZV4ev0UTIj0PzhzOcReJFyJaLjtSF55M8= +github.com/onsi/ginkgo/v2 v2.17.1/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= +github.com/onsi/gomega v1.33.0 h1:snPCflnZrpMsy94p4lXVEkHo12lmPnc3vY5XBbreexE= +github.com/onsi/gomega v1.33.0/go.mod h1:+925n5YtiFsLzzafLUHzVMBpvvRAzrydIBiSIxjX3wY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -43,39 +41,26 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= -golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= +golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.15 h1:1WP0I1XIkfylrOuo3YeOAt4QXsvESM1enkg3vH6FDmI= gopkg.in/cheggaaa/pb.v1 v1.0.15/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 16e9eb636c871d98d54d29b66dd93331bd1e7ced Mon Sep 17 00:00:00 2001 From: steveclay Date: Tue, 14 May 2024 12:00:42 -0500 Subject: [PATCH 5/6] chore: bump version to 1.4.0 (#404) --- bluemix/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bluemix/version.go b/bluemix/version.go index 74497e4..929106a 100644 --- a/bluemix/version.go +++ b/bluemix/version.go @@ -3,7 +3,7 @@ package bluemix import "fmt" // Version is the SDK version -var Version = VersionType{Major: 1, Minor: 3, Build: 0} +var Version = VersionType{Major: 1, Minor: 4, Build: 0} // VersionType describe version info type VersionType struct { From 72058f3e384afb87390f58f598f63f4c95c175c6 Mon Sep 17 00:00:00 2001 From: steveclay Date: Tue, 14 May 2024 12:14:51 -0500 Subject: [PATCH 6/6] Bump go version for CVEs (#406) * Bump go version for CVEs * Bump go used by travis --- .travis.yml | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f8bfd17..7cf6aea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go dist: focal go: -- '1.21.x' +- '1.22.x' addons: apt: packages: diff --git a/go.mod b/go.mod index 4ffc1b0..5d94099 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/IBM-Cloud/ibm-cloud-cli-sdk -go 1.21 +go 1.22.3 require ( github.com/fatih/color v1.7.1-0.20180516100307-2d684516a886