feat (auth/ldap): support for new ldap fields (#453)
This commit is contained in:
5 files changed
+194
-968
No files matched your search
@@ -5,6 +5,7 @@ package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
@@ -38,6 +39,8 @@ const (
|
||||
authMethodLdapAccountAttrMapsField = "account_attribute_maps"
|
||||
authMethodLdapPrimaryAuthMethodForScopeField = "is_primary_for_scope"
|
||||
authMethodLdapStateField = "state"
|
||||
authMethodLdapMaxPageSizeField = "maximum_page_size"
|
||||
authMethodLdapDerefAliasesField = "dereference_aliases"
|
||||
|
||||
// computed-only parameters
|
||||
authMethodLdapClientCertKeyHmacKey = "client_certificate_key_hmac"
|
||||
@@ -195,6 +198,17 @@ func resourceAuthMethodLdap() *schema.Resource {
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
authMethodLdapMaxPageSizeField: {
|
||||
Description: "MaximumPageSize specifies a maximum search result size to use when retrieving the authenticated user's groups (optional).",
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
authMethodLdapDerefAliasesField: {
|
||||
Description: "Control how aliases are dereferenced when performing the search. Can be one of: NeverDerefAliases, DerefInSearching, DerefFindingBaseObj, and DerefAlways (optional).",
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
// LDAP specific immutable and computed parameters
|
||||
authMethodLdapClientCertKeyHmacKey: {
|
||||
@@ -401,6 +415,18 @@ func setFromLdapAuthMethodResponseMap(d *schema.ResourceData, raw map[string]int
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if v, ok := attrs[authMethodLdapMaxPageSizeField]; ok {
|
||||
if err := d.Set(authMethodLdapMaxPageSizeField, v.(json.Number)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if v, ok := attrs[authMethodLdapDerefAliasesField]; ok {
|
||||
if err := d.Set(authMethodLdapDerefAliasesField, v.(string)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
d.SetId(raw["id"].(string))
|
||||
@@ -506,6 +532,14 @@ func resourceAuthMethodLdapCreate(ctx context.Context, d *schema.ResourceData, m
|
||||
opts = append(opts, authmethods.WithLdapAuthMethodUseTokenGroups(useTokenGrps.(bool)))
|
||||
}
|
||||
|
||||
if maxPageSize, ok := d.GetOk(authMethodLdapMaxPageSizeField); ok {
|
||||
opts = append(opts, authmethods.WithLdapAuthMethodMaximumPageSize(uint32(maxPageSize.(int))))
|
||||
}
|
||||
|
||||
if derefAliases, ok := d.GetOk(authMethodLdapDerefAliasesField); ok {
|
||||
opts = append(opts, authmethods.WithLdapAuthMethodDereferenceAliases(derefAliases.(string)))
|
||||
}
|
||||
|
||||
if rawAccountAttrMaps, ok := d.GetOk(authMethodLdapAccountAttrMapsField); ok {
|
||||
accountAttrMaps := []string{}
|
||||
for _, u := range rawAccountAttrMaps.([]interface{}) {
|
||||
@@ -785,6 +819,20 @@ func resourceAuthMethodLdapUpdate(ctx context.Context, d *schema.ResourceData, m
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange(authMethodLdapMaxPageSizeField) {
|
||||
opts = append(opts, authmethods.DefaultLdapAuthMethodMaximumPageSize())
|
||||
if maxPageSize, ok := d.GetOk(authMethodLdapMaxPageSizeField); ok {
|
||||
opts = append(opts, authmethods.WithLdapAuthMethodMaximumPageSize(uint32(maxPageSize.(int))))
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange(authMethodLdapDerefAliasesField) {
|
||||
opts = append(opts, authmethods.DefaultLdapAuthMethodDereferenceAliases())
|
||||
if derefAliases, ok := d.GetOk(authMethodLdapDerefAliasesField); ok {
|
||||
opts = append(opts, authmethods.WithLdapAuthMethodDereferenceAliases(derefAliases.(string)))
|
||||
}
|
||||
}
|
||||
|
||||
if len(opts) > 0 {
|
||||
opts = append(opts, authmethods.WithAutomaticVersioning(true))
|
||||
amur, err := amClient.Update(ctx, d.Id(), 0, opts...)
|
||||
|
||||
@@ -65,6 +65,8 @@ resource "boundary_auth_method_ldap" "test-ldap" {
|
||||
group_filter = "group-filter"
|
||||
bind_dn = "bind-dn"
|
||||
bind_password = "bind-password"
|
||||
maximum_page_size = 10
|
||||
dereference_aliases = "DerefAlways"
|
||||
use_token_groups = true
|
||||
certificates = [
|
||||
<<EOT
|
||||
@@ -112,6 +114,8 @@ resource "boundary_auth_method_ldap" "test-ldap" {
|
||||
bind_password = "bind-password-updated"
|
||||
use_token_groups = false
|
||||
state = "inactive"
|
||||
maximum_page_size = 100
|
||||
dereference_aliases = "NeverDerefAliases"
|
||||
certificates = [
|
||||
<<EOT
|
||||
%s
|
||||
@@ -160,6 +164,8 @@ func TestAccAuthMethodLdap(t *testing.T) {
|
||||
resource.TestCheckResourceAttr("boundary_auth_method_ldap.test-ldap", authMethodLdapBindDnField, "bind-dn"),
|
||||
resource.TestCheckResourceAttr("boundary_auth_method_ldap.test-ldap", authMethodLdapBindPasswordField, "bind-password"),
|
||||
resource.TestCheckResourceAttr("boundary_auth_method_ldap.test-ldap", authMethodLdapUseTokenGrpsField, "true"),
|
||||
resource.TestCheckResourceAttr("boundary_auth_method_ldap.test-ldap", authMethodLdapMaxPageSizeField, "10"),
|
||||
resource.TestCheckResourceAttr("boundary_auth_method_ldap.test-ldap", authMethodLdapDerefAliasesField, "DerefAlways"),
|
||||
testAccCheckAuthMethodAttrAryValueSet(provider, "boundary_auth_method_ldap.test-ldap", authMethodLdapCertificatesField, []string{tdCert}),
|
||||
),
|
||||
},
|
||||
@@ -187,6 +193,8 @@ func TestAccAuthMethodLdap(t *testing.T) {
|
||||
resource.TestCheckResourceAttr("boundary_auth_method_ldap.test-ldap", authMethodLdapBindDnField, "bind-dn-updated"),
|
||||
resource.TestCheckResourceAttr("boundary_auth_method_ldap.test-ldap", authMethodLdapBindPasswordField, "bind-password-updated"),
|
||||
resource.TestCheckResourceAttr("boundary_auth_method_ldap.test-ldap", authMethodLdapUseTokenGrpsField, "false"),
|
||||
resource.TestCheckResourceAttr("boundary_auth_method_ldap.test-ldap", authMethodLdapMaxPageSizeField, "100"),
|
||||
resource.TestCheckResourceAttr("boundary_auth_method_ldap.test-ldap", authMethodLdapDerefAliasesField, "NeverDerefAliases"),
|
||||
testAccCheckAuthMethodAttrAryValueSet(provider, "boundary_auth_method_ldap.test-ldap", authMethodLdapCertificatesField, []string{testAuthMethodLdapCert}),
|
||||
testAccCheckAuthMethodResourceExists(provider, "boundary_auth_method_ldap.test-ldap"),
|
||||
testAccIsPrimaryForScope(provider, "boundary_auth_method_ldap.test-ldap", true),
|
||||
|
||||
Reference in new issue
Block a user