Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from Zeerg/develop
Browse files Browse the repository at this point in the history
v0.1
  • Loading branch information
Zeerg authored Aug 31, 2021
2 parents a9ca2ff + 88196dd commit 0c2c912
Show file tree
Hide file tree
Showing 55 changed files with 100 additions and 3,287 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
bin/
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ WORKDIR /

# Until Go Embed stuff
COPY --from=build /helix-honeypot /helix-honeypot
COPY --from=build /app/kube_json /kube_json

EXPOSE 8000

Expand Down
32 changes: 12 additions & 20 deletions handler/apiHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,28 @@ import (
"github.com/labstack/echo/v4"
"net/http"
"encoding/json"
"io/ioutil"
)
// Root Route Handler
func ApiHandler(c echo.Context) error {
jsonFile, err := ioutil.ReadFile("./kube_json/api.json")
if err != nil {
c.Logger().Print(err)
}
var data map[string]interface{}
err = json.Unmarshal(jsonFile, &data)

err := json.Unmarshal(embedGet("api.json"), &data)
if err != nil {
c.Logger().Print(err)
}
return c.JSON(http.StatusOK, data)
}
// Basic API Handler
func ApiResourceList(c echo.Context) error {
jsonFile, err := ioutil.ReadFile("./kube_json/api_resourcelist.json")
if err != nil {
c.Logger().Print(err)
}
var data map[string]interface{}
err = json.Unmarshal(jsonFile, &data)

err := json.Unmarshal(embedGet("api_resourcelist.json"), &data)
if err != nil {
c.Logger().Print(err)
}
return c.JSON(http.StatusOK, data)
}
func ApiGroupList(c echo.Context) error {
jsonFile, err := ioutil.ReadFile("./kube_json/api_grouplist.json")
if err != nil {
c.Logger().Print(err)
}
var data map[string]interface{}
err = json.Unmarshal(jsonFile, &data)
err := json.Unmarshal(embedGet("api_grouplist.json"), &data)
if err != nil {
c.Logger().Print(err)
}
return c.JSON(http.StatusOK, data)
}
18 changes: 18 additions & 0 deletions handler/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package handler

import (
"embed"
"fmt"
)
// Embed the required files
//go:embed embedded/*
var embededFS embed.FS

// Embed FS function
func embedGet(fileName string) []byte {
fileBytes, err := embededFS.ReadFile("embedded/" + fileName)
if err != nil {
fmt.Print(err)
}
return fileBytes
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 2 additions & 6 deletions handler/openapiHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import (
"bytes"
"compress/gzip"
"crypto/sha512"
_ "embed"

"github.com/labstack/echo/v4"
"github.com/golang/protobuf/proto"
openapi_v2 "github.com/googleapis/gnostic/openapiv2"
)
// Embed the yaml file with go embed
//go:embed openapiYaml/k8s_v1.19.7_openapi.yaml
var openApiBytes []byte

// Kubectl expects gzip usually....I really don't know
func gzipHelper(data []byte) []byte {
var buf bytes.Buffer
Expand All @@ -29,8 +26,7 @@ func computeETag(data []byte) string {
}
// OpenAPI Handler becuase unless the swagger doc is cached locally it's transferred on every request :(
func OpenApiHandler(c echo.Context) error {

openApiDoc, err := openapi_v2.ParseDocument(openApiBytes)
openApiDoc, err := openapi_v2.ParseDocument(embedGet("v1.19.7_openapi.yaml"))
if err != nil {
c.Logger().Print(err)
}
Expand Down
11 changes: 4 additions & 7 deletions handler/resourcesHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ import (
"github.com/labstack/echo/v4"
"net/http"
"encoding/json"
"io/ioutil"
)

// Pods Handler for default routes etc..Just returns blank
func PodsHandler(c echo.Context) error {
jsonFile, err := ioutil.ReadFile("./kube_json/default_pods.json")
if err != nil {
c.Logger().Print(err)
}
var data map[string]interface{}
err = json.Unmarshal(jsonFile, &data)

err := json.Unmarshal(embedGet("empty_list.json"), &data)
if err != nil {
c.Logger().Print(err)
}
return c.JSON(http.StatusOK, data)
}
// Handler for any k8s resource like deployments etc.
Expand Down
12 changes: 4 additions & 8 deletions handler/rootHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import (
"github.com/labstack/echo/v4"
"net/http"
"encoding/json"
"fmt"
"io/ioutil"
)
// Root Route Handler
func RootHandler(c echo.Context) error {
jsonFile, err := ioutil.ReadFile("./kube_json/root.json")
if err != nil {
fmt.Print(err)
}
var data map[string]interface{}
err = json.Unmarshal(jsonFile, &data)

err := json.Unmarshal(embedGet("root.json"), &data)
if err != nil {
c.Logger().Print(err)
}
return c.JSON(http.StatusOK, data)
}
14 changes: 6 additions & 8 deletions handler/serviceHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ import (
"github.com/labstack/echo/v4"
"net/http"
"fmt"
"io/ioutil"
"encoding/json"

)
//Pods Handler
func ServiceHandler(c echo.Context) error {
servicePathBase := "./kube_json/resource_dump/"
servicePathBase := "resource_dump/"
service := c.Param("service")
version := c.Param("version")
fileName := "serverresources.json"
filePath := fmt.Sprintf("%s%s/%s/%s", servicePathBase, service, version, fileName)
jsonFile, err := ioutil.ReadFile(filePath)
if err != nil {
var data map[string]interface{}
err := json.Unmarshal(embedGet(filePath), &data)
if err != nil {
c.Logger().Print(err)
}
var result map[string]interface{}
json.Unmarshal(jsonFile, &result)
return c.JSON(http.StatusOK, result)
}
return c.JSON(http.StatusOK, data)
}
Loading

0 comments on commit 0c2c912

Please sign in to comment.