doc.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. Package policies provides information and interaction with the policies API
  3. resource for the OpenStack Identity service.
  4. Example to List Policies
  5. listOpts := policies.ListOpts{
  6. Type: "application/json",
  7. }
  8. allPages, err := policies.List(identityClient, listOpts).AllPages()
  9. if err != nil {
  10. panic(err)
  11. }
  12. allPolicies, err := policies.ExtractPolicies(allPages)
  13. if err != nil {
  14. panic(err)
  15. }
  16. for _, policy := range allPolicies {
  17. fmt.Printf("%+v\n", policy)
  18. }
  19. Example to Create a Policy
  20. createOpts := policies.CreateOpts{
  21. Type: "application/json",
  22. Blob: []byte("{'foobar_user': 'role:compute-user'}"),
  23. Extra: map[string]interface{}{
  24. "description": "policy for foobar_user",
  25. },
  26. }
  27. policy, err := policies.Create(identityClient, createOpts).Extract()
  28. if err != nil {
  29. panic(err)
  30. }
  31. Example to Get a Policy
  32. policyID := "0fe36e73809d46aeae6705c39077b1b3"
  33. policy, err := policies.Get(identityClient, policyID).Extract()
  34. if err != nil {
  35. panic(err)
  36. }
  37. fmt.Printf("%+v\n", policy)
  38. Example to Update a Policy
  39. policyID := "0fe36e73809d46aeae6705c39077b1b3"
  40. updateOpts := policies.UpdateOpts{
  41. Type: "application/json",
  42. Blob: []byte("{'foobar_user': 'role:compute-user'}"),
  43. Extra: map[string]interface{}{
  44. "description": "policy for foobar_user",
  45. },
  46. }
  47. policy, err := policies.Update(identityClient, policyID, updateOpts).Extract()
  48. if err != nil {
  49. panic(err)
  50. }
  51. fmt.Printf("%+v\n", policy)
  52. Example to Delete a Policy
  53. policyID := "0fe36e73809d46aeae6705c39077b1b3"
  54. err := policies.Delete(identityClient, policyID).ExtractErr()
  55. if err != nil {
  56. panic(err)
  57. }
  58. */
  59. package policies