Files
threshold/internal/session/connection_state.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
1.7 KiB
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
2023-02-02 17:15:17 -08:00
2020-09-16 12:02:02 -04:00
package session
import (
2020-09-20 12:51:08 -04:00
workerpbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services"
2020-09-16 12:02:02 -04:00
)
// ConnectionStatus of the connection's state
type ConnectionStatus string
const (
StatusAuthorized ConnectionStatus = "authorized"
StatusConnected ConnectionStatus = "connected"
StatusClosed ConnectionStatus = "closed"
StatusUnspecified ConnectionStatus = "unspecified" // Utility state not valid in the DB
2020-09-16 12:02:02 -04:00
)
// String representation of the state's status
func (s ConnectionStatus) String() string {
return string(s)
}
2020-09-20 12:51:08 -04:00
// ProtoVal returns the enum value corresponding to the state
func (s ConnectionStatus) ProtoVal() workerpbs.CONNECTIONSTATUS {
switch s {
case StatusAuthorized:
return workerpbs.CONNECTIONSTATUS_CONNECTIONSTATUS_AUTHORIZED
case StatusConnected:
return workerpbs.CONNECTIONSTATUS_CONNECTIONSTATUS_CONNECTED
case StatusClosed:
return workerpbs.CONNECTIONSTATUS_CONNECTIONSTATUS_CLOSED
}
return workerpbs.CONNECTIONSTATUS_CONNECTIONSTATUS_UNSPECIFIED
}
// ConnectionStatusFromProtoVal is the reverse of
// ConnectionStatus.ProtoVal.
func ConnectionStatusFromProtoVal(s workerpbs.CONNECTIONSTATUS) ConnectionStatus {
switch s {
case workerpbs.CONNECTIONSTATUS_CONNECTIONSTATUS_AUTHORIZED:
return StatusAuthorized
case workerpbs.CONNECTIONSTATUS_CONNECTIONSTATUS_CONNECTED:
return StatusConnected
case workerpbs.CONNECTIONSTATUS_CONNECTIONSTATUS_CLOSED:
return StatusClosed
}
return StatusUnspecified
}
func ConnectionStatusFromString(s string) ConnectionStatus {
switch s {
case "authorized":
return StatusAuthorized
case "connected":
return StatusConnected
case "closed":
return StatusClosed
2020-09-16 12:02:02 -04:00
}
return StatusUnspecified
2020-09-16 12:02:02 -04:00
}