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"`
|
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"`
|
GroupID string `json:"gid"`
|
||||||
Realm string `json:"realm"`
|
Realm string `json:"realm"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// returns an error if the groupname format was not correct
|
// 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) {
|
func ParseGroupname(groupname string) (Groupname, error) {
|
||||||
g := Groupname{}
|
g := Groupname{}
|
||||||
x := strings.Split(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) {
|
func (l LDAPClient) NewGroup(groupname common.Groupname) (int, error) {
|
||||||
|
// add new group by ID only
|
||||||
addRequest := ldap.NewAddRequest(
|
addRequest := ldap.NewAddRequest(
|
||||||
fmt.Sprintf("cn=%s,ou=groups,%s", groupname.GroupID, l.config.BaseDN), // DN
|
fmt.Sprintf("cn=%s,ou=groups,%s", groupname.GroupID, l.config.BaseDN), // DN
|
||||||
nil, // controls
|
nil, // controls
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ func NewGroup(backends *Backends, groupname common.Groupname) (int, error) {
|
|||||||
case "pve":
|
case "pve":
|
||||||
return backends.pve.NewGroup(groupname)
|
return backends.pve.NewGroup(groupname)
|
||||||
case "ldap":
|
case "ldap":
|
||||||
|
|
||||||
code, err := backends.ldap.NewGroup(groupname)
|
code, err := backends.ldap.NewGroup(groupname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return code, err
|
return code, err
|
||||||
|
|||||||
@@ -98,7 +98,8 @@ func (pve ProxmoxClient) DelPool(poolname string) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pve ProxmoxClient) NewGroup(groupname common.Groupname) (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) {
|
if proxmox.IsNotAuthorized(err) {
|
||||||
return 401, err
|
return 401, err
|
||||||
} else if err != nil {
|
} 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) {
|
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
|
if proxmox.IsNotFound(err) { // errors if group does not exist
|
||||||
return 404, err
|
return 404, err
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user