diff --git a/README.md b/README.md index 0cc25091e..ffa81f989 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ If every IoT device has a Shifu with it, we can leverage software to manage our ## Contact -Feel free to open a GitHub issue or contact us in the following ways: +Feel free to open a [GitHub issue](https://github.com/Edgenesis/shifu/issues/new) or contact us in the following ways: - Email: info@edgenesis.com - Wechat: - zhengkaiwen196649 diff --git a/deviceshifu/pkg/deviceshifu/deviceshifu.go b/deviceshifu/pkg/deviceshifu/deviceshifu.go index 11a75c345..ee3285ff5 100644 --- a/deviceshifu/pkg/deviceshifu/deviceshifu.go +++ b/deviceshifu/pkg/deviceshifu/deviceshifu.go @@ -61,6 +61,7 @@ const ( KUBERNETES_CONFIG_DEFAULT string = "" ) +// This function creates a new Device Shifu based on the configuration func New(deviceShifuMetadata *DeviceShifuMetaData) (*DeviceShifu, error) { if deviceShifuMetadata.Name == "" { return nil, fmt.Errorf("DeviceShifu's name can't be empty\n") @@ -100,6 +101,7 @@ func New(deviceShifuMetadata *DeviceShifuMetaData) (*DeviceShifu, error) { return nil, err } + // switch for different Shifu Protocols switch protocol := *edgeDevice.Spec.Protocol; protocol { case v1alpha1.ProtocolHTTP: for instruction, properties := range deviceShifuConfig.Instructions { @@ -158,6 +160,7 @@ func New(deviceShifuMetadata *DeviceShifuMetaData) (*DeviceShifu, error) { return ds, nil } +// deviceHealthHandler writes the status as healthy func deviceHealthHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, DEVICE_IS_HEALTHY_STR) } @@ -172,6 +175,12 @@ func instructionNotFoundHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, "Error: Device instruction does not exist!", http.StatusNotFound) } +// This function is to create a URL containing directives from the requested URL +// e.g.: +// if we have http://localhost:8081/start?time=10:00:00&target=machine1&target=machine2 +// and our address is http://localhost:8088 and instruction is start +// then we will get this URL string: +// http://localhost:8088/start?time=10:00:00&target=machine1&target=machine2 func createUriFromRequest(address string, handlerInstruction string, r *http.Request) string { queryStr := "?" @@ -191,6 +200,7 @@ func createUriFromRequest(address string, handlerInstruction string, r *http.Req return "http://" + address + "/" + handlerInstruction + queryStr } +// This function executes the instruction by requesting the url returned by createUriFromRequest func (handler DeviceCommandHandlerHTTP) commandHandleFunc() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { handlerProperties := handler.deviceShifuHTTPHandlerMetaData.properties diff --git a/deviceshifu/pkg/deviceshifu/deviceshifu_config.go b/deviceshifu/pkg/deviceshifu/deviceshifu_config.go index 861240e04..8e900dee2 100644 --- a/deviceshifu/pkg/deviceshifu/deviceshifu_config.go +++ b/deviceshifu/pkg/deviceshifu/deviceshifu_config.go @@ -61,6 +61,7 @@ const ( EDGEDEVICE_RESOURCE_STR = "edgedevices" ) +// Read the configuration under the path directory and return configuration func NewDeviceShifuConfig(path string) (*DeviceShifuConfig, error) { if path == "" { return nil, errors.New("DeviceShifuConfig path can't be empty") diff --git a/driver_util/http_to_ssh_stub.go b/driver_util/http_to_ssh_stub.go index fe9ee688e..f61d3dee5 100644 --- a/driver_util/http_to_ssh_stub.go +++ b/driver_util/http_to_ssh_stub.go @@ -12,6 +12,7 @@ import ( "golang.org/x/crypto/ssh" ) +// Get the required configuration from the environment variables var ( privateSSHKeyFile = os.Getenv("EDGEDEVICE_DRIVER_SSH_KEY_PATH") driverHTTPPort = os.Getenv("EDGEDEVICE_DRIVER_HTTP_PORT") @@ -77,6 +78,9 @@ func main() { http.Serve(ssh_listener, httpCmdlinePostHandler(sshClient)) } +// Create a session reply for the incoming connection, obtain the connection body information, +// process it, hand it over to the shell for processing,return both result and status code based +// on shell execution result func httpCmdlinePostHandler(sshConnection *ssh.Client) http.HandlerFunc { return func(resp http.ResponseWriter, req *http.Request) { session, err := sshConnection.NewSession()