Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MEN-3996 ws/shell for Remote Terminal. #94

Conversation

merlin-northern
Copy link
Contributor

ChangeLog:none
Signed-off-by: Peter Grzybowski peter@northern.tech

ChangeLog:none
Signed-off-by: Peter Grzybowski <peter@northern.tech>
Copy link
Contributor

@alfrunes alfrunes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, this wasn't quite what I had in mind.
My intention with the ProtoMsg definition is that we have a common and minimalistic application layer (on top of websocket) for all future kinds of messages that we communicate over a websocket.
So, for all shell specific messages (ProtoMsg.Header.Proto == ProtoTypeShell should apply some protocol specific logic for decoding the message body and what fields and properties should be set in the header.
Thus, what I was expecting in the shell sub-package are declarations of different MsgType headers, and a struct definition for each MsgType (that requires a message body) for encoding/decoding the ProtoMsg.Body.

Comment on lines +39 to +41
// * CommandData for the stdout / stderr coming from the terminal and keystrokes from the UI
// * StartSession for the session start
// * StopSession for stopping of the session
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is shell specific. This package is supposed to be generic.

Comment on lines +32 to +34
// * MenderShell for remote terminal
// * MenderConfiguration for configuration of devices
// * MenderMonitoring for the stats and monitoring
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also seems superfluous as the documentation for the different types should be placed by their definition. (Notice that this field is of ProtoType).

Comment on lines +44 to +51
// Status is the indicator of whether the response contains error or other
// conditions (required).
// E.g.: for the remote terminal case a StartSession MsgType maye result in
// an error due to mas session limit reached.
// * Normal message carries a data from successful processing
// * Error the given message returned error
// * ProtocolError higher level protocol error
Status int `msgpack:"state"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue this should be in the Properties. The reason being that a very small set of MsgType for a given Proto would actually set this field, and for some future Protos a status might not make sense at all.

Comment on lines +26 to +31
type Protocol interface {
DeEncapsulate(m *ProtoMsg) (interface{}, error)
Encapsulate(m interface{}) (*ProtoMsg, error)
}

var protoMap = map[ProtoType]Protocol{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the purpose of this interface. All messages holding shell data should be of ProtoTypeShell, thus this map holds at most one value.

ErrorMessage
)

var (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var (
const (

Comment on lines +37 to +51
type MenderShellMessage struct {
//type of message, used to determine the meaning of data
Type string `json:"type" msgpack:"type"`
//session id, as returned to the caller in a response to the MessageTypeSpawnShell
//message.
SessionId string `json:"session_id" msgpack:"session_id"`
//message status, currently normal and error message types are supported
Status MenderShellMessageStatus `json:"status_code" msgpack:"status_code"`
//the message payload, if
// * .Type===MessageTypeShellCommand interpreted as keystrokes and passed
// to the stdin of the terminal running the shell.
// * .Type===MessageTypeSpawnShell interpreted as user_id and passed
// to the session.NewMenderShellSession.
Data []byte `json:"data" msgpack:"data"`
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is overlapping with the ProtoMsg definition.

  • Type <-> Header.MsgType
  • SessionId <-> Header.SessionID
  • Data <-> Body

Comment on lines +53 to +55
type MenderShellProtocol struct {
version string
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I don't understand the purpose of this interface. Why can't we use ProtoMsg?
We discussed in the design document that a Version could be given as a ProtoMsg.Header.Properties.

@merlin-northern
Copy link
Contributor Author

To be honest, this wasn't quite what I had in mind.
My intention with the ProtoMsg definition is that we have a common and minimalistic application layer (on top of websocket) for all future kinds of messages that we communicate over a websocket.
So, for all shell specific messages (ProtoMsg.Header.Proto == ProtoTypeShell should apply some protocol specific logic for decoding the message body and what fields and properties should be set in the header.
Thus, what I was expecting in the shell sub-package are declarations of different MsgType headers, and a struct definition for each MsgType (that requires a message body) for encoding/decoding the ProtoMsg.Body.

basically same here. let me think on how to restructure to make it more to your taste :)

@tranchitella
Copy link
Contributor

FWIW, I fully agree with what @alfrunes said. Let's try to keep this library high-level, generic, without any specific use-case implementation (shell, in this case).

@alfrunes alfrunes closed this Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants