Skip to content

Commit

Permalink
Allow default team config project
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusfcr committed Apr 10, 2024
1 parent c008b80 commit 7dfa119
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Those are the variables you have to use:
|PG_SSLMODE|One of these (disable,allow,prefer,require,verify-ca,verify-full)|disable|
|AWSSERVERCREDENTIALS_KEY|Parent key in the AWS Secret Manager to store server secrets|/vulcan/k8s/tracker/jira/|
|AWSSERVERCREDENTIALS_ENDPOINT|Optional AWS endpoint|http://locacalstack/|
|DEFAULT_TEAM_PROJECT|team id with a project that will be used as project for all the non explicit declared teams|
|AWS_REGION||eu-west-1|


Expand Down
5 changes: 3 additions & 2 deletions cmd/vulcan-tracker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ func main() {
ticketTrackerBuilder := &tracking.TTBuilder{}

a := api.New(ticketServer, ticketTrackerBuilder, db, api.Options{
MaxSize: cfg.API.MaxSize,
DefaultSize: cfg.API.DefaultSize,
DefaultTeamProject: cfg.API.DefaultTeamProject,
MaxSize: cfg.API.MaxSize,
DefaultSize: cfg.API.DefaultSize,
})

e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Expand Down
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
max_size = 100
default_size = 20
port = $PORT
default_team_project = "$DEFAULT_TEAM_PROJECT"

[log]
level = "$LOG_LEVEL"
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ type API struct {

// Options represents size options for the API requests.
type Options struct {
MaxSize int
DefaultSize int
DefaultTeamProject string
MaxSize int
DefaultSize int
}

// New instantiates a new API.
Expand Down
13 changes: 11 additions & 2 deletions pkg/api/tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package api
import (
"database/sql"
"errors"
"fmt"
"net/http"
"regexp"

Expand Down Expand Up @@ -87,6 +88,7 @@ func (api *API) GetTicket(c echo.Context) error {
// CreateTicket creates a ticket and returns a JSON containing the new ticket.
func (api *API) CreateTicket(c echo.Context) error {
teamID := c.Param("team_id")
projectTeamID := teamID
ticket := new(model.Ticket)

// Check if the team is an uuid
Expand All @@ -105,7 +107,14 @@ func (api *API) CreateTicket(c echo.Context) error {
// Get the server and the configuration for the teamID.
configuration, err := api.ticketServer.ProjectConfigByTeamID(teamID)
if err != nil {
return responseError(err)
if api.Options.DefaultTeamProject == "" {
return responseError(err)
}
configuration, err = api.ticketServer.ProjectConfigByTeamID(api.Options.DefaultTeamProject)
if err != nil {
return responseError(fmt.Errorf("unable to find config for default team %s", api.Options.DefaultTeamProject))
}
projectTeamID = api.Options.DefaultTeamProject
}

// Retrieve the necessary values to create a ticket.
Expand All @@ -120,7 +129,7 @@ func (api *API) CreateTicket(c echo.Context) error {
}

// Get a ticket tracker client.
ttClient, err := api.ticketTrackerBuilder.GenerateTicketTrackerClient(api.ticketServer, teamID, c.Logger())
ttClient, err := api.ticketTrackerBuilder.GenerateTicketTrackerClient(api.ticketServer, projectTeamID, c.Logger())
if err != nil {
return responseError(err)
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/api/tracking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,30 @@ func TestCreateTicket(t *testing.T) {
Message: "project not found",
},
},
{
name: "TeamDefault",
teamID: "c99fed50-c612-4f99-863f-6d3274e2b2b6",
ticket: model.Ticket{
Summary: "Summary TEST-2",
Description: "Description TEST-2",
FindingID: "12345678",
},
api: &API{
ticketServer: &mockTicketServer{
projects: projects,
},
ticketTrackerBuilder: &mockTicketTrackerBuilder{
tickets: tickets,
projects: projects,
},
storage: &mockStorage{},
Options: Options{
DefaultTeamProject: "80287cf6-db31-47f8-a9aa-792f214b1f88",
},
},
wantStatusCode: http.StatusOK,
wantTicket: "TEST-3",
},
}

for _, tt := range tests {
Expand Down
7 changes: 4 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ type Config struct {
}

type apiConfig struct {
MaxSize int `toml:"max_size"`
DefaultSize int `toml:"default_size"`
Port int `toml:"port"`
MaxSize int `toml:"max_size"`
DefaultSize int `toml:"default_size"`
Port int `toml:"port"`
DefaultTeamProject string `toml:"default_team_project"`
}

type logConfig struct {
Expand Down

0 comments on commit 7dfa119

Please sign in to comment.