-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_target.go
51 lines (42 loc) · 1.21 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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.IsLoggedIn() {
return actionerror.NotLoggedInError{
BinaryName: actor.Config.BinaryName(),
}
}
if targetedOrganizationRequired {
if !actor.IsOrgTargeted() {
return actionerror.NoOrganizationTargetedError{
BinaryName: actor.Config.BinaryName(),
}
}
if targetedSpaceRequired {
if !actor.IsSpaceTargeted() {
return actionerror.NoSpaceTargetedError{
BinaryName: actor.Config.BinaryName(),
}
}
}
}
return nil
}
func (actor Actor) RequireCurrentUser() (string, error) {
if !actor.IsLoggedIn() {
return "", actionerror.NotLoggedInError{
BinaryName: actor.Config.BinaryName(),
}
}
return actor.Config.CurrentUserName()
}
func (actor Actor) RequireTargetedOrg() (string, error) {
if !actor.IsOrgTargeted() {
return "", actionerror.NoOrganizationTargetedError{
BinaryName: actor.Config.BinaryName(),
}
}
return actor.Config.TargetedOrganizationName(), nil
}