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

WIP: kor backend - http server #354

Open
wants to merge 16 commits into
base: kor-api
Choose a base branch
from

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.

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