2021-02-03 16:25:56 -08:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2021-06-30 10:53:54 -07:00
|
|
|
// 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 (
|
2021-06-30 10:53:54 -07:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-30 10:53:54 -07:00
|
|
|
// 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
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 14:19:21 -04:00
|
|
|
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
|
|
|
}
|
2024-07-23 14:19:21 -04:00
|
|
|
return StatusUnspecified
|
2020-09-16 12:02:02 -04:00
|
|
|
}
|