Converting all inputs which are coming as secret to lowercase (#1276)

Closes #926

Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
This commit is contained in:
Avinil Bedarkar 2022-10-16 18:28:13 +05:30 committed by GitHub
parent 711f12ed27
commit 11f37f4649
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 3 deletions

View file

@ -50,8 +50,9 @@ func secretCreate(c *cli.Context) error {
if err != nil {
return err
}
secret := &woodpecker.Secret{
Name: c.String("name"),
Name: strings.ToLower(c.String("name")),
Value: c.String("value"),
Images: c.StringSlice("image"),
Events: c.StringSlice("event"),

View file

@ -50,8 +50,9 @@ func secretUpdate(c *cli.Context) error {
if err != nil {
return err
}
secret := &woodpecker.Secret{
Name: c.String("name"),
Name: strings.ToLower(c.String("name")),
Value: c.String("value"),
Images: c.StringSlice("image"),
Events: c.StringSlice("event"),

View file

@ -16,6 +16,7 @@ package api
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
@ -50,7 +51,7 @@ func PostSecret(c *gin.Context) {
}
secret := &model.Secret{
RepoID: repo.ID,
Name: in.Name,
Name: strings.ToLower(in.Name),
Value: in.Value,
Events: in.Events,
Images: in.Images,

View file

@ -0,0 +1,27 @@
// Copyright 2022 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package migration
import (
"xorm.io/xorm"
)
var lowercaseSecretNames = task{
name: "lowercase-secret-names",
fn: func(sess *xorm.Session) (err error) {
_, err = sess.Exec("UPDATE secrets SET secret_name = LOWER(secret_name);")
return err
},
}

View file

@ -35,6 +35,7 @@ var migrationTasks = []*task{
&dropSenders,
&alterTableLogUpdateColumnLogDataType,
&alterTableSecretsAddUserCol,
&lowercaseSecretNames,
}
var allBeans = []interface{}{