77 dockerclient "github.com/docker/docker/client"
88 "github.com/shellhub-io/shellhub/pkg/agent/pkg/sysinfo"
99 "github.com/shellhub-io/shellhub/pkg/agent/server"
10- "github.com/shellhub-io/shellhub/pkg/agent/server/modes"
1110 "github.com/shellhub-io/shellhub/pkg/agent/server/modes/connector"
1211 "github.com/shellhub-io/shellhub/pkg/agent/server/modes/host"
1312)
@@ -39,25 +38,21 @@ type Mode interface {
3938//
4039// The host mode is the default mode one, and turns the host machine into a ShellHub's Agent. The host is
4140// responsible for the SSH server, authentication and authorization, `/etc/passwd`, `/etc/shadow`, and etc.
42- type HostMode struct {
43- serverMode modes.Mode
44- }
41+ type HostMode struct {}
4542
4643var _ Mode = new (HostMode )
4744
4845func (m * HostMode ) Serve (agent * Agent ) {
49- m .serverMode = & host.Mode {
50- Authenticator : * host .NewAuthenticator (agent .cli , agent .authData , agent .config .SingleUserPassword , & agent .authData .Name ),
51- Sessioner : * host .NewSessioner (& agent .authData .Name , make (map [string ]* exec.Cmd )),
52- }
53-
5446 agent .server = server .NewServer (
5547 agent .cli ,
5648 agent .authData ,
5749 agent .config .PrivateKey ,
5850 agent .config .KeepAliveInterval ,
5951 agent .config .SingleUserPassword ,
60- m .serverMode ,
52+ & host.Mode {
53+ Authenticator : * host .NewAuthenticator (agent .cli , agent .authData , agent .config .SingleUserPassword , & agent .authData .Name ),
54+ Sessioner : * host .NewSessioner (& agent .authData .Name , make (map [string ]* exec.Cmd )),
55+ },
6156 )
6257
6358 agent .server .SetDeviceName (agent .authData .Name )
@@ -81,26 +76,20 @@ func (m *HostMode) GetInfo() (*Info, error) {
8176// responsible for the SSH server, but the authentication and authorization is made by either the conainer
8277// internals, `passwd` or `shadow`, or by the ShellHub API.
8378type ConnectorMode struct {
84- cli * dockerclient.Client
85- serverMode * connector.Mode
86- identity string
79+ cli * dockerclient.Client
80+ identity string
8781}
8882
8983func NewConnectorMode (cli * dockerclient.Client , identity string ) (Mode , error ) {
9084 return & ConnectorMode {
91- identity : identity ,
9285 cli : cli ,
86+ identity : identity ,
9387 }, nil
9488}
9589
9690var _ Mode = new (ConnectorMode )
9791
9892func (m * ConnectorMode ) Serve (agent * Agent ) {
99- m .serverMode = & connector.Mode {
100- Authenticator : * connector .NewAuthenticator (agent .cli , m .cli , agent .authData , & agent .Identity .MAC ),
101- Sessioner : * connector .NewSessioner (& agent .Identity .MAC , m .cli ),
102- }
103-
10493 // NOTICE: When the agent is running in `Connector` mode, we need to identify the container ID to maintain the
10594 // communication between the server and the agent when the container name on the host changes. This information is
10695 // saved inside the device's identity, avoiding significant changes in the current state of the agent.
@@ -111,8 +100,12 @@ func (m *ConnectorMode) Serve(agent *Agent) {
111100 agent .config .PrivateKey ,
112101 agent .config .KeepAliveInterval ,
113102 agent .config .SingleUserPassword ,
114- m .serverMode ,
103+ & connector.Mode {
104+ Authenticator : * connector .NewAuthenticator (agent .cli , m .cli , agent .authData , & agent .Identity .MAC ),
105+ Sessioner : * connector .NewSessioner (& agent .Identity .MAC , m .cli ),
106+ },
115107 )
108+
116109 agent .server .SetContainerID (agent .Identity .MAC )
117110 agent .server .SetDeviceName (agent .authData .Name )
118111}
0 commit comments