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

     1  package ec2credentials
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // Credential represents the application credential object
     9  type Credential struct {
    10  	// UserID contains a User ID of the EC2 credential owner.
    11  	UserID string `json:"user_id"`
    12  	// TenantID contains an EC2 credential project scope.
    13  	TenantID string `json:"tenant_id"`
    14  	// Access contains an EC2 credential access UUID.
    15  	Access string `json:"access"`
    16  	// Secret contains an EC2 credential secret UUID.
    17  	Secret string `json:"secret"`
    18  	// TrustID contains an EC2 credential trust ID scope.
    19  	TrustID string `json:"trust_id"`
    20  	// Links contains referencing links to the application credential.
    21  	Links map[string]interface{} `json:"links"`
    22  }
    23  
    24  type credentialResult struct {
    25  	gophercloud.Result
    26  }
    27  
    28  // GetResult is the response from a Get operation. Call its Extract method
    29  // to interpret it as an Credential.
    30  type GetResult struct {
    31  	credentialResult
    32  }
    33  
    34  // CreateResult is the response from a Create operation. Call its Extract method
    35  // to interpret it as an Credential.
    36  type CreateResult struct {
    37  	credentialResult
    38  }
    39  
    40  // DeleteResult is the response from a Delete operation. Call its ExtractErr to
    41  // determine if the request succeeded or failed.
    42  type DeleteResult struct {
    43  	gophercloud.ErrResult
    44  }
    45  
    46  // an CredentialPage is a single page of an Credential results.
    47  type CredentialPage struct {
    48  	pagination.LinkedPageBase
    49  }
    50  
    51  // IsEmpty determines whether or not a an CredentialPage contains any results.
    52  func (r CredentialPage) IsEmpty() (bool, error) {
    53  	if r.StatusCode == 204 {
    54  		return true, nil
    55  	}
    56  
    57  	ec2Credentials, err := ExtractCredentials(r)
    58  	return len(ec2Credentials) == 0, err
    59  }
    60  
    61  // NextPageURL extracts the "next" link from the links section of the result.
    62  func (r CredentialPage) NextPageURL() (string, error) {
    63  	var s struct {
    64  		Links struct {
    65  			Next     string `json:"next"`
    66  			Previous string `json:"previous"`
    67  		} `json:"links"`
    68  	}
    69  	err := r.ExtractInto(&s)
    70  	if err != nil {
    71  		return "", err
    72  	}
    73  	return s.Links.Next, err
    74  }
    75  
    76  // Extractan Credentials returns a slice of Credentials contained in a single page of results.
    77  func ExtractCredentials(r pagination.Page) ([]Credential, error) {
    78  	var s struct {
    79  		Credentials []Credential `json:"credentials"`
    80  	}
    81  	err := (r.(CredentialPage)).ExtractInto(&s)
    82  	return s.Credentials, err
    83  }
    84  
    85  // Extract interprets any Credential results as a Credential.
    86  func (r credentialResult) Extract() (*Credential, error) {
    87  	var s struct {
    88  		Credential *Credential `json:"credential"`
    89  	}
    90  	err := r.ExtractInto(&s)
    91  	return s.Credential, err
    92  }