Skip to content

Commit

Permalink
Merge pull request #39 from howbazaar/start-no-base64
Browse files Browse the repository at this point in the history
Machine.Start should not base64 encode the userdata

Rely on the caller to have encoded it for us.
  • Loading branch information
jujubot committed Apr 15, 2016
2 parents d551d0a + ee23fd6 commit ced989b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func (s *controllerSuite) TestAddFileReader(c *gc.C) {
var versionResponse = `{"version": "unknown", "subversion": "", "capabilities": ["networks-management", "static-ipaddresses", "ipv6-deployment-ubuntu", "devices-management", "storage-deployment-ubuntu", "network-deployment-ubuntu"]}`

type cleanup interface {
AddCleanup(testing.CleanupFunc)
AddCleanup(func(*gc.C))
}

// createTestServerController creates a controller backed on to a test server
Expand Down
6 changes: 3 additions & 3 deletions dependencies.tsv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/juju/errors git 1b5e39b83d1835fa480e0c2ddefb040ee82d58b3 2015-09-16T12:56:42Z
github.com/juju/loggo git 8477fc936adf0e382d680310047ca27e128a309a 2015-05-27T03:58:39Z
github.com/juju/names git ef19de31613af3735aa69ba3b40accce2faf7316 2016-03-01T22:07:10Z
github.com/juju/names git 8a0aa0963bbacdc790914892e9ff942e94d6f795 2016-03-30T15:05:33Z
github.com/juju/schema git 1e25943f8c6fd6815282d6f1ac87091d21e14e19 2016-03-01T11:16:46Z
github.com/juju/testing git 45f216f8ef2a6fbed3f38cbcd57f68741d295053 2016-03-17T08:39:30Z
github.com/juju/utils git af32cfaf28093965fdf63373d8447c489efb2875 2016-03-09T18:28:39Z
github.com/juju/testing git 162fafccebf20a4207ab93d63b986c230e3f4d2e 2016-04-04T09:43:17Z
github.com/juju/utils git eb6cb958762135bb61aed1e0951f657c674d427f 2016-04-11T02:40:59Z
github.com/juju/version git ef897ad7f130870348ce306f61332f5335355063 2015-11-27T20:34:00Z
golang.org/x/crypto git aedad9a179ec1ea11b7064c57cbc6dc30d7724ec 2015-08-30T18:06:42Z
gopkg.in/check.v1 git 4f90aeace3a26ad7021961c297b22c42160c7b25 2016-01-05T16:49:36Z
Expand Down
10 changes: 3 additions & 7 deletions machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package gomaasapi

import (
"encoding/base64"
"net/http"

"github.com/juju/errors"
Expand Down Expand Up @@ -174,20 +173,17 @@ func (m *machine) Devices(args DevicesArgs) ([]Device, error) {
// StartArgs is an argument struct for passing parameters to the Machine.Start
// method.
type StartArgs struct {
UserData []byte
// UserData needs to be Base64 encoded user data for cloud-init.
UserData string
DistroSeries string
Kernel string
Comment string
}

// Start implements Machine.
func (m *machine) Start(args StartArgs) error {
var encodedUserData string
if args.UserData != nil {
encodedUserData = base64.StdEncoding.EncodeToString(args.UserData)
}
params := NewURLParams()
params.MaybeAdd("user_data", encodedUserData)
params.MaybeAdd("user_data", args.UserData)
params.MaybeAdd("distro_series", args.DistroSeries)
params.MaybeAdd("hwe_kernel", args.Kernel)
params.MaybeAdd("comment", args.Comment)
Expand Down
15 changes: 7 additions & 8 deletions machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package gomaasapi

import (
"encoding/base64"
"net/http"

"github.com/juju/errors"
Expand Down Expand Up @@ -100,7 +99,7 @@ func (s *machineSuite) TestStart(c *gc.C) {
server.AddPostResponse(machine.resourceURI+"?op=deploy", http.StatusOK, response)

err := machine.Start(StartArgs{
UserData: []byte("userdata"),
UserData: "userdata",
DistroSeries: "trusty",
Kernel: "kernel",
Comment: "a comment",
Expand All @@ -111,12 +110,12 @@ func (s *machineSuite) TestStart(c *gc.C) {

request := server.LastRequest()
// There should be one entry in the form values for each of the args.
c.Assert(request.PostForm, gc.HasLen, 4)
// The userdata should be base64 encoded.
userdata := request.PostForm.Get("user_data")
value, err := base64.StdEncoding.DecodeString(userdata)
c.Assert(err, jc.ErrorIsNil)
c.Assert(string(value), gc.Equals, "userdata")
form := request.PostForm
c.Assert(form, gc.HasLen, 4)
c.Check(form.Get("user_data"), gc.Equals, "userdata")
c.Check(form.Get("distro_series"), gc.Equals, "trusty")
c.Check(form.Get("hwe_kernel"), gc.Equals, "kernel")
c.Check(form.Get("comment"), gc.Equals, "a comment")
}

func (s *machineSuite) TestStartMachineNotFound(c *gc.C) {
Expand Down

0 comments on commit ced989b

Please sign in to comment.