Skip to content

Commit

Permalink
refactor out 'io/ioutil' (#224)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Valdron <[email protected]>
  • Loading branch information
michael-valdron authored Mar 13, 2024
1 parent e51ee89 commit 9445a83
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 118 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 17 additions & 15 deletions index/server/pkg/server/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package server
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -121,15 +120,15 @@ func (*Server) ServeDevfileIndexV1WithType(c *gin.Context, indexType string, par
buildIndexAPIResponse(c, indexType, true, IndexParams(params))
}

func (*Server) PostDevfileIndexV1WithType(c *gin.Context, indexType string, params PostDevfileIndexV1WithTypeParams){
func (*Server) PostDevfileIndexV1WithType(c *gin.Context, indexType string, params PostDevfileIndexV1WithTypeParams) {
SetMethodNotAllowedJSONResponse(c)
}

func (*Server) PutDevfileIndexV1WithType(c *gin.Context, indexType string, params PutDevfileIndexV1WithTypeParams){
func (*Server) PutDevfileIndexV1WithType(c *gin.Context, indexType string, params PutDevfileIndexV1WithTypeParams) {
SetMethodNotAllowedJSONResponse(c)
}

func (*Server) DeleteDevfileIndexV1WithType(c *gin.Context, indexType string, params DeleteDevfileIndexV1WithTypeParams){
func (*Server) DeleteDevfileIndexV1WithType(c *gin.Context, indexType string, params DeleteDevfileIndexV1WithTypeParams) {
SetMethodNotAllowedJSONResponse(c)
}

Expand Down Expand Up @@ -157,14 +156,17 @@ func (*Server) ServeHealthCheck(c *gin.Context) {
Message: "the server is up and running",
})
}

// PostHealthCheck serves endpoint `/health` for registry health check with POST request
func (*Server) PostHealthCheck(c *gin.Context) {
SetMethodNotAllowedJSONResponse(c)
}

// PutHealthCheck serves endpoint `/health` for registry health check with PUT request
func (*Server) PutHealthCheck(c *gin.Context) {
SetMethodNotAllowedJSONResponse(c)
}

// DeleteHealthCheck serves endpoint `/health` for registry health check with DELETE request
func (*Server) DeleteHealthCheck(c *gin.Context) {
SetMethodNotAllowedJSONResponse(c)
Expand Down Expand Up @@ -198,15 +200,15 @@ func (*Server) ServeDevfileWithVersion(c *gin.Context, name string, version stri
}
}

func (*Server) PostDevfileWithVersion(c *gin.Context, name string, version string){
func (*Server) PostDevfileWithVersion(c *gin.Context, name string, version string) {
SetMethodNotAllowedJSONResponse(c)
}

func (*Server) PutDevfileWithVersion(c *gin.Context, name string, version string){
func (*Server) PutDevfileWithVersion(c *gin.Context, name string, version string) {
SetMethodNotAllowedJSONResponse(c)
}

func (*Server) DeleteDevfileWithVersion(c *gin.Context, name string, version string){
func (*Server) DeleteDevfileWithVersion(c *gin.Context, name string, version string) {
SetMethodNotAllowedJSONResponse(c)
}

Expand Down Expand Up @@ -378,7 +380,7 @@ func (*Server) ServeDevfileStarterProjectWithVersion(c *gin.Context, name string
localLoc = downloadFilePath
}

downloadBytes, err = ioutil.ReadFile(filepath.Clean(localLoc))
downloadBytes, err = os.ReadFile(filepath.Clean(localLoc))
if err != nil {
log.Print(err.Error())
c.JSON(http.StatusInternalServerError, gin.H{
Expand Down Expand Up @@ -431,15 +433,15 @@ func (*Server) ServeDevfileStarterProjectWithVersion(c *gin.Context, name string
}
}

func (*Server) PostDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string){
func (*Server) PostDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string) {
SetMethodNotAllowedJSONResponse(c)
}

func (*Server) PutDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string){
func (*Server) PutDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string) {
SetMethodNotAllowedJSONResponse(c)
}

func (*Server) DeleteDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string){
func (*Server) DeleteDevfileStarterProjectWithVersion(c *gin.Context, name string, version string, starterProject string) {
SetMethodNotAllowedJSONResponse(c)
}

Expand Down Expand Up @@ -634,7 +636,7 @@ func buildProxyErrorResponse(w http.ResponseWriter, r *http.Request, err error,
// schema from `indexPath` given by server.
func fetchDevfile(c *gin.Context, name string, version string) ([]byte, indexSchema.Schema) {
var index []indexSchema.Schema
bytes, err := ioutil.ReadFile(indexPath)
bytes, err := os.ReadFile(indexPath)
if err != nil {
log.Print(err.Error())
c.JSON(http.StatusInternalServerError, gin.H{
Expand Down Expand Up @@ -730,7 +732,7 @@ func fetchDevfile(c *gin.Context, name string, version string) ([]byte, indexSch
if sampleDevfilePath != "" {
if _, err = os.Stat(sampleDevfilePath); err == nil {
/* #nosec G304 -- sampleDevfilePath is constructed from path.Join which cleans the input paths */
bytes, err = ioutil.ReadFile(sampleDevfilePath)
bytes, err = os.ReadFile(sampleDevfilePath)
}
if err != nil {
log.Print(err.Error())
Expand Down Expand Up @@ -803,8 +805,8 @@ func ServeOciProxy(c *gin.Context) {
proxy.ServeHTTP(c.Writer, c.Request)
}

func SetMethodNotAllowedJSONResponse(c *gin.Context){
func SetMethodNotAllowedJSONResponse(c *gin.Context) {
c.JSON(http.StatusMethodNotAllowed, MethodNotAllowedResponse{
Message: "Only GET requests are supported.",
})
}
}
Loading

0 comments on commit 9445a83

Please sign in to comment.