8000 fix(api): handle ssh vcs strategies while doing update as-code (#3882) · ovh/cds@78798ca · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 78798ca

Browse files
fsaminbnjjj
authored andcommitted
fix(api): handle ssh vcs strategies while doing update as-code (#3882)
closes #3876 1. Description 1. Related issues 1. About tests 1. Mentions @ovh/cds
1 parent 7c0e90b commit 78798ca

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

engine/api/cache/redis.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8+
"io/ioutil"
9+
stdlog "log"
810
"strconv"
911
"strings"
1012
"time"
@@ -47,6 +49,9 @@ func NewRedisStore(host, password string, ttl int) (*RedisStore, error) {
4749
IdleCheckFrequency: 30 * time.Second,
4850
})
4951
}
52+
53+
redis.SetLogger(stdlog.New(ioutil.Discard 8000 , "", stdlog.LstdFlags|stdlog.Lshortfile))
54+
5055
pong, err := client.Ping().Result()
5156
if err != nil {
5257
return nil, err

engine/api/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (b *eventsBroker) cacheSubscribe(c context.Context, cacheMsgChan chan<- sdk
8686
}
8787
var e sdk.Event
8888
if err := json.Unmarshal([]byte(msg), &e); err != nil {
89-
log.Warning("events.cacheSubscribe> Cannot unmarshal event %s: %s", msg, err)
89+
// don't print the error as we doesn't care
9090
continue
9191
}
9292

engine/api/group/aggregate_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package group
1+
package group_test
22

33
import (
44
"testing"
55

6+
"github.com/ovh/cds/engine/api/group"
67
"github.com/ovh/cds/engine/api/test"
78
"github.com/ovh/cds/sdk"
89
"github.com/stretchr/testify/assert"
@@ -26,7 +27,7 @@ func TestAggregateOnWorkflowTemplate(t *testing.T) {
2627
{GroupID: 2},
2728
}
2829

29-
assert.Nil(t, AggregateOnWorkflowTemplate(db, wts...))
30+
assert.Nil(t, group.AggregateOnWorkflowTemplate(db, wts...))
3031

3132
assert.NotNil(t, wts[0].Group)
3233
assert.Equal(t, "grp-1", wts[0].Group.Name)

engine/api/test/test.go

-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ func SetupPG(t log.Logger, bootstrapFunc ...Bootstrapf) (*gorp.DbMap, cache.Stor
121121
}
122122

123123
cancel := func() {
124-
log.Debug("Closing redis client")
125124
store.Client.Close()
126125
store.Client = nil
127126
}

engine/api/workflow/as_code.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,27 @@ func UpdateAsCode(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *
4747
return nil, sdk.WrapError(err, "cannot pull workflow")
4848
}
4949

50-
if err := application.DecryptVCSStrategyPassword(&app); err != nil {
51-
return nil, sdk.WrapError(err, "unable to decrypt vcs strategy")
50+
var vcsStrategy = app.RepositoryStrategy
51+
52+
if vcsStrategy.SSHKey != "" {
53+
key := proj.GetSSHKey(vcsStrategy.SSHKey)
54+
if key == nil {
55+
return nil, fmt.Errorf("unable to find key %s on project %s", vcsStrategy.SSHKey, proj.Key)
56+
}
57+
vcsStrategy.SSHKeyContent = key.Private
58+
} else {
59+
if err := application.DecryptVCSStrategyPassword(&app); err != nil {
60+
return nil, sdk.WrapError(err, "unable to decrypt vcs strategy")
61+
}
62+
vcsStrategy = app.RepositoryStrategy
5263
}
5364

5465
// Create VCS Operation
5566
ope := sdk.Operation{
5667
VCSServer: app.VCSServer,
5768
RepoFullName: app.RepositoryFullname,
5869
URL: "",
59-
RepositoryStrategy: app.RepositoryStrategy,
70+
RepositoryStrategy: vcsStrategy,
6071
Setup: sdk.OperationSetup{
6172
Push: sdk.OperationPush{
6273
FromBranch: fmt.Sprintf("cdsAsCode-%d", time.Now().Unix()),

engine/api/workflow_ascode.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ func (api *API) postWorkflowAsCodeHandler() service.Handler {
3838

3939
u := deprecatedGetUser(ctx)
4040

41-
proj, errP := project.Load(api.mustDB(), api.Cache, key, u, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, project.LoadOptions.WithPlatforms)
41+
proj, errP := project.Load(api.mustDB(), api.Cache, key, u,
42+
project.LoadOptions.WithApplicationWithDeploymentStrategies,
43+
project.LoadOptions.WithPipelines,
44+
project.LoadOptions.WithEnvironments,
45+
project.LoadOptions.WithPlatforms,
46+
project.LoadOptions.WithClearKeys)
4247
if errP != nil {
4348
return sdk.WrapError(errP, "unable to load project")
4449
}

0 commit comments

Comments
 (0)
0