Skip to content

Commit

Permalink
added missing files and some fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Jasmin Gacic <jasmin.gacic@gmail.com>
  • Loading branch information
jasmingacic committed May 11, 2022
1 parent 56ab6ea commit 8615747
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 43 deletions.
2 changes: 1 addition & 1 deletion api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ info:
title: Kusk Gateway API
description: "This is the Kusk Gateway Management API"
servers:
- url: http://localhost:8080/api
- url: http://localhost:8080
description: "My local endpoint mockup"
externalDocs:
description: "Find out more about Kusk-Gateway"
Expand Down
2 changes: 1 addition & 1 deletion kgw-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
app: kgwtest
spec:
containers:
- image: jasmingacic/kuskgateway-api:latest
- image: jasmingacic/kusk-gateway-api:latest
imagePullPolicy: Always
name: kuskgateway-api
serviceAccountName: kusk-gateway-manager
Expand Down
33 changes: 18 additions & 15 deletions server/go/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,94 +14,97 @@ import (
"net/http"
)



// ApisApiRouter defines the required methods for binding the api requests to a responses for the ApisApi
// The ApisApiRouter implementation should parse necessary information from the http request,
// pass the data to a ApisApiServicer to perform the required actions, then write the service results to the http response.
type ApisApiRouter interface {
type ApisApiRouter interface {
DeployApi(http.ResponseWriter, *http.Request)
GetApi(http.ResponseWriter, *http.Request)
GetApiCRD(http.ResponseWriter, *http.Request)
GetApiDefinition(http.ResponseWriter, *http.Request)
GetApis(http.ResponseWriter, *http.Request)
}

// CreateNewStaticRouteApiRouter defines the required methods for binding the api requests to a responses for the CreateNewStaticRouteApi
// The CreateNewStaticRouteApiRouter implementation should parse necessary information from the http request,
// pass the data to a CreateNewStaticRouteApiServicer to perform the required actions, then write the service results to the http response.
type CreateNewStaticRouteApiRouter interface {
type CreateNewStaticRouteApiRouter interface {
CreateStaticRoute(http.ResponseWriter, *http.Request)
}

// FleetsApiRouter defines the required methods for binding the api requests to a responses for the FleetsApi
// The FleetsApiRouter implementation should parse necessary information from the http request,
// pass the data to a FleetsApiServicer to perform the required actions, then write the service results to the http response.
type FleetsApiRouter interface {
type FleetsApiRouter interface {
GetEnvoyFleet(http.ResponseWriter, *http.Request)
GetEnvoyFleetCRD(http.ResponseWriter, *http.Request)
GetEnvoyFleets(http.ResponseWriter, *http.Request)
}

// ServicesApiRouter defines the required methods for binding the api requests to a responses for the ServicesApi
// The ServicesApiRouter implementation should parse necessary information from the http request,
// pass the data to a ServicesApiServicer to perform the required actions, then write the service results to the http response.
type ServicesApiRouter interface {
type ServicesApiRouter interface {
GetService(http.ResponseWriter, *http.Request)
GetServices(http.ResponseWriter, *http.Request)
}

// StaticRoutesApiRouter defines the required methods for binding the api requests to a responses for the StaticRoutesApi
// The StaticRoutesApiRouter implementation should parse necessary information from the http request,
// pass the data to a StaticRoutesApiServicer to perform the required actions, then write the service results to the http response.
type StaticRoutesApiRouter interface {
type StaticRoutesApiRouter interface {
GetStaticRoute(http.ResponseWriter, *http.Request)
GetStaticRouteCRD(http.ResponseWriter, *http.Request)
GetStaticRoutes(http.ResponseWriter, *http.Request)
}


// ApisApiServicer defines the api actions for the ApisApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type ApisApiServicer interface {
DeployApi(context.Context, APIPayload) (ImplResponse, error)
type ApisApiServicer interface {
DeployApi(context.Context, InlineObject) (ImplResponse, error)
GetApi(context.Context, string, string) (ImplResponse, error)
GetApiCRD(context.Context, string, string) (ImplResponse, error)
GetApiDefinition(context.Context, string, string) (ImplResponse, error)
GetApis(context.Context, string, string, string) (ImplResponse, error)
}


// CreateNewStaticRouteApiServicer defines the api actions for the CreateNewStaticRouteApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type CreateNewStaticRouteApiServicer interface {
type CreateNewStaticRouteApiServicer interface {
CreateStaticRoute(context.Context, StaticRouteItem) (ImplResponse, error)
}


// FleetsApiServicer defines the api actions for the FleetsApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type FleetsApiServicer interface {
type FleetsApiServicer interface {
GetEnvoyFleet(context.Context, string, string) (ImplResponse, error)
GetEnvoyFleetCRD(context.Context, string, string) (ImplResponse, error)
GetEnvoyFleets(context.Context, string) (ImplResponse, error)
}


// ServicesApiServicer defines the api actions for the ServicesApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type ServicesApiServicer interface {
type ServicesApiServicer interface {
GetService(context.Context, string, string) (ImplResponse, error)
GetServices(context.Context, string) (ImplResponse, error)
}


// StaticRoutesApiServicer defines the api actions for the StaticRoutesApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type StaticRoutesApiServicer interface {
type StaticRoutesApiServicer interface {
GetStaticRoute(context.Context, string, string) (ImplResponse, error)
GetStaticRouteCRD(context.Context, string, string) (ImplResponse, error)
GetStaticRoutes(context.Context, string) (ImplResponse, error)
Expand Down
28 changes: 14 additions & 14 deletions server/go/api_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

// ApisApiController binds http requests to an api service and writes the service results to the http response
type ApisApiController struct {
service ApisApiServicer
service ApisApiServicer
errorHandler ErrorHandler
}

Expand Down Expand Up @@ -49,43 +49,43 @@ func NewApisApiController(s ApisApiServicer, opts ...ApisApiOption) Router {

// Routes returns all of the api route for the ApisApiController
func (c *ApisApiController) Routes() Routes {
return Routes{
return Routes{
{
"DeployApi",
strings.ToUpper("Post"),
"/api/apis",
"/apis",
c.DeployApi,
},
{
"GetApi",
strings.ToUpper("Get"),
"/api/apis/{namespace}/{name}",
"/apis/{namespace}/{name}",
c.GetApi,
},
{
"GetApiCRD",
strings.ToUpper("Get"),
"/api/apis/{namespace}/{name}/crd",
"/apis/{namespace}/{name}/crd",
c.GetApiCRD,
},
{
"GetApiDefinition",
strings.ToUpper("Get"),
"/api/apis/{namespace}/{name}/definition",
"/apis/{namespace}/{name}/definition",
c.GetApiDefinition,
},
{
"GetApis",
strings.ToUpper("Get"),
"/api/apis",
"/apis",
c.GetApis,
},
}
}

// DeployApi - Deploy new API
func (c *ApisApiController) DeployApi(w http.ResponseWriter, r *http.Request) {
inlineObjectParam := APIPayload{}
inlineObjectParam := InlineObject{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
if err := d.Decode(&inlineObjectParam); err != nil {
Expand All @@ -111,9 +111,9 @@ func (c *ApisApiController) DeployApi(w http.ResponseWriter, r *http.Request) {
func (c *ApisApiController) GetApi(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
namespaceParam := params["namespace"]

nameParam := params["name"]

result, err := c.service.GetApi(r.Context(), namespaceParam, nameParam)
// If an error occurred, encode the error with the status code
if err != nil {
Expand All @@ -129,9 +129,9 @@ func (c *ApisApiController) GetApi(w http.ResponseWriter, r *http.Request) {
func (c *ApisApiController) GetApiCRD(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
namespaceParam := params["namespace"]

nameParam := params["name"]

result, err := c.service.GetApiCRD(r.Context(), namespaceParam, nameParam)
// If an error occurred, encode the error with the status code
if err != nil {
Expand All @@ -147,9 +147,9 @@ func (c *ApisApiController) GetApiCRD(w http.ResponseWriter, r *http.Request) {
func (c *ApisApiController) GetApiDefinition(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
namespaceParam := params["namespace"]

nameParam := params["name"]

result, err := c.service.GetApiDefinition(r.Context(), namespaceParam, nameParam)
// If an error occurred, encode the error with the status code
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/go/api_apis_service_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (s *ApisApiService) convertAPICRDtoAPIModel(api *kuskv1.API) ApiItem {
}

// DeployApi - Deploy new API
func (s *ApisApiService) DeployApi(ctx context.Context, payload APIPayload) (ImplResponse, error) {
func (s *ApisApiService) DeployApi(ctx context.Context, payload InlineObject) (ImplResponse, error) {
api, err := s.kuskClient.CreateApi(payload.Name, payload.Namespace, payload.Openapi, payload.EnvoyFleetName, payload.EnvoyFleetNamespace)
if err != nil {
return Response(http.StatusInternalServerError, err), err
Expand Down
82 changes: 82 additions & 0 deletions server/go/api_create_new_static_route.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Kusk Gateway API
*
* This is the Kusk Gateway Management API
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/

package openapi

import (
"encoding/json"
"net/http"
"strings"
)

// CreateNewStaticRouteApiController binds http requests to an api service and writes the service results to the http response
type CreateNewStaticRouteApiController struct {
service CreateNewStaticRouteApiServicer
errorHandler ErrorHandler
}

// CreateNewStaticRouteApiOption for how the controller is set up.
type CreateNewStaticRouteApiOption func(*CreateNewStaticRouteApiController)

// WithCreateNewStaticRouteApiErrorHandler inject ErrorHandler into controller
func WithCreateNewStaticRouteApiErrorHandler(h ErrorHandler) CreateNewStaticRouteApiOption {
return func(c *CreateNewStaticRouteApiController) {
c.errorHandler = h
}
}

// NewCreateNewStaticRouteApiController creates a default api controller
func NewCreateNewStaticRouteApiController(s CreateNewStaticRouteApiServicer, opts ...CreateNewStaticRouteApiOption) Router {
controller := &CreateNewStaticRouteApiController{
service: s,
errorHandler: DefaultErrorHandler,
}

for _, opt := range opts {
opt(controller)
}

return controller
}

// Routes returns all of the api route for the CreateNewStaticRouteApiController
func (c *CreateNewStaticRouteApiController) Routes() Routes {
return Routes{
{
"CreateStaticRoute",
strings.ToUpper("Post"),
"/staticroutes",
c.CreateStaticRoute,
},
}
}

// CreateStaticRoute - create new static route
func (c *CreateNewStaticRouteApiController) CreateStaticRoute(w http.ResponseWriter, r *http.Request) {
staticRouteItemParam := StaticRouteItem{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
if err := d.Decode(&staticRouteItemParam); err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
if err := AssertStaticRouteItemRequired(staticRouteItemParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
result, err := c.service.CreateStaticRoute(r.Context(), staticRouteItemParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}
41 changes: 41 additions & 0 deletions server/go/api_create_new_static_route_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Kusk Gateway API
*
* This is the Kusk Gateway Management API
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/

package openapi

import (
"context"
"net/http"
"errors"
)

// CreateNewStaticRouteApiService is a service that implements the logic for the CreateNewStaticRouteApiServicer
// This service should implement the business logic for every endpoint for the CreateNewStaticRouteApi API.
// Include any external packages or services that will be required by this service.
type CreateNewStaticRouteApiService struct {
}

// NewCreateNewStaticRouteApiService creates a default api service
func NewCreateNewStaticRouteApiService() CreateNewStaticRouteApiServicer {
return &CreateNewStaticRouteApiService{}
}

// CreateStaticRoute - create new static route
func (s *CreateNewStaticRouteApiService) CreateStaticRoute(ctx context.Context, staticRouteItem StaticRouteItem) (ImplResponse, error) {
// TODO - update CreateStaticRoute with the required logic for this service method.
// Add api_create_new_static_route_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.

//TODO: Uncomment the next line to return response Response(200, StaticRouteItem{}) or use other options such as http.Ok ...
//return Response(200, StaticRouteItem{}), nil

//TODO: Uncomment the next line to return response Response(400, string{}) or use other options such as http.Ok ...
//return Response(400, string{}), nil

return Response(http.StatusNotImplemented, nil), errors.New("CreateStaticRoute method not implemented")
}
6 changes: 3 additions & 3 deletions server/go/api_fleets.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ func (c *FleetsApiController) Routes() Routes {
{
"GetEnvoyFleet",
strings.ToUpper("Get"),
"/api/fleets/{namespace}/{name}",
"/fleets/{namespace}/{name}",
c.GetEnvoyFleet,
},
{
"GetEnvoyFleetCRD",
strings.ToUpper("Get"),
"/api/fleets/{namespace}/{name}/crd",
"/fleets/{namespace}/{name}/crd",
c.GetEnvoyFleetCRD,
},
{
"GetEnvoyFleets",
strings.ToUpper("Get"),
"/api/fleets",
"/fleets",
c.GetEnvoyFleets,
},
}
Expand Down
4 changes: 2 additions & 2 deletions server/go/api_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func (c *ServicesApiController) Routes() Routes {
{
"GetService",
strings.ToUpper("Get"),
"/api/services/{namespace}/{name}",
"/services/{namespace}/{name}",
c.GetService,
},
{
"GetServices",
strings.ToUpper("Get"),
"/api/services",
"/services",
c.GetServices,
},
}
Expand Down
Loading

0 comments on commit 8615747

Please sign in to comment.