2026-04-06 15:48:37 +05:30
// Copyright IBM Corp. 2020, 2026
2023-03-15 11:40:40 -04:00
// SPDX-License-Identifier: BUSL-1.1
package managedgroupscmd
import (
"fmt"
2026-10-12 10:33:41 -07:00
"repo.anhonesthost.net/CyberCoveLLC/threshold/api/managedgroups"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/cmd/base"
2023-03-15 11:40:40 -04:00
)
const (
groupNamesFlagName = "group-names"
)
type extraLdapCmdVars struct {
flagGroupNames [] string
}
func init () {
extraLdapFlagsFunc = extraLdapFlagsFuncImpl
extraLdapActionsFlagsMapFunc = extraLdapActionsFlagsMapFuncImpl
extraLdapFlagsHandlingFunc = extraLdapFlagsHandlingFuncImpl
}
func extraLdapActionsFlagsMapFuncImpl () map [ string ][] string {
return map [ string ][] string {
"create" : { groupNamesFlagName },
"update" : { groupNamesFlagName },
}
}
func ( c * LdapCommand ) extraLdapHelpFunc ( helpMap map [ string ] func () string ) string {
var helpStr string
switch c . Func {
case "create" :
helpStr = base . WrapForHelpText ([] string {
2026-10-12 10:20:06 -07:00
"Usage: threshold managed-groups create ldap [options] [args]" ,
2023-03-15 11:40:40 -04:00
"" ,
" Create a ldap-type managed group. Example:" ,
"" ,
2026-10-12 10:20:06 -07:00
` $ threshold managed-groups create ldap -group-names admin -description "Ldap managed group for ProdOps"` ,
2023-03-15 11:40:40 -04:00
"" ,
"" ,
})
case "update" :
helpStr = base . WrapForHelpText ([] string {
2026-10-12 10:20:06 -07:00
"Usage: threshold managed-groups update ldap [options] [args]" ,
2023-03-15 11:40:40 -04:00
"" ,
" Update an ldap-type managed group given its ID. Example:" ,
"" ,
2026-10-12 10:20:06 -07:00
` $ threshold managed-groups update ldap -id acctldap_1234567890 -name "devops" -description "Ldap managed group for DevOps"` ,
2023-03-15 11:40:40 -04:00
"" ,
"" ,
})
}
return helpStr + c . Flags (). Help ()
}
func extraLdapFlagsFuncImpl ( c * LdapCommand , _ * base . FlagSets , f * base . FlagSet ) {
for _ , name := range flagsLdapMap [ c . Func ] {
switch name {
case groupNamesFlagName :
f . StringSliceVar ( & base . StringSliceVar {
Name : groupNamesFlagName ,
Target : & c . flagGroupNames ,
Usage : "The LDAP group names against which an LDAP account's associated groups (discovered during login) will be evaluated to determine membership (required). May be specified multiple times" ,
})
}
}
}
func extraLdapFlagsHandlingFuncImpl ( c * LdapCommand , _ * base . FlagSets , opts * [] managedgroups . Option ) bool {
switch {
case len ( c . flagGroupNames ) == 0 :
case len ( c . flagGroupNames ) == 1 && c . flagGroupNames [ 0 ] == "null" :
c . UI . Error ( fmt . Sprintf ( "There must be at least one %q" , groupNamesFlagName ))
return false
default :
* opts = append ( * opts , managedgroups . WithLdapManagedGroupGroupNames ( c . flagGroupNames ))
}
return true
}