Adapt and update status package

This commit is contained in:
Daniel 2018-10-30 19:12:25 +01:00
parent c146c99273
commit 247c7dca00
3 changed files with 40 additions and 20 deletions

View file

@ -3,9 +3,15 @@ package status
// Definitions of Security and Status Levels // Definitions of Security and Status Levels
const ( const (
SecurityLevelOff uint8 = 0 SecurityLevelOff uint8 = 0
SecurityLevelDynamic uint8 = 1 SecurityLevelDynamic uint8 = 1
SecurityLevelSecure uint8 = 2 SecurityLevelSecure uint8 = 2
SecurityLevelFortress uint8 = 3 SecurityLevelFortress uint8 = 4
SecurityLevelsDynamicAndSecure uint8 = SecurityLevelDynamic | SecurityLevelSecure
SecurityLevelsDynamicAndFortress uint8 = SecurityLevelDynamic | SecurityLevelFortress
SecurityLevelsSecureAndFortress uint8 = SecurityLevelSecure | SecurityLevelFortress
SecurityLevelsAll uint8 = SecurityLevelDynamic | SecurityLevelSecure | SecurityLevelFortress
StatusOff uint8 = 0 StatusOff uint8 = 0
StatusError uint8 = 1 StatusError uint8 = 1

View file

@ -27,23 +27,37 @@ type SystemStatus struct {
Gate17StatusMsg string `json:",omitempty" bson:",omitempty"` Gate17StatusMsg string `json:",omitempty" bson:",omitempty"`
} }
// FmtSecurityLevel returns the current security level as a string. // FmtCurrentSecurityLevel returns the current security level as a string.
func FmtSecurityLevel() string { func FmtCurrentSecurityLevel() string {
current := CurrentSecurityLevel() current := CurrentSecurityLevel()
selected := SelectedSecurityLevel() selected := SelectedSecurityLevel()
var s string s := FmtSecurityLevel(current)
switch current {
case SecurityLevelOff:
s = "Off"
case SecurityLevelDynamic:
s = "Dynamic"
case SecurityLevelSecure:
s = "Secure"
case SecurityLevelFortress:
s = "Fortress"
}
if current != selected { if current != selected {
s += "*" s += "*"
} }
return s return s
} }
// FmtSecurityLevel returns the given security level as a string.
func FmtSecurityLevel(level uint8) string {
switch level {
case SecurityLevelOff:
return "Off"
case SecurityLevelDynamic:
return "Dynamic"
case SecurityLevelSecure:
return "Secure"
case SecurityLevelFortress:
return "Fortress"
case SecurityLevelsDynamicAndSecure:
return "Dynamic and Secure"
case SecurityLevelsDynamicAndFortress:
return "Dynamic and Fortress"
case SecurityLevelsSecureAndFortress:
return "Secure and Fortress"
case SecurityLevelsAll:
return "Dynamic, Secure and Fortress"
default:
return "INVALID"
}
}

View file

@ -6,30 +6,30 @@ func TestStatus(t *testing.T) {
SetCurrentSecurityLevel(SecurityLevelOff) SetCurrentSecurityLevel(SecurityLevelOff)
SetSelectedSecurityLevel(SecurityLevelOff) SetSelectedSecurityLevel(SecurityLevelOff)
if FmtSecurityLevel() != "Off" { if FmtCurrentSecurityLevel() != "Off" {
t.Error("unexpected string representation") t.Error("unexpected string representation")
} }
SetCurrentSecurityLevel(SecurityLevelDynamic) SetCurrentSecurityLevel(SecurityLevelDynamic)
SetSelectedSecurityLevel(SecurityLevelDynamic) SetSelectedSecurityLevel(SecurityLevelDynamic)
if FmtSecurityLevel() != "Dynamic" { if FmtCurrentSecurityLevel() != "Dynamic" {
t.Error("unexpected string representation") t.Error("unexpected string representation")
} }
SetCurrentSecurityLevel(SecurityLevelSecure) SetCurrentSecurityLevel(SecurityLevelSecure)
SetSelectedSecurityLevel(SecurityLevelSecure) SetSelectedSecurityLevel(SecurityLevelSecure)
if FmtSecurityLevel() != "Secure" { if FmtCurrentSecurityLevel() != "Secure" {
t.Error("unexpected string representation") t.Error("unexpected string representation")
} }
SetCurrentSecurityLevel(SecurityLevelFortress) SetCurrentSecurityLevel(SecurityLevelFortress)
SetSelectedSecurityLevel(SecurityLevelFortress) SetSelectedSecurityLevel(SecurityLevelFortress)
if FmtSecurityLevel() != "Fortress" { if FmtCurrentSecurityLevel() != "Fortress" {
t.Error("unexpected string representation") t.Error("unexpected string representation")
} }
SetSelectedSecurityLevel(SecurityLevelDynamic) SetSelectedSecurityLevel(SecurityLevelDynamic)
if FmtSecurityLevel() != "Fortress*" { if FmtCurrentSecurityLevel() != "Fortress*" {
t.Error("unexpected string representation") t.Error("unexpected string representation")
} }