github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/kms/v1/keys/requests.go (about)

     1  package keys
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	// "github.com/opentelekomcloud/gophertelekomcloud/pagination"
     6  )
     7  
     8  type CreateOpts struct {
     9  	// Alias of a CMK
    10  	KeyAlias string `json:"key_alias" required:"true"`
    11  	// CMK description
    12  	KeyDescription string `json:"key_description,omitempty"`
    13  	// Region where a CMK resides
    14  	Realm string `json:"realm,omitempty"`
    15  	// Purpose of a CMK (The default value is Encrypt_Decrypt)
    16  	KeyUsage string `json:"key_usage,omitempty"`
    17  }
    18  
    19  type DeleteOpts struct {
    20  	// ID of a CMK
    21  	KeyID string `json:"key_id" required:"true"`
    22  	// Number of days after which a CMK is scheduled to be deleted
    23  	// (The value ranges from 7 to 1096.)
    24  	PendingDays string `json:"pending_days" required:"true"`
    25  }
    26  
    27  type CancelDeleteOpts struct {
    28  	// ID of a CMK
    29  	KeyID string `json:"key_id" required:"true"`
    30  }
    31  
    32  type UpdateAliasOpts struct {
    33  	// ID of a CMK
    34  	KeyID string `json:"key_id" required:"true"`
    35  	// CMK description
    36  	KeyAlias string `json:"key_alias" required:"true"`
    37  }
    38  
    39  type UpdateDesOpts struct {
    40  	// ID of a CMK
    41  	KeyID string `json:"key_id" required:"true"`
    42  	// CMK description
    43  	KeyDescription string `json:"key_description" required:"true"`
    44  }
    45  
    46  type DataEncryptOpts struct {
    47  	// ID of a CMK
    48  	KeyID string `json:"key_id" required:"true"`
    49  	// CMK description
    50  	EncryptionContext string `json:"encryption_context,omitempty"`
    51  	// 36-byte serial number of a request message
    52  	DatakeyLength string `json:"datakey_length,omitempty"`
    53  }
    54  
    55  type EncryptDEKOpts struct {
    56  	// ID of a CMK
    57  	KeyID string `json:"key_id" required:"true"`
    58  	// CMK description
    59  	EncryptionContext string `json:"encryption_context,omitempty"`
    60  	// 36-byte serial number of a request message
    61  	DataKeyPlainLength string `json:"datakey_plain_length,omitempty"`
    62  	// Both the plaintext (64 bytes) of a DEK and the SHA-256 hash value (32 bytes)
    63  	// of the plaintext are expressed as a hexadecimal character string.
    64  	PlainText string `json:"plain_text" required:"true"`
    65  }
    66  
    67  // ListOpts holds options for listing Volumes. It is passed to the volumes.List
    68  // function.
    69  type ListOpts struct {
    70  	// State of a CMK
    71  	KeyState string `json:"key_state,omitempty"`
    72  	Limit    string `json:"limit,omitempty"`
    73  	Marker   string `json:"marker,omitempty"`
    74  }
    75  
    76  type RotationOpts struct {
    77  	// ID of a CMK
    78  	KeyID string `json:"key_id" required:"true"`
    79  	// Rotation interval of a CMK
    80  	Interval int `json:"rotation_interval"`
    81  	// 36-byte serial number of a request message
    82  	Sequence string `json:"sequence,omitempty"`
    83  }
    84  
    85  // ToKeyCreateMap assembles a request body based on the contents of a
    86  // CreateOpts.
    87  func (opts CreateOpts) ToKeyCreateMap() (map[string]interface{}, error) {
    88  	return golangsdk.BuildRequestBody(opts, "")
    89  }
    90  
    91  // ToKeyDeleteMap assembles a request body based on the contents of a
    92  // DeleteOpts.
    93  func (opts DeleteOpts) ToKeyDeleteMap() (map[string]interface{}, error) {
    94  	return golangsdk.BuildRequestBody(opts, "")
    95  }
    96  
    97  // ToKeyCancelDeleteMap assembles a request body based on the contents of a
    98  // CancelDeleteOpts.
    99  func (opts CancelDeleteOpts) ToKeyCancelDeleteMap() (map[string]interface{}, error) {
   100  	return golangsdk.BuildRequestBody(opts, "")
   101  }
   102  
   103  // ToKeyUpdateAliasMap assembles a request body based on the contents of a
   104  // UpdateAliasOpts.
   105  func (opts UpdateAliasOpts) ToKeyUpdateAliasMap() (map[string]interface{}, error) {
   106  	return golangsdk.BuildRequestBody(opts, "")
   107  }
   108  
   109  // ToKeyUpdateDesMap assembles a request body based on the contents of a
   110  // UpdateDesOpts.
   111  func (opts UpdateDesOpts) ToKeyUpdateDesMap() (map[string]interface{}, error) {
   112  	return golangsdk.BuildRequestBody(opts, "")
   113  }
   114  
   115  func (opts DataEncryptOpts) ToDataEncryptMap() (map[string]interface{}, error) {
   116  	return golangsdk.BuildRequestBody(opts, "")
   117  }
   118  
   119  func (opts EncryptDEKOpts) ToEncryptDEKMap() (map[string]interface{}, error) {
   120  	return golangsdk.BuildRequestBody(opts, "")
   121  }
   122  
   123  func (opts ListOpts) ToKeyListMap() (map[string]interface{}, error) {
   124  	return golangsdk.BuildRequestBody(opts, "")
   125  }
   126  
   127  // ToKeyRotationMap assembles a request body based on the contents of a
   128  // RotationOpts.
   129  func (opts RotationOpts) ToKeyRotationMap() (map[string]interface{}, error) {
   130  	return golangsdk.BuildRequestBody(opts, "")
   131  }
   132  
   133  type CreateOptsBuilder interface {
   134  	ToKeyCreateMap() (map[string]interface{}, error)
   135  }
   136  
   137  type DeleteOptsBuilder interface {
   138  	ToKeyDeleteMap() (map[string]interface{}, error)
   139  }
   140  
   141  type CancelDeleteOptsBuilder interface {
   142  	ToKeyCancelDeleteMap() (map[string]interface{}, error)
   143  }
   144  
   145  type UpdateAliasOptsBuilder interface {
   146  	ToKeyUpdateAliasMap() (map[string]interface{}, error)
   147  }
   148  
   149  type UpdateDesOptsBuilder interface {
   150  	ToKeyUpdateDesMap() (map[string]interface{}, error)
   151  }
   152  
   153  type DataEncryptOptsBuilder interface {
   154  	ToDataEncryptMap() (map[string]interface{}, error)
   155  }
   156  
   157  type EncryptDEKOptsBuilder interface {
   158  	ToEncryptDEKMap() (map[string]interface{}, error)
   159  }
   160  
   161  type ListOptsBuilder interface {
   162  	ToKeyListMap() (map[string]interface{}, error)
   163  }
   164  
   165  type RotationOptsBuilder interface {
   166  	ToKeyRotationMap() (map[string]interface{}, error)
   167  }
   168  
   169  // Create will create a new key based on the values in CreateOpts. To ExtractKeyInfo
   170  // the key object from the response, call the ExtractKeyInfo method on the
   171  // CreateResult.
   172  func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
   173  	b, err := opts.ToKeyCreateMap()
   174  	if err != nil {
   175  		r.Err = err
   176  		return
   177  	}
   178  	_, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{
   179  		OkCodes: []int{200},
   180  	})
   181  	return
   182  }
   183  
   184  // Get retrieves the key with the provided ID. To extract the key object
   185  // from the response, call the Extract method on the GetResult.
   186  func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
   187  	b := map[string]interface{}{"key_id": id}
   188  	_, r.Err = client.Post(getURL(client), &b, &r.Body, &golangsdk.RequestOpts{
   189  		OkCodes: []int{200},
   190  	})
   191  	return
   192  }
   193  
   194  // Delete will delete the existing key with the provided ID.
   195  func Delete(client *golangsdk.ServiceClient, opts DeleteOptsBuilder) (r DeleteResult) {
   196  	b, err := opts.ToKeyDeleteMap()
   197  	if err != nil {
   198  		r.Err = err
   199  		return
   200  	}
   201  	_, r.Err = client.Post(deleteURL(client), b, &r.Body, &golangsdk.RequestOpts{
   202  		OkCodes:      []int{200},
   203  		JSONResponse: &r.Body,
   204  	})
   205  	return
   206  }
   207  
   208  func UpdateAlias(client *golangsdk.ServiceClient, opts UpdateAliasOptsBuilder) (r UpdateAliasResult) {
   209  	b, err := opts.ToKeyUpdateAliasMap()
   210  	if err != nil {
   211  		r.Err = err
   212  		return
   213  	}
   214  	_, r.Err = client.Post(updateAliasURL(client), b, &r.Body, &golangsdk.RequestOpts{
   215  		OkCodes: []int{200},
   216  	})
   217  	return
   218  }
   219  
   220  func UpdateDes(client *golangsdk.ServiceClient, opts UpdateDesOptsBuilder) (r UpdateDesResult) {
   221  	b, err := opts.ToKeyUpdateDesMap()
   222  	if err != nil {
   223  		r.Err = err
   224  		return
   225  	}
   226  	_, r.Err = client.Post(updateDesURL(client), b, &r.Body, &golangsdk.RequestOpts{
   227  		OkCodes: []int{200},
   228  	})
   229  	return
   230  }
   231  
   232  func DataEncryptGet(client *golangsdk.ServiceClient, opts DataEncryptOptsBuilder) (r DataEncryptResult) {
   233  	b, err := opts.ToDataEncryptMap()
   234  	if err != nil {
   235  		r.Err = err
   236  		return
   237  	}
   238  	_, r.Err = client.Post(dataEncryptURL(client), b, &r.Body, &golangsdk.RequestOpts{
   239  		OkCodes: []int{200},
   240  	})
   241  	return
   242  }
   243  
   244  func DataEncryptGetWithoutPlaintext(client *golangsdk.ServiceClient, opts DataEncryptOptsBuilder) (r DataEncryptResult) {
   245  	b, err := opts.ToDataEncryptMap()
   246  	if err != nil {
   247  		r.Err = err
   248  		return
   249  	}
   250  	_, r.Err = client.Post(dataEncryptURL(client), b, &r.Body, &golangsdk.RequestOpts{
   251  		OkCodes: []int{200},
   252  	})
   253  	return
   254  }
   255  
   256  func EncryptDEKGet(client *golangsdk.ServiceClient, opts EncryptDEKOptsBuilder) (r EncryptDEKResult) {
   257  	b, err := opts.ToEncryptDEKMap()
   258  	if err != nil {
   259  		r.Err = err
   260  		return
   261  	}
   262  	_, r.Err = client.Post(encryptDEKURL(client), b, &r.Body, &golangsdk.RequestOpts{
   263  		OkCodes: []int{200},
   264  	})
   265  	return
   266  }
   267  
   268  func EnableKey(client *golangsdk.ServiceClient, id string) (r ExtractUpdateKeyStateResult) {
   269  	b := map[string]interface{}{"key_id": id}
   270  	_, r.Err = client.Post(enableKeyURL(client), b, &r.Body, &golangsdk.RequestOpts{
   271  		OkCodes: []int{200},
   272  	})
   273  	return
   274  }
   275  
   276  func DisableKey(client *golangsdk.ServiceClient, id string) (r ExtractUpdateKeyStateResult) {
   277  	b := map[string]interface{}{"key_id": id}
   278  	_, r.Err = client.Post(disableKeyURL(client), b, &r.Body, &golangsdk.RequestOpts{
   279  		OkCodes: []int{200},
   280  	})
   281  	return
   282  }
   283  
   284  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) (r ListResult) {
   285  	b, err := opts.ToKeyListMap()
   286  	if err != nil {
   287  		r.Err = err
   288  		return
   289  	}
   290  	_, r.Err = client.Post(listURL(client), b, &r.Body, &golangsdk.RequestOpts{
   291  		OkCodes: []int{200},
   292  	})
   293  	return
   294  }
   295  
   296  func ListAllKeys(client *golangsdk.ServiceClient, opts ListOptsBuilder) (r ListResult) {
   297  	b, err := opts.ToKeyListMap()
   298  	if err != nil {
   299  		r.Err = err
   300  		return
   301  	}
   302  	_, r.Err = client.Post(listURL(client), b, &r.Body, &golangsdk.RequestOpts{
   303  		OkCodes: []int{200},
   304  	})
   305  	return
   306  }
   307  
   308  func EnableKeyRotation(client *golangsdk.ServiceClient, opts RotationOptsBuilder) (r golangsdk.ErrResult) {
   309  	b, err := opts.ToKeyRotationMap()
   310  	if err != nil {
   311  		r.Err = err
   312  		return
   313  	}
   314  
   315  	_, r.Err = client.Post(enableKeyRotationURL(client), b, &r.Body, &golangsdk.RequestOpts{
   316  		OkCodes: []int{200},
   317  	})
   318  	return
   319  }
   320  
   321  func DisableKeyRotation(client *golangsdk.ServiceClient, opts RotationOptsBuilder) (r golangsdk.ErrResult) {
   322  	b, err := opts.ToKeyRotationMap()
   323  	if err != nil {
   324  		r.Err = err
   325  		return
   326  	}
   327  	_, r.Err = client.Post(disableKeyRotationURL(client), b, &r.Body, &golangsdk.RequestOpts{
   328  		OkCodes: []int{200},
   329  	})
   330  	return
   331  }
   332  
   333  func GetKeyRotationStatus(client *golangsdk.ServiceClient, opts RotationOptsBuilder) (r GetRotationResult) {
   334  	b, err := opts.ToKeyRotationMap()
   335  	if err != nil {
   336  		r.Err = err
   337  		return
   338  	}
   339  	_, r.Err = client.Post(getKeyRotationStatusURL(client), b, &r.Body, &golangsdk.RequestOpts{
   340  		OkCodes: []int{200},
   341  	})
   342  
   343  	return
   344  }
   345  
   346  func UpdateKeyRotationInterval(client *golangsdk.ServiceClient, opts RotationOptsBuilder) (r golangsdk.ErrResult) {
   347  	b, err := opts.ToKeyRotationMap()
   348  	if err != nil {
   349  		r.Err = err
   350  		return
   351  	}
   352  	_, r.Err = client.Post(updateKeyRotationIntervalURL(client), b, &r.Body, &golangsdk.RequestOpts{
   353  		OkCodes: []int{200},
   354  	})
   355  	return
   356  }
   357  
   358  // CancelDelete will cancel the scheduled deletion for a CMK only when the CMK's status is Scheduled deletion with the provided ID.
   359  func CancelDelete(client *golangsdk.ServiceClient, opts CancelDeleteOptsBuilder) (r DeleteResult) {
   360  	b, err := opts.ToKeyCancelDeleteMap()
   361  	if err != nil {
   362  		r.Err = err
   363  		return
   364  	}
   365  	_, r.Err = client.Post(cancelDeleteURL(client), b, &r.Body, &golangsdk.RequestOpts{
   366  		OkCodes:      []int{200},
   367  		JSONResponse: &r.Body,
   368  	})
   369  	return
   370  }