Skip to content

Commit ad8e979

Browse files
Added model for trasnactions streaming
1 parent 62798f9 commit ad8e979

File tree

1 file changed

+46
-21
lines changed

1 file changed

+46
-21
lines changed

internal/session/model.go

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,49 @@ const (
1818
StatusPending Status = "pending"
1919
)
2020

21-
/*
22-
session struct for a user
23-
appropriate fields must always be updated when any request is made
21+
/*
22+
session struct for a user
23+
appropriate fields must always be updated when any request is made
2424
*/
2525
type Session struct {
2626
/* keep count of completed and failed transactions */
27-
CompletedCount int
28-
FailedCount int
27+
CompletedCount int
28+
FailedCount int
2929

3030
/* session status: active: 1 / expired: 0 */
31-
Status Status
31+
Status Status
3232

3333
/* unique ID of session [will be associated with the user forever in logs] */
34-
ID uuid.UUID
34+
ID uuid.UUID
3535

3636
/* username of the user */
37-
Username string
37+
Username string
3838

39-
/*
39+
/*
4040
IP and UserAgent for security logs
41-
also can be used for blacklisting and whitelistings
41+
also can be used for blacklisting and whitelistings
4242
illegal useragents can be caught as well as unauthorized IP addresses
4343
*/
44-
IP string
45-
UserAgent string
44+
IP string
45+
UserAgent string
4646

4747
/* for logging user activity */
48-
CreatedAt time.Time
49-
LastActiveAt time.Time
50-
Expiry time.Time
51-
Timer *time.Timer
48+
CreatedAt time.Time
49+
LastActiveAt time.Time
50+
Expiry time.Time
51+
Timer *time.Timer
5252

5353
/* transactions issued by the user */
54-
TransactionQueue *list.List
54+
TransactionQueue *list.List
5555

56-
/*
57-
listElem stores it's node address in sessionOrder
56+
/*
57+
listElem stores it's node address in sessionOrder
5858
this is done to maintain O(1) runtime performance while deleting session
5959
*/
60-
listElem *list.Element
60+
listElem *list.Element
6161

6262
/* mutex for thread safety */
63-
Mutex sync.Mutex
63+
Mutex sync.Mutex
6464
}
6565

6666
/* SessionStreamData is a frontend-safe representation of a session that goes through websocket */
@@ -83,3 +83,28 @@ type StreamMessage struct {
8383
Data interface{} `json:"data"`
8484
Timestamp time.Time `json:"timestamp"`
8585
}
86+
87+
/* TransactionStreamData is a frontend-safe representation of a transaction sent via websocket */
88+
type TransactionStreamData struct {
89+
ID string `json:"id"`
90+
SessionID string `json:"sessionId"`
91+
Timestamp time.Time `json:"timestamp"`
92+
Operation string `json:"operation"`
93+
TargetPath string `json:"targetPath"`
94+
Entries []ACLEntryStream `json:"entries"`
95+
Status string `json:"status"`
96+
ErrorMsg string `json:"errorMsg,omitempty"`
97+
Output string `json:"output"`
98+
ExecutedBy string `json:"executedBy"`
99+
DurationMs int64 `json:"durationMs"`
100+
}
101+
102+
/* ACLEntryStream is a frontend-safe version of an individual ACL entry */
103+
type ACLEntryStream struct {
104+
EntityType string `json:"entityType"`
105+
Entity string `json:"entity"`
106+
Permissions string `json:"permissions"`
107+
Action string `json:"action"`
108+
Success bool `json:"success"`
109+
Error string `json:"error,omitempty"`
110+
}

0 commit comments

Comments
 (0)