put yaml unmarshal after find/replace

This commit is contained in:
Brad Rydzewski 2015-09-07 19:24:14 -07:00
parent 95c849a26b
commit 5feac33f85
2 changed files with 16 additions and 10 deletions

View file

@ -80,7 +80,13 @@
* @param {string} Plaintext to encrypt.
*/
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,

View file

@ -254,7 +254,7 @@ func Encrypt(c *gin.Context) {
repo := ToRepo(c)
in, err := ioutil.ReadAll(c.Request.Body)
if err != nil {
c.Fail(500, err)
c.Fail(400, err)
return
}
in, err = base64.StdEncoding.DecodeString(string(in))
@ -263,19 +263,19 @@ func Encrypt(c *gin.Context) {
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
// the yaml file when entered into a browser textarea.
// these need to be removed
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
out, err := secure.Encrypt(string(in), repo.Keys.Private)
if err != nil {