forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
organization.go
37 lines (29 loc) · 978 Bytes
/
organization.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
package v3action
import (
"fmt"
"net/url"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
)
// Organization represents a V3 actor organization.
type Organization ccv3.Organization
// OrganizationNotFoundError represents the error that occurs when the
// organization is not found.
type OrganizationNotFoundError struct {
Name string
}
func (e OrganizationNotFoundError) Error() string {
return fmt.Sprintf("Organization '%s' not found.", e.Name)
}
// GetOrganizationByName returns the organization with the given name.
func (actor Actor) GetOrganizationByName(name string) (Organization, Warnings, error) {
orgs, warnings, err := actor.CloudControllerClient.GetOrganizations(url.Values{
ccv3.NameFilter: []string{name},
})
if err != nil {
return Organization{}, Warnings(warnings), err
}
if len(orgs) == 0 {
return Organization{}, Warnings(warnings), OrganizationNotFoundError{Name: name}
}
return Organization(orgs[0]), Warnings(warnings), nil
}