Skip to content

Commit

Permalink
fix(api): remove noEnv environment (#5452)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Sep 28, 2020
1 parent 196a212 commit 453d24e
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 55 deletions.
5 changes: 0 additions & 5 deletions engine/api/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/go-gorp/gorp"

"github.com/ovh/cds/engine/api/action"
"github.com/ovh/cds/engine/api/environment"
"github.com/ovh/cds/engine/api/group"
"github.com/ovh/cds/engine/api/integration"
"github.com/ovh/cds/engine/api/workflow"
Expand Down Expand Up @@ -41,10 +40,6 @@ func InitiliazeDB(ctx context.Context, defaultValues sdk.DefaultValues, DBFunc f
return sdk.WrapError(err, "Cannot setup builtin actions")
}

if err := environment.CreateBuiltinEnvironments(tx); err != nil {
return sdk.WrapError(err, "Cannot setup builtin environments")
}

if err := tx.Commit(); err != nil {
return sdk.WithStack(err)
}
Expand Down
10 changes: 0 additions & 10 deletions engine/api/environment/builtin.go

This file was deleted.

30 changes: 0 additions & 30 deletions engine/api/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package environment

import (
"database/sql"
"fmt"
"time"

"github.com/go-gorp/gorp"
Expand Down Expand Up @@ -109,9 +108,6 @@ func Lock(db gorp.SqlExecutor, projectKey, envName string) error {

// LoadEnvironmentByID load the given environment
func LoadEnvironmentByID(db gorp.SqlExecutor, ID int64) (*sdk.Environment, error) {
if ID == sdk.DefaultEnv.ID {
return &sdk.DefaultEnv, nil
}
var env sdk.Environment
query := `
SELECT environment.id, environment.name, environment.project_id, environment.created,
Expand All @@ -132,10 +128,6 @@ func LoadEnvironmentByID(db gorp.SqlExecutor, ID int64) (*sdk.Environment, error

// LoadEnvironmentByName load the given environment
func LoadEnvironmentByName(db gorp.SqlExecutor, projectKey, envName string) (*sdk.Environment, error) {
if envName == "" || envName == sdk.DefaultEnv.Name {
return &sdk.DefaultEnv, nil
}

var env sdk.Environment
query := `
SELECT environment.id, environment.name, environment.project_id, environment.created,
Expand Down Expand Up @@ -186,28 +178,6 @@ func Exists(db gorp.SqlExecutor, projectKey, envName string) (bool, error) {
return n == 1, nil
}

// CheckDefaultEnv create default env if not exists
func CheckDefaultEnv(db gorp.SqlExecutor) error {
var env sdk.Environment
query := `SELECT environment.id, environment.name FROM environment WHERE environment.id = $1`
err := db.QueryRow(query, sdk.DefaultEnv.ID).Scan(&env.ID, &env.Name)
if err != nil {
if err == sql.ErrNoRows {
query := `INSERT INTO environment (name) VALUES($1) RETURNING id`
if err1 := db.QueryRow(query, sdk.DefaultEnv.Name).Scan(&env.ID); err1 != nil {
return err1
} else if env.ID != sdk.DefaultEnv.ID {
return sdk.WithStack(fmt.Errorf("default env created but with wrong id, please check db"))
}
return nil
}
return err
} else if env.ID != sdk.DefaultEnv.ID || env.Name != sdk.DefaultEnv.Name {
return sdk.WithStack(fmt.Errorf("default env exists but with wrong id or name, please check db"))
}
return nil
}

func loadDependencies(db gorp.SqlExecutor, env *sdk.Environment) error {
variables, err := LoadAllVariables(db, env.ID)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions engine/api/group/node_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ func InsertGroupsInNode(db gorp.SqlExecutor, groupPermission []sdk.GroupPermissi

// insertGroupInNode add permissions on Node to Group
func insertGroupInNode(db gorp.SqlExecutor, nodeID, groupID int64, role int) error {
// avoid insert default env
if sdk.DefaultEnv.ID == nodeID {
return nil
}
query := `INSERT INTO workflow_node_group (workflow_node_id, workflow_group_id, role)
VALUES(
$1,
Expand Down
6 changes: 0 additions & 6 deletions sdk/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,3 @@ func NewEnvironment(name string) *Environment {
}
return e
}

// DefaultEnv Default environment for pipeline build
var DefaultEnv = Environment{
ID: 1,
Name: "NoEnv",
}

0 comments on commit 453d24e

Please sign in to comment.