github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/sharedfilesystems/v2/securityservices/requests.go (about) 1 package securityservices 2 3 import ( 4 "context" 5 6 "github.com/vnpaycloud-console/gophercloud/v2" 7 "github.com/vnpaycloud-console/gophercloud/v2/pagination" 8 ) 9 10 type SecurityServiceType string 11 12 // Valid security service types 13 const ( 14 LDAP SecurityServiceType = "ldap" 15 Kerberos SecurityServiceType = "kerberos" 16 ActiveDirectory SecurityServiceType = "active_directory" 17 ) 18 19 // CreateOptsBuilder allows extensions to add additional parameters to the 20 // Create request. 21 type CreateOptsBuilder interface { 22 ToSecurityServiceCreateMap() (map[string]any, error) 23 } 24 25 // CreateOpts contains options for creating a SecurityService. This object is 26 // passed to the securityservices.Create function. For more information about 27 // these parameters, see the SecurityService object. 28 type CreateOpts struct { 29 // The security service type. A valid value is ldap, kerberos, or active_directory 30 Type SecurityServiceType `json:"type" required:"true"` 31 // The security service name 32 Name string `json:"name,omitempty"` 33 // The security service description 34 Description string `json:"description,omitempty"` 35 // The DNS IP address that is used inside the tenant network 36 DNSIP string `json:"dns_ip,omitempty"` 37 // The security service organizational unit (OU). Minimum supported microversion for OU is 2.44. 38 OU string `json:"ou,omitempty"` 39 // The security service user or group name that is used by the tenant 40 User string `json:"user,omitempty"` 41 // The user password, if you specify a user 42 Password string `json:"password,omitempty"` 43 // The security service domain 44 Domain string `json:"domain,omitempty"` 45 // The security service host name or IP address 46 Server string `json:"server,omitempty"` 47 } 48 49 // ToSecurityServicesCreateMap assembles a request body based on the contents of a 50 // CreateOpts. 51 func (opts CreateOpts) ToSecurityServiceCreateMap() (map[string]any, error) { 52 return gophercloud.BuildRequestBody(opts, "security_service") 53 } 54 55 // Create will create a new SecurityService based on the values in CreateOpts. To 56 // extract the SecurityService object from the response, call the Extract method 57 // on the CreateResult. 58 func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 59 b, err := opts.ToSecurityServiceCreateMap() 60 if err != nil { 61 r.Err = err 62 return 63 } 64 resp, err := client.Post(ctx, createURL(client), b, &r.Body, &gophercloud.RequestOpts{ 65 OkCodes: []int{200}, 66 }) 67 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 68 return 69 } 70 71 // Delete will delete the existing SecurityService with the provided ID. 72 func Delete(ctx context.Context, client *gophercloud.ServiceClient, id string) (r DeleteResult) { 73 resp, err := client.Delete(ctx, deleteURL(client, id), nil) 74 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 75 return 76 } 77 78 // ListOptsBuilder allows extensions to add additional parameters to the List 79 // request. 80 type ListOptsBuilder interface { 81 ToSecurityServiceListQuery() (string, error) 82 } 83 84 // ListOpts holds options for listing SecurityServices. It is passed to the 85 // securityservices.List function. 86 type ListOpts struct { 87 // admin-only option. Set it to true to see all tenant security services. 88 AllTenants bool `q:"all_tenants"` 89 // The security service ID 90 ID string `q:"id"` 91 // The security service domain 92 Domain string `q:"domain"` 93 // The security service type. A valid value is ldap, kerberos, or active_directory 94 Type SecurityServiceType `q:"type"` 95 // The security service name 96 Name string `q:"name"` 97 // The DNS IP address that is used inside the tenant network 98 DNSIP string `q:"dns_ip"` 99 // The security service organizational unit (OU). Minimum supported microversion for OU is 2.44. 100 OU string `q:"ou"` 101 // The security service user or group name that is used by the tenant 102 User string `q:"user"` 103 // The security service host name or IP address 104 Server string `q:"server"` 105 // The ID of the share network using security services 106 ShareNetworkID string `q:"share_network_id"` 107 } 108 109 // ToSecurityServiceListQuery formats a ListOpts into a query string. 110 func (opts ListOpts) ToSecurityServiceListQuery() (string, error) { 111 q, err := gophercloud.BuildQueryString(opts) 112 return q.String(), err 113 } 114 115 // List returns SecurityServices optionally limited by the conditions provided in ListOpts. 116 func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { 117 url := listURL(client) 118 if opts != nil { 119 query, err := opts.ToSecurityServiceListQuery() 120 if err != nil { 121 return pagination.Pager{Err: err} 122 } 123 url += query 124 } 125 126 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 127 return SecurityServicePage{pagination.SinglePageBase(r)} 128 }) 129 } 130 131 // Get retrieves the SecurityService with the provided ID. To extract the SecurityService 132 // object from the response, call the Extract method on the GetResult. 133 func Get(ctx context.Context, client *gophercloud.ServiceClient, id string) (r GetResult) { 134 resp, err := client.Get(ctx, getURL(client, id), &r.Body, nil) 135 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 136 return 137 } 138 139 // UpdateOptsBuilder allows extensions to add additional parameters to the 140 // Update request. 141 type UpdateOptsBuilder interface { 142 ToSecurityServiceUpdateMap() (map[string]any, error) 143 } 144 145 // UpdateOpts contain options for updating an existing SecurityService. This object is passed 146 // to the securityservices.Update function. For more information about the parameters, see 147 // the SecurityService object. 148 type UpdateOpts struct { 149 // The security service name 150 Name *string `json:"name"` 151 // The security service description 152 Description *string `json:"description,omitempty"` 153 // The security service type. A valid value is ldap, kerberos, or active_directory 154 Type string `json:"type,omitempty"` 155 // The DNS IP address that is used inside the tenant network 156 DNSIP *string `json:"dns_ip,omitempty"` 157 // The security service organizational unit (OU). Minimum supported microversion for OU is 2.44. 158 OU *string `json:"ou,omitempty"` 159 // The security service user or group name that is used by the tenant 160 User *string `json:"user,omitempty"` 161 // The user password, if you specify a user 162 Password *string `json:"password,omitempty"` 163 // The security service domain 164 Domain *string `json:"domain,omitempty"` 165 // The security service host name or IP address 166 Server *string `json:"server,omitempty"` 167 } 168 169 // ToSecurityServiceUpdateMap assembles a request body based on the contents of an 170 // UpdateOpts. 171 func (opts UpdateOpts) ToSecurityServiceUpdateMap() (map[string]any, error) { 172 return gophercloud.BuildRequestBody(opts, "security_service") 173 } 174 175 // Update will update the SecurityService with provided information. To extract the updated 176 // SecurityService from the response, call the Extract method on the UpdateResult. 177 func Update(ctx context.Context, client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 178 b, err := opts.ToSecurityServiceUpdateMap() 179 if err != nil { 180 r.Err = err 181 return 182 } 183 resp, err := client.Put(ctx, updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{ 184 OkCodes: []int{200}, 185 }) 186 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 187 return 188 }