Skip to content

Commit

Permalink
feat(api): rm feature flipping on as-code (#4138)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesnault authored and sguiheux committed Apr 2, 2019
1 parent b39ebac commit 4eb3af3
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 168 deletions.
9 changes: 0 additions & 9 deletions engine/api/ascode.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/gorilla/mux"

"github.com/ovh/cds/engine/api/feature"
"github.com/ovh/cds/engine/api/project"
"github.com/ovh/cds/engine/api/repositoriesmanager"
"github.com/ovh/cds/engine/api/workflow"
Expand Down Expand Up @@ -48,10 +47,6 @@ func (api *API) postImportAsCodeHandler() service.Handler {
sdk.WrapError(errP, "postImportAsCodeHandler> Cannot load project")
}

if enabled, has := p.Features[feature.FeatWorkflowAsCode]; has && !enabled {
return sdk.WrapError(sdk.ErrForbidden, "postImportAsCodeHandler> Project %s is not allowed for %s", key, feature.FeatWorkflowAsCode)
}

vcsServer := repositoriesmanager.GetProjectVCSServer(p, ope.VCSServer)
client, erra := repositoriesmanager.AuthorizedClient(ctx, api.mustDB(), api.Cache, vcsServer)
if erra != nil {
Expand Down Expand Up @@ -121,10 +116,6 @@ func (api *API) postPerformImportAsCodeHandler() service.Handler {
return sdk.WrapError(errp, "postPerformImportAsCodeHandler> Cannot load project %s", key)
}

if enabled, has := proj.Features[feature.FeatWorkflowAsCode]; has && !enabled {
return sdk.WrapError(sdk.ErrForbidden, "postPerformImportAsCodeHandler> Project %s is not allowed for %s", key, feature.FeatWorkflowAsCode)
}

var ope = new(sdk.Operation)
ope.UUID = uuid

Expand Down
76 changes: 0 additions & 76 deletions engine/api/ascode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
"testing"

izanami "github.com/ovhlabs/izanami-go-client"
"github.com/stretchr/testify/assert"

"github.com/ovh/cds/engine/api/feature"
Expand Down Expand Up @@ -124,45 +123,6 @@ func Test_postImportAsCodeHandler(t *testing.T) {
assert.NotEmpty(t, myOpe.UUID)
}

func Test_postImportAsCodeFeatureDisabledHandler(t *testing.T) {
api, db, _, end := newTestAPI(t)
defer end()

u, pass := assets.InsertAdminUser(db)

p := assets.InsertTestProject(t, db, api.Cache, sdk.RandomString(10), sdk.RandomString(10), u)
assert.NoError(t, repositoriesmanager.InsertForProject(db, p, &sdk.ProjectVCSServer{
Name: "github",
Data: map[string]string{
"token": "foo",
"secret": "bar",
},
}))

c, _ := izanami.New("", "clientID", "secret")
feature.SetClient(c)

api.Cache.Set("feature:"+p.Key, feature.ProjectFeatures{
Key: p.Key,
Features: map[string]bool{
feature.FeatWorkflowAsCode: false,
},
})

ope := `{"repo_fullname":"myrepo", "vcs_server": "github", "url":"https://github.com/fsamin/go-repo.git","strategy":{"connection_type":"https","ssh_key":"","user":"","password":"","branch":"","default_branch":"master","pgp_key":""},"setup":{"checkout":{"branch":"master"}}}`

uri := api.Router.GetRoute("POST", api.postImportAsCodeHandler, map[string]string{
"permProjectKey": p.Key,
})
req, err := http.NewRequest("POST", uri, strings.NewReader(ope))
test.NoError(t, err)
assets.AuthentifyRequest(t, req, u, pass)
// Do the request
w := httptest.NewRecorder()
api.Router.Mux.ServeHTTP(w, req)
assert.Equal(t, 403, w.Code)
}

func Test_getImportAsCodeHandler(t *testing.T) {
api, db, _, end := newTestAPI(t)
defer end()
Expand Down Expand Up @@ -319,39 +279,3 @@ version: v1.0`),
assert.Equal(t, 200, w.Code)
t.Logf(w.Body.String())
}

func Test_postPerformImportAsCodeDisabledFeatureHandler(t *testing.T) {
api, db, _, end := newTestAPI(t)
defer end()

u, pass := assets.InsertAdminUser(db)

assert.NoError(t, workflow.CreateBuiltinWorkflowHookModels(db))

//Insert Project
pkey := sdk.RandomString(10)
_ = assets.InsertTestProject(t, db, api.Cache, pkey, pkey, u)

c, _ := izanami.New("", "clientID", "secret")
feature.SetClient(c)

api.Cache.Set("feature:"+pkey, feature.ProjectFeatures{
Key: pkey,
Features: map[string]bool{
feature.FeatWorkflowAsCode: false,
},
})

uri := api.Router.GetRoute("POST", api.postPerformImportAsCodeHandler, map[string]string{
"permProjectKey": pkey,
"uuid": "123456",
})
req, err := http.NewRequest("POST", uri, nil)
test.NoError(t, err)
assets.AuthentifyRequest(t, req, u, pass)

// Do the request
w := httptest.NewRecorder()
api.Router.Mux.ServeHTTP(w, req)
assert.Equal(t, 403, w.Code)
}
7 changes: 2 additions & 5 deletions engine/api/feature/flipping.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ package feature
import (
"strings"

"github.com/ovhlabs/izanami-go-client"
client "github.com/ovhlabs/izanami-go-client"

"github.com/ovh/cds/engine/api/cache"
"github.com/ovh/cds/sdk/log"
)

const (
// FeatWorkflowAsCode is workflow as code feature id
FeatWorkflowAsCode = "cds:wasc"

// FeatEnableTracing is the opencensus tracing feature id
FeatEnableTracing = "cds:tracing"

Expand All @@ -37,7 +34,7 @@ type ProjectFeatures struct {

// List all features
func List() []string {
return []string{FeatWorkflowAsCode, FeatWNode, FeatEnableTracing}
return []string{FeatWNode, FeatEnableTracing}
}

// Init initialize Izanami client
Expand Down
9 changes: 0 additions & 9 deletions engine/api/workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/gorilla/mux"

"github.com/ovh/cds/engine/api/cache"
"github.com/ovh/cds/engine/api/feature"
"github.com/ovh/cds/engine/api/integration"
"github.com/ovh/cds/engine/api/objectstore"
"github.com/ovh/cds/engine/api/observability"
Expand Down Expand Up @@ -827,14 +826,6 @@ func (api *API) postWorkflowRunHandler() service.Handler {
return sdk.WrapError(errWf, "unable to load workflow %s", name)
}

// Check allow as code
if wf.FromRepository != "" {
enabled, has := p.Features[feature.FeatWorkflowAsCode]
if has && !enabled {
return sdk.WrapError(sdk.ErrForbidden, "as code is not allowed for project %s", p.Key)
}
}

// Check node permission
if getService(ctx) == nil && !permission.AccessToWorkflowNode(wf, &wf.WorkflowData.Node, u, permission.PermissionReadExecute) {
return sdk.WrapError(sdk.ErrNoPermExecution, "not enough right on node %s", wf.WorkflowData.Node.Name)
Expand Down
68 changes: 0 additions & 68 deletions engine/api/workflow_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import (
"testing"

"github.com/go-gorp/gorp"
izanami "github.com/ovhlabs/izanami-go-client"
"github.com/stretchr/testify/assert"

"github.com/ovh/cds/engine/api/application"
"github.com/ovh/cds/engine/api/bootstrap"
"github.com/ovh/cds/engine/api/environment"
"github.com/ovh/cds/engine/api/feature"
"github.com/ovh/cds/engine/api/group"
"github.com/ovh/cds/engine/api/pipeline"
"github.com/ovh/cds/engine/api/project"
Expand Down Expand Up @@ -1373,72 +1371,6 @@ func Test_postWorkflowRunHandlerWithoutRightOnEnvironment(t *testing.T) {
assert.Equal(t, 403, rec.Code)
}

func Test_postWorkflowAsCodeRunDisabledHandler(t *testing.T) {
api, db, router, end := newTestAPI(t, bootstrap.InitiliazeDB)
defer end()
u, pass := assets.InsertAdminUser(api.mustDB())
key := sdk.RandomString(10)
proj := assets.InsertTestProject(t, db, api.Cache, key, key, u)

c, _ := izanami.New("", "clientID", "secret")
feature.SetClient(c)

api.Cache.Set("feature:"+proj.Key, feature.ProjectFeatures{
Key: proj.Key,
Features: map[string]bool{
feature.FeatWorkflowAsCode: false,
},
})

//First pipeline
pip := sdk.Pipeline{
ProjectID: proj.ID,
ProjectKey: proj.Key,
Name: "pip1",
}
test.NoError(t, pipeline.InsertPipeline(api.mustDB(), api.Cache, proj, &pip, u))

w := sdk.Workflow{
Name: "test_1",
ProjectID: proj.ID,
ProjectKey: proj.Key,
WorkflowData: &sdk.WorkflowData{
Node: sdk.Node{
Name: "root",
Type: sdk.NodeTypePipeline,
Context: &sdk.NodeContext{
PipelineID: pip.ID,
},
},
},
FromRepository: "ovh/cds",
}

(&w).RetroMigrate()
proj2, errP := project.Load(api.mustDB(), api.Cache, proj.Key, u, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations)
test.NoError(t, errP)

test.NoError(t, workflow.Insert(api.mustDB(), api.Cache, &w, proj2, u))
w1, err := workflow.Load(context.TODO(), api.mustDB(), api.Cache, proj, "test_1", u, workflow.LoadOptions{})
test.NoError(t, err)

//Prepare request
vars := map[string]string{
"key": proj.Key,
"permWorkflowName": w1.Name,
}
uri := router.GetRoute("POST", api.postWorkflowRunHandler, vars)
test.NotEmpty(t, uri)

opts := &sdk.WorkflowRunPostHandlerOption{}
req := assets.NewAuthentifiedRequest(t, u, pass, "POST", uri, opts)

//Do the request
rec := httptest.NewRecorder()
router.Mux.ServeHTTP(rec, req)
assert.Equal(t, 403, rec.Code)
}

func Test_postWorkflowRunHandler_Forbidden(t *testing.T) {
api, db, router, end := newTestAPI(t, bootstrap.InitiliazeDB)
defer end()
Expand Down
2 changes: 1 addition & 1 deletion ui/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@
"pipeline_administration": "General administration of the pipeline",

"pipeline_run_test_filter_empty": "There is no test matching '{{criteria}}'",
"pipeline_run_test_no_error": "All tests are successfull",
"pipeline_run_test_no_error": "All tests are successful",
"pipeline_run_test_total_title_s": " tests",
"pipeline_run_test_total_title": " test",
"pipeline_run_test_failed_title_s": " tests failed",
Expand Down

0 comments on commit 4eb3af3

Please sign in to comment.