outposts/ldap: fix type assertion after upgrading to new API Client
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
987f03c4be
commit
88a8b7d2fa
|
@ -16,7 +16,7 @@ type LDAPGroup struct {
|
||||||
Member []string
|
Member []string
|
||||||
IsSuperuser bool
|
IsSuperuser bool
|
||||||
IsVirtualGroup bool
|
IsVirtualGroup bool
|
||||||
AKAttributes interface{}
|
AKAttributes map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lg *LDAPGroup) Entry() *ldap.Entry {
|
func (lg *LDAPGroup) Entry() *ldap.Entry {
|
||||||
|
|
|
@ -36,13 +36,12 @@ func ldapResolveTypeSingle(in interface{}) *string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func AKAttrsToLDAP(attrs interface{}) []*ldap.EntryAttribute {
|
func AKAttrsToLDAP(attrs map[string]interface{}) []*ldap.EntryAttribute {
|
||||||
attrList := []*ldap.EntryAttribute{}
|
attrList := []*ldap.EntryAttribute{}
|
||||||
if attrs == nil {
|
if attrs == nil {
|
||||||
return attrList
|
return attrList
|
||||||
}
|
}
|
||||||
a := attrs.(*map[string]interface{})
|
for attrKey, attrValue := range attrs {
|
||||||
for attrKey, attrValue := range *a {
|
|
||||||
entry := &ldap.EntryAttribute{Name: attrKey}
|
entry := &ldap.EntryAttribute{Name: attrKey}
|
||||||
switch t := attrValue.(type) {
|
switch t := attrValue.(type) {
|
||||||
case []string:
|
case []string:
|
||||||
|
|
|
@ -13,45 +13,45 @@ func Test_ldapResolveTypeSingle_nil(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAKAttrsToLDAP_String(t *testing.T) {
|
func TestAKAttrsToLDAP_String(t *testing.T) {
|
||||||
var d *map[string]interface{}
|
u := api.User{}
|
||||||
|
|
||||||
// normal string
|
// normal string
|
||||||
d = &map[string]interface{}{
|
u.Attributes = map[string]interface{}{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
}
|
}
|
||||||
assert.Equal(t, 1, len(AKAttrsToLDAP(d)))
|
assert.Equal(t, 1, len(AKAttrsToLDAP(u.Attributes)))
|
||||||
assert.Equal(t, "foo", AKAttrsToLDAP(d)[0].Name)
|
assert.Equal(t, "foo", AKAttrsToLDAP(u.Attributes)[0].Name)
|
||||||
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(d)[0].Values)
|
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(u.Attributes)[0].Values)
|
||||||
// pointer string
|
// pointer string
|
||||||
d = &map[string]interface{}{
|
u.Attributes = map[string]interface{}{
|
||||||
"foo": api.PtrString("bar"),
|
"foo": api.PtrString("bar"),
|
||||||
}
|
}
|
||||||
assert.Equal(t, 1, len(AKAttrsToLDAP(d)))
|
assert.Equal(t, 1, len(AKAttrsToLDAP(u.Attributes)))
|
||||||
assert.Equal(t, "foo", AKAttrsToLDAP(d)[0].Name)
|
assert.Equal(t, "foo", AKAttrsToLDAP(u.Attributes)[0].Name)
|
||||||
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(d)[0].Values)
|
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(u.Attributes)[0].Values)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAKAttrsToLDAP_String_List(t *testing.T) {
|
func TestAKAttrsToLDAP_String_List(t *testing.T) {
|
||||||
var d *map[string]interface{}
|
u := api.User{}
|
||||||
// string list
|
// string list
|
||||||
d = &map[string]interface{}{
|
u.Attributes = map[string]interface{}{
|
||||||
"foo": []string{"bar"},
|
"foo": []string{"bar"},
|
||||||
}
|
}
|
||||||
assert.Equal(t, 1, len(AKAttrsToLDAP(d)))
|
assert.Equal(t, 1, len(AKAttrsToLDAP(u.Attributes)))
|
||||||
assert.Equal(t, "foo", AKAttrsToLDAP(d)[0].Name)
|
assert.Equal(t, "foo", AKAttrsToLDAP(u.Attributes)[0].Name)
|
||||||
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(d)[0].Values)
|
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(u.Attributes)[0].Values)
|
||||||
// pointer string list
|
// pointer string list
|
||||||
d = &map[string]interface{}{
|
u.Attributes = map[string]interface{}{
|
||||||
"foo": &[]string{"bar"},
|
"foo": &[]string{"bar"},
|
||||||
}
|
}
|
||||||
assert.Equal(t, 1, len(AKAttrsToLDAP(d)))
|
assert.Equal(t, 1, len(AKAttrsToLDAP(u.Attributes)))
|
||||||
assert.Equal(t, "foo", AKAttrsToLDAP(d)[0].Name)
|
assert.Equal(t, "foo", AKAttrsToLDAP(u.Attributes)[0].Name)
|
||||||
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(d)[0].Values)
|
assert.Equal(t, []string{"bar"}, AKAttrsToLDAP(u.Attributes)[0].Values)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAKAttrsToLDAP_Dict(t *testing.T) {
|
func TestAKAttrsToLDAP_Dict(t *testing.T) {
|
||||||
// dict
|
// dict
|
||||||
d := &map[string]interface{}{
|
d := map[string]interface{}{
|
||||||
"foo": map[string]string{
|
"foo": map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
},
|
},
|
||||||
|
@ -64,7 +64,7 @@ func TestAKAttrsToLDAP_Dict(t *testing.T) {
|
||||||
|
|
||||||
func TestAKAttrsToLDAP_Mixed(t *testing.T) {
|
func TestAKAttrsToLDAP_Mixed(t *testing.T) {
|
||||||
// dict
|
// dict
|
||||||
d := &map[string]interface{}{
|
d := map[string]interface{}{
|
||||||
"foo": []interface{}{
|
"foo": []interface{}{
|
||||||
"foo",
|
"foo",
|
||||||
6,
|
6,
|
||||||
|
|
Reference in New Issue