github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/actor/sharedaction/check_target.go (about)

     1  package sharedaction
     2  
     3  import "code.cloudfoundry.org/cli/actor/actionerror"
     4  
     5  // CheckTarget confirms that the user is logged in. Optionally it will also
     6  // check if an organization and space are targeted.
     7  func (actor Actor) CheckTarget(targetedOrganizationRequired bool, targetedSpaceRequired bool) error {
     8  	if !actor.IsLoggedIn() {
     9  		return actionerror.NotLoggedInError{
    10  			BinaryName: actor.Config.BinaryName(),
    11  		}
    12  	}
    13  
    14  	if targetedOrganizationRequired {
    15  		if !actor.IsOrgTargeted() {
    16  			return actionerror.NoOrganizationTargetedError{
    17  				BinaryName: actor.Config.BinaryName(),
    18  			}
    19  		}
    20  
    21  		if targetedSpaceRequired {
    22  			if !actor.IsSpaceTargeted() {
    23  				return actionerror.NoSpaceTargetedError{
    24  					BinaryName: actor.Config.BinaryName(),
    25  				}
    26  			}
    27  		}
    28  	}
    29  
    30  	return nil
    31  }
    32  
    33  func (actor Actor) RequireCurrentUser() (string, error) {
    34  	if !actor.IsLoggedIn() {
    35  		return "", actionerror.NotLoggedInError{
    36  			BinaryName: actor.Config.BinaryName(),
    37  		}
    38  	}
    39  
    40  	return actor.Config.CurrentUserName()
    41  }
    42  
    43  func (actor Actor) RequireTargetedOrg() (string, error) {
    44  	if !actor.IsOrgTargeted() {
    45  		return "", actionerror.NoOrganizationTargetedError{
    46  			BinaryName: actor.Config.BinaryName(),
    47  		}
    48  	}
    49  
    50  	return actor.Config.TargetedOrganizationName(), nil
    51  }