Skip to content

Commit

Permalink
Add option for ACL
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie-Root committed Oct 9, 2024
1 parent f822ddc commit 5878ffa
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
49 changes: 49 additions & 0 deletions cmd/acl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cmd

import (
"github.com/Charlie-Root/smcli/host"
"github.com/spf13/cobra"
)

// Parent ACL command (no direct functionality)
var AclCmd = &cobra.Command{
Use: "acl",
Short: "Manage ACL settings",
}

// Subcommand to enable ACL on the host
var EnableAclCmd = &cobra.Command{
Use: "enable <host>",
Short: "Enable ACL on the specified host",
Args: cobra.ExactArgs(1), // Expect exactly one argument for the host
Run: func(cmd *cobra.Command, args []string) {
hostName := args[0]
host.SelectHost(hostName)
host.ServerEnableACL() // Call to enable ACL on the host
},
}

// Subcommand to add an ACL entry
var AddAclCmd = &cobra.Command{
Use: "add <address> <prefix> <policy> <host>",
Short: "Add new ACL entry",
Args: cobra.ExactArgs(4), // Expect address, prefix, policy, and host as arguments
Run: func(cmd *cobra.Command, args []string) {
address := args[0]
prefix := args[1]
policy := args[2]
hostName := args[3]

host.SelectHost(hostName)
host.ServerCreateACL(address, prefix, policy) // Call to add ACL entry
},
}

func init() {
// Register subcommands under the acl command
AclCmd.AddCommand(EnableAclCmd)
AclCmd.AddCommand(AddAclCmd)

// Register acl command to the root command (assuming RootCmd is the root cobra command)
RootCmd.AddCommand(AclCmd)
}
13 changes: 13 additions & 0 deletions host/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ func ServerCreateUser(username string, password string) {

MakeRequest("POST", url, body)
}

func ServerEnableACL() {
url := fmt.Sprintf("https://%s/redfish/v1/Managers/1/Oem/Supermicro/IPAccessControl", CurrentHost.BMCAddress)
body := []byte(`{"ServiceEnabled": true}`)

MakeRequest("PATCH", url, body)
}
func ServerCreateACL(address string, netmask string, policy string) {
url := fmt.Sprintf("https://%s/redfish/v1/Managers/1/Oem/Supermicro/IPAccessControl/FilterRules", CurrentHost.BMCAddress)
body := []byte(fmt.Sprintf(`{"Address": "%s", "PrefixLength": %s, "Policy": "%s"}`, address, netmask, policy))

MakeRequest("POST", url, body)
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func main() {
rootCmd.AddCommand(cmd.MediaCmd)
rootCmd.AddCommand(cmd.BootCmd)
rootCmd.AddCommand(cmd.UserCmd)
rootCmd.AddCommand(cmd.AclCmd)


if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 5878ffa

Please sign in to comment.