github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/actor/sharedaction/check_target.go (about) 1 package sharedaction 2 3 // NotLoggedInError represents the scenario when the user is not logged in. 4 type NotLoggedInError struct { 5 BinaryName string 6 } 7 8 func (e NotLoggedInError) Error() string { 9 // The error message will be replaced by a translated message, returning the 10 // empty string does not add to the translation files. 11 return "" 12 } 13 14 // NoTargetedOrganizationError represents the scenario when an org is not targeted. 15 type NoTargetedOrganizationError struct { 16 BinaryName string 17 } 18 19 func (e NoTargetedOrganizationError) Error() string { 20 // The error message will be replaced by a translated message, returning the 21 // empty string does not add to the translation files. 22 return "" 23 } 24 25 // NoTargetedSpaceError represents the scenario when a space is not targeted. 26 type NoTargetedSpaceError struct { 27 BinaryName string 28 } 29 30 func (e NoTargetedSpaceError) Error() string { 31 // The error message will be replaced by a translated message, returning the 32 // empty string does not add to the translation files. 33 return "" 34 } 35 36 // CheckTarget confirms that the user is logged in. Optionally it will also 37 // check if an organization and space are targeted. 38 func (_ Actor) CheckTarget(config Config, targetedOrganizationRequired bool, targetedSpaceRequired bool) error { 39 if config.AccessToken() == "" && config.RefreshToken() == "" { 40 return NotLoggedInError{ 41 BinaryName: config.BinaryName(), 42 } 43 } 44 45 if targetedOrganizationRequired { 46 if !config.HasTargetedOrganization() { 47 return NoTargetedOrganizationError{ 48 BinaryName: config.BinaryName(), 49 } 50 } 51 52 if targetedSpaceRequired { 53 if !config.HasTargetedSpace() { 54 return NoTargetedSpaceError{ 55 BinaryName: config.BinaryName(), 56 } 57 } 58 } 59 } 60 61 return nil 62 }