forked from cloudfoundry-community/cloudfoundry-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
domain.go
75 lines (61 loc) · 2.1 KB
/
domain.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package v2actions
import "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
// Domain represents a CLI Domain.
type Domain ccv2.Domain
// DomainNotFoundError is an error wrapper that represents the case
// when the domain is not found.
type DomainNotFoundError struct{}
// Error method to display the error message.
func (e DomainNotFoundError) Error() string {
return "Domain not found."
}
func isResourceNotFoundError(err error) bool {
_, isResourceNotFound := err.(ccv2.ResourceNotFoundError)
return isResourceNotFound
}
// GetDomain returns the shared or private domain associated with the provided
// Domain GUID.
func (actor Actor) GetDomain(domainGUID string) (Domain, Warnings, error) {
var allWarnings Warnings
domain, warnings, err := actor.GetSharedDomain(domainGUID)
allWarnings = append(allWarnings, warnings...)
switch err.(type) {
case nil:
return domain, allWarnings, nil
case DomainNotFoundError:
default:
return Domain{}, allWarnings, err
}
domain, warnings, err = actor.GetPrivateDomain(domainGUID)
allWarnings = append(allWarnings, warnings...)
switch err.(type) {
case nil:
return domain, allWarnings, nil
default:
return Domain{}, allWarnings, err
}
}
// GetSharedDomain returns the shared domain associated with the provided
// Domain GUID.
func (actor Actor) GetSharedDomain(domainGUID string) (Domain, Warnings, error) {
domain, warnings, err := actor.CloudControllerClient.GetSharedDomain(domainGUID)
if err == nil {
return Domain(domain), Warnings(warnings), nil
}
if isResourceNotFoundError(err) {
return Domain{}, Warnings(warnings), DomainNotFoundError{}
}
return Domain{}, Warnings(warnings), err
}
// GetPrivateDomain returns the private domain associated with the provided
// Domain GUID.
func (actor Actor) GetPrivateDomain(domainGUID string) (Domain, Warnings, error) {
domain, warnings, err := actor.CloudControllerClient.GetPrivateDomain(domainGUID)
if err == nil {
return Domain(domain), Warnings(warnings), nil
}
if isResourceNotFoundError(err) {
return Domain{}, Warnings(warnings), DomainNotFoundError{}
}
return Domain{}, Warnings(warnings), err
}