forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_target.go
31 lines (26 loc) · 849 Bytes
/
check_target.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package sharedaction
import "code.cloudfoundry.org/cli/actor/actionerror"
// CheckTarget confirms that the user is logged in. Optionally it will also
// check if an organization and space are targeted.
func (actor Actor) CheckTarget(targetedOrganizationRequired bool, targetedSpaceRequired bool) error {
if actor.Config.AccessToken() == "" && actor.Config.RefreshToken() == "" {
return actionerror.NotLoggedInError{
BinaryName: actor.Config.BinaryName(),
}
}
if targetedOrganizationRequired {
if !actor.Config.HasTargetedOrganization() {
return actionerror.NoOrganizationTargetedError{
BinaryName: actor.Config.BinaryName(),
}
}
if targetedSpaceRequired {
if !actor.Config.HasTargetedSpace() {
return actionerror.NoSpaceTargetedError{
BinaryName: actor.Config.BinaryName(),
}
}
}
}
return nil
}