github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v2/extensions/vpnaas/ikepolicies/requests.go (about)

     1  package ikepolicies
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     6  )
     7  
     8  type AuthAlgorithm string
     9  type EncryptionAlgorithm string
    10  type PFS string
    11  type Unit string
    12  type IKEVersion string
    13  type Phase1NegotiationMode string
    14  
    15  const (
    16  	AuthAlgorithmMD5          AuthAlgorithm         = "md5"
    17  	AuthAlgorithmSHA1         AuthAlgorithm         = "sha1"
    18  	AuthAlgorithmSHA256       AuthAlgorithm         = "sha2-256"
    19  	AuthAlgorithmSHA384       AuthAlgorithm         = "sha2-384"
    20  	AuthAlgorithmSHA512       AuthAlgorithm         = "sha2-512"
    21  	EncryptionAlgorithm3DES   EncryptionAlgorithm   = "3des"
    22  	EncryptionAlgorithmAES128 EncryptionAlgorithm   = "aes-128"
    23  	EncryptionAlgorithmAES256 EncryptionAlgorithm   = "aes-256"
    24  	EncryptionAlgorithmAES192 EncryptionAlgorithm   = "aes-192"
    25  	UnitSeconds               Unit                  = "seconds"
    26  	UnitKilobytes             Unit                  = "kilobytes"
    27  	PFSGroup2                 PFS                   = "group2"
    28  	PFSGroup5                 PFS                   = "group5"
    29  	PFSGroup14                PFS                   = "group14"
    30  	IKEVersionv1              IKEVersion            = "v1"
    31  	IKEVersionv2              IKEVersion            = "v2"
    32  	Phase1NegotiationModeMain Phase1NegotiationMode = "main"
    33  )
    34  
    35  // CreateOptsBuilder allows extensions to add additional parameters to the
    36  // Create request.
    37  type CreateOptsBuilder interface {
    38  	ToPolicyCreateMap() (map[string]interface{}, error)
    39  }
    40  
    41  // CreateOpts contains all the values needed to create a new IKE policy
    42  type CreateOpts struct {
    43  	// TenantID specifies a tenant to own the IKE policy. The caller must have
    44  	// an admin role in order to set this. Otherwise, this field is left unset
    45  	// and the caller will be the owner.
    46  	TenantID string `json:"tenant_id,omitempty"`
    47  
    48  	// Description is the human readable description of the policy.
    49  	Description string `json:"description,omitempty"`
    50  
    51  	// Name is the human readable name of the policy.
    52  	// Does not have to be unique.
    53  	Name string `json:"name,omitempty"`
    54  
    55  	// AuthAlgorithm is the authentication hash algorithm.
    56  	// Valid values are sha1, sha256, sha384, sha512.
    57  	// The default is sha1.
    58  	AuthAlgorithm AuthAlgorithm `json:"auth_algorithm,omitempty"`
    59  
    60  	// EncryptionAlgorithm is the encryption algorithm.
    61  	// A valid value is 3des, aes-128, aes-192, aes-256, and so on.
    62  	// Default is aes-128.
    63  	EncryptionAlgorithm EncryptionAlgorithm `json:"encryption_algorithm,omitempty"`
    64  
    65  	// PFS is the Perfect forward secrecy mode.
    66  	// A valid value is Group1, Group2, Group5, Group14, and so on.
    67  	// Default is Group5.
    68  	PFS PFS `json:"pfs,omitempty"`
    69  
    70  	// The IKE mode.
    71  	// A valid value is main, which is the default.
    72  	Phase1NegotiationMode Phase1NegotiationMode `json:"phase1_negotiation_mode,omitempty"`
    73  
    74  	// The IKE version.
    75  	// A valid values are v1 v2.
    76  	// Default is v1.
    77  	IKEVersion IKEVersion `json:"ike_version,omitempty"`
    78  
    79  	// Lifetime is the lifetime of the security association
    80  	Lifetime *LifetimeCreateOpts `json:"lifetime,omitempty"`
    81  }
    82  
    83  // The lifetime consists of a unit and integer value
    84  // You can omit either the unit or value portion of the lifetime
    85  type LifetimeCreateOpts struct {
    86  	// Units is the units for the lifetime of the security association
    87  	// Default unit is seconds
    88  	Units Unit `json:"units,omitempty"`
    89  
    90  	// The lifetime value.
    91  	// Must be a positive integer.
    92  	// Default value is 3600.
    93  	Value int `json:"value,omitempty"`
    94  }
    95  
    96  // ToPolicyCreateMap casts a CreateOpts struct to a map.
    97  func (opts CreateOpts) ToPolicyCreateMap() (map[string]interface{}, error) {
    98  	return golangsdk.BuildRequestBody(opts, "ikepolicy")
    99  }
   100  
   101  // Create accepts a CreateOpts struct and uses the values to create a new
   102  // IKE policy
   103  func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
   104  	b, err := opts.ToPolicyCreateMap()
   105  	if err != nil {
   106  		r.Err = err
   107  		return
   108  	}
   109  	_, r.Err = c.Post(rootURL(c), b, &r.Body, nil)
   110  	return
   111  }
   112  
   113  // Get retrieves a particular IKE policy based on its unique ID.
   114  func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
   115  	_, r.Err = c.Get(resourceURL(c, id), &r.Body, nil)
   116  	return
   117  }
   118  
   119  // Delete will permanently delete a particular IKE policy based on its
   120  // unique ID.
   121  func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) {
   122  	_, r.Err = c.Delete(resourceURL(c, id), nil)
   123  	return
   124  }
   125  
   126  // ListOptsBuilder allows extensions to add additional parameters to the
   127  // List request.
   128  type ListOptsBuilder interface {
   129  	ToPolicyListQuery() (string, error)
   130  }
   131  
   132  // ListOpts allows the filtering of paginated collections through
   133  // the API. Filtering is achieved by passing in struct field values that map to
   134  // the IKE policy attributes you want to see returned.
   135  type ListOpts struct {
   136  	TenantID              string `q:"tenant_id"`
   137  	Name                  string `q:"name"`
   138  	Description           string `q:"description"`
   139  	ProjectID             string `q:"project_id"`
   140  	AuthAlgorithm         string `q:"auth_algorithm"`
   141  	EncapsulationMode     string `q:"encapsulation_mode"`
   142  	EncryptionAlgorithm   string `q:"encryption_algorithm"`
   143  	PFS                   string `q:"pfs"`
   144  	Phase1NegotiationMode string `q:"phase_1_negotiation_mode"`
   145  	IKEVersion            string `q:"ike_version"`
   146  }
   147  
   148  // ToPolicyListQuery formats a ListOpts into a query string.
   149  func (opts ListOpts) ToPolicyListQuery() (string, error) {
   150  	q, err := golangsdk.BuildQueryString(opts)
   151  	if err != nil {
   152  		return "", err
   153  	}
   154  	return q.String(), err
   155  }
   156  
   157  // List returns a Pager which allows you to iterate over a collection of
   158  // IKE policies. It accepts a ListOpts struct, which allows you to filter
   159  // the returned collection for greater efficiency.
   160  func List(c *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
   161  	url := rootURL(c)
   162  	if opts != nil {
   163  		query, err := opts.ToPolicyListQuery()
   164  		if err != nil {
   165  			return pagination.Pager{Err: err}
   166  		}
   167  		url += query
   168  	}
   169  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
   170  		return PolicyPage{pagination.LinkedPageBase{PageResult: r}}
   171  	})
   172  }
   173  
   174  // UpdateOptsBuilder allows extensions to add additional parameters to the
   175  // Update request.
   176  type UpdateOptsBuilder interface {
   177  	ToPolicyUpdateMap() (map[string]interface{}, error)
   178  }
   179  
   180  type LifetimeUpdateOpts struct {
   181  	Units Unit `json:"units,omitempty"`
   182  	Value int  `json:"value,omitempty"`
   183  }
   184  
   185  // UpdateOpts contains the values used when updating an IKE policy
   186  type UpdateOpts struct {
   187  	Description           string                `json:"description,omitempty"`
   188  	Name                  string                `json:"name,omitempty"`
   189  	AuthAlgorithm         AuthAlgorithm         `json:"auth_algorithm,omitempty"`
   190  	EncryptionAlgorithm   EncryptionAlgorithm   `json:"encryption_algorithm,omitempty"`
   191  	PFS                   PFS                   `json:"pfs,omitempty"`
   192  	Lifetime              *LifetimeUpdateOpts   `json:"lifetime,omitempty"`
   193  	Phase1NegotiationMode Phase1NegotiationMode `json:"phase_1_negotiation_mode,omitempty"`
   194  	IKEVersion            IKEVersion            `json:"ike_version,omitempty"`
   195  }
   196  
   197  // ToPolicyUpdateMap casts an UpdateOpts struct to a map.
   198  func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) {
   199  	return golangsdk.BuildRequestBody(opts, "ikepolicy")
   200  }
   201  
   202  // Update allows IKE policies to be updated.
   203  func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
   204  	b, err := opts.ToPolicyUpdateMap()
   205  	if err != nil {
   206  		r.Err = err
   207  		return
   208  	}
   209  	_, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{
   210  		OkCodes: []int{200},
   211  	})
   212  	return
   213  }