Add Termination Reason (#573)

This commit is contained in:
Todd Knight authored and GitHub committed 2020-10-07 21:37:30 -04:00
1 parent 5bc8c8d921
commit abe5e9b950
7 files changed
+54 -28

No files matched your search

+19 -18
View File
@@ -13,24 +13,25 @@ import (
)
type Session struct {
Id string `json:"id,omitempty"`
TargetId string `json:"target_id,omitempty"`
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
CreatedTime time.Time `json:"created_time,omitempty"`
UpdatedTime time.Time `json:"updated_time,omitempty"`
Version uint32 `json:"version,omitempty"`
Type string `json:"type,omitempty"`
ExpirationTime time.Time `json:"expiration_time,omitempty"`
AuthTokenId string `json:"auth_token_id,omitempty"`
UserId string `json:"user_id,omitempty"`
HostSetId string `json:"host_set_id,omitempty"`
HostId string `json:"host_id,omitempty"`
ScopeId string `json:"scope_id,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
States []*SessionState `json:"states,omitempty"`
Status string `json:"status,omitempty"`
WorkerInfo []*WorkerInfo `json:"worker_info,omitempty"`
Certificate []byte `json:"certificate,omitempty"`
Id string `json:"id,omitempty"`
TargetId string `json:"target_id,omitempty"`
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
CreatedTime time.Time `json:"created_time,omitempty"`
UpdatedTime time.Time `json:"updated_time,omitempty"`
Version uint32 `json:"version,omitempty"`
Type string `json:"type,omitempty"`
ExpirationTime time.Time `json:"expiration_time,omitempty"`
AuthTokenId string `json:"auth_token_id,omitempty"`
UserId string `json:"user_id,omitempty"`
HostSetId string `json:"host_set_id,omitempty"`
HostId string `json:"host_id,omitempty"`
ScopeId string `json:"scope_id,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
States []*SessionState `json:"states,omitempty"`
Status string `json:"status,omitempty"`
WorkerInfo []*WorkerInfo `json:"worker_info,omitempty"`
Certificate []byte `json:"certificate,omitempty"`
TerminationReason string `json:"termination_reason,omitempty"`
responseBody *bytes.Buffer
responseMap map[string]interface{}
+4
View File
@@ -2,6 +2,7 @@ package sessions
import (
"fmt"
"strings"
"time"
"github.com/hashicorp/boundary/api/sessions"
@@ -24,6 +25,9 @@ func generateSessionTableOutput(in *sessions.Session) string {
"Endpoint": in.Endpoint,
"Status": in.Status,
}
if len(strings.TrimSpace(in.TerminationReason)) > 0 {
nonAttributeMap["Termination Reason"] = in.TerminationReason
}
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
+1 -1
View File
@@ -156,7 +156,7 @@ func (c *Command) Run(args []string) int {
case "table":
if len(listedSessions) == 0 {
c.UI.Output("No auth tokens found")
c.UI.Output("No sessions found")
return 0
}
var output []string
+5
View File
@@ -3048,6 +3048,11 @@
"format": "byte",
"description": "Output only. The certificate generated for the session. Raw DER bytes.",
"readOnly": true
},
"termination_reason": {
"type": "string",
"description": "Output only. If the session is terminated, this provides a short description as to why.",
"readOnly": true
}
},
"title": "Session contains all fields related to a Session resource"
@@ -187,6 +187,8 @@ type Session struct {
WorkerInfo []*WorkerInfo `protobuf:"bytes,190,rep,name=worker_info,proto3" json:"worker_info,omitempty"`
// Output only. The certificate generated for the session. Raw DER bytes.
Certificate []byte `protobuf:"bytes,200,opt,name=certificate,proto3" json:"certificate,omitempty"`
// Output only. If the session is terminated, this provides a short description as to why.
TerminationReason string `protobuf:"bytes,210,opt,name=termination_reason,proto3" json:"termination_reason,omitempty"`
}
func (x *Session) Reset() {
@@ -347,6 +349,13 @@ func (x *Session) GetCertificate() []byte {
return nil
}
func (x *Session) GetTerminationReason() string {
if x != nil {
return x.TerminationReason
}
return ""
}
var File_controller_api_resources_sessions_v1_session_proto protoreflect.FileDescriptor
var file_controller_api_resources_sessions_v1_session_proto_rawDesc = []byte{
@@ -382,7 +391,7 @@ var file_controller_api_resources_sessions_v1_session_proto_rawDesc = []byte{
0x74, 0x69, 0x6d, 0x65, 0x12, 0x36, 0x0a, 0x08, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65,
0x18, 0x1e, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61,
0x6d, 0x70, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x22, 0x86, 0x06, 0x0a,
0x6d, 0x70, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x22, 0xb7, 0x06, 0x0a,
0x07, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x0a,
0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x61, 0x72, 0x67,
0x65, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x61, 0x72,
@@ -431,13 +440,16 @@ var file_controller_api_resources_sessions_v1_session_proto_rawDesc = []byte{
0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0b, 0x77, 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x5f, 0x69, 0x6e,
0x66, 0x6f, 0x12, 0x21, 0x0a, 0x0b, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74,
0x65, 0x18, 0xc8, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66,
0x69, 0x63, 0x61, 0x74, 0x65, 0x42, 0x57, 0x5a, 0x55, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e,
0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x62, 0x6f,
0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f,
0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x61,
0x70, 0x69, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2f, 0x73, 0x65, 0x73,
0x73, 0x69, 0x6f, 0x6e, 0x73, 0x3b, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x69, 0x63, 0x61, 0x74, 0x65, 0x12, 0x2f, 0x0a, 0x12, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0xd2, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x12, 0x74, 0x65, 0x72, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f,
0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x42, 0x57, 0x5a, 0x55, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62,
0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x62,
0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c,
0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f,
0x61, 0x70, 0x69, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2f, 0x73, 0x65,
0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x3b, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -82,4 +82,7 @@ message Session {
// Output only. The certificate generated for the session. Raw DER bytes.
bytes certificate = 200;
// Output only. If the session is terminated, this provides a short description as to why.
string termination_reason = 210 [json_name = "termination_reason"];
}
@@ -201,6 +201,7 @@ func toProto(in *session.Session) *pb.Session {
UpdatedTime: in.UpdateTime.GetTimestamp(),
ExpirationTime: in.ExpirationTime.GetTimestamp(),
Certificate: in.Certificate,
TerminationReason: in.TerminationReason,
}
if len(in.States) > 0 {
out.Status = in.States[0].Status.String()
@@ -243,7 +244,7 @@ func validateListRequest(req *pbs.ListSessionsRequest) error {
func validateCancelRequest(req *pbs.CancelSessionRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(session.SessionPrefix, req.GetId()) {
badFields["id"] = "Impropperly formatted identifier."
badFields["id"] = "Improperly formatted identifier."
}
if req.GetVersion() == 0 {
badFields["version"] = "Required field."