mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-20 13:16:18 +00:00
put yaml unmarshal after find/replace
This commit is contained in:
parent
95c849a26b
commit
5feac33f85
2 changed files with 16 additions and 10 deletions
|
@ -80,7 +80,13 @@
|
||||||
* @param {string} Plaintext to encrypt.
|
* @param {string} Plaintext to encrypt.
|
||||||
*/
|
*/
|
||||||
this.encrypt = function (repoName, plaintext) {
|
this.encrypt = function (repoName, plaintext) {
|
||||||
return $http.post('/api/repos/' + repoName + '/encrypt', btoa(plaintext));
|
var conf = {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'text/plain; charset=UTF-8'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $http.post('/api/repos/' + repoName + '/encrypt', btoa(plaintext), conf);
|
||||||
};
|
};
|
||||||
|
|
||||||
var callback,
|
var callback,
|
||||||
|
|
|
@ -254,7 +254,7 @@ func Encrypt(c *gin.Context) {
|
||||||
repo := ToRepo(c)
|
repo := ToRepo(c)
|
||||||
in, err := ioutil.ReadAll(c.Request.Body)
|
in, err := ioutil.ReadAll(c.Request.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.Fail(400, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
in, err = base64.StdEncoding.DecodeString(string(in))
|
in, err = base64.StdEncoding.DecodeString(string(in))
|
||||||
|
@ -263,19 +263,19 @@ func Encrypt(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure the Yaml is valid format to prevent
|
|
||||||
// a malformed value from being used in the build
|
|
||||||
err = yaml.Unmarshal(in, &yaml.MapSlice{})
|
|
||||||
if err != nil {
|
|
||||||
c.Fail(500, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// we found some strange characters included in
|
// we found some strange characters included in
|
||||||
// the yaml file when entered into a browser textarea.
|
// the yaml file when entered into a browser textarea.
|
||||||
// these need to be removed
|
// these need to be removed
|
||||||
in = bytes.Replace(in, []byte{'\xA0'}, []byte{' '}, -1)
|
in = bytes.Replace(in, []byte{'\xA0'}, []byte{' '}, -1)
|
||||||
|
|
||||||
|
// make sure the Yaml is valid format to prevent
|
||||||
|
// a malformed value from being used in the build
|
||||||
|
err = yaml.Unmarshal(in, &yaml.MapSlice{})
|
||||||
|
if err != nil {
|
||||||
|
c.Fail(500, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// encrypts using go-jose
|
// encrypts using go-jose
|
||||||
out, err := secure.Encrypt(string(in), repo.Keys.Private)
|
out, err := secure.Encrypt(string(in), repo.Keys.Private)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue