github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/imageservice/v2/members/requests.go (about) 1 package members 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 /* 9 Create member for specific image 10 11 Preconditions 12 13 * The specified images must exist. 14 * You can only add a new member to an image which 'visibility' attribute is 15 private. 16 * You must be the owner of the specified image. 17 18 Synchronous Postconditions 19 20 With correct permissions, you can see the member status of the image as 21 pending through API calls. 22 23 More details here: 24 http://developer.openstack.org/api-ref-image-v2.html#createImageMember-v2 25 */ 26 func Create(client *golangsdk.ServiceClient, id string, member string) (r CreateResult) { 27 b := map[string]interface{}{"member": member} 28 _, r.Err = client.Post(createMemberURL(client, id), b, &r.Body, &golangsdk.RequestOpts{ 29 OkCodes: []int{200}, 30 }) 31 return 32 } 33 34 // List members returns list of members for specifed image id. 35 func List(client *golangsdk.ServiceClient, id string) pagination.Pager { 36 return pagination.NewPager(client, listMembersURL(client, id), func(r pagination.PageResult) pagination.Page { 37 return MemberPage{pagination.SinglePageBase(r)} 38 }) 39 } 40 41 // Get image member details. 42 func Get(client *golangsdk.ServiceClient, imageID string, memberID string) (r DetailsResult) { 43 _, r.Err = client.Get(getMemberURL(client, imageID, memberID), &r.Body, &golangsdk.RequestOpts{OkCodes: []int{200}}) 44 return 45 } 46 47 // Delete membership for given image. Callee should be image owner. 48 func Delete(client *golangsdk.ServiceClient, imageID string, memberID string) (r DeleteResult) { 49 _, r.Err = client.Delete(deleteMemberURL(client, imageID, memberID), &golangsdk.RequestOpts{OkCodes: []int{204}}) 50 return 51 } 52 53 // UpdateOptsBuilder allows extensions to add additional attributes to the 54 // Update request. 55 type UpdateOptsBuilder interface { 56 ToImageMemberUpdateMap() (map[string]interface{}, error) 57 } 58 59 // UpdateOpts represents options to an Update request. 60 type UpdateOpts struct { 61 Status string 62 } 63 64 // ToMemberUpdateMap formats an UpdateOpts structure into a request body. 65 func (opts UpdateOpts) ToImageMemberUpdateMap() (map[string]interface{}, error) { 66 return map[string]interface{}{ 67 "status": opts.Status, 68 }, nil 69 } 70 71 // Update function updates member. 72 func Update(client *golangsdk.ServiceClient, imageID string, memberID string, opts UpdateOptsBuilder) (r UpdateResult) { 73 b, err := opts.ToImageMemberUpdateMap() 74 if err != nil { 75 r.Err = err 76 return 77 } 78 _, r.Err = client.Put(updateMemberURL(client, imageID, memberID), b, &r.Body, 79 &golangsdk.RequestOpts{OkCodes: []int{200}}) 80 return 81 }