github.com/gophercloud/gophercloud@v1.11.0/openstack/identity/v3/extensions/ec2credentials/requests.go (about)

     1  package ec2credentials
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // List enumerates the Credentials to which the current token has access.
     9  func List(client *gophercloud.ServiceClient, userID string) pagination.Pager {
    10  	url := listURL(client, userID)
    11  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
    12  		return CredentialPage{pagination.LinkedPageBase{PageResult: r}}
    13  	})
    14  }
    15  
    16  // Get retrieves details on a single EC2 credential by ID.
    17  func Get(client *gophercloud.ServiceClient, userID string, id string) (r GetResult) {
    18  	resp, err := client.Get(getURL(client, userID, id), &r.Body, nil)
    19  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    20  	return
    21  }
    22  
    23  // CreateOpts provides options used to create an EC2 credential.
    24  type CreateOpts struct {
    25  	// TenantID is the project ID scope of the EC2 credential.
    26  	TenantID string `json:"tenant_id" required:"true"`
    27  }
    28  
    29  // ToCredentialCreateMap formats a CreateOpts into a create request.
    30  func (opts CreateOpts) ToCredentialCreateMap() (map[string]interface{}, error) {
    31  	return gophercloud.BuildRequestBody(opts, "")
    32  }
    33  
    34  // Create creates a new EC2 Credential.
    35  func Create(client *gophercloud.ServiceClient, userID string, opts CreateOpts) (r CreateResult) {
    36  	b, err := opts.ToCredentialCreateMap()
    37  	if err != nil {
    38  		r.Err = err
    39  		return
    40  	}
    41  	resp, err := client.Post(createURL(client, userID), &b, &r.Body, &gophercloud.RequestOpts{
    42  		OkCodes: []int{201},
    43  	})
    44  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    45  	return
    46  }
    47  
    48  // Delete deletes an EC2 credential.
    49  func Delete(client *gophercloud.ServiceClient, userID string, id string) (r DeleteResult) {
    50  	resp, err := client.Delete(deleteURL(client, userID, id), nil)
    51  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    52  	return
    53  }