{"action":"created","issue":{"url":"https://api.github.com/repos/coreos/bugs/issues/741","labels_url":"https://api.github.com/repos/coreos/bugs/issues/741/labels{/name}","comments_url":"https://api.github.com/repos/coreos/bugs/issues/741/comments","events_url":"https://api.github.com/repos/coreos/bugs/issues/741/events","html_url":"https://github.com/coreos/bugs/issues/741","id":108030611,"number":741,"title":"Support gzip compression","user":{"login":"crawford","id":368848,"avatar_url":"https://avatars.githubusercontent.com/u/368848?v=3","gravatar_id":"","url":"https://api.github.com/users/crawford","html_url":"https://github.com/crawford","followers_url":"https://api.github.com/users/crawford/followers","following_url":"https://api.github.com/users/crawford/following{/other_user}","gists_url":"https://api.github.com/users/crawford/gists{/gist_id}","starred_url":"https://api.github.com/users/crawford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crawford/subscriptions","organizations_url":"https://api.github.com/users/crawford/orgs","repos_url":"https://api.github.com/users/crawford/repos","events_url":"https://api.github.com/users/crawford/events{/privacy}","received_events_url":"https://api.github.com/users/crawford/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/coreos/bugs/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-24T00:00:07Z","updated_at":"2015-09-24T00:00:08Z","closed_at":null,"body":"<a href=\"https://github.com/yawn\"><img src=\"https://avatars.githubusercontent.com/u/18242?v=3\" align=\"left\" width=\"96\" height=\"96\" hspace=\"10\"></img></a> **Issue by [yawn](https://github.com/yawn)**\n_Friday Jun 06, 2014 at 11:22 GMT_\n_Originally opened as https://github.com/coreos/coreos-cloudinit/issues/143_\n\n----\n\nConsider supporting base64 + gzip encoding of cloudinit scripts\n"},"comment":{"url":"https://api.github.com/repos/coreos/bugs/issues/comments/142764236","html_url":"https://github.com/coreos/bugs/issues/741#issuecomment-142764236","issue_url":"https://api.github.com/repos/coreos/bugs/issues/741","id":142764236,"user":{"login":"crawford","id":368848,"avatar_url":"https://avatars.githubusercontent.com/u/368848?v=3","gravatar_id":"","url":"https://api.github.com/users/crawford","html_url":"https://github.com/crawford","followers_url":"https://api.github.com/users/crawford/followers","following_url":"https://api.github.com/users/crawford/following{/other_user}","gists_url":"https://api.github.com/users/crawford/gists{/gist_id}","starred_url":"https://api.github.com/users/crawford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crawford/subscriptions","organizations_url":"https://api.github.com/users/crawford/orgs","repos_url":"https://api.github.com/users/crawford/repos","events_url":"https://api.github.com/users/crawford/events{/privacy}","received_events_url":"https://api.github.com/users/crawford/received_events","type":"User","site_admin":false},"created_at":"2015-09-24T00:00:08Z","updated_at":"2015-09-24T00:00:08Z","body":"<a href=\"https://github.com/yawn\"><img src=\"https://avatars.githubusercontent.com/u/18242?v=3\" align=\"left\" width=\"48\" height=\"48\" hspace=\"10\"></img></a> **Comment by [yawn](https://github.com/yawn)**\n_Monday Jun 09, 2014 at 15:25 GMT_\n\n----\n\nSomething like this maybe:\r\n\r\n```\r\npackage initialize\r\n\r\nimport (\r\n\t\"bytes\"\r\n\t\"compress/gzip\"\r\n\t\"encoding/base64\"\r\n\t\"fmt\"\r\n\t\"io/ioutil\"\r\n\t\"strings\"\r\n)\r\n\r\nfunc Preprocess(contents string) (string, error) {\r\n\r\n\tif isDecoded(contents) {\r\n\t\treturn contents, nil\r\n\t} else if base64, err := tryBase64(contents); err != nil {\r\n\t\treturn \"\", err\r\n\t} else if isDecoded(base64) {\r\n\t\treturn base64, nil\r\n\t} else if zipped, err := tryGzip(base64); err != nil {\r\n\t\treturn \"\", err\r\n\t} else if isDecoded(zipped) {\r\n\t\treturn zipped, nil\r\n\t} else {\r\n\t\treturn \"\", fmt.Errorf(\"Unable to reconstruct valid configuration via postprocessing from %v\", contents)\r\n\t}\r\n\r\n}\r\n\r\nfunc isDecoded(contents string) bool {\r\n\treturn strings.Contains(contents, \"coreos\")\r\n}\r\n\r\nfunc tryBase64(contents string) (string, error) {\r\n\r\n\tbase64, err := base64.StdEncoding.DecodeString(contents)\r\n\r\n\tif err != nil {\r\n\t\treturn \"\", err\r\n\t}\r\n\r\n\treturn string(base64), nil\r\n\r\n}\r\n\r\nfunc tryGzip(base64 string) (string, error) {\r\n\r\n\tvar zipped []byte\r\n\r\n\tzr, err := gzip.NewReader(bytes.NewReader([]byte(base64)))\r\n\tzipped, err = ioutil.ReadAll(zr)\r\n\r\n\tif err != nil {\r\n\t\treturn \"\", err\r\n\t}\r\n\r\n\tif err = zr.Close(); err != nil {\r\n\t\treturn \"\", err\r\n\t}\r\n\r\n\treturn string(zipped), nil\r\n\r\n}\r\n```\r\n\r\nIf you agree in principle I'd open a pull request + test. Integration should probably happen [here](https://github.com/coreos/coreos-cloudinit/blob/master/initialize/config.go#L119)\n"}}