Skip to content

Commit

Permalink
code annotation (#95)
Browse files Browse the repository at this point in the history
* change version of k8s.io to v0.24.0 from v0.24.0-alpha.4 (#92)

* change version of k8s.io to v0.24.0 from v0.24.0-alpha.4 (#92)

* change version of k8s.io to v0.24.0 from v0.24.0-alpha.4 (#92)

* Unnecessary modifications were removed

* Unnecessary modifications were removed

* add anno

* remove something

* remove something

* remove something

* Modified

* remove

Co-authored-by: Tom Qin <[email protected]>
Co-authored-by: xiaoyu0803 <xiaoyu0803>
  • Loading branch information
xiaoyu0803 and Tom Qin authored May 13, 2022
1 parent 4b6242a commit fac9752
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
- Wechat:
- zhengkaiwen196649
Expand Down
10 changes: 10 additions & 0 deletions deviceshifu/pkg/deviceshifu/deviceshifu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 := "?"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions deviceshifu/pkg/deviceshifu/deviceshifu_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions driver_util/http_to_ssh_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit fac9752

Please sign in to comment.