func DisplayCurrentTargetInformation(config commands.Config, commandUI commands.UI) error { user, err := config.CurrentUser() if err != nil { return err } commandUI.DisplayPair("API endpoint", config.Target()) commandUI.DisplayPair("API version", config.APIVersion()) commandUI.DisplayPair("User", user.Name) commandUI.DisplayPair("Org", config.TargetedOrganization().Name) commandUI.DisplayPair("Space", config.TargetedSpace().Name) return nil }
func NewCloudControllerClient(config commands.Config) (*ccv2.CloudControllerClient, error) { if config.Target() == "" { return nil, NoAPISetError{ BinaryName: config.BinaryName(), } } client := ccv2.NewCloudControllerClient() _, err := client.TargetCF(config.Target(), config.SkipSSLValidation()) if err != nil { return nil, err } uaaClient := uaa.NewClient(client.TokenEndpoint(), config) client.WrapConnection(wrapper.NewUAAAuthentication(uaaClient)) //Retry Wrapper return client, err }
// CheckTarget confirms that the config has an API set and the user is logged // in. Optionally it will also check if an organization and space are targeted. func CheckTarget(config commands.Config, targetedOrganizationRequired bool, targetedSpaceRequired bool) error { if config.AccessToken() == "" && config.RefreshToken() == "" { return NotLoggedInError{ BinaryName: config.BinaryName(), } } if targetedOrganizationRequired { if config.TargetedOrganization().GUID == "" { return NoTargetedOrgError{ BinaryName: config.BinaryName(), } } if targetedSpaceRequired { if config.TargetedSpace().GUID == "" { return NoTargetedSpaceError{ BinaryName: config.BinaryName(), } } } } return nil }
func NewCloudControllerClient(config commands.Config) (*cloudcontrollerv2.CloudControllerClient, error) { client := cloudcontrollerv2.NewCloudControllerClient() _, err := client.TargetCF(config.Target(), config.SkipSSLValidation()) return client, err }