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

feat(api, sql): worker hooks #5980

Merged
merged 11 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/cdsctl/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"path"
"strings"
"time"
Expand Down Expand Up @@ -213,7 +213,7 @@ func actionDocRun(v cli.Values) error {
}
defer contentFile.Close()

body, err := ioutil.ReadAll(contentFile)
body, err := io.ReadAll(contentFile)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cli/cdsctl/admin_broadcasts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -58,7 +58,7 @@ level warning:
}

func adminBroadcastCreateRun(v cli.Values) error {
content, err := ioutil.ReadAll(os.Stdin)
content, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
68 changes: 68 additions & 0 deletions cli/cdsctl/project_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package main

import (
"fmt"
"io"
"os"

"github.com/spf13/cobra"
"gopkg.in/yaml.v2"

"github.com/ovh/cds/cli"
"github.com/ovh/cds/sdk"
"github.com/ovh/cds/sdk/cdsclient"
"github.com/ovh/cds/sdk/exportentities"
)
Expand All @@ -23,6 +26,8 @@ func projectIntegration() *cobra.Command {
cli.NewDeleteCommand(projectIntegrationDeleteCmd, projectIntegrationDeleteFunc, nil, withAllCommandModifiers()...),
cli.NewCommand(projectIntegrationImportCmd, projectIntegrationImportFunc, nil, withAllCommandModifiers()...),
cli.NewCommand(projectIntegrationExportCmd, projectIntegrationExportFunc, nil, withAllCommandModifiers()...),
cli.NewCommand(projectIntegrationWorkerHooksExportCmd, projectIntegrationWorkerHooksExportFunc, nil, withAllCommandModifiers()...),
cli.NewCommand(projectIntegrationWorkerHooksImportCmd, projectIntegrationWorkerHooksImportFunc, nil, withAllCommandModifiers()...),
})
}

Expand Down Expand Up @@ -111,3 +116,66 @@ func projectIntegrationExportFunc(v cli.Values) error {
fmt.Println(string(btes))
return nil
}

var projectIntegrationWorkerHooksExportCmd = cli.Command{
Name: "worker-hooks-export",
Short: "Export integration worker hook configuration",
Ctx: []cli.Arg{
{Name: _ProjectKey},
},
Args: []cli.Arg{
{Name: "integration"},
},
}

func projectIntegrationWorkerHooksExportFunc(v cli.Values) error {
res, err := client.ProjectIntegrationWorkerHooksGet(v.GetString(_ProjectKey), v.GetString("integration"))
if err != nil {
return err
}

btes, err := exportentities.Marshal(res, exportentities.FormatYAML)
if err != nil {
return err
}

fmt.Println(string(btes))
return err
}

var projectIntegrationWorkerHooksImportCmd = cli.Command{
Name: "worker-hooks-import",
Short: "Import integration worker hook configuration",
Ctx: []cli.Arg{
{Name: _ProjectKey},
},
Args: []cli.Arg{
{Name: "integration"},
{Name: "filename"},
},
}

func projectIntegrationWorkerHooksImportFunc(v cli.Values) error {
f, err := os.Open(v.GetString("filename"))
if err != nil {
return cli.WrapError(err, "unable to open file %s", v.GetString("filename"))
}
defer f.Close()

btes, err := io.ReadAll(f)
if err != nil {
return cli.WrapError(err, "unable to read file %s", v.GetString("filename"))
}

var wh sdk.WorkerHookProjectIntegrationModel
if err := yaml.Unmarshal(btes, &wh); err != nil {
return cli.WrapError(err, "unable to parse file %s", v.GetString("filename"))
}

err = client.ProjectIntegrationWorkerHooksImport(v.GetString(_ProjectKey), v.GetString("integration"), wh)
if err != nil {
return err
}

return nil
}
6 changes: 3 additions & 3 deletions cli/cdsctl/project_variable.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"io/ioutil"
"io"
"os"

"github.com/pkg/errors"
Expand Down Expand Up @@ -57,7 +57,7 @@ func projectCreateVariableRun(v cli.Values) error {
}

if variable.Value == "" && v.GetBool("stdin") {
btes, err := ioutil.ReadAll(os.Stdin)
btes, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down Expand Up @@ -150,7 +150,7 @@ func projectUpdateVariableRun(v cli.Values) error {
variable.Value = v.GetString("variable-value")

if variable.Value == "" && v.GetBool("stdin") {
btes, err := ioutil.ReadAll(os.Stdin)
btes, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions engine/api/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

import (
"context"
"io/ioutil"
"io"
"net/http"

"github.com/go-gorp/gorp"
Expand Down Expand Up @@ -628,7 +628,7 @@ func (api *API) getActionExportHandler() service.Handler {
// importActionHandler insert OR update an existing action.
func (api *API) importActionHandler() service.Handler {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions engine/api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -163,7 +163,7 @@ func putPostAdminServiceCallHandler(api *API, method string) service.Handler {
}

query := r.FormValue("query")
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return sdk.WrapError(err, "Unable to read body")
}
Expand Down
1 change: 1 addition & 0 deletions engine/api/api_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func (api *API) InitRouter() {
r.Handle("/project/{permProjectKey}/applications", Scope(sdk.AuthConsumerScopeProject), r.GET(api.getApplicationsHandler), r.POST(api.addApplicationHandler))
r.Handle("/project/{permProjectKey}/integrations", Scope(sdk.AuthConsumerScopeProject), r.GET(api.getProjectIntegrationsHandler), r.POST(api.postProjectIntegrationHandler))
r.Handle("/project/{permProjectKey}/integrations/{integrationName}", Scope(sdk.AuthConsumerScopeProject), r.GET(api.getProjectIntegrationHandler), r.PUT(api.putProjectIntegrationHandler), r.DELETE(api.deleteProjectIntegrationHandler))
r.Handle("/project/{permProjectKey}/integrations/{integrationName}/workerhooks", Scope(sdk.AuthConsumerScopeProject), r.GET(api.getProjectIntegrationWorkerHookHandler), r.POST(api.postProjectIntegrationWorkerHookHandler))
r.Handle("/project/{permProjectKey}/notifications", Scope(sdk.AuthConsumerScopeProject), r.GET(api.getProjectNotificationsHandler, DEPRECATED))
r.Handle("/project/{permProjectKey}/keys", Scope(sdk.AuthConsumerScopeProject), r.GET(api.getKeysInProjectHandler), r.POST(api.addKeyInProjectHandler))
r.Handle("/project/{permProjectKey}/keys/{name}", Scope(sdk.AuthConsumerScopeProject), r.DELETE(api.deleteKeyInProjectHandler))
Expand Down
4 changes: 2 additions & 2 deletions engine/api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -648,7 +648,7 @@ func (api *API) postApplicationMetadataHandler() service.Handler {
oldApp := *app

m := vars["metadata"]
v, err := ioutil.ReadAll(r.Body)
v, err := io.ReadAll(r.Body)
if err != nil {
return sdk.WrapError(err, "postApplicationMetadataHandler")
}
Expand Down
4 changes: 2 additions & 2 deletions engine/api/application_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/gorilla/mux"
Expand All @@ -29,7 +29,7 @@ func (api *API) postApplicationImportHandler() service.Handler {
return sdk.WrapError(err, "unable load project")
}

body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return sdk.NewError(sdk.ErrWrongRequest, err)
}
Expand Down
3 changes: 2 additions & 1 deletion engine/api/ascode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -95,7 +96,7 @@ func Test_postImportAsCodeHandler(t *testing.T) {
}
default:
ope := new(sdk.Operation)
btes, err := ioutil.ReadAll(r.Body)
btes, err := io.ReadAll(r.Body)
if err != nil {
return writeError(w, err)
}
Expand Down
4 changes: 2 additions & 2 deletions engine/api/authentication/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package github
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -116,7 +116,7 @@ func (d authDriver) GetUserInfo(ctx context.Context, req sdk.AuthConsumerSigninR
}

defer res.Body.Close()
resBody, err := ioutil.ReadAll(res.Body)
resBody, err := io.ReadAll(res.Body)
if err != nil {
return info, sdk.WithStack(err)
}
Expand Down
8 changes: 4 additions & 4 deletions engine/api/environment_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

import (
"context"
"io/ioutil"
"io"
"net/http"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -32,7 +32,7 @@ func (api *API) postEnvironmentImportHandler() service.Handler {
return sdk.WrapError(err, "unable load project")
}

body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return sdk.NewError(sdk.ErrWrongRequest, err)
}
Expand Down Expand Up @@ -88,7 +88,7 @@ func (api *API) importNewEnvironmentHandler() service.Handler {
return sdk.WrapError(err, "cannot load %s", key)
}

body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return sdk.NewError(sdk.ErrWrongRequest, sdk.WrapError(err, "unable to read body"))
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func (api *API) importIntoEnvironmentHandler() service.Handler {
return sdk.WrapError(err, "cannot load env %s/%s", key, envName)
}

body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return sdk.NewErrorWithStack(err, sdk.NewErrorFrom(sdk.ErrWrongRequest, "unable to read body"))
}
Expand Down
12 changes: 6 additions & 6 deletions engine/api/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -50,7 +50,7 @@ func TestAddEnvironmentHandler(t *testing.T) {
router.Mux.ServeHTTP(w, req)

assert.Equal(t, 200, w.Code)
res, _ := ioutil.ReadAll(w.Body)
res, _ := io.ReadAll(w.Body)
projectResult := &sdk.Project{}
json.Unmarshal(res, &projectResult)
assert.Equal(t, len(projectResult.Environments), 1)
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestUpdateEnvironmentHandler(t *testing.T) {
router.Mux.ServeHTTP(w, req)

assert.Equal(t, 200, w.Code)
res, _ := ioutil.ReadAll(w.Body)
res, _ := io.ReadAll(w.Body)
t.Logf(string(res))
projectResult := &sdk.Project{}
json.Unmarshal(res, &projectResult)
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestDeleteEnvironmentHandler(t *testing.T) {
router.Mux.ServeHTTP(w, req)

assert.Equal(t, 200, w.Code)
res, _ := ioutil.ReadAll(w.Body)
res, _ := io.ReadAll(w.Body)
projectResult := &sdk.Project{}
json.Unmarshal(res, &projectResult)
assert.Equal(t, len(projectResult.Environments), 0)
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestGetEnvironmentsHandler(t *testing.T) {
router.Mux.ServeHTTP(w, req)

assert.Equal(t, 200, w.Code)
res, _ := ioutil.ReadAll(w.Body)
res, _ := io.ReadAll(w.Body)
envsResults := []sdk.Environment{}
json.Unmarshal(res, &envsResults)
assert.Equal(t, len(envsResults), 1)
Expand Down Expand Up @@ -246,7 +246,7 @@ func TestGetEnvironmentHandler(t *testing.T) {
router.Mux.ServeHTTP(w, req)

assert.Equal(t, 200, w.Code)
res, _ := ioutil.ReadAll(w.Body)
res, _ := io.ReadAll(w.Body)
envResults := sdk.Environment{}
json.Unmarshal(res, &envResults)
assert.Equal(t, envResults.Name, "Preproduction")
Expand Down
8 changes: 4 additions & 4 deletions engine/api/environment_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestAddVariableInEnvironmentHandler(t *testing.T) {
router.Mux.ServeHTTP(w, req)

assert.Equal(t, 200, w.Code)
res, _ := ioutil.ReadAll(w.Body)
res, _ := io.ReadAll(w.Body)
v := &sdk.Variable{}
assert.NoError(t, json.Unmarshal(res, &v))
assert.NotEqual(t, v.ID, 0)
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestUpdateVariableInEnvironmentHandler(t *testing.T) {
router.Mux.ServeHTTP(w, req)

assert.Equal(t, 200, w.Code)
res, _ := ioutil.ReadAll(w.Body)
res, _ := io.ReadAll(w.Body)
vUpdated := sdk.Variable{}
assert.NoError(t, json.Unmarshal(res, &vUpdated))
assert.Equal(t, vUpdated.Value, "new bar")
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestGetVariablesInEnvironmentHandler(t *testing.T) {
router.Mux.ServeHTTP(w, req)

assert.Equal(t, 200, w.Code)
res, _ := ioutil.ReadAll(w.Body)
res, _ := io.ReadAll(w.Body)
varsResult := []sdk.Variable{}
json.Unmarshal(res, &varsResult)
assert.Equal(t, len(varsResult), 1)
Expand Down
Loading