Skip to content

Commit d3fa081

Browse files
nirshtNirSht
authored andcommitted
Initial commit
add go.mod and main.go add main test remove current pattern initial add /backend add /backend change file directories change file directories change file directories change file directories change file directories and fix import issues add frontend template add esentianl pckages Bump github.com/gin-gonic/gin from 1.5.0 to 1.7.0 Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from 1.5.0 to 1.7.0. - [Release notes](https://github.com/gin-gonic/gin/releases) - [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md) - [Commits](gin-gonic/gin@v1.5.0...v1.7.0) --- updated-dependencies: - dependency-name: github.com/gin-gonic/gin dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> ADD CORS, change default App.tsx to React convention serverless and bucket configurstion with go libraries reorder files and directories Update package-lock.json add build for local and prod, move tests change enpoint url of serverless change serveless cunfiguration build cod-infra in order backend to be stable move backend dir remove installation configure netlify and clear README Add makefile and endpoints to backend Add documentation and makefile Configure basic UI and logo add routes generate basic UI with text area add yarn.lock to main project extand api functionallity extand api functionallity move utils to anther directory start interact with kube-neat OS organize go.mod and go.sun download kubernetes write neat yaml wrappper clean functionallty arounf button and converting yaml to neat remove welcode path change name to kubevalid rename all files to validkube add new fetching change routes and endpoint for kubeval change lambda getway + add error on fetching add kubeval wrapper + functionallity in forntend fix scrolling to the side handle errors from front end in go server change documentation change documentation add trivy endpoint run 'go mod tidy' configure image to trivy New brand UI + trivy configuration UI fixes and generate new Dockerfile some we can run Trivy CLI suit application wo mobile out trivy as yaml UI fixes, relative to screen size + LOGO UI improvements and add GitStart small rename Add example and clear button functionallity remove target yaml and add documentation convert kubeval output to yaml try adding githuba actions try adding githuba actions remvoe github actions UI fixes change manifest and kubeval functionallity more UI fixes move kubeval to serverless as image move kubeval to serverless more litlle fixes on UI add styled yaml bump go versions
0 parents  commit d3fa081

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+13051
-0
lines changed

.gitignore

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port
105+
106+
# Local Netlify folder
107+
.netlify
108+
109+
#deploy
110+
/bin

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
ARG BUILDER_IMAGE
2+
FROM alpine:3.14 as deps
3+
RUN apk --no-cache add curl
4+
RUN curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.22.0
5+
RUN wget https://github.com/instrumenta/kubeval/releases/latest/download/kubeval-linux-amd64.tar.gz
6+
RUN tar xf kubeval-linux-amd64.tar.gz
7+
RUN cp kubeval /usr/local/bin
8+
9+
FROM golang:1.17
10+
11+
ARG FUNCTION_DIR="/var/task"
12+
RUN mkdir -p ${FUNCTION_DIR}
13+
14+
COPY /bin/lambda ${FUNCTION_DIR}
15+
16+
17+
COPY --from=deps /usr/local/bin/trivy /usr/local/bin/trivy
18+
RUN chmod +x /usr/local/bin/trivy
19+
COPY --from=deps /usr/local/bin/kubeval /usr/local/bin/kubeval
20+
RUN chmod +x /usr/local/bin/kubeval
21+
22+
23+
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
24+
CMD [ "/var/task/lambda" ]

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.PHONY: build clean deploy
2+
3+
clean:
4+
rm -rf ./bin
5+
6+
build:
7+
rm -f bin/*
8+
env GOOS=linux go build -ldflags="-s -w" -o bin/lambda backend/endpoints/aws/lambda.go
9+
10+
deploy: clean build
11+
sls deploy --verbose

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# validkube
2+
3+
### Prerequisite
4+
5+
- aws CLI with access to your AWS
6+
- yarn
7+
- npm
8+
- serverless CLI
9+
10+
---
11+
12+
### Deploy backend server less
13+
14+
```bash
15+
make deploy
16+
```
17+
18+
Serverless endpoint: https://gtgmn58dh9.execute-api.us-east-1.amazonaws.com/production
19+
20+
Frontend-domain: https://validkube.com
21+
22+
In order to update web domin:
23+
24+
```bash
25+
aws ssm put-parameter --name /validkube/config/allowed_origin --type String --value {frontend-domain} --overwrite
26+
```
27+
28+
In order to deploy frontend:
29+
30+
```bash
31+
cd frontend
32+
netlify deploy --prod
33+
```
34+
35+
# Local environment
36+
37+
Set local env of allowed origin, example in Unix-like:
38+
39+
```bash
40+
export ALLOWED_ORIGIN=http://localhost:3000
41+
```
42+
43+
In order to start backend run:
44+
45+
```bash
46+
go run backend/development/localdev.go
47+
```
48+
49+
In order to start frontend run:
50+
51+
```bash
52+
cd frontend
53+
yarn insatll
54+
yarn start
55+
```

backend/api/hello/hello.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package hello
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
7+
"github.com/gin-gonic/gin"
8+
"github.com/komodorio/validkube/backend/internal/routing"
9+
)
10+
11+
const Path = "/hello"
12+
const Method = routing.GET
13+
14+
func ProcessRequest(c *gin.Context) {
15+
name := c.Query("name")
16+
c.JSON(http.StatusOK, gin.H{"msg": fmt.Sprintf("Hello %v!", name)})
17+
}

backend/api/kubeneat/kubeneat.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package kubeneat
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
"io/ioutil"
7+
"net/http"
8+
"unicode"
9+
10+
"github.com/gin-gonic/gin"
11+
"github.com/itaysk/kubectl-neat/cmd"
12+
"github.com/komodorio/validkube/backend/api/utils"
13+
"github.com/komodorio/validkube/backend/internal/routing"
14+
"sigs.k8s.io/yaml"
15+
)
16+
17+
const Path = "/kubeneat"
18+
const Method = routing.POST
19+
20+
func NeatYAMLOrJSONWrapper(in []byte) (out []byte, errrDescription string, err error) {
21+
var injson, outjson string
22+
23+
itsYaml := !bytes.HasPrefix(bytes.TrimLeftFunc(in, unicode.IsSpace), []byte{'{'})
24+
if itsYaml {
25+
injsonbytes, err := yaml.YAMLToJSON(in)
26+
if err != nil {
27+
return nil, "error converting from yaml to json", err
28+
}
29+
injson = string(injsonbytes)
30+
} else {
31+
injson = string(in)
32+
}
33+
34+
outjson, err = cmd.Neat(injson)
35+
if err != nil {
36+
return nil, "error neating", err
37+
}
38+
39+
if itsYaml {
40+
out, err = yaml.JSONToYAML([]byte(outjson))
41+
if err != nil {
42+
return nil, "error converting from json to ymls", err
43+
}
44+
} else {
45+
out = []byte(outjson)
46+
}
47+
return out, "", nil
48+
}
49+
50+
func ProcessRequest(c *gin.Context) {
51+
body, err := ioutil.ReadAll(c.Request.Body)
52+
if err != nil {
53+
errDescription := fmt.Sprintf("Erorr has with reading request body: %v", err.Error())
54+
c.JSON(http.StatusPartialContent, gin.H{"data": "", "err": errDescription})
55+
return
56+
}
57+
bodyAsMap, err := utils.JsonToMap(body)
58+
if err != nil {
59+
c.JSON(http.StatusPartialContent, gin.H{"data": "", "err": err.Error()})
60+
return
61+
}
62+
yamlAsInterface := bodyAsMap["yaml"]
63+
neatYaml, errDescription, err := NeatYAMLOrJSONWrapper(utils.InterfaceToBytes(yamlAsInterface))
64+
if err != nil {
65+
fullError := fmt.Sprintf("%v: %v", errDescription, err.Error())
66+
c.JSON(http.StatusOK, gin.H{"data": "", "err": fullError})
67+
}
68+
c.JSON(http.StatusOK, gin.H{"data": string(neatYaml), "err": nil})
69+
}

backend/api/kubeval/kubeval.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package kubeval
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"net/http"
7+
"os"
8+
"os/exec"
9+
10+
"github.com/gin-gonic/gin"
11+
"github.com/komodorio/validkube/backend/api/utils"
12+
"github.com/komodorio/validkube/backend/internal/routing"
13+
"sigs.k8s.io/yaml"
14+
)
15+
16+
const Path = "/kubeval"
17+
const Method = routing.POST
18+
19+
func kubevalWrapper(inputYaml []byte) ([]byte, error) {
20+
_, err := utils.RunCommand("mkdir", "-p", "/tmp/yaml")
21+
if err != nil {
22+
return nil, err
23+
}
24+
25+
file, err := os.Create("/tmp/yaml/target_yaml.yaml")
26+
if err != nil {
27+
return nil, err
28+
} else {
29+
file.WriteString(string(inputYaml))
30+
}
31+
file.Close()
32+
33+
outputFromKubevalAsJson, _ := exec.Command("kubeval", "-o", "json", "/tmp/yaml/target_yaml.yaml").Output()
34+
35+
outputFromKubevalAsYaml, err := yaml.JSONToYAML(outputFromKubevalAsJson)
36+
if err != nil {
37+
return nil, err
38+
}
39+
return outputFromKubevalAsYaml, nil
40+
}
41+
42+
func ProcessRequest(c *gin.Context) {
43+
body, err := ioutil.ReadAll(c.Request.Body)
44+
if err != nil {
45+
fmt.Printf("Erorr has with reading request body: %v", err)
46+
c.JSON(http.StatusOK, gin.H{"data": "", "err": err.Error()})
47+
return
48+
}
49+
bodyAsMap, err := utils.JsonToMap(body)
50+
if err != nil {
51+
c.JSON(http.StatusOK, gin.H{"data": "", "err": err.Error()})
52+
return
53+
}
54+
yamlAsInterface := bodyAsMap["yaml"]
55+
kubevalOutput, err := kubevalWrapper(utils.InterfaceToBytes(yamlAsInterface))
56+
if err != nil {
57+
c.JSON(http.StatusOK, gin.H{"data": "", "err": err.Error()})
58+
return
59+
}
60+
c.JSON(http.StatusOK, gin.H{"data": string(kubevalOutput), "err": nil})
61+
}

0 commit comments

Comments
 (0)