Skip to content

Commit 4e320d2

Browse files
authored
feat(api, sql): worker hooks (#5980)
1 parent 1cfdf9d commit 4e320d2

File tree

121 files changed

+1425
-411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+1425
-411
lines changed

cli/cdsctl/action.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"path"
77
"strings"
88
"time"
@@ -213,7 +213,7 @@ func actionDocRun(v cli.Values) error {
213213
}
214214
defer contentFile.Close()
215215

216-
body, err := ioutil.ReadAll(contentFile)
216+
body, err := io.ReadAll(contentFile)
217217
if err != nil {
218218
return err
219219
}

cli/cdsctl/admin_broadcasts.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"os"
77

88
"github.com/spf13/cobra"
@@ -58,7 +58,7 @@ level warning:
5858
}
5959

6060
func adminBroadcastCreateRun(v cli.Values) error {
61-
content, err := ioutil.ReadAll(os.Stdin)
61+
content, err := io.ReadAll(os.Stdin)
6262
if err != nil {
6363
return err
6464
}

cli/cdsctl/project_integration.go

+68
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ package main
22

33
import (
44
"fmt"
5+
"io"
56
"os"
67

78
"github.com/spf13/cobra"
9+
"gopkg.in/yaml.v2"
810

911
"github.com/ovh/cds/cli"
12+
"github.com/ovh/cds/sdk"
1013
"github.com/ovh/cds/sdk/cdsclient"
1114
"github.com/ovh/cds/sdk/exportentities"
1215
)
@@ -23,6 +26,8 @@ func projectIntegration() *cobra.Command {
2326
cli.NewDeleteCommand(projectIntegrationDeleteCmd, projectIntegrationDeleteFunc, nil, withAllCommandModifiers()...),
2427
cli.NewCommand(projectIntegrationImportCmd, projectIntegrationImportFunc, nil, withAllCommandModifiers()...),
2528
cli.NewCommand(projectIntegrationExportCmd, projectIntegrationExportFunc, nil, withAllCommandModifiers()...),
29+
cli.NewCommand(projectIntegrationWorkerHooksExportCmd, projectIntegrationWorkerHooksExportFunc, nil, withAllCommandModifiers()...),
30+
cli.NewCommand(projectIntegrationWorkerHooksImportCmd, projectIntegrationWorkerHooksImportFunc, nil, withAllCommandModifiers()...),
2631
})
2732
}
2833

@@ -111,3 +116,66 @@ func projectIntegrationExportFunc(v cli.Values) error {
111116
fmt.Println(string(btes))
112117
return nil
113118
}
119+
120+
var projectIntegrationWorkerHooksExportCmd = cli.Command{
121+
Name: "worker-hooks-export",
122+
Short: "Export integration worker hook configuration",
123+
Ctx: []cli.Arg{
124+
{Name: _ProjectKey},
125+
},
126+
Args: []cli.Arg{
127+
{Name: "integration"},
128+
},
129+
}
130+
131+
func projectIntegrationWorkerHooksExportFunc(v cli.Values) error {
132+
res, err := client.ProjectIntegrationWorkerHooksGet(v.GetString(_ProjectKey), v.GetString("integration"))
133+
if err != nil {
134+
return err
135+
}
136+
137+
btes, err := exportentities.Marshal(res, exportentities.FormatYAML)
138+
if err != nil {
139+
return err
140+
}
141+
142+
fmt.Println(string(btes))
143+
return err
144+
}
145+
146+
var projectIntegrationWorkerHooksImportCmd = cli.Command{
147+
Name: "worker-hooks-import",
148+
Short: "Import integration worker hook configuration",
149+
Ctx: []cli.Arg{
150+
{Name: _ProjectKey},
151+
},
152+
Args: []cli.Arg{
153+
{Name: "integration"},
154+
{Name: "filename"},
155+
},
156+
}
157+
158+
func projectIntegrationWorkerHooksImportFunc(v cli.Values) error {
159+
f, err := os.Open(v.GetString("filename"))
160+
if err != nil {
161+
return cli.WrapError(err, "unable to open file %s", v.GetString("filename"))
162+
}
163+
defer f.Close()
164+
165+
btes, err := io.ReadAll(f)
166+
if err != nil {
167+
return cli.WrapError(err, "unable to read file %s", v.GetString("filename"))
168+
}
169+
170+
var wh sdk.WorkerHookProjectIntegrationModel
171+
if err := yaml.Unmarshal(btes, &wh); err != nil {
172+
return cli.WrapError(err, "unable to parse file %s", v.GetString("filename"))
173+
}
174+
175+
err = client.ProjectIntegrationWorkerHooksImport(v.GetString(_ProjectKey), v.GetString("integration"), wh)
176+
if err != nil {
177+
return err
178+
}
179+
180+
return nil
181+
}

cli/cdsctl/project_variable.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
"io/ioutil"
4+
"io"
55
"os"
66

77
"github.com/pkg/errors"
@@ -57,7 +57,7 @@ func projectCreateVariableRun(v cli.Values) error {
5757
}
5858

5959
if variable.Value == "" && v.GetBool("stdin") {
60-
btes, err := ioutil.ReadAll(os.Stdin)
60+
btes, err := io.ReadAll(os.Stdin)
6161
if err != nil {
6262
return err
6363
}
@@ -150,7 +150,7 @@ func projectUpdateVariableRun(v cli.Values) error {
150150
variable.Value = v.GetString("variable-value")
151151

152152
if variable.Value == "" && v.GetBool("stdin") {
153-
btes, err := ioutil.ReadAll(os.Stdin)
153+
btes, err := io.ReadAll(os.Stdin)
154154
if err != nil {
155155
return err
156156
}

engine/api/action.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package api
22

33
import (
44
"context"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77

88
"github.com/go-gorp/gorp"
@@ -628,7 +628,7 @@ func (api *API) getActionExportHandler() service.Handler {
628628
// importActionHandler insert OR update an existing action.
629629
func (api *API) importActionHandler() service.Handler {
630630
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
631-
body, err := ioutil.ReadAll(r.Body)
631+
body, err := io.ReadAll(r.Body)
632632
if err != nil {
633633
return err
634634
}

engine/api/admin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"strings"
1010

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

165165
query := r.FormValue("query")
166-
body, err := ioutil.ReadAll(r.Body)
166+
body, err := io.ReadAll(r.Body)
167167
if err != nil {
168168
return sdk.WrapError(err, "Unable to read body")
169169
}

engine/api/api_routes.go

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func (api *API) InitRouter() {
166166
r.Handle("/project/{permProjectKey}/applications", Scope(sdk.AuthConsumerScopeProject), r.GET(api.getApplicationsHandler), r.POST(api.addApplicationHandler))
167167
r.Handle("/project/{permProjectKey}/integrations", Scope(sdk.AuthConsumerScopeProject), r.GET(api.getProjectIntegrationsHandler), r.POST(api.postProjectIntegrationHandler))
168168
r.Handle("/project/{permProjectKey}/integrations/{integrationName}", Scope(sdk.AuthConsumerScopeProject), r.GET(api.getProjectIntegrationHandler), r.PUT(api.putProjectIntegrationHandler), r.DELETE(api.deleteProjectIntegrationHandler))
169+
r.Handle("/project/{permProjectKey}/integrations/{integrationName}/workerhooks", Scope(sdk.AuthConsumerScopeProject), r.GET(api.getProjectIntegrationWorkerHookHandler), r.POST(api.postProjectIntegrationWorkerHookHandler))
169170
r.Handle("/project/{permProjectKey}/notifications", Scope(sdk.AuthConsumerScopeProject), r.GET(api.getProjectNotificationsHandler, DEPRECATED))
170171
r.Handle("/project/{permProjectKey}/keys", Scope(sdk.AuthConsumerScopeProject), r.GET(api.getKeysInProjectHandler), r.POST(api.addKeyInProjectHandler))
171172
r.Handle("/project/{permProjectKey}/keys/{name}", Scope(sdk.AuthConsumerScopeProject), r.DELETE(api.deleteKeyInProjectHandler))

engine/api/application.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"database/sql"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"strings"
1010

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

650650
m := vars["metadata"]
651-
v, err := ioutil.ReadAll(r.Body)
651+
v, err := io.ReadAll(r.Body)
652652
if err != nil {
653653
return sdk.WrapError(err, "postApplicationMetadataHandler")
654654
}

engine/api/application_import.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package api
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88

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

32-
body, err := ioutil.ReadAll(r.Body)
32+
body, err := io.ReadAll(r.Body)
3333
if err != nil {
3434
return sdk.NewError(sdk.ErrWrongRequest, err)
3535
}

engine/api/ascode_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8+
"io"
89
"io/ioutil"
910
"net/http"
1011
"net/http/httptest"
@@ -95,7 +96,7 @@ func Test_postImportAsCodeHandler(t *testing.T) {
9596
}
9697
default:
9798
ope := new(sdk.Operation)
98-
btes, err := ioutil.ReadAll(r.Body)
99+
btes, err := io.ReadAll(r.Body)
99100
if err != nil {
100101
return writeError(w, err)
101102
}

engine/api/authentication/github/github.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package github
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"time"
99

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

118118
defer res.Body.Close()
119-
resBody, err := ioutil.ReadAll(res.Body)
119+
resBody, err := io.ReadAll(res.Body)
120120
if err != nil {
121121
return info, sdk.WithStack(err)
122122
}

engine/api/environment_import.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package api
22

33
import (
44
"context"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77

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

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

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

170-
body, err := ioutil.ReadAll(r.Body)
170+
body, err := io.ReadAll(r.Body)
171171
if err != nil {
172172
return sdk.NewErrorWithStack(err, sdk.NewErrorFrom(sdk.ErrWrongRequest, "unable to read body"))
173173
}

engine/api/environment_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package api
33
import (
44
"bytes"
55
"encoding/json"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/http/httptest"
99
"testing"
@@ -50,7 +50,7 @@ func TestAddEnvironmentHandler(t *testing.T) {
5050
router.Mux.ServeHTTP(w, req)
5151

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

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

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

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

248248
assert.Equal(t, 200, w.Code)
249-
res, _ := ioutil.ReadAll(w.Body)
249+
res, _ := io.ReadAll(w.Body)
250250
envResults := sdk.Environment{}
251251
json.Unmarshal(res, &envResults)
252252
assert.Equal(t, envResults.Name, "Preproduction")

engine/api/environment_variable_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package api
33
import (
44
"bytes"
55
"encoding/json"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/http/httptest"
99
"testing"
@@ -63,7 +63,7 @@ func TestAddVariableInEnvironmentHandler(t *testing.T) {
6363
router.Mux.ServeHTTP(w, req)
6464

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

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

254254
assert.Equal(t, 200, w.Code)
255-
res, _ := ioutil.ReadAll(w.Body)
255+
res, _ := io.ReadAll(w.Body)
256256
varsResult := []sdk.Variable{}
257257
json.Unmarshal(res, &varsResult)
258258
assert.Equal(t, len(varsResult), 1)

0 commit comments

Comments
 (0)