func NewSession(context context.T) *Session {
	sessionContext := context.With("[" + mgsConfig.SessionServiceName + "]")
	log := sessionContext.Log()
	appConfig := context.AppConfig()

	instanceID, err := platform.InstanceID()

	targetID, err := platform.TargetID()

	if instanceID == "" {
		log.Errorf("no instanceID provided, %s", err)
		return nil
	}

	// If the current os is Nano server, SSM Agent doesn't support the Session Manager.
	isNanoServer, _ := platform.IsPlatformNanoServer(log)
	if isNanoServer {
		log.Info("Session core module is not supported on Windows Nano server.")
		return nil
	}

	agentInfo := contracts.AgentInfo{
		Lang:      appConfig.Os.Lang,
		Name:      appConfig.Agent.Name,
		Version:   appConfig.Agent.Version,
		Os:        appConfig.Os.Name,
		OsVersion: appConfig.Os.Version,
	}

	agentConfig := contracts.AgentConfiguration{
		AgentInfo:  agentInfo,
		InstanceID: instanceID,
		TargetID:   targetID,
	}

	messageGatewayServiceConfig := appConfig.Mgs
	if messageGatewayServiceConfig.Region == "" {
		fetchedRegion, err := platform.Region()
		if err != nil {
			log.Errorf("Failed to get region with error: %s", err)
			return nil
		}
		messageGatewayServiceConfig.Region = fetchedRegion
	}

	if messageGatewayServiceConfig.Endpoint == "" {
		fetchedEndpoint, err := getMgsEndpoint(messageGatewayServiceConfig.Region)
		if err != nil {
			log.Errorf("Failed to get MessageGatewayService endpoint with error: %s", err)
			return nil
		}
		messageGatewayServiceConfig.Endpoint = fetchedEndpoint
	}

	connectionTimeout := time.Duration(messageGatewayServiceConfig.StopTimeoutMillis) * time.Millisecond

	mgsService := service.NewService(log, messageGatewayServiceConfig, connectionTimeout)
	processor := processor.NewEngineProcessor(
		sessionContext,
		messageGatewayServiceConfig.SessionWorkersLimit,
		3, // TODO adjust this value
		[]contracts.DocumentType{contracts.StartSession, contracts.TerminateSession})

	controlChannel := &controlchannel.ControlChannel{}

	return &Session{
		context:        sessionContext,
		agentConfig:    agentConfig,
		name:           mgsConfig.SessionServiceName,
		mgsConfig:      messageGatewayServiceConfig,
		service:        mgsService,
		processor:      processor,
		controlChannel: controlChannel,
	}
}
// NewSession gets session core module that manages the web-socket connection between Agent and message gateway service.
NewSession gets session core module that manages the web-socket connection between Agent and message gateway service.
// NewSession gets session core module that manages the web - socket connection between Agent and message gateway service .
func NewSession(context context.T) *Session {
	sessionContext := context.With("[" + mgsConfig.SessionServiceName + "]")
	log := sessionContext.Log()
	appConfig := context.AppConfig()
	instanceID, err := platform.InstanceID()
	targetID, err := platform.TargetID()
	if instanceID == "" {
		log.Errorf("no instanceID provided, %s", err)
		return nil
	}
	isNanoServer, _ := platform.IsPlatformNanoServer(log)
	if isNanoServer {
		log.Info("Session core module is not supported on Windows Nano server.")
		return nil
	}
	agentInfo := contracts.AgentInfo{
		Lang:      appConfig.Os.Lang,
		Name:      appConfig.Agent.Name,
		Version:   appConfig.Agent.Version,
		Os:        appConfig.Os.Name,
		OsVersion: appConfig.Os.Version,
	}
	agentConfig := contracts.AgentConfiguration{
		AgentInfo:  agentInfo,
		InstanceID: instanceID,
		TargetID:   targetID,
	}
	messageGatewayServiceConfig := appConfig.Mgs
	if messageGatewayServiceConfig.Region == "" {
		fetchedRegion, err := platform.Region()
		if err != nil {
			log.Errorf("Failed to get region with error: %s", err)
			return nil
		}
		messageGatewayServiceConfig.Region = fetchedRegion
	}
	if messageGatewayServiceConfig.Endpoint == "" {
		fetchedEndpoint, err := getMgsEndpoint(messageGatewayServiceConfig.Region)
		if err != nil {
			log.Errorf("Failed to get MessageGatewayService endpoint with error: %s", err)
			return nil
		}
		messageGatewayServiceConfig.Endpoint = fetchedEndpoint
	}
	connectionTimeout := time.Duration(messageGatewayServiceConfig.StopTimeoutMillis) * time.Millisecond
	mgsService := service.NewService(log, messageGatewayServiceConfig, connectionTimeout)
	processor := processor.NewEngineProcessor(
		sessionContext,
		messageGatewayServiceConfig.SessionWorkersLimit,
		3, 
		[]contracts.DocumentType{contracts.StartSession, contracts.TerminateSession})
	controlChannel := &controlchannel.ControlChannel{}
	return &Session{
		context:        sessionContext,
		agentConfig:    agentConfig,
		name:           mgsConfig.SessionServiceName,
		mgsConfig:      messageGatewayServiceConfig,
		service:        mgsService,
		processor:      processor,
		controlChannel: controlChannel,
	}
}
func NewSession ( context context . T ) * Session { sessionContext := context . With ( " " + mgsConfig . SessionServiceName + " " ) log := sessionContext . Log ( ) appConfig := context . AppConfig ( ) instanceID , err := platform . InstanceID ( ) targetID , err := platform . TargetID ( ) if instanceID == " " { log . Errorf ( " " , err ) return nil } isNanoServer , _ := platform . IsPlatformNanoServer ( log ) if isNanoServer { log . Info ( " " ) return nil } agentInfo := contracts . AgentInfo { Lang : appConfig . Os . Lang , Name : appConfig . Agent . Name , Version : appConfig . Agent . Version , Os : appConfig . Os . Name , OsVersion : appConfig . Os . Version , } agentConfig := contracts . AgentConfiguration { AgentInfo : agentInfo , InstanceID : instanceID , TargetID : targetID , } messageGatewayServiceConfig := appConfig . Mgs if messageGatewayServiceConfig . Region == " " { fetchedRegion , err := platform . Region ( ) if err != nil { log . Errorf ( " " , err ) return nil } messageGatewayServiceConfig . Region = fetchedRegion } if messageGatewayServiceConfig . Endpoint == " " { fetchedEndpoint , err := getMgsEndpoint ( messageGatewayServiceConfig . Region ) if err != nil { log . Errorf ( " " , err ) return nil } messageGatewayServiceConfig . Endpoint = fetchedEndpoint } connectionTimeout := time . Duration ( messageGatewayServiceConfig . StopTimeoutMillis ) * time . Millisecond mgsService := service . NewService ( log , messageGatewayServiceConfig , connectionTimeout ) processor := processor . NewEngineProcessor ( sessionContext , messageGatewayServiceConfig . SessionWorkersLimit , 3 , [ ] contracts . DocumentType { contracts . StartSession , contracts . TerminateSession } ) controlChannel := & controlchannel . ControlChannel { } return & Session { context : sessionContext , agentConfig : agentConfig , name : mgsConfig . SessionServiceName , mgsConfig : messageGatewayServiceConfig , service : mgsService , processor : processor , controlChannel : controlChannel , } }
NewSession gets session core module that manages the web-socket connection between Agent and message gateway service.
NewSession gets session core module that manages the web - socket connection between Agent and message gateway service .
// If the current os is Nano server, SSM Agent doesn't support the Session Manager. // TODO adjust this value