github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/identity/v3/federation/providers/requests.go (about) 1 package providers 2 3 import ( 4 "fmt" 5 6 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 7 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 8 ) 9 10 type CreateOptsBuilder interface { 11 Id() string 12 ToProviderCreateMap() (map[string]interface{}, error) 13 } 14 15 type CreateOpts struct { 16 ID string `json:"-"` 17 Description string `json:"description,omitempty"` 18 Enabled bool `json:"enabled,omitempty"` 19 } 20 21 func (opts CreateOpts) ToProviderCreateMap() (map[string]interface{}, error) { 22 return golangsdk.BuildRequestBody(opts, "identity_provider") 23 } 24 25 func (opts CreateOpts) Id() string { 26 return opts.ID 27 } 28 29 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 30 if opts.Id() == "" { 31 r.Err = fmt.Errorf("missing identity provider ID") 32 return 33 } 34 b, err := opts.ToProviderCreateMap() 35 if err != nil { 36 r.Err = fmt.Errorf("error building provider create body: %s", err) 37 } 38 _, r.Err = client.Put(providerURL(client, opts.Id()), b, &r.Body, &golangsdk.RequestOpts{ 39 OkCodes: []int{201}, 40 }) 41 return 42 } 43 44 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 45 _, r.Err = client.Get(providerURL(client, id), &r.Body, nil) 46 return 47 } 48 49 func List(client *golangsdk.ServiceClient) pagination.Pager { 50 return pagination.NewPager(client, listURL(client), func(r pagination.PageResult) pagination.Page { 51 return ProviderPage{pagination.LinkedPageBase{PageResult: r}} 52 }) 53 } 54 55 type UpdateOptsBuilder interface { 56 ToUpdateOptsMap() (map[string]interface{}, error) 57 } 58 59 type UpdateOpts struct { 60 Description string `json:"description,omitempty"` 61 Enabled *bool `json:"enabled,omitempty"` 62 } 63 64 func (opts UpdateOpts) ToUpdateOptsMap() (map[string]interface{}, error) { 65 return golangsdk.BuildRequestBody(opts, "identity_provider") 66 } 67 68 func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 69 b, err := opts.ToUpdateOptsMap() 70 if err != nil { 71 r.Err = err 72 return 73 } 74 _, r.Err = client.Patch(providerURL(client, id), b, &r.Body, &golangsdk.RequestOpts{ 75 OkCodes: []int{200}, 76 }) 77 return 78 } 79 80 func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { 81 _, r.Err = client.Delete(providerURL(client, id), nil) 82 return 83 }