From 5b1748aafd4cdd32a8d8f65e0c7614ceb00bf150 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Mon, 23 May 2016 18:47:44 -0700 Subject: [PATCH] ability to provide secret to agent and generate token --- drone/agent/agent.go | 19 +++++++++++++++++-- drone/server.go | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/drone/agent/agent.go b/drone/agent/agent.go index 64dda603..f8d0d213 100644 --- a/drone/agent/agent.go +++ b/drone/agent/agent.go @@ -5,6 +5,7 @@ import ( "time" "github.com/drone/drone/client" + "github.com/drone/drone/shared/token" "github.com/samalba/dockerclient" "github.com/Sirupsen/logrus" @@ -69,6 +70,11 @@ var AgentCmd = cli.Command{ Name: "drone-token", Usage: "drone authorization token", }, + cli.StringFlag{ + EnvVar: "DRONE_SECRET,DRONE_AGENT_SECRET", + Name: "drone-secret", + Usage: "drone agent secret", + }, cli.DurationFlag{ EnvVar: "DRONE_BACKOFF", Name: "backoff", @@ -133,14 +139,23 @@ func start(c *cli.Context) { } else { logrus.SetLevel(logrus.WarnLevel) } + + var accessToken string + if c.String("drone-secret") != "" { + secretToken := c.String("drone-secret") + accessToken, _ = token.New(token.AgentToken, "").Sign(secretToken) + } else { + accessToken = c.String("drone-token") + } + logrus.Infof("Connecting to %s with token %s", c.String("drone-server"), - c.String("drone-token"), + accessToken, ) client := client.NewClientToken( c.String("drone-server"), - c.String("drone-token"), + accessToken, ) tls, err := dockerclient.TLSConfigFromCertPath(c.String("docker-cert-path")) diff --git a/drone/server.go b/drone/server.go index d7027f42..3ff2bab0 100644 --- a/drone/server.go +++ b/drone/server.go @@ -72,7 +72,7 @@ var serverCmd = cli.Command{ Value: time.Minute * 15, }, cli.StringFlag{ - EnvVar: "DRONE_AGENT_SECRET", + EnvVar: "DRONE_AGENT_SECRET,DRONE_SECRET", Name: "agent-secret", Usage: "agent secret passcode", },