List sessions CLI reports correct target id and status (#511)

* Including some missing session fields and improving reporting of sessions of CLI.
This commit is contained in:
Todd Knight authored and GitHub committed 2020-10-01 15:57:01 -07:00
1 parent 9bd6045c46
commit d1d94c19c8
4 files changed
+14 -2

No files matched your search

+3 -1
View File
@@ -33,7 +33,9 @@ func generateSessionTableOutput(in *sessions.Session) string {
m := map[string]interface{}{ m := map[string]interface{}{
"Status": state.Status, "Status": state.Status,
"Start Time": state.StartTime.Local().Format(time.RFC1123), "Start Time": state.StartTime.Local().Format(time.RFC1123),
"End Time": state.EndTime.Local().Format(time.RFC1123), }
if !state.EndTime.IsZero() {
m["End Time"] = state.EndTime.Local().Format(time.RFC1123)
} }
statesMaps = append(statesMaps, m) statesMaps = append(statesMaps, m)
} }
+2 -1
View File
@@ -170,11 +170,12 @@ func (c *Command) Run(args []string) int {
} }
output = append(output, output = append(output,
fmt.Sprintf(" ID: %s", t.Id), fmt.Sprintf(" ID: %s", t.Id),
fmt.Sprintf(" Status: %s", t.Status),
fmt.Sprintf(" Created Time: %s", t.CreatedTime.Local().Format(time.RFC3339)), fmt.Sprintf(" Created Time: %s", t.CreatedTime.Local().Format(time.RFC3339)),
fmt.Sprintf(" Expiration Time: %s", t.ExpirationTime.Local().Format(time.RFC3339)), fmt.Sprintf(" Expiration Time: %s", t.ExpirationTime.Local().Format(time.RFC3339)),
fmt.Sprintf(" Updated Time: %s", t.UpdatedTime.Local().Format(time.RFC3339)), fmt.Sprintf(" Updated Time: %s", t.UpdatedTime.Local().Format(time.RFC3339)),
fmt.Sprintf(" User ID: %s", t.UserId), fmt.Sprintf(" User ID: %s", t.UserId),
fmt.Sprintf(" Target ID: %s", t.UserId), fmt.Sprintf(" Target ID: %s", t.TargetId),
) )
} }
c.UI.Output(base.WrapForHelpText(output)) c.UI.Output(base.WrapForHelpText(output))
@@ -12,6 +12,7 @@ import (
"github.com/hashicorp/boundary/internal/servers/controller/common" "github.com/hashicorp/boundary/internal/servers/controller/common"
"github.com/hashicorp/boundary/internal/servers/controller/handlers" "github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/hashicorp/boundary/internal/session" "github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/internal/types/action" "github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource" "github.com/hashicorp/boundary/internal/types/resource"
"github.com/hashicorp/boundary/internal/types/scope" "github.com/hashicorp/boundary/internal/types/scope"
@@ -192,6 +193,8 @@ func toProto(in *session.Session) *pb.Session {
HostId: in.HostId, HostId: in.HostId,
HostSetId: in.HostSetId, HostSetId: in.HostSetId,
AuthTokenId: in.AuthTokenId, AuthTokenId: in.AuthTokenId,
Endpoint: in.Endpoint,
Type: target.SubtypeFromId(in.TargetId).String(),
// TODO: Provide the ServerType and the ServerId when that information becomes relevant in the API. // TODO: Provide the ServerType and the ServerId when that information becomes relevant in the API.
CreatedTime: in.CreateTime.GetTimestamp(), CreatedTime: in.CreateTime.GetTimestamp(),
@@ -67,6 +67,7 @@ func TestGetSession(t *testing.T) {
Id: sess.GetPublicId(), Id: sess.GetPublicId(),
ScopeId: p.GetPublicId(), ScopeId: p.GetPublicId(),
AuthTokenId: at.GetPublicId(), AuthTokenId: at.GetPublicId(),
Endpoint: sess.Endpoint,
UserId: at.GetIamUserId(), UserId: at.GetIamUserId(),
TargetId: sess.TargetId, TargetId: sess.TargetId,
HostSetId: sess.HostSetId, HostSetId: sess.HostSetId,
@@ -79,6 +80,7 @@ func TestGetSession(t *testing.T) {
Scope: &scopes.ScopeInfo{Id: p.GetPublicId(), Type: scope.Project.String()}, Scope: &scopes.ScopeInfo{Id: p.GetPublicId(), Type: scope.Project.String()},
States: []*pb.SessionState{{Status: session.StatusPending.String(), StartTime: sess.CreateTime.GetTimestamp()}}, States: []*pb.SessionState{{Status: session.StatusPending.String(), StartTime: sess.CreateTime.GetTimestamp()}},
Certificate: sess.Certificate, Certificate: sess.Certificate,
Type: target.TcpSubType.String(),
} }
cases := []struct { cases := []struct {
@@ -183,6 +185,7 @@ func TestList(t *testing.T) {
AuthTokenId: at.GetPublicId(), AuthTokenId: at.GetPublicId(),
UserId: at.GetIamUserId(), UserId: at.GetIamUserId(),
TargetId: sess.TargetId, TargetId: sess.TargetId,
Endpoint: sess.Endpoint,
HostSetId: sess.HostSetId, HostSetId: sess.HostSetId,
HostId: sess.HostId, HostId: sess.HostId,
Version: sess.Version, Version: sess.Version,
@@ -193,6 +196,7 @@ func TestList(t *testing.T) {
Status: status, Status: status,
States: states, States: states,
Certificate: sess.Certificate, Certificate: sess.Certificate,
Type: target.TcpSubType.String(),
}) })
} }
@@ -297,11 +301,13 @@ func TestCancel(t *testing.T) {
HostSetId: sess.HostSetId, HostSetId: sess.HostSetId,
HostId: sess.HostId, HostId: sess.HostId,
Version: sess.Version, Version: sess.Version,
Endpoint: sess.Endpoint,
CreatedTime: sess.CreateTime.GetTimestamp(), CreatedTime: sess.CreateTime.GetTimestamp(),
ExpirationTime: sess.ExpirationTime.GetTimestamp(), ExpirationTime: sess.ExpirationTime.GetTimestamp(),
Scope: &scopes.ScopeInfo{Id: p.GetPublicId(), Type: scope.Project.String()}, Scope: &scopes.ScopeInfo{Id: p.GetPublicId(), Type: scope.Project.String()},
Status: session.StatusCanceling.String(), Status: session.StatusCanceling.String(),
Certificate: sess.Certificate, Certificate: sess.Certificate,
Type: target.TcpSubType.String(),
} }
version := wireSess.GetVersion() version := wireSess.GetVersion()