yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/google/saml.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package google 16 17 import ( 18 "time" 19 20 "yunion.io/x/log" 21 "yunion.io/x/pkg/errors" 22 ) 23 24 type SOrganizationOwner struct { 25 DirectoryCustomerId string `json:"directoryCustomerId"` 26 } 27 28 type SOrganization struct { 29 OrganizationId string `json:"organizationId"` 30 DisplayName string `json:"displayName"` 31 Owner SOrganizationOwner `json:"owner"` 32 CreationTime time.Time `json:"creationTime"` 33 LifecycleState string `json:"lifecycleState"` 34 Name string `json:"name"` 35 } 36 37 // https://cloud.google.com/resource-manager/reference/rest/v1/organizations/search 38 // require Organization Viewer privilege 39 func (self *SGoogleClient) ListOrganizations() ([]SOrganization, error) { 40 resource := "organizations" 41 params := map[string]string{ 42 "pageSize": "1000", 43 } 44 resp, err := jsonRequest(self.client, "GET", GOOGLE_MANAGER_DOMAIN, "v1beta1", resource, params, nil, self.debug) 45 if err != nil { 46 return nil, errors.Wrap(err, "ListOrganizations") 47 } 48 log.Debugf("ListOrganization: %s", resp) 49 ret := make([]SOrganization, 0) 50 err = resp.Unmarshal(&ret, "organizations") 51 if err != nil { 52 return nil, errors.Wrap(err, "resp.Unmarshal") 53 } 54 return ret, nil 55 }