Skip to content

Commit

Permalink
feat(plugin): remove sensitive token from other plugins(except AzureD…
Browse files Browse the repository at this point in the history
…evops)
  • Loading branch information
d4x1 committed Nov 21, 2023
1 parent 5dbee61 commit 4cc5ff1
Show file tree
Hide file tree
Showing 32 changed files with 315 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (connApi *DsConnectionApiHelper[C, S, SC]) Delete(input *plugin.ApiResource
Data: refs,
}, Status: err.GetType().GetHttpCode()}, nil
}
conn = connApi.executeCleanUp(conn)
return &plugin.ApiResourceOutput{
Body: conn,
}, nil
Expand Down
30 changes: 18 additions & 12 deletions backend/helpers/pluginhelper/api/model_api_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,28 @@ func (self *ModelApiHelper[M]) GetDetail(input *plugin.ApiResourceInput) (*plugi
if err != nil {
return nil, err
}
model = self.executeCleanUp(model)
return &plugin.ApiResourceOutput{
Body: model,
}, nil
}

func (self *ModelApiHelper[M]) executeCleanUp(model *M) *M {
if self.cleanUp != nil {
for _, clean := range self.cleanUp {
cleanedModel := clean(*model)
model = &cleanedModel
}
}
return &plugin.ApiResourceOutput{
Body: model,
}, nil
return model
}

func (self *ModelApiHelper[M]) executeCleanUps(models []*M) []*M {
for idx, m := range models {
model := *m
models[idx] = self.executeCleanUp(&model)
}
return models
}

func (self *ModelApiHelper[M]) Patch(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
Expand All @@ -128,6 +141,7 @@ func (self *ModelApiHelper[M]) Patch(input *plugin.ApiResourceInput) (*plugin.Ap
if err != nil {
return nil, err
}
model = self.executeCleanUp(model)
return &plugin.ApiResourceOutput{
Body: model,
}, nil
Expand All @@ -149,15 +163,7 @@ func (self *ModelApiHelper[M]) Delete(input *plugin.ApiResourceInput) (*plugin.A

func (self *ModelApiHelper[M]) GetAll(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
all, err := self.dalHelper.GetAll()
if self.cleanUp != nil {
for idx, m := range all {
model := *m
for _, clean := range self.cleanUp {
model = clean(model)
}
all[idx] = &model
}
}
all = self.executeCleanUps(all)
return &plugin.ApiResourceOutput{
Body: all,
}, err
Expand Down
18 changes: 14 additions & 4 deletions backend/plugins/ae/api/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func PostConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection, Status: http.StatusOK}, nil
return &plugin.ApiResourceOutput{Body: connection.CleanUp(), Status: http.StatusOK}, nil
}

// @Summary get all ae connections
Expand All @@ -96,6 +96,9 @@ func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
for idx, c := range connections {
connections[idx] = c.CleanUp()
}
return &plugin.ApiResourceOutput{Body: connections, Status: http.StatusOK}, nil
}

Expand All @@ -109,7 +112,7 @@ func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
func GetConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
connection := &models.AeConnection{}
err := connectionHelper.First(connection, input.Params)
return &plugin.ApiResourceOutput{Body: connection}, err
return &plugin.ApiResourceOutput{Body: connection.CleanUp()}, err
}

// @Summary patch ae connection
Expand All @@ -126,7 +129,7 @@ func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection, Status: http.StatusOK}, nil
return &plugin.ApiResourceOutput{Body: connection.CleanUp(), Status: http.StatusOK}, nil
}

// @Summary delete a ae connection
Expand All @@ -138,5 +141,12 @@ func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/ae/connections/{connectionId} [DELETE]
func DeleteConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return connectionHelper.Delete(&models.AeConnection{}, input)
conn := &models.AeConnection{}
output, err := connectionHelper.Delete(conn, input)
if err != nil {
return output, err
}
output.Body = conn.CleanUp()
return output, nil

}
5 changes: 5 additions & 0 deletions backend/plugins/ae/models/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func (AeConnection) TableName() string {
return "_tool_ae_connections"
}

func (connection AeConnection) CleanUp() AeConnection {
connection.AeAppKey.SecretKey = ""
return connection
}

func signRequest(query url.Values, appId, secretKey, nonceStr, timestamp string) string {
// clone query because we need to add items
kvs := make([]string, 0, len(query)+3)
Expand Down
17 changes: 13 additions & 4 deletions backend/plugins/bamboo/api/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func PostConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection, Status: http.StatusOK}, nil
return &plugin.ApiResourceOutput{Body: connection.CleanUp(), Status: http.StatusOK}, nil
}

// @Summary patch bamboo connection
Expand All @@ -100,7 +100,7 @@ func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection}, nil
return &plugin.ApiResourceOutput{Body: connection.CleanUp()}, nil
}

// @Summary delete a bamboo connection
Expand All @@ -113,7 +113,13 @@ func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internel Error"
// @Router /plugins/bamboo/connections/{connectionId} [DELETE]
func DeleteConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return connectionHelper.Delete(&models.BambooConnection{}, input)
conn := &models.BambooConnection{}
output, err := connectionHelper.Delete(conn, input)
if err != nil {
return output, err
}
output.Body = conn.CleanUp()
return output, nil
}

// @Summary get all bamboo connections
Expand All @@ -129,6 +135,9 @@ func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
for idx, c := range connections {
connections[idx] = c.CleanUp()
}
return &plugin.ApiResourceOutput{Body: connections, Status: http.StatusOK}, nil
}

Expand All @@ -143,5 +152,5 @@ func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
func GetConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
connection := &models.BambooConnection{}
err := connectionHelper.First(connection, input.Params)
return &plugin.ApiResourceOutput{Body: connection}, err
return &plugin.ApiResourceOutput{Body: connection.CleanUp()}, err
}
5 changes: 5 additions & 0 deletions backend/plugins/bamboo/models/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ type BambooConnection struct {
BambooConn `mapstructure:",squash"`
}

func (connection BambooConnection) CleanUp() BambooConnection {
connection.Password = ""
return connection
}

// TODO Please modify the following code to fit your needs
// This object conforms to what the frontend currently sends.
type BambooConn struct {
Expand Down
18 changes: 14 additions & 4 deletions backend/plugins/bitbucket/api/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func PostConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection, Status: http.StatusOK}, nil
return &plugin.ApiResourceOutput{Body: connection.CleanUp(), Status: http.StatusOK}, nil
}

// @Summary patch bitbucket connection
Expand All @@ -106,7 +106,7 @@ func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection}, nil
return &plugin.ApiResourceOutput{Body: connection.CleanUp()}, nil
}

// @Summary delete a bitbucket connection
Expand All @@ -118,7 +118,14 @@ func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/bitbucket/connections/{connectionId} [DELETE]
func DeleteConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return connectionHelper.Delete(&models.BitbucketConnection{}, input)
conn := &models.BitbucketConnection{}
output, err := connectionHelper.Delete(conn, input)
if err != nil {
return output, err
}
output.Body = conn.CleanUp()
return output, nil

}

// @Summary get all bitbucket connections
Expand All @@ -134,6 +141,9 @@ func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
for idx, c := range connections {
connections[idx] = c.CleanUp()
}
return &plugin.ApiResourceOutput{Body: connections, Status: http.StatusOK}, nil
}

Expand All @@ -147,5 +157,5 @@ func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
func GetConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
connection := &models.BitbucketConnection{}
err := connectionHelper.First(connection, input.Params)
return &plugin.ApiResourceOutput{Body: connection}, err
return &plugin.ApiResourceOutput{Body: connection.CleanUp()}, err
}
5 changes: 5 additions & 0 deletions backend/plugins/bitbucket/models/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ type BitbucketConnection struct {
func (BitbucketConnection) TableName() string {
return "_tool_bitbucket_connections"
}

func (connection BitbucketConnection) CleanUp() BitbucketConnection {
connection.Password = ""
return connection
}
18 changes: 14 additions & 4 deletions backend/plugins/circleci/api/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func PostConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection, Status: http.StatusOK}, nil
return &plugin.ApiResourceOutput{Body: connection.CleanUp(), Status: http.StatusOK}, nil
}

// PatchConnection @Summary patch circleci connection
Expand All @@ -103,7 +103,7 @@ func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection}, nil
return &plugin.ApiResourceOutput{Body: connection.CleanUp()}, nil
}

// DeleteConnection @Summary delete a circleci connection
Expand All @@ -114,7 +114,14 @@ func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/circleci/connections/{connectionId} [DELETE]
func DeleteConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return connectionHelper.Delete(&models.CircleciConnection{}, input)
conn := &models.CircleciConnection{}
output, err := connectionHelper.Delete(conn, input)
if err != nil {
return output, err
}
output.Body = conn.CleanUp()
return output, nil

}

// ListConnections @Summary get all circleci connections
Expand All @@ -130,6 +137,9 @@ func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
for idx, c := range connections {
connections[idx] = c.CleanUp()
}
return &plugin.ApiResourceOutput{Body: connections, Status: http.StatusOK}, nil
}

Expand All @@ -143,5 +153,5 @@ func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
func GetConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
connection := &models.CircleciConnection{}
err := connectionHelper.First(connection, input.Params)
return &plugin.ApiResourceOutput{Body: connection}, err
return &plugin.ApiResourceOutput{Body: connection.CleanUp()}, err
}
5 changes: 5 additions & 0 deletions backend/plugins/circleci/models/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ func (cc *CircleciConn) SetupAuthentication(req *http.Request) errors.Error {
func (CircleciConnection) TableName() string {
return "_tool_circleci_connections"
}

func (connection CircleciConnection) CleanUp() CircleciConnection {
connection.Token = ""
return connection
}
19 changes: 14 additions & 5 deletions backend/plugins/feishu/api/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func PostConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection, Status: http.StatusOK}, nil
return &plugin.ApiResourceOutput{Body: connection.CleanUp(), Status: http.StatusOK}, nil
}

// @Summary patch feishu connection
Expand All @@ -93,7 +93,7 @@ func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection, Status: http.StatusOK}, nil
return &plugin.ApiResourceOutput{Body: connection.CleanUp(), Status: http.StatusOK}, nil
}

// @Summary delete a feishu connection
Expand All @@ -105,7 +105,14 @@ func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/feishu/connections/{connectionId} [DELETE]
func DeleteConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return connectionHelper.Delete(&models.FeishuConnection{}, input)
conn := &models.FeishuConnection{}
output, err := connectionHelper.Delete(conn, input)
if err != nil {
return output, err
}
output.Body = conn.CleanUp()
return output, nil

}

// @Summary get all feishu connections
Expand All @@ -121,7 +128,9 @@ func ListConnections(_ *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, err
if err != nil {
return nil, err
}

for idx, c := range connections {
connections[idx] = c.CleanUp()
}
return &plugin.ApiResourceOutput{Body: connections}, nil
}

Expand All @@ -138,5 +147,5 @@ func GetConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, e
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection}, err
return &plugin.ApiResourceOutput{Body: connection.CleanUp()}, err
}
5 changes: 5 additions & 0 deletions backend/plugins/feishu/models/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,8 @@ type FeishuConnection struct {
func (FeishuConnection) TableName() string {
return "_tool_feishu_connections"
}

func (connection FeishuConnection) CleanUp() FeishuConnection {
connection.SecretKey = ""
return connection
}
Loading

0 comments on commit 4cc5ff1

Please sign in to comment.