Skip to content

WIP: kor backend - http server#354

Open
hagay3 wants to merge 16 commits intoyonahd:kor-apifrom
hagay3:feature/hagai/addKorBackend
Open

WIP: kor backend - http server#354
hagay3 wants to merge 16 commits intoyonahd:kor-apifrom
hagay3:feature/hagai/addKorBackend

Conversation

@hagay3
Copy link
Contributor

@hagay3 hagay3 commented Sep 5, 2024

What this PR does / why we need it?

Defines KOR HTTP server that uses the Gorilla Mux router, JWT authentication, and Swagger documentation

Functionality:

  • Security: The API requires JWT tokens for most routes, with optional disabling of auth via an environment variable (NO_AUTH).
  • Documentation: Swagger provides a UI for exploring and interacting with the API endpoints.
  • HTTPS: The server runs with HTTPS using TLS, ensuring secure communication.

PR Checklist

  • This PR adds K8s exceptions (false positives)
  • This PR adds new code
  • This PR includes tests for new/existing code
  • This PR adds docs

GitHub Issue

Notes for your reviewers

@hagay3 hagay3 changed the base branch from main to kor-api September 5, 2024 10:00
Copy link
Owner

@yonahd yonahd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API's look good overall, there are some conventions from kor cli that should be implemented here

}

// Validate list namespaces
func validateListNamespaces(next http.Handler) http.Handler {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move this to namespaces.go

api := router.PathPrefix("/api/v1").Subrouter()

router.HandleFunc("/healthcheck", healthCheckHandler).Methods("GET")
api.Handle("/configmaps", authMiddleware(validateListNamespaces(http.HandlerFunc(getUnusedConfigmaps)))).Methods("GET")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this will grow, maybe this should be in a create routes function

RUN go build -o /go-service

# Use a smaller base image for the final container
FROM alpine:latest
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use FROM scratch it will make the image significantly smaller

@@ -0,0 +1,33 @@
# Use an official Golang image as the build environment
FROM golang:1.22.2-alpine AS builder
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at the kor dockerfile https://github.com/yonahd/kor/blob/main/Dockerfile

making it easier to integrate into web services, dashboards, and automation pipelines.

## Swagger
```swag init```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the swagger initialized by default in the docker?

package main

import (
"crypto/tls"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sort the imports as we do in kor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants