Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor out io/ioutil #224

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions index/generator/vendor/github.com/hashicorp/hcl/.gitignore

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 @@
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -121,15 +120,15 @@
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 @@
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) 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 @@
localLoc = downloadFilePath
}

downloadBytes, err = ioutil.ReadFile(filepath.Clean(localLoc))
downloadBytes, err = os.ReadFile(filepath.Clean(localLoc))

Check warning on line 383 in index/server/pkg/server/endpoint.go

View check run for this annotation

Codecov / codecov/patch

index/server/pkg/server/endpoint.go#L383

Added line #L383 was not covered by tests
if err != nil {
log.Print(err.Error())
c.JSON(http.StatusInternalServerError, gin.H{
Expand Down Expand Up @@ -431,15 +433,15 @@
}
}

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 @@
// 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 @@
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)

Check warning on line 735 in index/server/pkg/server/endpoint.go

View check run for this annotation

Codecov / codecov/patch

index/server/pkg/server/endpoint.go#L735

Added line #L735 was not covered by tests
}
if err != nil {
log.Print(err.Error())
Expand Down Expand Up @@ -803,8 +805,8 @@
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
Loading