github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/kms/v1/keys/results.go (about)

     1  package keys
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  type commonResult struct {
     9  	golangsdk.Result
    10  }
    11  
    12  // Key contains all the information associated with a CMK.
    13  type Key struct {
    14  	// Current ID of a CMK
    15  	KeyID string `json:"key_id"`
    16  	// ID of a user domain for the key.
    17  	DomainID string `json:"domain_id"`
    18  	// Alias of a CMK
    19  	KeyAlias string `json:"key_alias"`
    20  	// Region where a CMK resides
    21  	Realm string `json:"realm"`
    22  	// Description of a CMK
    23  	KeyDescription string `json:"key_description"`
    24  	// Creation time (time stamp) of a CMK
    25  	CreationDate string `json:"creation_date"`
    26  	// Scheduled deletion time (time stamp) of a CMK
    27  	ScheduledDeletionDate string `json:"scheduled_deletion_date"`
    28  	// State of a CMK
    29  	KeyState string `json:"key_state"`
    30  	// Identification of a Master Key. The value 1 indicates a Default
    31  	// Master Key, and the value 0 indicates a CMK
    32  	DefaultKeyFlag string `json:"default_key_flag"`
    33  	// Expiration time
    34  	ExpirationTime string `json:"expiration_time"`
    35  	// Origin of a CMK. The default value is kms. The following values
    36  	// are enumerated: kms indicates that the CMK material is generated by KMS.
    37  	Origin string `json:"origin"`
    38  	//Enterprise peoject id
    39  	EnterpriseProjectID string `json:"sys_enterprise_project_id"`
    40  }
    41  
    42  type ListKey struct {
    43  	Keys       []string `json:"keys"`
    44  	KeyDetails []Key    `json:"key_details"`
    45  	NextMarker string   `json:"next_marker"`
    46  	Truncated  string   `json:"truncated"`
    47  }
    48  
    49  type DataKey struct {
    50  	// Current ID of a CMK
    51  	KeyID      string `json:"key_id"`
    52  	PlainText  string `json:"plain_text"`
    53  	CipherText string `json:"cipher_text"`
    54  }
    55  
    56  type EncryptDEK struct {
    57  	// Current ID of a CMK
    58  	KeyID         string `json:"key_id"`
    59  	DataKeyLength string `json:"datakey_length"`
    60  	CipherText    string `json:"cipher_text"`
    61  }
    62  
    63  type UpdateKeyState struct {
    64  	// Current ID of a CMK
    65  	KeyID    string `json:"key_id"`
    66  	KeyState string `json:"key_state"`
    67  }
    68  
    69  // CreateResult contains the response body and error from a Create request.
    70  type CreateResult struct {
    71  	commonResult
    72  }
    73  
    74  // GetResult contains the response body and error from a Get request.
    75  type GetResult struct {
    76  	commonResult
    77  }
    78  
    79  // DeleteResult contains the response body and error from a Delete request.
    80  type DeleteResult struct {
    81  	commonResult
    82  }
    83  
    84  // UpdateAliasResult contains the response body and error from a UpdateAlias request.
    85  type UpdateAliasResult struct {
    86  	commonResult
    87  }
    88  
    89  // UpdateDesResult contains the response body and error from a UpdateDes request.
    90  type UpdateDesResult struct {
    91  	commonResult
    92  }
    93  
    94  type DataEncryptResult struct {
    95  	commonResult
    96  }
    97  
    98  type EncryptDEKResult struct {
    99  	commonResult
   100  }
   101  
   102  type ExtractUpdateKeyStateResult struct {
   103  	commonResult
   104  }
   105  
   106  type ListResult struct {
   107  	commonResult
   108  }
   109  
   110  func (r commonResult) ExtractListKey() (*ListKey, error) {
   111  	var s *ListKey
   112  	err := r.ExtractInto(&s)
   113  	return s, err
   114  }
   115  
   116  func (r commonResult) Extract() (*Key, error) {
   117  	var s *Key
   118  	err := r.ExtractInto(&s)
   119  	return s, err
   120  }
   121  
   122  func (r commonResult) ExtractKeyInfo() (*Key, error) {
   123  	var s Key
   124  	err := r.ExtractKeyInfoInto(&s)
   125  	return &s, err
   126  }
   127  
   128  func (r commonResult) ExtractKeyInfoInto(v interface{}) error {
   129  	return r.Result.ExtractIntoStructPtr(v, "key_info")
   130  }
   131  
   132  func (r commonResult) ExtractDataKey() (*DataKey, error) {
   133  	var s *DataKey
   134  	err := r.ExtractInto(&s)
   135  	return s, err
   136  }
   137  
   138  func (r commonResult) ExtractEncryptDEK() (*EncryptDEK, error) {
   139  	var s *EncryptDEK
   140  	err := r.ExtractInto(&s)
   141  	return s, err
   142  }
   143  
   144  type KeyPage struct {
   145  	pagination.LinkedPageBase
   146  }
   147  
   148  func (r KeyPage) IsEmpty() (bool, error) {
   149  	s, err := ExtractKeys(r)
   150  	return len(s) == 0, err
   151  }
   152  
   153  func ExtractKeys(r pagination.Page) ([]Key, error) {
   154  	var s struct {
   155  		Keys []Key `json:"keys"`
   156  	}
   157  	err := (r.(KeyPage)).ExtractInto(&s)
   158  	return s.Keys, err
   159  }