Skip to content

Commit

Permalink
Adds vip routes to routes service
Browse files Browse the repository at this point in the history
  • Loading branch information
rspurgeon committed Aug 19, 2024
1 parent 71c7d86 commit ac64cac
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 27 deletions.
67 changes: 40 additions & 27 deletions flight-data/routes/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,63 @@ package api
import (
"github.com/Kong/KongAir/flight-data/routes/api/models"
"github.com/labstack/echo/v4"
"net/http"
"net/http"
)

type RouteService struct {
Routes []models.Route
Routes []models.Route
PrivateRoutes []models.Route
}

func NewRouteService() *RouteService {
rv := RouteService{}
rv.Routes = []models.Route{
{Id: "LHR-JFK", Origin: "LHR", Destination: "JFK", AvgDuration: 470},
{Id: "LHR-SFO", Origin: "LHR", Destination: "SFO", AvgDuration: 660},
{Id: "LHR-DXB", Origin: "LHR", Destination: "DXB", AvgDuration: 420},
{Id: "LHR-HKG", Origin: "LHR", Destination: "HKG", AvgDuration: 745},
{Id: "LHR-BOM", Origin: "LHR", Destination: "BOM", AvgDuration: 540},
{Id: "LHR-HND", Origin: "LHR", Destination: "HND", AvgDuration: 830},
{Id: "LHR-CPT", Origin: "LHR", Destination: "CPT", AvgDuration: 700},
{Id: "LHR-SYD", Origin: "LHR", Destination: "SYD", AvgDuration: 1320},
{Id: "LHR-SIN", Origin: "LHR", Destination: "SIN", AvgDuration: 800},
{Id: "LHR-LAX", Origin: "LHR", Destination: "LAX", AvgDuration: 675},
{Id: "LHR-JFK", Origin: "LHR", Destination: "JFK", AvgDuration: 470},
{Id: "LHR-SFO", Origin: "LHR", Destination: "SFO", AvgDuration: 660},
{Id: "LHR-DXB", Origin: "LHR", Destination: "DXB", AvgDuration: 420},
{Id: "LHR-HKG", Origin: "LHR", Destination: "HKG", AvgDuration: 745},
{Id: "LHR-BOM", Origin: "LHR", Destination: "BOM", AvgDuration: 540},
{Id: "LHR-HND", Origin: "LHR", Destination: "HND", AvgDuration: 830},
{Id: "LHR-CPT", Origin: "LHR", Destination: "CPT", AvgDuration: 700},
{Id: "LHR-SYD", Origin: "LHR", Destination: "SYD", AvgDuration: 1320},
{Id: "LHR-SIN", Origin: "LHR", Destination: "SIN", AvgDuration: 800},
{Id: "LHR-LAX", Origin: "LHR", Destination: "LAX", AvgDuration: 675},
}
rv.PrivateRoutes = []models.Route{
{Id: "VIP-LHR-JFK", Origin: "LHR", Destination: "VIP-JFK", AvgDuration: 430},
{Id: "VIP-LHR-SFO", Origin: "LHR", Destination: "VIP-SFO", AvgDuration: 620},
{Id: "VIP-LHR-DXB", Origin: "LHR", Destination: "VIP-DXB", AvgDuration: 390},
{Id: "VIP-LHR-HKG", Origin: "LHR", Destination: "VIP-HKG", AvgDuration: 645},
}
return &rv
}

func (s *RouteService) GetHealth(ctx echo.Context) error {
return ctx.JSON(http.StatusOK, map[string]string{"status": "OK"})
return ctx.JSON(http.StatusOK, map[string]string{"status": "OK"})
}

func (s *RouteService) GetRoutes(ctx echo.Context, params models.GetRoutesParams) error {
err := ctx.JSON(200, s.Routes)
if err != nil {
return err
if ctx.Request().Header.Get("x-vip") == "true" {
allRoutes := append(s.Routes, s.PrivateRoutes...)
return ctx.JSON(200, allRoutes)
}
return nil

return ctx.JSON(200, s.Routes)
}

func (s *RouteService) GetRoute(ctx echo.Context, id string) error {
for _, route := range s.Routes {
if route.Id == id {
err := ctx.JSON(200, route)
if err != nil {
return err
}
return nil
}
}
return ctx.JSON(404, nil)
routes := s.Routes
if ctx.Request().Header.Get("x-vip") == "true" {
routes = append(routes, s.PrivateRoutes...)
}
for _, route := range routes {
if route.Id == id {
err := ctx.JSON(200, route)
if err != nil {
return err
}
return nil
}
}
return ctx.JSON(404, nil)
}
25 changes: 25 additions & 0 deletions flight-data/routes/dev/kong/patches.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
_format_version: "1.0"

patches:
- selectors:
- $
values:
consumers:
- username: anonymous
- username: daliya
keyauth_credentials:
- key: kongftw
consumer_groups:
- name: vip
plugins:
- name: request-transformer
config:
add:
headers:
x-vip: true
consumers:
- username: daliya
- selectors:
- $.services[?(@.name=="routes-service")]
values:
host: routes.kong-air.dev
port: 443
protocol: https
plugins:
- name: key-auth
config:
key_names:
- apikey
hide_credentials: true
anonymous: "anonymous"

0 comments on commit ac64cac

Please sign in to comment.