Beispiel #1
0
func (s *RemoteClient) Handle(ctx context.Context, msg transport.Extractor) (interface{}, error) {
	req := api.RequestV1{}
	err := msg.Extract(&req)
	if err != nil {
		return nil, err
	}
	switch req.Method {
	case api.Connect:
		s.connected <- struct{}{}
		return nil, nil
	default:
		return nil, fmt.Errorf("Unknown method requested %s", req.Method)
	}
}
Beispiel #2
0
func (s *RemoteServer) Handle(ctx context.Context, msg transport.Extractor) (interface{}, error) {
	req := api.RequestV1{}
	resp := api.ResponseV1{}
	err := msg.Extract(&req)
	if err != nil {
		return nil, err
	}

	switch req.Method {
	case api.GetConfig:
		if data, err := s.GetConfig(ctx); err != nil {
			return nil, err
		} else {
			resp.GetConfig = data
		}

	case api.GetPluginVersions:
		if data, err := s.GetPluginVersions(ctx, req.GetPluginVersions); err != nil {
			return nil, err
		} else {
			resp.GetPluginVersions = data
		}

	case api.RunPlugin:
		if data, err := s.RunPlugin(ctx, req.RunPlugin); err != nil {
			return nil, err
		} else {
			resp.RunPlugin = data
		}

	case api.SendReport:
		if err := s.SendReport(ctx, req.SendReport); err != nil {
			return nil, err
		}
	case api.DownloadFile:
		if data, err := s.DownloadFile(ctx, req.DownloadFile); err != nil {
			return nil, err
		} else {
			resp.DownloadFile = data
		}
	default:
		return nil, fmt.Errorf("Unknown method requested %s", req.Method)
	}

	return resp, nil
}