-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ehaligow-chassis-alignment-with-OpenRMC1.0
- Loading branch information
Showing
10 changed files
with
298 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,7 @@ prereq: | |
&& sudo mv /tmp/protoc3/bin/* /usr/local/bin/ \ | ||
&& sudo mv /tmp/protoc3/include/* /usr/local/include/ | ||
rm -rf /tmp/protoc3 | ||
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go get -v google.golang.org/grpc | ||
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go get -v google.golang.org/grpc@v1.57.0 | ||
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest | ||
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go install github.com/golang/protobuf/[email protected] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package rest | ||
|
||
import ( | ||
"devicemanager/config" | ||
"devicemanager/rest/redfish" | ||
"fmt" | ||
"github.com/kataras/iris/v12" | ||
"github.com/kataras/iris/v12/context" | ||
"github.com/sirupsen/logrus" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
type patchPowerHandler struct { | ||
cfg config.Config | ||
} | ||
|
||
func (r *patchPowerHandler) handle(ctx iris.Context) { | ||
if ctx.GetHeader("Authorization") == "" { | ||
noValidAuthError := "No valid authorization" | ||
ctx.StatusCode(http.StatusUnauthorized) | ||
logrus.Error(noValidAuthError) | ||
ctx.WriteString(noValidAuthError) | ||
return | ||
} | ||
|
||
var reqInfo redfish.RequestInformation | ||
|
||
// Get information from the request. | ||
err := ctx.ReadJSON(&reqInfo) | ||
if err != nil { | ||
missingInfoError := "Unable to retrieve information from a request: " + err.Error() | ||
logrus.Error(missingInfoError) | ||
ctx.StatusCode(http.StatusBadRequest) | ||
ctx.WriteString(missingInfoError) | ||
return | ||
} | ||
|
||
httpClient := redfish.NewHttpClient(r.cfg).WithBasicAuth(reqInfo.Username, string(reqInfo.Password)) | ||
uri := fmt.Sprintf("https://%s%s", reqInfo.Host, ctx.Request().RequestURI) | ||
|
||
response, err := httpClient.Patch(uri, reqInfo.Body) | ||
if err != nil { | ||
errorMessage := fmt.Sprintf("PATCH action failed on %s due to: %s", uri, err.Error()) | ||
logrus.Error(errorMessage) | ||
if response == nil { | ||
ctx.StatusCode(http.StatusInternalServerError) | ||
ctx.WriteString(errorMessage) | ||
return | ||
} | ||
} | ||
|
||
defer response.Body.Close() | ||
body, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
errorMessage := "Error while reading response body: " + err.Error() | ||
logrus.Error(errorMessage) | ||
ctx.StatusCode(http.StatusInternalServerError) | ||
ctx.WriteString(errorMessage) | ||
return | ||
} | ||
|
||
ctx.StatusCode(response.StatusCode) | ||
ctx.Write(body) | ||
} | ||
|
||
func newPatchPowerHandler(cfg config.Config) context.Handler { | ||
return (&patchPowerHandler{ | ||
cfg: cfg, | ||
}).handle | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.