fix issue with pve group creation appending unused realm string
This commit is contained in:
@@ -9,7 +9,10 @@ type Pool struct {
|
||||
Templates Templates `json:"templates"`
|
||||
}
|
||||
|
||||
type Groupname struct { // proxmox typically formats as gid-realm for non pve realms
|
||||
// proxmox typically formats as gid-realm for non pve realms
|
||||
// proxmox realms are formatted without realm values
|
||||
// I assume that backends store groups by ID only and only proxmox will append the realm string
|
||||
type Groupname struct {
|
||||
GroupID string `json:"gid"`
|
||||
Realm string `json:"realm"`
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
)
|
||||
|
||||
// returns an error if the groupname format was not correct
|
||||
// TODO: handle group names with x-y format where y is not a registered realm
|
||||
// TODO: handle group names with x-y-z-... format
|
||||
func ParseGroupname(groupname string) (Groupname, error) {
|
||||
g := Groupname{}
|
||||
x := strings.Split(groupname, "-")
|
||||
|
||||
@@ -169,6 +169,7 @@ func (l LDAPClient) GetGroup(groupname common.Groupname) (common.Group, int, err
|
||||
}
|
||||
|
||||
func (l LDAPClient) NewGroup(groupname common.Groupname) (int, error) {
|
||||
// add new group by ID only
|
||||
addRequest := ldap.NewAddRequest(
|
||||
fmt.Sprintf("cn=%s,ou=groups,%s", groupname.GroupID, l.config.BaseDN), // DN
|
||||
nil, // controls
|
||||
|
||||
@@ -19,7 +19,6 @@ func NewGroup(backends *Backends, groupname common.Groupname) (int, error) {
|
||||
case "pve":
|
||||
return backends.pve.NewGroup(groupname)
|
||||
case "ldap":
|
||||
|
||||
code, err := backends.ldap.NewGroup(groupname)
|
||||
if err != nil {
|
||||
return code, err
|
||||
|
||||
@@ -98,7 +98,8 @@ func (pve ProxmoxClient) DelPool(poolname string) (int, error) {
|
||||
}
|
||||
|
||||
func (pve ProxmoxClient) NewGroup(groupname common.Groupname) (int, error) {
|
||||
err := pve.client.NewGroup(context.Background(), groupname.ToString(), "")
|
||||
// add new group ny ID only
|
||||
err := pve.client.NewGroup(context.Background(), groupname.GroupID, "")
|
||||
if proxmox.IsNotAuthorized(err) {
|
||||
return 401, err
|
||||
} else if err != nil {
|
||||
@@ -109,7 +110,7 @@ func (pve ProxmoxClient) NewGroup(groupname common.Groupname) (int, error) {
|
||||
}
|
||||
|
||||
func (pve ProxmoxClient) DelGroup(groupname common.Groupname) (int, error) {
|
||||
pvegroup, err := pve.client.Group(context.Background(), groupname.ToString())
|
||||
pvegroup, err := pve.client.Group(context.Background(), groupname.GroupID)
|
||||
if proxmox.IsNotFound(err) { // errors if group does not exist
|
||||
return 404, err
|
||||
} else if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user