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

Applications API v2 #72

Merged
merged 12 commits into from
Nov 30, 2022
Merged
2 changes: 1 addition & 1 deletion .github/workflows/ci-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ env:
LOCAL_REGISTRY: registry.localhost:5000

CARAML_CHARTS_REPOSITORY: romanwozniak/helm-charts
CARAML_CHARTS_REF: feat-mlp-support-configmap
CARAML_CHARTS_REF: feat-mlp-apps-configuration

jobs:
build-ui:
Expand Down
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ UI_BUILD_PATH := ${UI_PATH}/build
API_PATH := api
API_ALL_PACKAGES := $(shell cd ${API_PATH} && go list ./... | grep -v github.com/gojek/mlp/client | grep -v mocks)
BIN_NAME := $(if ${APP_NAME},${APP_NAME},mlp)
DOCKER_COMPOSE_BIN := "docker-compose"
DOCKER_COMPOSE_ARG := ""

all: setup init-dep lint test clean build run

Expand Down Expand Up @@ -150,22 +148,22 @@ generate-client:
.PHONY: local-db
local-db:
@echo "> Starting up DB ..."
@$(DOCKER_COMPOSE_BIN) $(DOCKER_COMPOSE_ARG) up -d postgres
@docker-compose up -d postgres

.PHONY: start-keto
start-keto:
@echo "> Starting up keto server ..."
@$(DOCKER_COMPOSE_BIN) $(DOCKER_COMPOSE_ARG) up -d keto
@docker-compose up -d keto

.PHONY: stop-docker
stop-docker:
@echo "> Stopping Docker compose ..."
@$(DOCKER_COMPOSE_BIN) $(DOCKER_COMPOSE_ARG) down
@docker-compose down

.PHONY: swagger-ui
swagger-ui:
@echo "> Starting up Swagger UI ..."
@$(DOCKER_COMPOSE_BIN) $(DOCKER_COMPOSE_ARG) up -d swagger-ui
@docker-compose up -d swagger-ui

.PHONY: version
version:
Expand Down
17 changes: 15 additions & 2 deletions api/api/applications_api.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package api

import "net/http"
import (
http "net/http"
)

type ApplicationsController struct {
*AppContext
}

func (c *ApplicationsController) ListApplications(r *http.Request, _ map[string]string, _ interface{}) *Response {
func (c *ApplicationsController) ListApplications(_ *http.Request, _ map[string]string, _ interface{}) *Response {
applications, err := c.ApplicationService.List()
if err != nil {
return InternalServerError(err.Error())
}
return Ok(applications)
}

func (c *ApplicationsController) Routes() []Route {
return []Route{
{
http.MethodGet,
"/applications",
nil,
c.ListApplications,
"ListApplications",
},
}
}
38 changes: 35 additions & 3 deletions api/api/projects_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"net/http"
"strings"

"github.com/gojek/mlp/api/pkg/authz/enforcer"
"github.com/jinzhu/gorm"

"github.com/gojek/mlp/api/log"
"github.com/gojek/mlp/api/models"
"github.com/gojek/mlp/api/pkg/authz/enforcer"
"github.com/jinzhu/gorm"
)

type ProjectsController struct {
Expand Down Expand Up @@ -135,6 +134,39 @@ func (c *ProjectsController) filterAuthorizedProjects(
return projects, nil
}

func (c *ProjectsController) Routes() []Route {
return []Route{
{
http.MethodGet,
"/projects/{project_id:[0-9]+}",
nil,
c.GetProject,
"GetProject",
},
{
http.MethodGet,
"/projects",
nil,
c.ListProjects,
"ListProjects",
},
{
http.MethodPost,
"/projects",
models.Project{},
c.CreateProject,
"CreateProject",
},
{
http.MethodPut,
"/projects/{project_id:[0-9]+}",
models.Project{},
c.UpdateProject,
"UpdateProject",
},
}
}

// addRequester add requester to users slice if it doesn't exists
func addRequester(requester string, users []string) []string {
for _, user := range users {
Expand Down
33 changes: 20 additions & 13 deletions api/api/projects_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/gojek/mlp/api/it/database"
"github.com/gojek/mlp/api/models"
enforcerMock "github.com/gojek/mlp/api/pkg/authz/enforcer/mocks"
"github.com/gojek/mlp/api/service"
"github.com/gojek/mlp/api/storage"
)
Expand Down Expand Up @@ -207,13 +206,15 @@ func TestCreateProject(t *testing.T) {
_, err := prjStorage.Save(tC.existingProject)
assert.NoError(t, err)
}
projectService, err := service.NewProjectsService(mlflowTrackingURL, prjStorage, &enforcerMock.Enforcer{}, false)
projectService, err := service.NewProjectsService(mlflowTrackingURL, prjStorage, nil, false)
assert.NoError(t, err)

r := NewRouter(AppContext{
appCtx := &AppContext{
ProjectsService: projectService,
AuthorizationEnabled: false,
})
}
controllers := []Controller{&ProjectsController{appCtx}}
r := NewRouter(appCtx, controllers)

requestByte, _ := json.Marshal(tC.body)
req, err := http.NewRequest(http.MethodPost, "/v1/projects", bytes.NewReader(requestByte))
Expand Down Expand Up @@ -315,13 +316,15 @@ func TestListProjects(t *testing.T) {
assert.NoError(t, err)
}
}
projectService, err := service.NewProjectsService(mlflowTrackingURL, prjStorage, &enforcerMock.Enforcer{}, false)
projectService, err := service.NewProjectsService(mlflowTrackingURL, prjStorage, nil, false)
assert.NoError(t, err)

r := NewRouter(AppContext{
appCtx := &AppContext{
ProjectsService: projectService,
AuthorizationEnabled: false,
})
}
controllers := []Controller{&ProjectsController{appCtx}}
r := NewRouter(appCtx, controllers)

req, err := http.NewRequest(http.MethodGet, "/v1/projects", nil)
if err != nil {
Expand Down Expand Up @@ -473,13 +476,15 @@ func TestUpdateProject(t *testing.T) {
_, err := prjStorage.Save(tC.existingProject)
assert.NoError(t, err)
}
projectService, err := service.NewProjectsService(mlflowTrackingURL, prjStorage, &enforcerMock.Enforcer{}, false)
projectService, err := service.NewProjectsService(mlflowTrackingURL, prjStorage, nil, false)
assert.NoError(t, err)

r := NewRouter(AppContext{
appCtx := &AppContext{
ProjectsService: projectService,
AuthorizationEnabled: false,
})
}
controllers := []Controller{&ProjectsController{appCtx}}
r := NewRouter(appCtx, controllers)

requestByte, _ := json.Marshal(tC.body)
req, err := http.NewRequest(http.MethodPut, "/v1/projects/"+tC.projectID.String(), bytes.NewReader(requestByte))
Expand Down Expand Up @@ -590,13 +595,15 @@ func TestGetProject(t *testing.T) {
_, err := prjStorage.Save(tC.existingProject)
assert.NoError(t, err)
}
projectService, err := service.NewProjectsService(mlflowTrackingURL, prjStorage, &enforcerMock.Enforcer{}, false)
projectService, err := service.NewProjectsService(mlflowTrackingURL, prjStorage, nil, false)
assert.NoError(t, err)

r := NewRouter(AppContext{
appCtx := &AppContext{
ProjectsService: projectService,
AuthorizationEnabled: false,
})
}
controllers := []Controller{&ProjectsController{appCtx}}
r := NewRouter(appCtx, controllers)

req, err := http.NewRequest(http.MethodGet, "/v1/projects/"+tC.projectID.String(), nil)
if err != nil {
Expand Down
Loading