Skip to content

Commit

Permalink
Merge pull request #266 from open-amt-cloud-toolkit/devicemaintenance
Browse files Browse the repository at this point in the history
feat: add device info maintenance
  • Loading branch information
rjbrache authored Oct 26, 2023
2 parents 5e51a7d + 4e15a09 commit 3611777
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Flags struct {
amtMaintenanceSyncClockCommand *flag.FlagSet
amtMaintenanceSyncHostnameCommand *flag.FlagSet
amtMaintenanceChangePasswordCommand *flag.FlagSet
amtMaintenanceSyncDeviceInfoCommand *flag.FlagSet
versionCommand *flag.FlagSet
flagSetAddWifiSettings *flag.FlagSet
amtCommand amt.AMTCommand
Expand All @@ -99,6 +100,7 @@ func NewFlags(args []string) *Flags {
flags.amtMaintenanceSyncClockCommand = flag.NewFlagSet("syncclock", flag.ContinueOnError)
flags.amtMaintenanceSyncHostnameCommand = flag.NewFlagSet("synchostname", flag.ContinueOnError)
flags.amtMaintenanceChangePasswordCommand = flag.NewFlagSet("changepassword", flag.ContinueOnError)
flags.amtMaintenanceSyncDeviceInfoCommand = flag.NewFlagSet("syncdeviceinfo", flag.ContinueOnError)

flags.versionCommand = flag.NewFlagSet(utils.CommandVersion, flag.ContinueOnError)
flags.versionCommand.BoolVar(&flags.JsonOutput, "json", false, "json output")
Expand Down Expand Up @@ -167,6 +169,7 @@ func (f *Flags) setupCommonFlags() {
f.amtActivateCommand,
f.amtDeactivateCommand,
f.amtMaintenanceChangePasswordCommand,
f.amtMaintenanceSyncDeviceInfoCommand,
f.amtMaintenanceSyncClockCommand,
f.amtMaintenanceSyncHostnameCommand,
f.amtMaintenanceSyncIPCommand} {
Expand Down
12 changes: 12 additions & 0 deletions internal/flags/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func (f *Flags) printMaintenanceUsage() string {
usage = usage + "Supported Maintenance Commands:\n"
usage = usage + " changepassword Change the AMT password. A random password is generated by default. Specify -static to set manually. AMT password is required\n"
usage = usage + " Example: " + executable + " maintenance changepassword -u wss://server/activate\n"
usage = usage + " syncdeviceinfo Sync device information. AMT password is required\n"
usage = usage + " Example: " + executable + " maintenance syncdeviceinfo -u wss://server/activate\n"
usage = usage + " syncclock Sync the host OS clock to AMT. AMT password is required\n"
usage = usage + " Example: " + executable + " maintenance syncclock -u wss://server/activate\n"
usage = usage + " synchostname Sync the hostname of the client to AMT. AMT password is required\n"
Expand Down Expand Up @@ -55,6 +57,9 @@ func (f *Flags) handleMaintenanceCommand() utils.ReturnCode {
case "changepassword":
rc = f.handleMaintenanceSyncChangePassword()
break
case "syncdeviceinfo":
rc = f.handleMaintenanceSyncDeviceInfo()
break
default:
f.printMaintenanceUsage()
rc = utils.IncorrectCommandLineParameters
Expand Down Expand Up @@ -90,6 +95,13 @@ func (f *Flags) handleMaintenanceSyncClock() utils.ReturnCode {
return utils.Success
}

func (f *Flags) handleMaintenanceSyncDeviceInfo() utils.ReturnCode {
if err := f.amtMaintenanceSyncDeviceInfoCommand.Parse(f.commandLineArgs[3:]); err != nil {
return utils.IncorrectCommandLineParameters
}
return utils.Success
}

func (f *Flags) handleMaintenanceSyncHostname() utils.ReturnCode {
var err error
if err = f.amtMaintenanceSyncHostnameCommand.Parse(f.commandLineArgs[3:]); err != nil {
Expand Down
11 changes: 11 additions & 0 deletions internal/flags/maintenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func TestPrintMaintenanceUsage(t *testing.T) {
usage = usage + "Supported Maintenance Commands:\n"
usage = usage + " changepassword Change the AMT password. A random password is generated by default. Specify -static to set manually. AMT password is required\n"
usage = usage + " Example: " + executable + " maintenance changepassword -u wss://server/activate\n"
usage = usage + " syncdeviceinfo Sync device information. AMT password is required\n"
usage = usage + " Example: " + executable + " maintenance syncdeviceinfo -u wss://server/activate\n"
usage = usage + " syncclock Sync the host OS clock to AMT. AMT password is required\n"
usage = usage + " Example: " + executable + " maintenance syncclock -u wss://server/activate\n"
usage = usage + " synchostname Sync the hostname of the client to AMT. AMT password is required\n"
Expand All @@ -39,6 +41,7 @@ func TestParseFlagsMaintenance(t *testing.T) {
argSyncHostname := "synchostname"
argSyncIp := "syncip"
argChangePw := "changepassword"
argSyncDeviceInfo := "syncdeviceinfo"
newPassword := trickyPassword + "123"
cmdBase := "./rpc maintenance"

Expand Down Expand Up @@ -102,6 +105,14 @@ func TestParseFlagsMaintenance(t *testing.T) {
cmdLine: cmdBase + " " + argSyncHostname + " -nope " + argUrl + " " + argCurPw,
wantResult: utils.IncorrectCommandLineParameters,
},
"should pass - syncdeviceinfo": {
cmdLine: cmdBase + " " + argSyncDeviceInfo + " " + argUrl + " " + argCurPw,
wantResult: utils.Success,
},
"should fail - syncdeviceinfo bad param": {
cmdLine: cmdBase + " " + argSyncDeviceInfo + " -nope " + argUrl + " " + argCurPw,
wantResult: utils.IncorrectCommandLineParameters,
},
"should pass - syncip no params": {
cmdLine: cmdBase + " " + argSyncIp + " " + argUrl + " " + argCurPw,
wantResult: utils.Success,
Expand Down
2 changes: 2 additions & 0 deletions pkg/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (

SubCommandAddWifiSettings = "addwifisettings"
SubCommandChangePassword = "changepassword"
SubCommandSyncDeviceInfo = "syncdeviceinfo"
SubCommandSyncClock = "syncclock"
SubCommandSyncHostname = "synchostname"
SubCommandSyncIP = "syncip"
Expand Down Expand Up @@ -96,6 +97,7 @@ const (
SyncHostnameFailed ReturnCode = 151
SyncIpFailed ReturnCode = 152
ChangePasswordFailed ReturnCode = 153
SyncDeviceInfoFailed ReturnCode = 154

// (200-299) KPMU

Expand Down

0 comments on commit 3611777

Please sign in to comment.