Skip to content

Commit

Permalink
refactor: result codes (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-shockley authored Aug 9, 2023
1 parent 4774bd5 commit 5a8d8a8
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 43 deletions.
2 changes: 1 addition & 1 deletion cmd/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func rpcExec(Input *C.char, Output **C.char) int {
args, err := r.Read()
if err != nil {
log.Error(err.Error())
return utils.InvalidParameters
return utils.InvalidParameterCombination
}
args = append([]string{"rpc"}, args...)
runStatus := runRPC(args)
Expand Down
4 changes: 2 additions & 2 deletions internal/flags/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func (f *Flags) handleActivateCommand() int {
}
if f.Local && f.URL != "" {
fmt.Println("provide either a 'url' or a 'local', but not both")
return utils.InvalidParameters
return utils.InvalidParameterCombination
}
//if f.Local {
// if !f.UseCCM && !f.UseACM || f.UseCCM && f.UseACM {
// fmt.Println("must specify -ccm or -acm, but not both")
// return false, utils.InvalidParameters
// return false, utils.InvalidParameterCombination
// }
//}

Expand Down
2 changes: 1 addition & 1 deletion internal/flags/activate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestHandleActivateCommandBothURLandLocal(t *testing.T) {
args := []string{"./rpc", "activate", "-u", "wss://localhost", "-local"}
flags := NewFlags(args)
success := flags.ParseFlags()
assert.EqualValues(t, success, utils.InvalidParameters)
assert.EqualValues(t, success, utils.InvalidParameterCombination)
}

func TestHandleActivateCommandNoURL(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/flags/deactivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (f *Flags) handleDeactivateCommand() int {
}
if f.Local && f.URL != "" {
fmt.Println("provide either a 'url' or a 'local', but not both")
return utils.InvalidParameters
return utils.InvalidParameterCombination
}
if !f.Local {
if f.URL == "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/flags/deactivate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestHandleDeactivateCommandWithURLAndLocal(t *testing.T) {
args := []string{"./rpc", "deactivate", "-u", "wss://localhost", "--password", "password", "-local"}
flags := NewFlags(args)
success := flags.handleDeactivateCommand()
assert.EqualValues(t, success, utils.InvalidParameters)
assert.EqualValues(t, success, utils.InvalidParameterCombination)
assert.Equal(t, "wss://localhost", flags.URL)
}
func TestHandleDeactivateCommandWithForce(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/local/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (service *ProvisioningService) Configure() int {
err = service.Configure8021xWiFi()
break
default:
resultCode = utils.InvalidParameters
resultCode = utils.InvalidParameterCombination
}
if err != nil {
resultCode = utils.WiFiConfigurationFailed
Expand Down
2 changes: 1 addition & 1 deletion internal/local/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestConfigure(t *testing.T) {
f.SubCommand = "notvalid"
lps := setupWithWsmanClient(f, handler)
resultCode := lps.Configure()
assert.Equal(t, utils.InvalidParameters, resultCode)
assert.Equal(t, utils.InvalidParameterCombination, resultCode)
})
t.Run("returns error when SubCommand is not handled", func(t *testing.T) {
f.SubCommand = utils.SubCommandAddWifiSettings
Expand Down
2 changes: 1 addition & 1 deletion internal/local/lps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestExecute(t *testing.T) {
t.Run("execute CommandMaintenance with no SubCommand fails", func(t *testing.T) {
f.Command = utils.CommandMaintenance
resultCode := ExecuteCommand(f)
assert.Equal(t, utils.InvalidParameters, resultCode)
assert.Equal(t, utils.InvalidParameterCombination, resultCode)
})

}
70 changes: 36 additions & 34 deletions pkg/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,52 @@ const (
// (1-99) General Errors

// (1-19) Basic errors outside of Open AMT Cloud Toolkit
IncorrectPermissions = 1 // Incorrect permissions (not admin or sudo)
HECIDriverNotDetected = 2 // HECI driver not detected
AmtNotDetected = 3 // AMT not detected
AmtNotReady = 4 // AMT not ready
IncorrectPermissions = 1 // (not admin or sudo)
HECIDriverNotDetected = 2
AmtNotDetected = 3
AmtNotReady = 4

// (20-69) Input errors to RPC
MissingOrIncorrectURL = 20 // Missing or incorrect URL
MissingOrIncorrectProfile = 21 // Missing or incorrect profile
ServerCerificateVerificationFailed = 22 // Server certificate verification failed
MissingOrIncorrectPassword = 23 // Missing or incorrect password
MissingDNSSuffix = 24 // Missing DNS Suffix
MissingHostname = 25 // Missing hostname
MissingProxyAddressAndPort = 26 // Missing proxy address and port
MissingOrIncorrectStaticIP = 27 // Missing static IP information
IncorrectCommandLineParameters = 28 // Incorrect number of command line parameters
MissingOrIncorrectNetworkMask = 29 // Missing or incorrect network mask
MissingOrIncorrectGateway = 30 // Missing or incorrect gateway
MissingOrIncorrectPrimaryDNS = 31 // Missing primary DNS Suffix
MissingOrIncorrectSecondaryDNS = 32 // Missing secondary DNS Suffix
InvalidParameters = 33 // Invalid parameter combination
MissingOrIncorrectURL = 20
MissingOrIncorrectProfile = 21
ServerCerificateVerificationFailed = 22
MissingOrIncorrectPassword = 23
MissingDNSSuffix = 24
MissingHostname = 25
MissingProxyAddressAndPort = 26
MissingOrIncorrectStaticIP = 27
IncorrectCommandLineParameters = 28
MissingOrIncorrectNetworkMask = 29
MissingOrIncorrectGateway = 30
MissingOrIncorrectPrimaryDNS = 31
MissingOrIncorrectSecondaryDNS = 32
InvalidParameterCombination = 33

// (70-99) Connection Errors
RPSAuthenticationFailed = 70 // RPS authentication failed
RPSAuthenticationFailed = 70
AMTConnectionFailed = 71
OSNetworkInterfacesLookupFailed = 72

// (100-149) Activation, and configuration errors
AMTAuthenticationFailed = 100 // AMT authentication failed
WSMANMessageError = 101 // WSMAN message error
ActivationFailed = 102 // Activation failed
NetworkConfigurationFailed = 103 // Network configuration failed
CIRAConfigurationFailed = 104 // CIRA configuration failed
TLSConfigurationFailed = 105 // TLS configuration failed
WiFiConfigurationFailed = 106 // WiFi configuration failed
AMTConfigurationFailed = 107 // AMT features configuration failed
EightZeroTwoConfigurationFailed = 108 // 802.1x configuration failed
UnableToDeactivate = 109 // Device is not in CCM mode
DeactivationFailed = 110 // Deactivation Failed
UnableToActivate = 111 // Device is not in pre-provisioning mode
AMTAuthenticationFailed = 100
WSMANMessageError = 101
ActivationFailed = 102
NetworkConfigurationFailed = 103
CIRAConfigurationFailed = 104
TLSConfigurationFailed = 105
WiFiConfigurationFailed = 106
AMTFeaturesConfigurationFailed = 107
Ieee8021xConfigurationFailed = 108
UnableToDeactivate = 109
DeactivationFailed = 110
UnableToActivate = 111
WifiConfigurationWithWarnings = 112

// (150-199) Maintenance Errors
ClockSyncFailed = 150 // Clock sync failed
HostnameSyncFailed = 151 // Hostname sync failed
NetworkSyncFailed = 152 // Network sync failed
SyncClockFailed = 150
SyncHostnameFailed = 151
SyncIpFailed = 152
ChangePasswordFailed = 153

// (200-299) KPMU

Expand Down

0 comments on commit 5a8d8a8

Please sign in to comment.