From 8e3cf23d520830799caf6efd655678b0cbe26011 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 11 Oct 2014 17:50:52 -0700 Subject: [PATCH 01/10] added gitter badge to repository --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c4acbfe59..94c56d328 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Build Status](http://test.drone.io/v1/badge/github.com/drone/drone/status.svg)](http://test.drone.io/github.com/drone/drone) [![GoDoc](https://godoc.org/github.com/drone/drone?status.png)](https://godoc.org/github.com/drone/drone) +[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/drone/drone?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ## System Requirements @@ -29,7 +30,7 @@ described in the **Setup** section. Below are some example configurations that you can use as reference: -``` +```toml # to use postgres [database] driver="postgres" @@ -39,7 +40,6 @@ datasource="host=127.0.0.1 user=postgres dbname=drone sslmode=disable" [database] driver="mysql" datasource="root@tcp(127.0.0.1:3306)/drone" - ``` ## Setup From 82a7ea857dd5c39ab5abaaf9d57d005651d0ffd5 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 11 Oct 2014 18:37:27 -0700 Subject: [PATCH 02/10] unit tests for git deploy plugin --- plugin/deploy/git/git.go | 56 +++++++++++++++++++++++++ plugin/deploy/git/git_test.go | 78 +++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 plugin/deploy/git/git.go create mode 100644 plugin/deploy/git/git_test.go diff --git a/plugin/deploy/git/git.go b/plugin/deploy/git/git.go new file mode 100644 index 000000000..033d14892 --- /dev/null +++ b/plugin/deploy/git/git.go @@ -0,0 +1,56 @@ +package git + +import ( + "fmt" + "github.com/drone/drone/plugin/condition" + "github.com/drone/drone/shared/build/buildfile" +) + +const ( + // Gommand to the current commit hash + CmdRevParse = "COMMIT=$(git rev-parse HEAD)" + + // Command to set the git user and email based on the + // individual that made the commit. + CmdGlobalEmail = "git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')" + CmdGlobalUser = "git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')" +) + +type Git struct { + Target string `yaml:"target,omitempty"` + Force bool `yaml:"force,omitempty"` + Branch string `yaml:"branch,omitempty"` + + Condition *condition.Condition `yaml:"when,omitempty"` +} + +func (g *Git) Write(f *buildfile.Buildfile) { + f.WriteCmdSilent(CmdRevParse) + f.WriteCmdSilent(CmdGlobalUser) + f.WriteCmdSilent(CmdGlobalEmail) + + // add target as a git remote + f.WriteCmd(fmt.Sprintf("git remote add deploy %s", g.Target)) + + dest := g.Branch + if len(dest) == 0 { + dest = "master" + } + + switch g.Force { + case true: + // this is useful when the there are artifacts generated + // by the build script, such as less files converted to css, + // that need to be deployed to git remote. + f.WriteCmd(fmt.Sprintf("git add -A")) + f.WriteCmd(fmt.Sprintf("git commit -m 'add build artifacts'")) + f.WriteCmd(fmt.Sprintf("git push deploy HEAD:%s --force", dest)) + case false: + // otherwise we just do a standard git push + f.WriteCmd(fmt.Sprintf("git push deploy $COMMIT:%s", dest)) + } +} + +func (g *Git) GetCondition() *condition.Condition { + return g.Condition +} diff --git a/plugin/deploy/git/git_test.go b/plugin/deploy/git/git_test.go new file mode 100644 index 000000000..5502647ad --- /dev/null +++ b/plugin/deploy/git/git_test.go @@ -0,0 +1,78 @@ +package git + +import ( + "strings" + "testing" + + "github.com/drone/drone/shared/build/buildfile" + "github.com/franela/goblin" +) + +func Test_Git(t *testing.T) { + + g := goblin.Goblin(t) + g.Describe("Git Deploy", func() { + + g.It("Should set git.config", func() { + b := new(buildfile.Buildfile) + d := Git{ + Target: "git://foo.com/bar/baz.git", + } + + d.Write(b) + out := b.String() + g.Assert(strings.Contains(out, CmdRevParse)).Equal(true) + g.Assert(strings.Contains(out, CmdGlobalUser)).Equal(true) + g.Assert(strings.Contains(out, CmdGlobalEmail)).Equal(true) + }) + + g.It("Should add remote", func() { + b := new(buildfile.Buildfile) + d := Git{ + Target: "git://foo.com/bar/baz.git", + } + + d.Write(b) + out := b.String() + g.Assert(strings.Contains(out, "\ngit remote add deploy git://foo.com/bar/baz.git\n")).Equal(true) + }) + + g.It("Should push to remote", func() { + b := new(buildfile.Buildfile) + d := Git{ + Target: "git://foo.com/bar/baz.git", + } + + d.Write(b) + out := b.String() + g.Assert(strings.Contains(out, "\ngit push deploy $COMMIT:master\n")).Equal(true) + }) + + g.It("Should push to alternate branch", func() { + b := new(buildfile.Buildfile) + d := Git{ + Branch: "foo", + Target: "git://foo.com/bar/baz.git", + } + + d.Write(b) + out := b.String() + g.Assert(strings.Contains(out, "\ngit push deploy $COMMIT:foo\n")).Equal(true) + }) + + g.It("Should force push to remote", func() { + b := new(buildfile.Buildfile) + d := Git{ + Force: true, + Target: "git://foo.com/bar/baz.git", + } + + d.Write(b) + out := b.String() + g.Assert(strings.Contains(out, "\ngit add -A\n")).Equal(true) + g.Assert(strings.Contains(out, "\ngit commit -m 'add build artifacts'\n")).Equal(true) + g.Assert(strings.Contains(out, "\ngit push deploy HEAD:master --force\n")).Equal(true) + }) + + }) +} From e5f43667727f397b2604601ddc416f9b78e18a97 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 11 Oct 2014 18:49:40 -0700 Subject: [PATCH 03/10] added unit tests for Heroku deploy --- plugin/deploy/git/git.go | 2 +- plugin/deploy/heroku/heroku.go | 50 ++++++++++++++++++++++ plugin/deploy/heroku/heroku_test.go | 66 +++++++++++++++++++++++++++++ plugin/publish/npm/npm_test.go | 13 ------ 4 files changed, 117 insertions(+), 14 deletions(-) create mode 100644 plugin/deploy/heroku/heroku.go create mode 100644 plugin/deploy/heroku/heroku_test.go diff --git a/plugin/deploy/git/git.go b/plugin/deploy/git/git.go index 033d14892..298c502ae 100644 --- a/plugin/deploy/git/git.go +++ b/plugin/deploy/git/git.go @@ -13,7 +13,7 @@ const ( // Command to set the git user and email based on the // individual that made the commit. CmdGlobalEmail = "git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')" - CmdGlobalUser = "git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')" + CmdGlobalUser = "git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')" ) type Git struct { diff --git a/plugin/deploy/heroku/heroku.go b/plugin/deploy/heroku/heroku.go new file mode 100644 index 000000000..60cca50eb --- /dev/null +++ b/plugin/deploy/heroku/heroku.go @@ -0,0 +1,50 @@ +package heroku + +import ( + "fmt" + "github.com/drone/drone/plugin/condition" + "github.com/drone/drone/shared/build/buildfile" +) + +const ( + // Gommand to the current commit hash + CmdRevParse = "COMMIT=$(git rev-parse HEAD)" + + // Command to set the git user and email based on the + // individual that made the commit. + CmdGlobalEmail = "git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')" + CmdGlobalUser = "git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')" +) + +type Heroku struct { + App string `yaml:"app,omitempty"` + Force bool `yaml:"force,omitempty"` + + Condition *condition.Condition `yaml:"when,omitempty"` +} + +func (h *Heroku) Write(f *buildfile.Buildfile) { + f.WriteCmdSilent(CmdRevParse) + f.WriteCmdSilent(CmdGlobalUser) + f.WriteCmdSilent(CmdGlobalEmail) + + // add heroku as a git remote + f.WriteCmd(fmt.Sprintf("git remote add heroku git@heroku.com:%s.git", h.App)) + + switch h.Force { + case true: + // this is useful when the there are artifacts generated + // by the build script, such as less files converted to css, + // that need to be deployed to Heroku. + f.WriteCmd(fmt.Sprintf("git add -A")) + f.WriteCmd(fmt.Sprintf("git commit -m 'adding build artifacts'")) + f.WriteCmd(fmt.Sprintf("git push heroku HEAD:master --force")) + case false: + // otherwise we just do a standard git push + f.WriteCmd(fmt.Sprintf("git push heroku $COMMIT:master")) + } +} + +func (h *Heroku) GetCondition() *condition.Condition { + return h.Condition +} diff --git a/plugin/deploy/heroku/heroku_test.go b/plugin/deploy/heroku/heroku_test.go new file mode 100644 index 000000000..1a7ff70b0 --- /dev/null +++ b/plugin/deploy/heroku/heroku_test.go @@ -0,0 +1,66 @@ +package heroku + +import ( + "strings" + "testing" + + "github.com/drone/drone/shared/build/buildfile" + "github.com/franela/goblin" +) + +func Test_Git(t *testing.T) { + + g := goblin.Goblin(t) + g.Describe("Heroku Deploy", func() { + + g.It("Should set git.config", func() { + b := new(buildfile.Buildfile) + h := Heroku{ + App: "drone", + } + + h.Write(b) + out := b.String() + g.Assert(strings.Contains(out, CmdRevParse)).Equal(true) + g.Assert(strings.Contains(out, CmdGlobalUser)).Equal(true) + g.Assert(strings.Contains(out, CmdGlobalEmail)).Equal(true) + }) + + g.It("Should add remote", func() { + b := new(buildfile.Buildfile) + h := Heroku{ + App: "drone", + } + + h.Write(b) + out := b.String() + g.Assert(strings.Contains(out, "\ngit remote add heroku git@heroku.com:drone.git\n")).Equal(true) + }) + + g.It("Should push to remote", func() { + b := new(buildfile.Buildfile) + d := Heroku{ + App: "drone", + } + + d.Write(b) + out := b.String() + g.Assert(strings.Contains(out, "\ngit push heroku $COMMIT:master\n")).Equal(true) + }) + + g.It("Should force push to remote", func() { + b := new(buildfile.Buildfile) + h := Heroku{ + Force: true, + App: "drone", + } + + h.Write(b) + out := b.String() + g.Assert(strings.Contains(out, "\ngit add -A\n")).Equal(true) + g.Assert(strings.Contains(out, "\ngit commit -m 'adding build artifacts'\n")).Equal(true) + g.Assert(strings.Contains(out, "\ngit push heroku HEAD:master --force\n")).Equal(true) + }) + + }) +} diff --git a/plugin/publish/npm/npm_test.go b/plugin/publish/npm/npm_test.go index b0562c5d2..575f249b1 100644 --- a/plugin/publish/npm/npm_test.go +++ b/plugin/publish/npm/npm_test.go @@ -36,19 +36,6 @@ func Test_NPM(t *testing.T) { g.Assert(strings.Contains(out, "\nnpm config set")).Equal(false) }) - /* - n := NPM{ - Email: "foo@bar.com", - Username: "foo", - Password: "bar", - Force: true, - Registry: "", - Folder: "/path/to/repo", - Tag: "1.0.0", - AlwaysAuth: false, - } - */ - g.It("Should set force", func() { b := new(buildfile.Buildfile) n := NPM{ From 418e3cab45fe3d7f84cbda74eec111f386a18756 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 11 Oct 2014 18:52:31 -0700 Subject: [PATCH 04/10] unit tests for Tsuru plugin --- plugin/deploy/tsuru/tsuru.go | 50 +++++++++++++++++++++++ plugin/deploy/tsuru/tsuru_test.go | 66 +++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 plugin/deploy/tsuru/tsuru.go create mode 100644 plugin/deploy/tsuru/tsuru_test.go diff --git a/plugin/deploy/tsuru/tsuru.go b/plugin/deploy/tsuru/tsuru.go new file mode 100644 index 000000000..808f8867b --- /dev/null +++ b/plugin/deploy/tsuru/tsuru.go @@ -0,0 +1,50 @@ +package tsuru + +import ( + "fmt" + "github.com/drone/drone/plugin/condition" + "github.com/drone/drone/shared/build/buildfile" +) + +const ( + // Gommand to the current commit hash + CmdRevParse = "COMMIT=$(git rev-parse HEAD)" + + // Command to set the git user and email based on the + // individual that made the commit. + CmdGlobalEmail = "git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')" + CmdGlobalUser = "git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')" +) + +type Tsuru struct { + Force bool `yaml:"force,omitempty"` + Remote string `yaml:"remote,omitempty"` + + Condition *condition.Condition `yaml:"when,omitempty"` +} + +func (t *Tsuru) Write(f *buildfile.Buildfile) { + f.WriteCmdSilent(CmdRevParse) + f.WriteCmdSilent(CmdGlobalUser) + f.WriteCmdSilent(CmdGlobalEmail) + + // add tsuru as a git remote + f.WriteCmd(fmt.Sprintf("git remote add tsuru %s", t.Remote)) + + switch t.Force { + case true: + // this is useful when the there are artifacts generated + // by the build script, such as less files converted to css, + // that need to be deployed to Tsuru. + f.WriteCmd(fmt.Sprintf("git add -A")) + f.WriteCmd(fmt.Sprintf("git commit -m 'adding build artifacts'")) + f.WriteCmd(fmt.Sprintf("git push tsuru HEAD:master --force")) + case false: + // otherwise we just do a standard git push + f.WriteCmd(fmt.Sprintf("git push tsuru $COMMIT:master")) + } +} + +func (t *Tsuru) GetCondition() *condition.Condition { + return t.Condition +} diff --git a/plugin/deploy/tsuru/tsuru_test.go b/plugin/deploy/tsuru/tsuru_test.go new file mode 100644 index 000000000..c456d7d44 --- /dev/null +++ b/plugin/deploy/tsuru/tsuru_test.go @@ -0,0 +1,66 @@ +package tsuru + +import ( + "strings" + "testing" + + "github.com/drone/drone/shared/build/buildfile" + "github.com/franela/goblin" +) + +func Test_Git(t *testing.T) { + + g := goblin.Goblin(t) + g.Describe("Tsuru Deploy", func() { + + g.It("Should set git.config", func() { + b := new(buildfile.Buildfile) + d := Tsuru{ + Remote: "git://foo.com/bar/baz.git", + } + + d.Write(b) + out := b.String() + g.Assert(strings.Contains(out, CmdRevParse)).Equal(true) + g.Assert(strings.Contains(out, CmdGlobalUser)).Equal(true) + g.Assert(strings.Contains(out, CmdGlobalEmail)).Equal(true) + }) + + g.It("Should add remote", func() { + b := new(buildfile.Buildfile) + d := Tsuru{ + Remote: "git://foo.com/bar/baz.git", + } + + d.Write(b) + out := b.String() + g.Assert(strings.Contains(out, "\ngit remote add tsuru git://foo.com/bar/baz.git\n")).Equal(true) + }) + + g.It("Should push to remote", func() { + b := new(buildfile.Buildfile) + d := Tsuru{ + Remote: "git://foo.com/bar/baz.git", + } + + d.Write(b) + out := b.String() + g.Assert(strings.Contains(out, "\ngit push tsuru $COMMIT:master\n")).Equal(true) + }) + + g.It("Should force push to remote", func() { + b := new(buildfile.Buildfile) + d := Tsuru{ + Force: true, + Remote: "git://foo.com/bar/baz.git", + } + + d.Write(b) + out := b.String() + g.Assert(strings.Contains(out, "\ngit add -A\n")).Equal(true) + g.Assert(strings.Contains(out, "\ngit commit -m 'adding build artifacts'\n")).Equal(true) + g.Assert(strings.Contains(out, "\ngit push tsuru HEAD:master --force\n")).Equal(true) + }) + + }) +} From 5c13d6ba35766b64c17777a764c155f3530cdec9 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 11 Oct 2014 18:55:58 -0700 Subject: [PATCH 05/10] removed unused deployment file stubs --- plugin/deploy/appfog.go | 12 --------- plugin/deploy/cloudcontrol.go | 12 --------- plugin/deploy/deployment.go | 23 ++++++++-------- plugin/deploy/engineyard.go | 12 --------- plugin/deploy/git.go | 50 ----------------------------------- plugin/deploy/heroku.go | 45 ------------------------------- plugin/deploy/openshift.go | 12 --------- plugin/deploy/tsuru.go | 45 ------------------------------- 8 files changed, 11 insertions(+), 200 deletions(-) delete mode 100644 plugin/deploy/appfog.go delete mode 100644 plugin/deploy/cloudcontrol.go delete mode 100644 plugin/deploy/engineyard.go delete mode 100644 plugin/deploy/git.go delete mode 100644 plugin/deploy/heroku.go delete mode 100644 plugin/deploy/openshift.go delete mode 100644 plugin/deploy/tsuru.go diff --git a/plugin/deploy/appfog.go b/plugin/deploy/appfog.go deleted file mode 100644 index 716db6ccb..000000000 --- a/plugin/deploy/appfog.go +++ /dev/null @@ -1,12 +0,0 @@ -package deploy - -import ( - "github.com/drone/drone/shared/build/buildfile" -) - -type AppFog struct { -} - -func (a *AppFog) Write(f *buildfile.Buildfile) { - -} diff --git a/plugin/deploy/cloudcontrol.go b/plugin/deploy/cloudcontrol.go deleted file mode 100644 index 3d16a681d..000000000 --- a/plugin/deploy/cloudcontrol.go +++ /dev/null @@ -1,12 +0,0 @@ -package deploy - -import ( - "github.com/drone/drone/shared/build/buildfile" -) - -type CloudControl struct { -} - -func (c *CloudControl) Write(f *buildfile.Buildfile) { - -} diff --git a/plugin/deploy/deployment.go b/plugin/deploy/deployment.go index 1f28cf69b..635fdfc92 100644 --- a/plugin/deploy/deployment.go +++ b/plugin/deploy/deployment.go @@ -2,6 +2,9 @@ package deploy import ( "github.com/drone/drone/plugin/condition" + "github.com/drone/drone/plugin/deploy/git" + "github.com/drone/drone/plugin/deploy/heroku" + "github.com/drone/drone/plugin/deploy/tsuru" "github.com/drone/drone/shared/build/buildfile" "github.com/drone/drone/shared/build/repo" ) @@ -10,18 +13,14 @@ import ( // for deploying build artifacts when // a Build has succeeded type Deploy struct { - AppFog *AppFog `yaml:"appfog,omitempty"` - CloudControl *CloudControl `yaml:"cloudcontrol,omitempty"` - CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"` - EngineYard *EngineYard `yaml:"engineyard,omitempty"` - Git *Git `yaml:"git,omitempty"` - Heroku *Heroku `yaml:"heroku,omitempty"` - Modulus *Modulus `yaml:"modulus,omitempty"` - Nodejitsu *Nodejitsu `yaml:"nodejitsu,omitempty"` - Openshift *Openshift `yaml:"openshift,omitempty"` - SSH *SSH `yaml:"ssh,omitempty"` - Tsuru *Tsuru `yaml:"tsuru,omitempty"` - Bash *Bash `yaml:"bash,omitempty"` + CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"` + Git *git.Git `yaml:"git,omitempty"` + Heroku *heroku.Heroku `yaml:"heroku,omitempty"` + Modulus *Modulus `yaml:"modulus,omitempty"` + Nodejitsu *Nodejitsu `yaml:"nodejitsu,omitempty"` + SSH *SSH `yaml:"ssh,omitempty"` + Tsuru *tsuru.Tsuru `yaml:"tsuru,omitempty"` + Bash *Bash `yaml:"bash,omitempty"` } func (d *Deploy) Write(f *buildfile.Buildfile, r *repo.Repo) { diff --git a/plugin/deploy/engineyard.go b/plugin/deploy/engineyard.go deleted file mode 100644 index 8ffa814ae..000000000 --- a/plugin/deploy/engineyard.go +++ /dev/null @@ -1,12 +0,0 @@ -package deploy - -import ( - "github.com/drone/drone/shared/build/buildfile" -) - -type EngineYard struct { -} - -func (e *EngineYard) Write(f *buildfile.Buildfile) { - -} diff --git a/plugin/deploy/git.go b/plugin/deploy/git.go deleted file mode 100644 index 451dc8411..000000000 --- a/plugin/deploy/git.go +++ /dev/null @@ -1,50 +0,0 @@ -package deploy - -import ( - "fmt" - "github.com/drone/drone/plugin/condition" - "github.com/drone/drone/shared/build/buildfile" -) - -type Git struct { - Target string `yaml:"target,omitempty"` - Force bool `yaml:"force,omitempty"` - Branch string `yaml:"branch,omitempty"` - - Condition *condition.Condition `yaml:"when,omitempty"` -} - -func (g *Git) Write(f *buildfile.Buildfile) { - // get the current commit hash - f.WriteCmdSilent("COMMIT=$(git rev-parse HEAD)") - - // set the git user and email based on the individual - // that made the commit. - f.WriteCmdSilent("git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')") - f.WriteCmdSilent("git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')") - - // add target as a git remote - f.WriteCmd(fmt.Sprintf("git remote add deploy %s", g.Target)) - - destinationBranch := g.Branch - if destinationBranch == "" { - destinationBranch = "master" - } - - switch g.Force { - case true: - // this is useful when the there are artifacts generated - // by the build script, such as less files converted to css, - // that need to be deployed to git remote. - f.WriteCmd(fmt.Sprintf("git add -A")) - f.WriteCmd(fmt.Sprintf("git commit -m 'add build artifacts'")) - f.WriteCmd(fmt.Sprintf("git push deploy HEAD:%s --force", destinationBranch)) - case false: - // otherwise we just do a standard git push - f.WriteCmd(fmt.Sprintf("git push deploy $COMMIT:%s", destinationBranch)) - } -} - -func (g *Git) GetCondition() *condition.Condition { - return g.Condition -} diff --git a/plugin/deploy/heroku.go b/plugin/deploy/heroku.go deleted file mode 100644 index 3c90ed82a..000000000 --- a/plugin/deploy/heroku.go +++ /dev/null @@ -1,45 +0,0 @@ -package deploy - -import ( - "fmt" - "github.com/drone/drone/plugin/condition" - "github.com/drone/drone/shared/build/buildfile" -) - -type Heroku struct { - App string `yaml:"app,omitempty"` - Force bool `yaml:"force,omitempty"` - Branch string `yaml:"branch,omitempty"` - - Condition *condition.Condition `yaml:"when,omitempty"` -} - -func (h *Heroku) Write(f *buildfile.Buildfile) { - // get the current commit hash - f.WriteCmdSilent("COMMIT=$(git rev-parse HEAD)") - - // set the git user and email based on the individual - // that made the commit. - f.WriteCmdSilent("git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')") - f.WriteCmdSilent("git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')") - - // add heroku as a git remote - f.WriteCmd(fmt.Sprintf("git remote add heroku git@heroku.com:%s.git", h.App)) - - switch h.Force { - case true: - // this is useful when the there are artifacts generated - // by the build script, such as less files converted to css, - // that need to be deployed to Heroku. - f.WriteCmd(fmt.Sprintf("git add -A")) - f.WriteCmd(fmt.Sprintf("git commit -m 'adding build artifacts'")) - f.WriteCmd(fmt.Sprintf("git push heroku HEAD:master --force")) - case false: - // otherwise we just do a standard git push - f.WriteCmd(fmt.Sprintf("git push heroku $COMMIT:master")) - } -} - -func (h *Heroku) GetCondition() *condition.Condition { - return h.Condition -} diff --git a/plugin/deploy/openshift.go b/plugin/deploy/openshift.go deleted file mode 100644 index 749b4353a..000000000 --- a/plugin/deploy/openshift.go +++ /dev/null @@ -1,12 +0,0 @@ -package deploy - -import ( - "github.com/drone/drone/shared/build/buildfile" -) - -type Openshift struct { -} - -func (o *Openshift) Write(f *buildfile.Buildfile) { - -} diff --git a/plugin/deploy/tsuru.go b/plugin/deploy/tsuru.go deleted file mode 100644 index 2a074b5dd..000000000 --- a/plugin/deploy/tsuru.go +++ /dev/null @@ -1,45 +0,0 @@ -package deploy - -import ( - "fmt" - "github.com/drone/drone/plugin/condition" - "github.com/drone/drone/shared/build/buildfile" -) - -type Tsuru struct { - Force bool `yaml:"force,omitempty"` - Branch string `yaml:"branch,omitempty"` - Remote string `yaml:"remote,omitempty"` - - Condition *condition.Condition `yaml:"when,omitempty"` -} - -func (t *Tsuru) Write(f *buildfile.Buildfile) { - // get the current commit hash - f.WriteCmdSilent("COMMIT=$(git rev-parse HEAD)") - - // set the git user and email based on the individual - // that made the commit. - f.WriteCmdSilent("git config --global user.name $(git --no-pager log -1 --pretty=format:'%an')") - f.WriteCmdSilent("git config --global user.email $(git --no-pager log -1 --pretty=format:'%ae')") - - // add tsuru as a git remote - f.WriteCmd(fmt.Sprintf("git remote add tsuru %s", t.Remote)) - - switch t.Force { - case true: - // this is useful when the there are artifacts generated - // by the build script, such as less files converted to css, - // that need to be deployed to Tsuru. - f.WriteCmd(fmt.Sprintf("git add -A")) - f.WriteCmd(fmt.Sprintf("git commit -m 'adding build artifacts'")) - f.WriteCmd(fmt.Sprintf("git push tsuru HEAD:master --force")) - case false: - // otherwise we just do a standard git push - f.WriteCmd(fmt.Sprintf("git push tsuru $COMMIT:master")) - } -} - -func (t *Tsuru) GetCondition() *condition.Condition { - return t.Condition -} From aac863b896d0d865aa5dbb6e44d25dc5bb4bc627 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 11 Oct 2014 19:20:47 -0700 Subject: [PATCH 06/10] moved modulus deploy to separate package with unit tests --- plugin/deploy/deployment.go | 24 ++++++------ plugin/deploy/heroku/heroku_test.go | 2 +- plugin/deploy/modulus/modulus.go | 36 ++++++++++++++++++ plugin/deploy/modulus/modulus_test.go | 54 +++++++++++++++++++++++++++ plugin/deploy/tsuru/tsuru_test.go | 2 +- 5 files changed, 105 insertions(+), 13 deletions(-) create mode 100644 plugin/deploy/modulus/modulus.go create mode 100644 plugin/deploy/modulus/modulus_test.go diff --git a/plugin/deploy/deployment.go b/plugin/deploy/deployment.go index 635fdfc92..4d0697c4f 100644 --- a/plugin/deploy/deployment.go +++ b/plugin/deploy/deployment.go @@ -2,25 +2,27 @@ package deploy import ( "github.com/drone/drone/plugin/condition" - "github.com/drone/drone/plugin/deploy/git" - "github.com/drone/drone/plugin/deploy/heroku" - "github.com/drone/drone/plugin/deploy/tsuru" "github.com/drone/drone/shared/build/buildfile" "github.com/drone/drone/shared/build/repo" + + "github.com/drone/drone/plugin/deploy/git" + "github.com/drone/drone/plugin/deploy/heroku" + "github.com/drone/drone/plugin/deploy/modulus" + "github.com/drone/drone/plugin/deploy/tsuru" ) // Deploy stores the configuration details // for deploying build artifacts when // a Build has succeeded type Deploy struct { - CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"` - Git *git.Git `yaml:"git,omitempty"` - Heroku *heroku.Heroku `yaml:"heroku,omitempty"` - Modulus *Modulus `yaml:"modulus,omitempty"` - Nodejitsu *Nodejitsu `yaml:"nodejitsu,omitempty"` - SSH *SSH `yaml:"ssh,omitempty"` - Tsuru *tsuru.Tsuru `yaml:"tsuru,omitempty"` - Bash *Bash `yaml:"bash,omitempty"` + CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"` + Git *git.Git `yaml:"git,omitempty"` + Heroku *heroku.Heroku `yaml:"heroku,omitempty"` + Modulus *modulus.Modulus `yaml:"modulus,omitempty"` + Nodejitsu *Nodejitsu `yaml:"nodejitsu,omitempty"` + SSH *SSH `yaml:"ssh,omitempty"` + Tsuru *tsuru.Tsuru `yaml:"tsuru,omitempty"` + Bash *Bash `yaml:"bash,omitempty"` } func (d *Deploy) Write(f *buildfile.Buildfile, r *repo.Repo) { diff --git a/plugin/deploy/heroku/heroku_test.go b/plugin/deploy/heroku/heroku_test.go index 1a7ff70b0..b938f603f 100644 --- a/plugin/deploy/heroku/heroku_test.go +++ b/plugin/deploy/heroku/heroku_test.go @@ -8,7 +8,7 @@ import ( "github.com/franela/goblin" ) -func Test_Git(t *testing.T) { +func Test_Heroku(t *testing.T) { g := goblin.Goblin(t) g.Describe("Heroku Deploy", func() { diff --git a/plugin/deploy/modulus/modulus.go b/plugin/deploy/modulus/modulus.go new file mode 100644 index 000000000..f9f945321 --- /dev/null +++ b/plugin/deploy/modulus/modulus.go @@ -0,0 +1,36 @@ +package modulus + +import ( + "fmt" + "github.com/drone/drone/plugin/condition" + "github.com/drone/drone/shared/build/buildfile" +) + +type Modulus struct { + Project string `yaml:"project,omitempty"` + Token string `yaml:"token,omitempty"` + + Condition *condition.Condition `yaml:"when,omitempty"` +} + +func (m *Modulus) Write(f *buildfile.Buildfile) { + if len(m.Token) == 0 || len(m.Project) == 0 { + return + } + f.WriteEnv("MODULUS_TOKEN", m.Token) + + // Verify npm exists, otherwise we cannot install the + // modulus command line utility. + f.WriteCmdSilent("[ -f /usr/bin/npm ] || echo ERROR: npm is required for moduls deployments") + f.WriteCmdSilent("[ -f /usr/bin/npm ] || exit 1") + + // Install the Modulus command line interface then deploy the configured + // project. + f.WriteCmdSilent("[ -f /usr/bin/sudo ] || npm install -g modulus") + f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo npm install -g modulus") + f.WriteCmd(fmt.Sprintf("modulus deploy -p %q", m.Project)) +} + +func (m *Modulus) GetCondition() *condition.Condition { + return m.Condition +} diff --git a/plugin/deploy/modulus/modulus_test.go b/plugin/deploy/modulus/modulus_test.go new file mode 100644 index 000000000..357bdb828 --- /dev/null +++ b/plugin/deploy/modulus/modulus_test.go @@ -0,0 +1,54 @@ +package modulus + +import ( + //"strings" + "testing" + + "github.com/drone/drone/shared/build/buildfile" + "github.com/franela/goblin" +) + +func Test_Modulus(t *testing.T) { + + g := goblin.Goblin(t) + g.Describe("Modulus Deploy", func() { + + g.It("Requires a Project name", func() { + b := new(buildfile.Buildfile) + m := Modulus{ + Project: "foo", + } + + m.Write(b) + g.Assert(b.String()).Equal("") + }) + + g.It("Requires a Token", func() { + b := new(buildfile.Buildfile) + m := Modulus{ + Token: "bar", + } + + m.Write(b) + g.Assert(b.String()).Equal("") + }) + + g.It("Should execute deploy commands", func() { + b := new(buildfile.Buildfile) + m := Modulus{ + Project: "foo", + Token: "bar", + } + + m.Write(b) + g.Assert(b.String()).Equal(`export MODULUS_TOKEN=bar +[ -f /usr/bin/npm ] || echo ERROR: npm is required for moduls deployments +[ -f /usr/bin/npm ] || exit 1 +[ -f /usr/bin/sudo ] || npm install -g modulus +[ -f /usr/bin/sudo ] && sudo npm install -g modulus +echo '#DRONE:6d6f64756c7573206465706c6f79202d702022666f6f22' +modulus deploy -p "foo" +`) + }) + }) +} diff --git a/plugin/deploy/tsuru/tsuru_test.go b/plugin/deploy/tsuru/tsuru_test.go index c456d7d44..4473e69e3 100644 --- a/plugin/deploy/tsuru/tsuru_test.go +++ b/plugin/deploy/tsuru/tsuru_test.go @@ -8,7 +8,7 @@ import ( "github.com/franela/goblin" ) -func Test_Git(t *testing.T) { +func Test_Tsuru(t *testing.T) { g := goblin.Goblin(t) g.Describe("Tsuru Deploy", func() { From c4838dfaed8d55b8362d28bb289cb58274755f28 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 11 Oct 2014 19:30:19 -0700 Subject: [PATCH 07/10] fixed modulus typos --- plugin/deploy/modulus/modulus.go | 2 +- plugin/deploy/modulus/modulus_test.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/plugin/deploy/modulus/modulus.go b/plugin/deploy/modulus/modulus.go index f9f945321..fa06236ee 100644 --- a/plugin/deploy/modulus/modulus.go +++ b/plugin/deploy/modulus/modulus.go @@ -21,7 +21,7 @@ func (m *Modulus) Write(f *buildfile.Buildfile) { // Verify npm exists, otherwise we cannot install the // modulus command line utility. - f.WriteCmdSilent("[ -f /usr/bin/npm ] || echo ERROR: npm is required for moduls deployments") + f.WriteCmdSilent("[ -f /usr/bin/npm ] || echo ERROR: npm is required for modulus.io deployments") f.WriteCmdSilent("[ -f /usr/bin/npm ] || exit 1") // Install the Modulus command line interface then deploy the configured diff --git a/plugin/deploy/modulus/modulus_test.go b/plugin/deploy/modulus/modulus_test.go index 357bdb828..59c8e6bfd 100644 --- a/plugin/deploy/modulus/modulus_test.go +++ b/plugin/deploy/modulus/modulus_test.go @@ -1,7 +1,6 @@ package modulus import ( - //"strings" "testing" "github.com/drone/drone/shared/build/buildfile" @@ -42,7 +41,7 @@ func Test_Modulus(t *testing.T) { m.Write(b) g.Assert(b.String()).Equal(`export MODULUS_TOKEN=bar -[ -f /usr/bin/npm ] || echo ERROR: npm is required for moduls deployments +[ -f /usr/bin/npm ] || echo ERROR: npm is required for modulus.io deployments [ -f /usr/bin/npm ] || exit 1 [ -f /usr/bin/sudo ] || npm install -g modulus [ -f /usr/bin/sudo ] && sudo npm install -g modulus From 89f8d17b8d4d0d49567f3d55793122ec2234b652 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 11 Oct 2014 19:32:31 -0700 Subject: [PATCH 08/10] moved nodejitsu deploy to its own package with unit tests --- plugin/deploy/deployment.go | 17 ++++---- plugin/deploy/nodejitsu/nodejitsu.go | 32 ++++++++++++++ plugin/deploy/nodejitsu/nodejitsu_test.go | 52 +++++++++++++++++++++++ 3 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 plugin/deploy/nodejitsu/nodejitsu.go create mode 100644 plugin/deploy/nodejitsu/nodejitsu_test.go diff --git a/plugin/deploy/deployment.go b/plugin/deploy/deployment.go index 4d0697c4f..6cb5e960c 100644 --- a/plugin/deploy/deployment.go +++ b/plugin/deploy/deployment.go @@ -8,6 +8,7 @@ import ( "github.com/drone/drone/plugin/deploy/git" "github.com/drone/drone/plugin/deploy/heroku" "github.com/drone/drone/plugin/deploy/modulus" + "github.com/drone/drone/plugin/deploy/nodejitsu" "github.com/drone/drone/plugin/deploy/tsuru" ) @@ -15,14 +16,14 @@ import ( // for deploying build artifacts when // a Build has succeeded type Deploy struct { - CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"` - Git *git.Git `yaml:"git,omitempty"` - Heroku *heroku.Heroku `yaml:"heroku,omitempty"` - Modulus *modulus.Modulus `yaml:"modulus,omitempty"` - Nodejitsu *Nodejitsu `yaml:"nodejitsu,omitempty"` - SSH *SSH `yaml:"ssh,omitempty"` - Tsuru *tsuru.Tsuru `yaml:"tsuru,omitempty"` - Bash *Bash `yaml:"bash,omitempty"` + CloudFoundry *CloudFoundry `yaml:"cloudfoundry,omitempty"` + Git *git.Git `yaml:"git,omitempty"` + Heroku *heroku.Heroku `yaml:"heroku,omitempty"` + Modulus *modulus.Modulus `yaml:"modulus,omitempty"` + Nodejitsu *nodejitsu.Nodejitsu `yaml:"nodejitsu,omitempty"` + SSH *SSH `yaml:"ssh,omitempty"` + Tsuru *tsuru.Tsuru `yaml:"tsuru,omitempty"` + Bash *Bash `yaml:"bash,omitempty"` } func (d *Deploy) Write(f *buildfile.Buildfile, r *repo.Repo) { diff --git a/plugin/deploy/nodejitsu/nodejitsu.go b/plugin/deploy/nodejitsu/nodejitsu.go new file mode 100644 index 000000000..11eb215c7 --- /dev/null +++ b/plugin/deploy/nodejitsu/nodejitsu.go @@ -0,0 +1,32 @@ +package nodejitsu + +import ( + "github.com/drone/drone/plugin/condition" + "github.com/drone/drone/shared/build/buildfile" +) + +type Nodejitsu struct { + User string `yaml:"user,omitempty"` + Token string `yaml:"token,omitempty"` + + Condition *condition.Condition `yaml:"when,omitempty"` +} + +func (n *Nodejitsu) Write(f *buildfile.Buildfile) { + if len(n.Token) == 0 || len(n.User) == 0 { + return + } + + f.WriteEnv("username", n.User) + f.WriteEnv("apiToken", n.Token) + + // Install the jitsu command line interface then + // deploy the configured app. + f.WriteCmdSilent("[ -f /usr/bin/sudo ] || npm install -g jitsu") + f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo npm install -g jitsu") + f.WriteCmd("jitsu deploy") +} + +func (n *Nodejitsu) GetCondition() *condition.Condition { + return n.Condition +} diff --git a/plugin/deploy/nodejitsu/nodejitsu_test.go b/plugin/deploy/nodejitsu/nodejitsu_test.go new file mode 100644 index 000000000..f1424d94b --- /dev/null +++ b/plugin/deploy/nodejitsu/nodejitsu_test.go @@ -0,0 +1,52 @@ +package nodejitsu + +import ( + "testing" + + "github.com/drone/drone/shared/build/buildfile" + "github.com/franela/goblin" +) + +func Test_Modulus(t *testing.T) { + + g := goblin.Goblin(t) + g.Describe("Nodejitsu Deploy", func() { + + g.It("Requires a User", func() { + b := new(buildfile.Buildfile) + n := Nodejitsu{ + User: "foo", + } + + n.Write(b) + g.Assert(b.String()).Equal("") + }) + + g.It("Requires a Token", func() { + b := new(buildfile.Buildfile) + n := Nodejitsu{ + Token: "bar", + } + + n.Write(b) + g.Assert(b.String()).Equal("") + }) + + g.It("Should execute deploy commands", func() { + b := new(buildfile.Buildfile) + n := Nodejitsu{ + User: "foo", + Token: "bar", + } + + n.Write(b) + g.Assert(b.String()).Equal(`export username=foo +export apiToken=bar +[ -f /usr/bin/sudo ] || npm install -g jitsu +[ -f /usr/bin/sudo ] && sudo npm install -g jitsu +echo '#DRONE:6a69747375206465706c6f79' +jitsu deploy +`) + }) + }) +} From ab6b666650bb2050a6359a058a60b626335bbf38 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 11 Oct 2014 19:33:13 -0700 Subject: [PATCH 09/10] removed modulus and jitsu from deployment package --- plugin/deploy/modulus.go | 28 ---------------------------- plugin/deploy/nodejitsu.go | 29 ----------------------------- 2 files changed, 57 deletions(-) delete mode 100644 plugin/deploy/modulus.go delete mode 100644 plugin/deploy/nodejitsu.go diff --git a/plugin/deploy/modulus.go b/plugin/deploy/modulus.go deleted file mode 100644 index be2b6f165..000000000 --- a/plugin/deploy/modulus.go +++ /dev/null @@ -1,28 +0,0 @@ -package deploy - -import ( - "fmt" - "github.com/drone/drone/plugin/condition" - "github.com/drone/drone/shared/build/buildfile" -) - -type Modulus struct { - Project string `yaml:"project,omitempty"` - Token string `yaml:"token,omitempty"` - - Condition *condition.Condition `yaml:"when,omitempty"` -} - -func (m *Modulus) Write(f *buildfile.Buildfile) { - f.WriteEnv("MODULUS_TOKEN", m.Token) - - // Install the Modulus command line interface then deploy the configured - // project. - f.WriteCmdSilent("[ -f /usr/bin/sudo ] || npm install -g modulus") - f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo npm install -g modulus") - f.WriteCmd(fmt.Sprintf("modulus deploy -p '%s'", m.Project)) -} - -func (m *Modulus) GetCondition() *condition.Condition { - return m.Condition -} diff --git a/plugin/deploy/nodejitsu.go b/plugin/deploy/nodejitsu.go deleted file mode 100644 index cf8f5b405..000000000 --- a/plugin/deploy/nodejitsu.go +++ /dev/null @@ -1,29 +0,0 @@ -package deploy - -import ( - "github.com/drone/drone/plugin/condition" - "github.com/drone/drone/shared/build/buildfile" -) - -type Nodejitsu struct { - App string `yaml:"app,omitempty"` - User string `yaml:"user,omitempty"` - Token string `yaml:"token,omitempty"` - - Condition *condition.Condition `yaml:"when,omitempty"` -} - -func (n *Nodejitsu) Write(f *buildfile.Buildfile) { - f.WriteEnv("username", n.User) - f.WriteEnv("apiToken", n.Token) - - // Install the jitsu command line interface then - // deploy the configured app. - f.WriteCmdSilent("[ -f /usr/bin/sudo ] || npm install -g jitsu") - f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo npm install -g jitsu") - f.WriteCmd("jitsu deploy") -} - -func (n *Nodejitsu) GetCondition() *condition.Condition { - return n.Condition -} From cd1fbe5d853c14e002dfd4563e9c0323636338bf Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 11 Oct 2014 20:33:06 -0700 Subject: [PATCH 10/10] ability to customize the session secret and expiration --- README.md | 4 ++ debian/drone/etc/drone/drone.toml | 8 ++-- plugin/deploy/cloudfoundry/cloudfoundry.go | 51 ++++++++++++++++++++++ server/session/session.go | 15 +++++-- 4 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 plugin/deploy/cloudfoundry/cloudfoundry.go diff --git a/README.md b/README.md index 94c56d328..e2696ca03 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,10 @@ port="" key="" cert="" +[session] +secret="" +duration="" + [database] driver="" datasource="" diff --git a/debian/drone/etc/drone/drone.toml b/debian/drone/etc/drone/drone.toml index f7ab89a31..06d17a9e7 100644 --- a/debian/drone/etc/drone/drone.toml +++ b/debian/drone/etc/drone/drone.toml @@ -3,16 +3,18 @@ port=":80" ##################################################################### -# SSL configuration for Drone. Provide you key and cert chain -# to server Drone over https. +# SSL configuration # # [server.ssl] # key="" # cert="" +# [session] +# secret="" +# duration="" ##################################################################### -# Database configuration for Drone, by default using SQLite3. +# Database configuration, by default using SQLite3. # You can also use postgres and mysql. See the documentation # for more details. diff --git a/plugin/deploy/cloudfoundry/cloudfoundry.go b/plugin/deploy/cloudfoundry/cloudfoundry.go new file mode 100644 index 000000000..73e5e0405 --- /dev/null +++ b/plugin/deploy/cloudfoundry/cloudfoundry.go @@ -0,0 +1,51 @@ +package cloudfoundry + +import ( + "fmt" + "github.com/drone/drone/plugin/condition" + "github.com/drone/drone/shared/build/buildfile" +) + +type CloudFoundry struct { + Target string `yaml:"target,omitempty"` + Username string `yaml:"username,omitempty"` + Password string `yaml:"password,omitempty"` + Org string `yaml:"org,omitempty"` + Space string `yaml:"space,omitempty"` + + App string `yaml:"app,omitempty"` + + Condition *condition.Condition `yaml:"when,omitempty"` +} + +func (cf *CloudFoundry) Write(f *buildfile.Buildfile) { + downloadCmd := "curl -sLO http://go-cli.s3-website-us-east-1.amazonaws.com/releases/latest/cf-cli_amd64.deb" + installCmd := "dpkg -i cf-cli_amd64.deb 1> /dev/null 2> /dev/null" + + // download and install the cf tool + f.WriteCmdSilent(fmt.Sprintf("[ -f /usr/bin/sudo ] && sudo %s || %s", downloadCmd, downloadCmd)) + f.WriteCmdSilent(fmt.Sprintf("[ -f /usr/bin/sudo ] && sudo %s || %s", installCmd, installCmd)) + + // login + loginCmd := "cf login -a %s -u %s -p %s" + + organization := cf.Org + if organization != "" { + loginCmd += fmt.Sprintf(" -o %s", organization) + } + + space := cf.Space + if space != "" { + loginCmd += fmt.Sprintf(" -s %s", space) + } + + f.WriteCmdSilent(fmt.Sprintf(loginCmd, cf.Target, cf.Username, cf.Password)) + + // push app + pushCmd := "cf push %s" + f.WriteCmd(fmt.Sprintf(pushCmd, cf.App)) +} + +func (cf *CloudFoundry) GetCondition() *condition.Condition { + return cf.Condition +} diff --git a/server/session/session.go b/server/session/session.go index 924b0d69c..9330ab0da 100644 --- a/server/session/session.go +++ b/server/session/session.go @@ -7,14 +7,21 @@ import ( "code.google.com/p/go.net/context" "github.com/dgrijalva/jwt-go" + "github.com/drone/config" "github.com/drone/drone/server/datastore" "github.com/drone/drone/shared/httputil" "github.com/drone/drone/shared/model" "github.com/gorilla/securecookie" ) -// secret key used to create jwt -var secret = securecookie.GenerateRandomKey(32) +// random key used to create jwt if none +// provided in the configuration. +var random = securecookie.GenerateRandomKey(32) + +var ( + secret = config.String("session-secret", string(random)) + expires = config.Duration("session-expires", time.Hour*72) +) // GetUser gets the currently authenticated user for the // http.Request. The user details will be stored as either @@ -38,7 +45,7 @@ func GenerateToken(c context.Context, r *http.Request, user *model.User) (string token.Claims["user_id"] = user.ID token.Claims["audience"] = httputil.GetURL(r) token.Claims["expires"] = time.Now().UTC().Add(time.Hour * 72).Unix() - return token.SignedString(secret) + return token.SignedString([]byte(*secret)) } // getUserToken gets the currently authenticated user for the given @@ -56,7 +63,7 @@ func getUserBearer(c context.Context, r *http.Request) *model.User { fmt.Sscanf(tokenstr, "Bearer %s", &tokenstr) var token, err = jwt.Parse(tokenstr, func(t *jwt.Token) (interface{}, error) { - return secret, nil + return []byte(*secret), nil }) if err != nil || !token.Valid { println("invalid token")