saml.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. package google
  15. import (
  16. "time"
  17. "yunion.io/x/log"
  18. "yunion.io/x/pkg/errors"
  19. )
  20. type SOrganizationOwner struct {
  21. DirectoryCustomerId string `json:"directoryCustomerId"`
  22. }
  23. type SOrganization struct {
  24. OrganizationId string `json:"organizationId"`
  25. DisplayName string `json:"displayName"`
  26. Owner SOrganizationOwner `json:"owner"`
  27. CreationTime time.Time `json:"creationTime"`
  28. LifecycleState string `json:"lifecycleState"`
  29. Name string `json:"name"`
  30. }
  31. // https://cloud.google.com/resource-manager/reference/rest/v1/organizations/search
  32. // require Organization Viewer privilege
  33. func (self *SGoogleClient) ListOrganizations() ([]SOrganization, error) {
  34. resource := "organizations"
  35. params := map[string]string{
  36. "pageSize": "1000",
  37. }
  38. resp, err := jsonRequest(self.client, "GET", GOOGLE_MANAGER_DOMAIN, "v1beta1", resource, params, nil, self.debug)
  39. if err != nil {
  40. return nil, errors.Wrap(err, "ListOrganizations")
  41. }
  42. log.Debugf("ListOrganization: %s", resp)
  43. ret := struct {
  44. Organizations []SOrganization
  45. }{}
  46. err = resp.Unmarshal(&ret)
  47. if err != nil {
  48. return nil, errors.Wrapf(err, "resp.Unmarshal")
  49. }
  50. return ret.Organizations, nil
  51. }